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

@ -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));
}