use set_content_unchecked; replace modify with a single set

This commit is contained in:
Folkert 2022-05-21 14:06:43 +02:00
parent f1e1c45f2f
commit 8c44661bc2
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 16 additions and 21 deletions

View file

@ -3028,13 +3028,7 @@ 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 {
subs.modify(var, |descriptor| { subs.set_copy_unchecked(var, OptVariable::NONE);
if descriptor.copy.is_some() {
descriptor.rank = Rank::NONE;
descriptor.mark = Mark::NONE;
descriptor.copy = OptVariable::NONE;
}
});
} }
copy copy
@ -3198,7 +3192,7 @@ fn deep_copy_var_help(
} }
}; };
subs.set(copy, make_descriptor(Structure(new_flat_type))); subs.set_content_unchecked(copy, Structure(new_flat_type));
copy copy
} }
@ -3211,25 +3205,24 @@ fn deep_copy_var_help(
} => { } => {
let new_structure = deep_copy_var_help(subs, max_rank, pools, visited, structure); let new_structure = deep_copy_var_help(subs, max_rank, pools, visited, structure);
subs.set( let content = RecursionVar {
copy, opt_name,
make_descriptor(RecursionVar { structure: new_structure,
opt_name, };
structure: new_structure,
}), subs.set_content_unchecked(copy, content);
);
copy copy
} }
RigidVar(name) => { RigidVar(name) => {
subs.set(copy, make_descriptor(FlexVar(Some(name)))); subs.set_content_unchecked(copy, FlexVar(Some(name)));
copy copy
} }
RigidAbleVar(name, ability) => { RigidAbleVar(name, ability) => {
subs.set(copy, make_descriptor(FlexAbleVar(Some(name), ability))); subs.set_content_unchecked(copy, FlexAbleVar(Some(name), ability));
copy copy
} }
@ -3247,7 +3240,7 @@ fn deep_copy_var_help(
deep_copy_var_help(subs, max_rank, pools, visited, real_type_var); deep_copy_var_help(subs, max_rank, pools, visited, real_type_var);
let new_content = Alias(symbol, new_arguments, new_real_type_var, kind); let new_content = Alias(symbol, new_arguments, new_real_type_var, kind);
subs.set(copy, make_descriptor(new_content)); subs.set_content_unchecked(copy, new_content);
copy copy
} }
@ -3259,7 +3252,7 @@ fn deep_copy_var_help(
let new_content = RangedNumber(new_type_var, new_variables); let new_content = RangedNumber(new_type_var, new_variables);
subs.set(copy, make_descriptor(new_content)); subs.set_content_unchecked(copy, new_content);
copy copy
} }

View file

@ -1720,11 +1720,13 @@ impl Subs {
} }
pub fn set_content(&mut self, key: Variable, content: Content) { pub fn set_content(&mut self, key: Variable, content: Content) {
// let l_key = self.utable.inlined_get_root_key(key);
self.utable.set_content(key, content); self.utable.set_content(key, content);
} }
pub fn set_content_unchecked(&mut self, key: Variable, content: Content) {
self.utable.set_content_unchecked(key, content);
}
pub fn modify<F, T>(&mut self, key: Variable, mapper: F) -> T pub fn modify<F, T>(&mut self, key: Variable, mapper: F) -> T
where where
F: FnOnce(&mut Descriptor) -> T, F: FnOnce(&mut Descriptor) -> T,