Sanity check the Expr visitation count
This commit is contained in:
parent
3a511e06a5
commit
dba2ca888a
2 changed files with 20 additions and 0 deletions
|
|
@ -252,6 +252,11 @@ pub struct ScopeTree {
|
|||
/// stores the `Span` of the last one and the number of expressions
|
||||
/// which came before it in a generator body.
|
||||
yield_in_scope: FxHashMap<Scope, (Span, usize)>,
|
||||
|
||||
/// The number of visit_expr calls done in the body.
|
||||
/// Used to sanity check visit_expr call count when
|
||||
/// calculating geneartor interiors.
|
||||
body_expr_count: FxHashMap<hir::BodyId, usize>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
|
|
@ -619,6 +624,13 @@ impl<'tcx> ScopeTree {
|
|||
pub fn yield_in_scope(&self, scope: Scope) -> Option<(Span, usize)> {
|
||||
self.yield_in_scope.get(&scope).cloned()
|
||||
}
|
||||
|
||||
/// Gives the number of expressions visited in a body.
|
||||
/// Used to sanity check visit_expr call count when
|
||||
/// calculating geneartor interiors.
|
||||
pub fn body_expr_count(&self, body_id: hir::BodyId) -> Option<usize> {
|
||||
self.body_expr_count.get(&body_id).map(|r| *r)
|
||||
}
|
||||
}
|
||||
|
||||
/// Records the lifetime of a local variable as `cx.var_parent`
|
||||
|
|
@ -1166,6 +1178,10 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionResolutionVisitor<'a, 'tcx> {
|
|||
resolve_local(self, None, Some(&body.value));
|
||||
}
|
||||
|
||||
if body.is_generator {
|
||||
self.scope_tree.body_expr_count.insert(body_id, self.expr_count);
|
||||
}
|
||||
|
||||
// Restore context we had at the start.
|
||||
self.expr_count = outer_ec;
|
||||
self.cx = outer_cx;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue