constrain expects in the right order

This commit is contained in:
Folkert 2022-07-18 21:38:24 +02:00 committed by Richard Feldman
parent c2206f3e4d
commit b6f1fd6f40
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798

View file

@ -1357,8 +1357,22 @@ pub(crate) fn sort_can_defs_new(
// TODO: inefficient, but I want to make this what CanDefs contains in the future // TODO: inefficient, but I want to make this what CanDefs contains in the future
let mut defs: Vec<_> = defs.into_iter().map(|x| x.unwrap()).collect(); let mut defs: Vec<_> = defs.into_iter().map(|x| x.unwrap()).collect();
// symbols are put in declarations in dependency order, from "main" up, so
//
// x = 3
// y = x + 1
//
// will get ordering [ y, x ]
let mut declarations = Declarations::with_capacity(defs.len()); let mut declarations = Declarations::with_capacity(defs.len());
// because of the ordering of declarations, expects should come first because they are
// independent, but can rely on all other top-level symbols in the module
for (condition, region) in expects.conditions.into_iter().zip(expects.regions) {
// an `expect` does not have a user-defined name, but we'll need a name to call the expectation
let name = scope.gen_unique_symbol();
declarations.push_expect(name, Loc::at(region, condition));
}
for (symbol, alias) in aliases.into_iter() { for (symbol, alias) in aliases.into_iter() {
output.aliases.insert(symbol, alias); output.aliases.insert(symbol, alias);
} }
@ -1523,12 +1537,6 @@ pub(crate) fn sort_can_defs_new(
} }
} }
for (condition, region) in expects.conditions.into_iter().zip(expects.regions) {
// an `expect` does not have a user-defined name, but we'll need a name to call the expectation
let name = scope.gen_unique_symbol();
declarations.push_expect(name, Loc::at(region, condition));
}
(declarations, output) (declarations, output)
} }