mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
use modify over getting a mutable reference
This commit is contained in:
parent
8a361bb68a
commit
4489a308e4
4 changed files with 27 additions and 27 deletions
|
@ -391,14 +391,14 @@ fn deep_copy_type_vars<'a>(
|
||||||
// in one go (without looking at the UnificationTable) and clear the copy field
|
// in one go (without looking at the UnificationTable) and clear the copy field
|
||||||
let mut result = Vec::with_capacity_in(copied.len(), arena);
|
let mut result = Vec::with_capacity_in(copied.len(), arena);
|
||||||
for var in copied {
|
for var in copied {
|
||||||
let descriptor = subs.get_ref_mut(var);
|
subs.modify(var, |descriptor| {
|
||||||
|
|
||||||
if let Some(copy) = descriptor.copy.into_variable() {
|
if let Some(copy) = descriptor.copy.into_variable() {
|
||||||
result.push((var, copy));
|
result.push((var, copy));
|
||||||
descriptor.copy = OptVariable::NONE;
|
descriptor.copy = OptVariable::NONE;
|
||||||
} else {
|
} else {
|
||||||
debug_assert!(false, "{:?} marked as copied but it wasn't", var);
|
debug_assert!(false, "{:?} marked as copied but it wasn't", var);
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert!(result.contains(&(var, cloned_var)));
|
debug_assert!(result.contains(&(var, cloned_var)));
|
||||||
|
|
|
@ -124,7 +124,7 @@ impl FunctionLayout {
|
||||||
subs: &Subs,
|
subs: &Subs,
|
||||||
var: Variable,
|
var: Variable,
|
||||||
) -> Result<Self, LayoutError> {
|
) -> Result<Self, LayoutError> {
|
||||||
let content = &subs.get_ref(var).content;
|
let content = &subs.get_content_without_compacting(var);
|
||||||
Self::from_content(layouts, subs, var, content)
|
Self::from_content(layouts, subs, var, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ impl LambdaSet {
|
||||||
subs: &Subs,
|
subs: &Subs,
|
||||||
var: Variable,
|
var: Variable,
|
||||||
) -> Result<Self, LayoutError> {
|
) -> Result<Self, LayoutError> {
|
||||||
let content = &subs.get_ref(var).content;
|
let content = &subs.get_content_without_compacting(var);
|
||||||
Self::from_content(layouts, subs, var, content)
|
Self::from_content(layouts, subs, var, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,7 +598,7 @@ impl Layout {
|
||||||
subs: &Subs,
|
subs: &Subs,
|
||||||
var: Variable,
|
var: Variable,
|
||||||
) -> Result<Layout, LayoutError> {
|
) -> Result<Layout, LayoutError> {
|
||||||
let content = &subs.get_ref(var).content;
|
let content = &subs.get_content_without_compacting(var);
|
||||||
Self::from_content(layouts, subs, var, content)
|
Self::from_content(layouts, subs, var, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -612,7 +612,7 @@ impl Layout {
|
||||||
subs: &Subs,
|
subs: &Subs,
|
||||||
var: Variable,
|
var: Variable,
|
||||||
) -> Result<Layout, LayoutError> {
|
) -> Result<Layout, LayoutError> {
|
||||||
let content = &subs.get_ref(var).content;
|
let content = &subs.get_content_without_compacting(var);
|
||||||
|
|
||||||
match content {
|
match content {
|
||||||
Content::FlexVar(_) | Content::RigidVar(_) => Ok(Layout::VOID),
|
Content::FlexVar(_) | Content::RigidVar(_) => Ok(Layout::VOID),
|
||||||
|
|
|
@ -2999,13 +2999,13 @@ fn instantiate_rigids_help(subs: &mut Subs, max_rank: Rank, initial: Variable) {
|
||||||
// we have tracked all visited variables, and can now traverse them
|
// we have tracked all visited variables, and can now traverse them
|
||||||
// in one go (without looking at the UnificationTable) and clear the copy field
|
// in one go (without looking at the UnificationTable) and clear the copy field
|
||||||
for var in visited {
|
for var in visited {
|
||||||
let descriptor = subs.get_ref_mut(var);
|
subs.modify(var, |descriptor| {
|
||||||
|
|
||||||
if descriptor.copy.is_some() {
|
if descriptor.copy.is_some() {
|
||||||
descriptor.rank = Rank::NONE;
|
descriptor.rank = Rank::NONE;
|
||||||
descriptor.mark = Mark::NONE;
|
descriptor.mark = Mark::NONE;
|
||||||
descriptor.copy = OptVariable::NONE;
|
descriptor.copy = OptVariable::NONE;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3023,13 +3023,13 @@ fn deep_copy_var_in(
|
||||||
// we have tracked all visited variables, and can now traverse them
|
// we have tracked all visited variables, and can now traverse them
|
||||||
// in one go (without looking at the UnificationTable) and clear the copy field
|
// in one go (without looking at the UnificationTable) and clear the copy field
|
||||||
for var in visited {
|
for var in visited {
|
||||||
let descriptor = subs.get_ref_mut(var);
|
subs.modify(var, |descriptor| {
|
||||||
|
|
||||||
if descriptor.copy.is_some() {
|
if descriptor.copy.is_some() {
|
||||||
descriptor.rank = Rank::NONE;
|
descriptor.rank = Rank::NONE;
|
||||||
descriptor.mark = Mark::NONE;
|
descriptor.mark = Mark::NONE;
|
||||||
descriptor.copy = OptVariable::NONE;
|
descriptor.copy = OptVariable::NONE;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
copy
|
copy
|
||||||
|
|
|
@ -1784,7 +1784,7 @@ impl Subs {
|
||||||
|
|
||||||
pub fn modify<F>(&mut self, key: Variable, mapper: F)
|
pub fn modify<F>(&mut self, key: Variable, mapper: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut Descriptor),
|
F: FnOnce(&mut Descriptor),
|
||||||
{
|
{
|
||||||
mapper(self.get_ref_mut(key));
|
mapper(self.get_ref_mut(key));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue