mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-24 06:55:15 +00:00
feedback
This commit is contained in:
parent
93ea086115
commit
f0addf5300
1 changed files with 14 additions and 35 deletions
|
@ -4939,7 +4939,7 @@ pub fn with_hole<'a>(
|
|||
Err(_) => return runtime_error(env, "Can't update record with improper layout"),
|
||||
};
|
||||
|
||||
let single_struct_field = sorted_fields.len() == 1;
|
||||
let single_field_struct = sorted_fields.len() == 1;
|
||||
|
||||
// The struct indexing generated by the current context
|
||||
let mut current_struct_indexing = Vec::with_capacity_in(sorted_fields.len(), env.arena);
|
||||
|
@ -4962,7 +4962,7 @@ pub fn with_hole<'a>(
|
|||
|
||||
// The struct with a single field is optimized in such a way that replacing later indexing will cause an incorrect IR.
|
||||
// Thus, only insert these struct_indices if there is more than one field in the struct.
|
||||
if !single_struct_field {
|
||||
if !single_field_struct {
|
||||
let original_struct_symbol = env.unique_symbol();
|
||||
env.struct_indexing
|
||||
.insert(record_index, original_struct_symbol);
|
||||
|
@ -4999,7 +4999,7 @@ pub fn with_hole<'a>(
|
|||
_ => arena.alloc([record_layout]),
|
||||
};
|
||||
|
||||
if single_struct_field {
|
||||
if single_field_struct {
|
||||
// TODO we can probably special-case this more, skipping the generation of
|
||||
// UpdateExisting
|
||||
let mut stmt = hole.clone();
|
||||
|
@ -5032,9 +5032,7 @@ pub fn with_hole<'a>(
|
|||
let expr = Expr::Struct(new_struct_symbols);
|
||||
let mut stmt = Stmt::Let(assigned, expr, record_layout, hole);
|
||||
|
||||
let it = new_struct_symbols.iter().zip(fields);
|
||||
|
||||
for (new_struct_symbol, what_to_do) in it {
|
||||
for (new_struct_symbol, what_to_do) in new_struct_symbols.iter().zip(fields) {
|
||||
match what_to_do {
|
||||
UpdateExisting(field) => {
|
||||
stmt = assign_to_symbol(
|
||||
|
@ -5047,7 +5045,10 @@ pub fn with_hole<'a>(
|
|||
stmt,
|
||||
);
|
||||
}
|
||||
CopyExisting => {}
|
||||
CopyExisting => {
|
||||
// When a field is copied, the indexing symbol is already placed in new_struct_symbols
|
||||
// Thus, we don't need additional logic here.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7673,19 +7674,10 @@ fn can_reuse_symbol<'a>(
|
|||
Err(_) => unreachable!("Can't access record with improper layout"),
|
||||
};
|
||||
|
||||
let index =
|
||||
sorted_fields
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.find_map(
|
||||
|(current, (label, _, _))| {
|
||||
if label == *field {
|
||||
Some(current)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
);
|
||||
let index = sorted_fields
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.find_map(|(current, (label, _, _))| (label == *field).then_some(current));
|
||||
|
||||
let struct_index = index.expect("field not in its own type");
|
||||
|
||||
|
@ -10069,24 +10061,11 @@ enum Usage {
|
|||
Unused,
|
||||
}
|
||||
|
||||
pub struct UsageTrackingMap<K, V>
|
||||
where
|
||||
K: std::cmp::Eq + std::hash::Hash,
|
||||
{
|
||||
#[derive(Default)]
|
||||
pub struct UsageTrackingMap<K, V> {
|
||||
map: MutMap<K, (V, Usage)>,
|
||||
}
|
||||
|
||||
impl<K, V> Default for UsageTrackingMap<K, V>
|
||||
where
|
||||
K: std::cmp::Eq + std::hash::Hash,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
map: MutMap::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> UsageTrackingMap<K, V>
|
||||
where
|
||||
K: std::cmp::Eq + std::hash::Hash,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue