mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Make var_contains_content
a loop
This commit is contained in:
parent
53be0e2674
commit
b281ea8c2c
1 changed files with 57 additions and 65 deletions
|
@ -3483,8 +3483,17 @@ fn var_contains_content_help<P>(
|
|||
where
|
||||
P: Fn(&Content) -> bool + Copy,
|
||||
{
|
||||
let mut stack = vec![var];
|
||||
|
||||
macro_rules! push_var_slice {
|
||||
($slice:expr) => {
|
||||
stack.extend(subs.get_subs_slice($slice))
|
||||
};
|
||||
}
|
||||
|
||||
while let Some(var) = stack.pop() {
|
||||
if seen_recursion_vars.contains(&var) {
|
||||
return false;
|
||||
continue;
|
||||
}
|
||||
|
||||
let content = subs.get_content_without_compacting(var);
|
||||
|
@ -3493,67 +3502,50 @@ where
|
|||
return true;
|
||||
}
|
||||
|
||||
macro_rules! check_var {
|
||||
($v:expr) => {
|
||||
var_contains_content_help(subs, $v, predicate, seen_recursion_vars)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! check_var_slice {
|
||||
($slice:expr) => {
|
||||
subs.get_subs_slice($slice)
|
||||
.into_iter()
|
||||
.any(|v| check_var!(*v))
|
||||
};
|
||||
}
|
||||
|
||||
use Content::*;
|
||||
use FlatType::*;
|
||||
match content {
|
||||
FlexVar(_) => false,
|
||||
RigidVar(_) => false,
|
||||
FlexVar(_) | RigidVar(_) => {}
|
||||
RecursionVar {
|
||||
structure,
|
||||
opt_name: _,
|
||||
} => {
|
||||
seen_recursion_vars.insert(var);
|
||||
var_contains_content_help(subs, *structure, predicate, seen_recursion_vars)
|
||||
stack.push(*structure);
|
||||
}
|
||||
Structure(flat_type) => match flat_type {
|
||||
Apply(_, vars) => check_var_slice!(*vars),
|
||||
Apply(_, vars) => push_var_slice!(*vars),
|
||||
Func(args, clos, ret) => {
|
||||
check_var_slice!(*args) || check_var!(*clos) || check_var!(*ret)
|
||||
push_var_slice!(*args);
|
||||
stack.push(*clos);
|
||||
stack.push(*ret);
|
||||
}
|
||||
Record(fields, var) => {
|
||||
push_var_slice!(fields.variables());
|
||||
stack.push(*var);
|
||||
}
|
||||
Record(fields, var) => check_var_slice!(fields.variables()) || check_var!(*var),
|
||||
TagUnion(tags, ext_var) => {
|
||||
for i in tags.variables() {
|
||||
if check_var_slice!(subs[i]) {
|
||||
return true;
|
||||
push_var_slice!(subs[i]);
|
||||
}
|
||||
stack.push(*ext_var);
|
||||
}
|
||||
if check_var!(*ext_var) {
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
FunctionOrTagUnion(_, _, var) => check_var!(*var),
|
||||
FunctionOrTagUnion(_, _, var) => stack.push(*var),
|
||||
RecursiveTagUnion(rec_var, tags, ext_var) => {
|
||||
seen_recursion_vars.insert(*rec_var);
|
||||
for i in tags.variables() {
|
||||
if check_var_slice!(subs[i]) {
|
||||
return true;
|
||||
push_var_slice!(subs[i]);
|
||||
}
|
||||
stack.push(*ext_var);
|
||||
}
|
||||
Erroneous(_) | EmptyRecord | EmptyTagUnion => {}
|
||||
},
|
||||
Alias(_, arguments, real_type_var) => {
|
||||
push_var_slice!(arguments.variables());
|
||||
stack.push(*real_type_var);
|
||||
}
|
||||
Error => {}
|
||||
}
|
||||
if check_var!(*ext_var) {
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
Erroneous(_) | EmptyRecord | EmptyTagUnion => false,
|
||||
},
|
||||
Alias(_, arguments, real_type_var) => {
|
||||
check_var_slice!(arguments.variables()) || check_var!(*real_type_var)
|
||||
}
|
||||
Error => false,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue