Skip to content

Commit

Permalink
Store less information for destruction scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Aug 13, 2021
1 parent 85afbb0 commit a404da8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
11 changes: 4 additions & 7 deletions compiler/rustc_middle/src/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ pub struct ScopeTree {
var_map: FxHashMap<hir::ItemLocalId, Scope>,

/// Maps from a `NodeId` to the associated destruction scope (if any).
destruction_scopes: FxHashMap<(hir::ItemLocalId, bool), Scope>,
destruction_scopes: FxHashMap<hir::ItemLocalId, Scope>,

/// `rvalue_scopes` includes entries for those expressions whose
/// cleanup scope is larger than the default. The map goes from the
Expand Down Expand Up @@ -341,15 +341,12 @@ impl ScopeTree {

// Record the destruction scopes for later so we can query them.
if let ScopeData::Destruction = child.data {
assert_eq!(
self.destruction_scopes.insert((child.item_local_id(), child.for_stmt), child),
None
);
assert_eq!(self.destruction_scopes.insert(child.item_local_id(), child), None);
}
}

pub fn opt_destruction_scope(&self, n: hir::ItemLocalId, for_stmt: bool) -> Option<Scope> {
self.destruction_scopes.get(&(n, for_stmt)).cloned()
pub fn opt_destruction_scope(&self, n: hir::ItemLocalId) -> Option<Scope> {
self.destruction_scopes.get(&n).cloned()
}

pub fn record_var_scope(&mut self, var: hir::ItemLocalId, lifetime: Scope) {
Expand Down
13 changes: 8 additions & 5 deletions compiler/rustc_mir_build/src/thir/cx/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl<'tcx> Cx<'tcx> {
// in order to get the lexical scoping correctly.
let stmts = self.mirror_stmts(block.hir_id.local_id, block.stmts);
let opt_destruction_scope =
self.region_scope_tree.opt_destruction_scope(block.hir_id.local_id, false);
self.region_scope_tree.opt_destruction_scope(block.hir_id.local_id);
Block {
targeted_by_break: block.targeted_by_break,
region_scope: region::Scope {
Expand Down Expand Up @@ -47,8 +47,11 @@ impl<'tcx> Cx<'tcx> {
.enumerate()
.filter_map(|(index, stmt)| {
let hir_id = stmt.kind.hir_id();
let opt_dxn_ext =
self.region_scope_tree.opt_destruction_scope(hir_id.local_id, true);
let dxn_scope = region::Scope {
id: hir_id.local_id,
data: region::ScopeData::Destruction,
for_stmt: true,
};
match stmt.kind {
hir::StmtKind::Expr(ref expr) | hir::StmtKind::Semi(ref expr) => {
let stmt = Stmt {
Expand All @@ -60,7 +63,7 @@ impl<'tcx> Cx<'tcx> {
},
expr: self.mirror_expr(expr),
},
opt_destruction_scope: opt_dxn_ext,
opt_destruction_scope: Some(dxn_scope),
};
Some(self.thir.stmts.push(stmt))
}
Expand Down Expand Up @@ -111,7 +114,7 @@ impl<'tcx> Cx<'tcx> {
initializer: local.init.map(|init| self.mirror_expr(init)),
lint_level: LintLevel::Explicit(local.hir_id),
},
opt_destruction_scope: opt_dxn_ext,
opt_destruction_scope: Some(dxn_scope),
};
Some(self.thir.stmts.push(stmt))
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'tcx> Cx<'tcx> {

// Finally, create a destruction scope, if any.
if let Some(region_scope) =
self.region_scope_tree.opt_destruction_scope(hir_expr.hir_id.local_id, false)
self.region_scope_tree.opt_destruction_scope(hir_expr.hir_id.local_id)
{
expr = Expr {
temp_lifetime,
Expand Down

0 comments on commit a404da8

Please sign in to comment.