mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +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"),
|
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
|
// The struct indexing generated by the current context
|
||||||
let mut current_struct_indexing = Vec::with_capacity_in(sorted_fields.len(), env.arena);
|
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.
|
// 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.
|
// 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();
|
let original_struct_symbol = env.unique_symbol();
|
||||||
env.struct_indexing
|
env.struct_indexing
|
||||||
.insert(record_index, original_struct_symbol);
|
.insert(record_index, original_struct_symbol);
|
||||||
|
@ -4999,7 +4999,7 @@ pub fn with_hole<'a>(
|
||||||
_ => arena.alloc([record_layout]),
|
_ => arena.alloc([record_layout]),
|
||||||
};
|
};
|
||||||
|
|
||||||
if single_struct_field {
|
if single_field_struct {
|
||||||
// TODO we can probably special-case this more, skipping the generation of
|
// TODO we can probably special-case this more, skipping the generation of
|
||||||
// UpdateExisting
|
// UpdateExisting
|
||||||
let mut stmt = hole.clone();
|
let mut stmt = hole.clone();
|
||||||
|
@ -5032,9 +5032,7 @@ pub fn with_hole<'a>(
|
||||||
let expr = Expr::Struct(new_struct_symbols);
|
let expr = Expr::Struct(new_struct_symbols);
|
||||||
let mut stmt = Stmt::Let(assigned, expr, record_layout, hole);
|
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 new_struct_symbols.iter().zip(fields) {
|
||||||
|
|
||||||
for (new_struct_symbol, what_to_do) in it {
|
|
||||||
match what_to_do {
|
match what_to_do {
|
||||||
UpdateExisting(field) => {
|
UpdateExisting(field) => {
|
||||||
stmt = assign_to_symbol(
|
stmt = assign_to_symbol(
|
||||||
|
@ -5047,7 +5045,10 @@ pub fn with_hole<'a>(
|
||||||
stmt,
|
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"),
|
Err(_) => unreachable!("Can't access record with improper layout"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let index =
|
let index = sorted_fields
|
||||||
sorted_fields
|
.into_iter()
|
||||||
.into_iter()
|
.enumerate()
|
||||||
.enumerate()
|
.find_map(|(current, (label, _, _))| (label == *field).then_some(current));
|
||||||
.find_map(
|
|
||||||
|(current, (label, _, _))| {
|
|
||||||
if label == *field {
|
|
||||||
Some(current)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
let struct_index = index.expect("field not in its own type");
|
let struct_index = index.expect("field not in its own type");
|
||||||
|
|
||||||
|
@ -10069,24 +10061,11 @@ enum Usage {
|
||||||
Unused,
|
Unused,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UsageTrackingMap<K, V>
|
#[derive(Default)]
|
||||||
where
|
pub struct UsageTrackingMap<K, V> {
|
||||||
K: std::cmp::Eq + std::hash::Hash,
|
|
||||||
{
|
|
||||||
map: MutMap<K, (V, Usage)>,
|
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>
|
impl<K, V> UsageTrackingMap<K, V>
|
||||||
where
|
where
|
||||||
K: std::cmp::Eq + std::hash::Hash,
|
K: std::cmp::Eq + std::hash::Hash,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue