Correct order of cached occurs check

This commit is contained in:
Ayaz Hafiz 2023-04-07 20:19:58 -05:00
parent a816f8bc83
commit e6be13052b
No known key found for this signature in database
GPG Key ID: 0E2A37416A25EF58

View File

@ -3503,9 +3503,8 @@ fn occurs(
} else if subs.get_mark_unchecked(root_var) == Mark::VISITED_IN_OCCURS_CHECK { } else if subs.get_mark_unchecked(root_var) == Mark::VISITED_IN_OCCURS_CHECK {
Ok(()) Ok(())
} else { } else {
ctx.all_visited.push(root_var);
subs.set_mark_unchecked(root_var, Mark::VISITED_IN_OCCURS_CHECK);
ctx.seen.push(root_var); ctx.seen.push(root_var);
ctx.all_visited.push(root_var);
let result = (|| match subs.get_content_without_compacting(root_var) { let result = (|| match subs.get_content_without_compacting(root_var) {
FlexVar(_) FlexVar(_)
| RigidVar(_) | RigidVar(_)
@ -3584,6 +3583,12 @@ fn occurs(
} }
RangedNumber(_range_vars) => Ok(()), RangedNumber(_range_vars) => Ok(()),
})(); })();
// Cache the variable's property of having no cycle, but only if it indeed has no cycle.
if result.is_ok() {
subs.set_mark_unchecked(root_var, Mark::VISITED_IN_OCCURS_CHECK);
}
ctx.seen.pop(); ctx.seen.pop();
result result
} }