Skip to content

Commit

Permalink
perf(check): Remove some branches in the occurs check¨
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Aug 31, 2019
1 parent 78967bd commit 03e7c3b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions check/src/substitution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,26 @@ where
var: u32,
subs: &'a Substitution<T>,
}
impl<'a, 't, T> Walker<'t, T> for Occurs<'a, T>
impl<'t, T> Walker<'t, T> for Occurs<'t, T>
where
T: Substitutable,
{
fn walk(&mut self, typ: &'t T) {
if !typ.contains_variables() || self.occurs {
fn walk(&mut self, mut typ: &'t T) {
if !typ.contains_variables() {
return;
}
let typ = self.subs.real(typ);
if let Some(other) = typ.get_var() {
if self.var.get_id() == other.get_id() {
self.occurs = true;
typ.traverse(self);
return;
let other_id = other.get_id();
if let Some(real_type) = self.subs.find_type_for_var(other_id) {
typ = real_type;
} else {
if self.var.get_id() == other_id {
self.occurs = true;
typ.traverse(self);
return;
}
self.subs.update_level(self.var, other.get_id());
}
self.subs.update_level(self.var, other.get_id());
}
typ.traverse(self);
}
Expand Down

0 comments on commit 03e7c3b

Please sign in to comment.