Order by index + clippy

This commit is contained in:
J.Teeuwissen 2023-05-27 14:52:25 +02:00
parent 378a298b45
commit 16da790fac
No known key found for this signature in database
GPG key ID: DB5F7A1ED8D478AD
3 changed files with 19 additions and 14 deletions

View file

@ -5783,7 +5783,7 @@ fn make_specializations<'a>(
abilities: AbilitiesView::World(&world_abilities),
exposed_by_module,
derived_module: &derived_module,
struct_indexing: UsageTrackingMap::new(),
struct_indexing: UsageTrackingMap::default(),
};
let mut procs = Procs::new_in(arena);
@ -5884,7 +5884,7 @@ fn build_pending_specializations<'a>(
abilities: AbilitiesView::Module(&abilities_store),
exposed_by_module,
derived_module: &derived_module,
struct_indexing: UsageTrackingMap::new(),
struct_indexing: UsageTrackingMap::default(),
};
let layout_cache_snapshot = layout_cache.snapshot();
@ -6366,7 +6366,7 @@ fn load_derived_partial_procs<'a>(
abilities: AbilitiesView::World(world_abilities),
exposed_by_module,
derived_module,
struct_indexing: UsageTrackingMap::new(),
struct_indexing: UsageTrackingMap::default(),
};
let partial_proc = match derived_expr {

View file

@ -13,7 +13,7 @@ use roc_can::abilities::SpecializationId;
use roc_can::expr::{AnnotatedMark, ClosureData, ExpectLookup};
use roc_can::module::ExposedByModule;
use roc_collections::all::{default_hasher, BumpMap, BumpMapDefault, MutMap};
use roc_collections::{MutSet, VecMap};
use roc_collections::VecMap;
use roc_debug_flags::dbg_do;
#[cfg(debug_assertions)]
use roc_debug_flags::{
@ -4941,7 +4941,7 @@ pub fn with_hole<'a>(
};
// The struct indexing generated by the current context
let mut current_struct_indexing = MutSet::default();
let mut current_struct_indexing = Vec::with_capacity_in(sorted_fields.len(), env.arena);
// The symbols that are used to create the new struct
let mut new_struct_symbols = Vec::with_capacity_in(sorted_fields.len(), env.arena);
// Information about the fields that are being updated
@ -4952,15 +4952,15 @@ pub fn with_hole<'a>(
match opt_field_layout {
Err(_) => {
debug_assert!(!updates.contains_key(&label));
debug_assert!(!updates.contains_key(label));
// this was an optional field, and now does not exist!
// do not increment `index`!
}
Ok(_field_layout) => {
current_struct_indexing.insert(record_index);
current_struct_indexing.push(record_index);
let original_struct_symbol = env.unique_symbol();
if let Some(field) = updates.get(&label) {
if let Some(field) = updates.get(label) {
// TODO this should probably used around here.
// let field_symbol = possible_reuse_symbol_or_specialize(
// env,
@ -5064,8 +5064,8 @@ pub fn with_hole<'a>(
structure
};
for record_index in current_struct_indexing.iter() {
let (symbol, usage) = env.struct_indexing.pop(record_index).unwrap();
for record_index in current_struct_indexing.into_iter().rev() {
let (symbol, usage) = env.struct_indexing.pop(&record_index).unwrap();
match usage {
Usage::Used => {
let layout = field_layouts[record_index.1 as usize];
@ -10080,16 +10080,21 @@ where
map: MutMap<K, (V, Usage)>,
}
impl<K, V> UsageTrackingMap<K, V>
impl<K, V> Default for UsageTrackingMap<K, V>
where
K: std::cmp::Eq + std::hash::Hash,
{
pub fn new() -> Self {
fn default() -> Self {
Self {
map: MutMap::default(),
}
}
}
impl<K, V> UsageTrackingMap<K, V>
where
K: std::cmp::Eq + std::hash::Hash,
{
pub fn insert(&mut self, key: K, value: V) {
self.map.insert(key, (value, Usage::Unused));
}

View file

@ -26,9 +26,9 @@ procedure Num.22 (#Attr.2, #Attr.3):
ret Num.281;
procedure Test.1 (Test.2):
let Test.10 : List U64 = StructAtIndex 2 Test.2;
let Test.8 : List U64 = StructAtIndex 1 Test.2;
let Test.6 : List U64 = StructAtIndex 0 Test.2;
let Test.8 : List U64 = StructAtIndex 1 Test.2;
let Test.10 : List U64 = StructAtIndex 2 Test.2;
let Test.13 : U64 = 8i64;
let Test.14 : U64 = 8i64;
let Test.9 : List U64 = CallByName List.3 Test.8 Test.13 Test.14;