mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
fix todos regarding InvalidCycle
This commit is contained in:
parent
39b70232de
commit
744b8ce32b
3 changed files with 38 additions and 30 deletions
|
@ -872,38 +872,35 @@ pub fn constrain_decls(
|
||||||
) -> Constraint {
|
) -> Constraint {
|
||||||
let mut constraint = Constraint::SaveTheEnvironment;
|
let mut constraint = Constraint::SaveTheEnvironment;
|
||||||
|
|
||||||
|
let mut env = Env {
|
||||||
|
home,
|
||||||
|
rigids: ImMap::default(),
|
||||||
|
};
|
||||||
|
|
||||||
for decl in decls.iter().rev() {
|
for decl in decls.iter().rev() {
|
||||||
// NOTE: rigids are empty because they are not shared between top-level definitions
|
// Clear the rigids from the previous iteration.
|
||||||
|
// rigids are not shared between top-level definitions
|
||||||
|
env.rigids.clear();
|
||||||
|
|
||||||
match decl {
|
match decl {
|
||||||
Declaration::Declare(def) => {
|
Declaration::Declare(def) => {
|
||||||
constraint = exists_with_aliases(
|
constraint = exists_with_aliases(
|
||||||
aliases.clone(),
|
aliases.clone(),
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
constrain_def(
|
constrain_def(&env, def, constraint),
|
||||||
&Env {
|
|
||||||
home,
|
|
||||||
rigids: ImMap::default(),
|
|
||||||
},
|
|
||||||
def,
|
|
||||||
constraint,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Declaration::DeclareRec(defs) => {
|
Declaration::DeclareRec(defs) => {
|
||||||
constraint = exists_with_aliases(
|
constraint = exists_with_aliases(
|
||||||
aliases.clone(),
|
aliases.clone(),
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
constrain_recursive_defs(
|
constrain_recursive_defs(&env, defs, constraint),
|
||||||
&Env {
|
|
||||||
home,
|
|
||||||
rigids: ImMap::default(),
|
|
||||||
},
|
|
||||||
defs,
|
|
||||||
constraint,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Declaration::InvalidCycle(_, _) => panic!("TODO handle invalid cycle"),
|
Declaration::InvalidCycle(_, _) => {
|
||||||
|
// invalid cycles give a canonicalization error. we skip them here.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,24 +78,33 @@ pub fn constrain_decls(
|
||||||
sharing::annotate_usage(&def.loc_expr.value, &mut var_usage);
|
sharing::annotate_usage(&def.loc_expr.value, &mut var_usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Declaration::InvalidCycle(_, _) => panic!("TODO handle invalid cycle"),
|
Declaration::InvalidCycle(_, _) => {
|
||||||
|
// any usage of a value defined in an invalid cycle will blow up
|
||||||
|
// so for the analysis usage by such values doesn't count
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
aliases_to_attr_type(var_store, &mut aliases);
|
aliases_to_attr_type(var_store, &mut aliases);
|
||||||
|
|
||||||
|
let mut env = Env {
|
||||||
|
home,
|
||||||
|
rigids: ImMap::default(),
|
||||||
|
};
|
||||||
|
|
||||||
for decl in decls.iter().rev() {
|
for decl in decls.iter().rev() {
|
||||||
// NOTE: rigids are empty because they are not shared between top-level definitions
|
// clear the set of rigids from the previous iteration.
|
||||||
|
// rigids are not shared between top-level definitions.
|
||||||
|
env.rigids.clear();
|
||||||
|
|
||||||
match decl {
|
match decl {
|
||||||
Declaration::Declare(def) => {
|
Declaration::Declare(def) => {
|
||||||
constraint = exists_with_aliases(
|
constraint = exists_with_aliases(
|
||||||
aliases.clone(),
|
aliases.clone(),
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
constrain_def(
|
constrain_def(
|
||||||
&Env {
|
&env,
|
||||||
home,
|
|
||||||
rigids: ImMap::default(),
|
|
||||||
},
|
|
||||||
var_store,
|
var_store,
|
||||||
&var_usage,
|
&var_usage,
|
||||||
&mut ImSet::default(),
|
&mut ImSet::default(),
|
||||||
|
@ -109,10 +118,7 @@ pub fn constrain_decls(
|
||||||
aliases.clone(),
|
aliases.clone(),
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
constrain_recursive_defs(
|
constrain_recursive_defs(
|
||||||
&Env {
|
&env,
|
||||||
home,
|
|
||||||
rigids: ImMap::default(),
|
|
||||||
},
|
|
||||||
var_store,
|
var_store,
|
||||||
&var_usage,
|
&var_usage,
|
||||||
&mut ImSet::default(),
|
&mut ImSet::default(),
|
||||||
|
@ -121,7 +127,10 @@ pub fn constrain_decls(
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Declaration::InvalidCycle(_, _) => panic!("TODO handle invalid cycle"),
|
Declaration::InvalidCycle(_, _) => {
|
||||||
|
// invalid cycles give a canonicalization error. we skip them here.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1702,6 +1702,7 @@ mod test_reporting {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn circular_definition_self() {
|
fn circular_definition_self() {
|
||||||
|
// invalid recursion
|
||||||
report_problem_as(
|
report_problem_as(
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
|
@ -1723,6 +1724,7 @@ mod test_reporting {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn circular_definition() {
|
fn circular_definition() {
|
||||||
|
// invalid mutual recursion
|
||||||
report_problem_as(
|
report_problem_as(
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
|
@ -2413,7 +2415,7 @@ mod test_reporting {
|
||||||
report_problem_as(
|
report_problem_as(
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
Foo : { x: Bar }
|
Foo : { x : Bar }
|
||||||
Bar : { y : Foo }
|
Bar : { y : Foo }
|
||||||
|
|
||||||
f : Foo
|
f : Foo
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue