some work on expect comment regions

This commit is contained in:
Folkert 2022-07-19 00:32:04 +02:00 committed by Richard Feldman
parent 7597d11b59
commit 5a93da5a11
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798
3 changed files with 20 additions and 4 deletions

View file

@ -1367,10 +1367,17 @@ pub(crate) fn sort_can_defs_new(
// 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) {
let it = expects
.conditions
.into_iter()
.zip(expects.regions)
.zip(expects.preceding_comment);
for ((condition, region), preceding_comment) in it {
// 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.push_expect(preceding_comment, name, Loc::at(region, condition));
}
for (symbol, alias) in aliases.into_iter() {

View file

@ -2190,12 +2190,17 @@ impl Declarations {
index
}
pub fn push_expect(&mut self, name: Symbol, loc_expr: Loc<Expr>) -> usize {
pub fn push_expect(
&mut self,
preceding_comment: Region,
name: Symbol,
loc_expr: Loc<Expr>,
) -> usize {
let index = self.declarations.len();
self.declarations.push(DeclarationTag::Expectation);
self.variables.push(Variable::BOOL);
self.symbols.push(Loc::at_zero(name));
self.symbols.push(Loc::at(preceding_comment, name));
self.annotations.push(None);
self.expressions.push(loc_expr);

View file

@ -5014,6 +5014,10 @@ fn build_pending_specializations<'a>(
is_self_recursive: false,
};
// TODO use the region of the preceding comment (stored as the Symbol's regino)
// let name_region = declarations.symbols[index].region;
// let expr_region = declarations.expressions[index].region;
// let region = Region::span_across(&name_region, &expr_region);
let region = declarations.expressions[index].region;
toplevel_expects.insert(symbol, region);