Auto merge of #116170 - matthewjasper:remove-thir-destruction-scopes, r=cjgillot
Don't include destruction scopes in THIR They are not used by anyone, and add memory/performance overhead.
This commit is contained in:
commit
1dfb2283d7
11 changed files with 235 additions and 468 deletions
|
@ -13,32 +13,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
ast_block: BlockId,
|
||||
source_info: SourceInfo,
|
||||
) -> BlockAnd<()> {
|
||||
let Block {
|
||||
region_scope,
|
||||
opt_destruction_scope,
|
||||
span,
|
||||
ref stmts,
|
||||
expr,
|
||||
targeted_by_break,
|
||||
safety_mode,
|
||||
} = self.thir[ast_block];
|
||||
let Block { region_scope, span, ref stmts, expr, targeted_by_break, safety_mode } =
|
||||
self.thir[ast_block];
|
||||
let expr = expr.map(|expr| &self.thir[expr]);
|
||||
self.in_opt_scope(opt_destruction_scope.map(|de| (de, source_info)), move |this| {
|
||||
this.in_scope((region_scope, source_info), LintLevel::Inherited, move |this| {
|
||||
if targeted_by_break {
|
||||
this.in_breakable_scope(None, destination, span, |this| {
|
||||
Some(this.ast_block_stmts(
|
||||
destination,
|
||||
block,
|
||||
span,
|
||||
stmts,
|
||||
expr,
|
||||
safety_mode,
|
||||
region_scope,
|
||||
))
|
||||
})
|
||||
} else {
|
||||
this.ast_block_stmts(
|
||||
self.in_scope((region_scope, source_info), LintLevel::Inherited, move |this| {
|
||||
if targeted_by_break {
|
||||
this.in_breakable_scope(None, destination, span, |this| {
|
||||
Some(this.ast_block_stmts(
|
||||
destination,
|
||||
block,
|
||||
span,
|
||||
|
@ -46,9 +27,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
expr,
|
||||
safety_mode,
|
||||
region_scope,
|
||||
)
|
||||
}
|
||||
})
|
||||
))
|
||||
})
|
||||
} else {
|
||||
this.ast_block_stmts(
|
||||
destination,
|
||||
block,
|
||||
span,
|
||||
stmts,
|
||||
expr,
|
||||
safety_mode,
|
||||
region_scope,
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -92,20 +83,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
|
||||
let source_info = this.source_info(span);
|
||||
for stmt in stmts {
|
||||
let Stmt { ref kind, opt_destruction_scope } = this.thir[*stmt];
|
||||
let Stmt { ref kind } = this.thir[*stmt];
|
||||
match kind {
|
||||
StmtKind::Expr { scope, expr } => {
|
||||
this.block_context.push(BlockFrame::Statement { ignores_expr_result: true });
|
||||
let si = (*scope, source_info);
|
||||
unpack!(
|
||||
block = this.in_opt_scope(
|
||||
opt_destruction_scope.map(|de| (de, source_info)),
|
||||
|this| {
|
||||
let si = (*scope, source_info);
|
||||
this.in_scope(si, LintLevel::Inherited, |this| {
|
||||
this.stmt_expr(block, &this.thir[*expr], Some(*scope))
|
||||
})
|
||||
}
|
||||
)
|
||||
block = this.in_scope(si, LintLevel::Inherited, |this| {
|
||||
this.stmt_expr(block, &this.thir[*expr], Some(*scope))
|
||||
})
|
||||
);
|
||||
}
|
||||
StmtKind::Let {
|
||||
|
@ -221,43 +207,38 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
|
||||
let init = &this.thir[*initializer];
|
||||
let initializer_span = init.span;
|
||||
let scope = (*init_scope, source_info);
|
||||
let failure = unpack!(
|
||||
block = this.in_opt_scope(
|
||||
opt_destruction_scope.map(|de| (de, source_info)),
|
||||
|this| {
|
||||
let scope = (*init_scope, source_info);
|
||||
this.in_scope(scope, *lint_level, |this| {
|
||||
this.declare_bindings(
|
||||
visibility_scope,
|
||||
remainder_span,
|
||||
pattern,
|
||||
None,
|
||||
Some((Some(&destination), initializer_span)),
|
||||
);
|
||||
this.visit_primary_bindings(
|
||||
pattern,
|
||||
UserTypeProjections::none(),
|
||||
&mut |this, _, _, _, node, span, _, _| {
|
||||
this.storage_live_binding(
|
||||
block,
|
||||
node,
|
||||
span,
|
||||
OutsideGuard,
|
||||
true,
|
||||
);
|
||||
},
|
||||
);
|
||||
this.ast_let_else(
|
||||
block = this.in_scope(scope, *lint_level, |this| {
|
||||
this.declare_bindings(
|
||||
visibility_scope,
|
||||
remainder_span,
|
||||
pattern,
|
||||
None,
|
||||
Some((Some(&destination), initializer_span)),
|
||||
);
|
||||
this.visit_primary_bindings(
|
||||
pattern,
|
||||
UserTypeProjections::none(),
|
||||
&mut |this, _, _, _, node, span, _, _| {
|
||||
this.storage_live_binding(
|
||||
block,
|
||||
init,
|
||||
initializer_span,
|
||||
*else_block,
|
||||
&last_remainder_scope,
|
||||
pattern,
|
||||
)
|
||||
})
|
||||
}
|
||||
)
|
||||
node,
|
||||
span,
|
||||
OutsideGuard,
|
||||
true,
|
||||
);
|
||||
},
|
||||
);
|
||||
this.ast_let_else(
|
||||
block,
|
||||
init,
|
||||
initializer_span,
|
||||
*else_block,
|
||||
&last_remainder_scope,
|
||||
pattern,
|
||||
)
|
||||
})
|
||||
);
|
||||
this.cfg.goto(failure, source_info, failure_entry);
|
||||
|
||||
|
@ -298,25 +279,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
if let Some(init) = initializer {
|
||||
let init = &this.thir[*init];
|
||||
let initializer_span = init.span;
|
||||
let scope = (*init_scope, source_info);
|
||||
|
||||
unpack!(
|
||||
block = this.in_opt_scope(
|
||||
opt_destruction_scope.map(|de| (de, source_info)),
|
||||
|this| {
|
||||
let scope = (*init_scope, source_info);
|
||||
this.in_scope(scope, *lint_level, |this| {
|
||||
this.declare_bindings(
|
||||
visibility_scope,
|
||||
remainder_span,
|
||||
pattern,
|
||||
None,
|
||||
Some((None, initializer_span)),
|
||||
);
|
||||
this.expr_into_pattern(block, pattern, init)
|
||||
// irrefutable pattern
|
||||
})
|
||||
},
|
||||
)
|
||||
block = this.in_scope(scope, *lint_level, |this| {
|
||||
this.declare_bindings(
|
||||
visibility_scope,
|
||||
remainder_span,
|
||||
pattern,
|
||||
None,
|
||||
Some((None, initializer_span)),
|
||||
);
|
||||
this.expr_into_pattern(block, &pattern, init)
|
||||
// irrefutable pattern
|
||||
})
|
||||
)
|
||||
} else {
|
||||
let scope = (*init_scope, source_info);
|
||||
|
|
|
@ -536,27 +536,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
(then_block, else_block)
|
||||
}
|
||||
|
||||
pub(crate) fn in_opt_scope<F, R>(
|
||||
&mut self,
|
||||
opt_scope: Option<(region::Scope, SourceInfo)>,
|
||||
f: F,
|
||||
) -> BlockAnd<R>
|
||||
where
|
||||
F: FnOnce(&mut Builder<'a, 'tcx>) -> BlockAnd<R>,
|
||||
{
|
||||
debug!("in_opt_scope(opt_scope={:?})", opt_scope);
|
||||
if let Some(region_scope) = opt_scope {
|
||||
self.push_scope(region_scope);
|
||||
}
|
||||
let mut block;
|
||||
let rv = unpack!(block = f(self));
|
||||
if let Some(region_scope) = opt_scope {
|
||||
unpack!(block = self.pop_scope(region_scope, block));
|
||||
}
|
||||
debug!("in_scope: exiting opt_scope={:?} block={:?}", opt_scope, block);
|
||||
block.and(rv)
|
||||
}
|
||||
|
||||
/// Convenience wrapper that pushes a scope and then executes `f`
|
||||
/// to build its contents, popping the scope afterwards.
|
||||
#[instrument(skip(self, f), level = "debug")]
|
||||
|
|
|
@ -13,15 +13,12 @@ impl<'tcx> Cx<'tcx> {
|
|||
// We have to eagerly lower the "spine" of the statements
|
||||
// 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);
|
||||
let block = Block {
|
||||
targeted_by_break: block.targeted_by_break,
|
||||
region_scope: region::Scope {
|
||||
id: block.hir_id.local_id,
|
||||
data: region::ScopeData::Node,
|
||||
},
|
||||
opt_destruction_scope,
|
||||
span: block.span,
|
||||
stmts,
|
||||
expr: block.expr.map(|expr| self.mirror_expr(expr)),
|
||||
|
@ -49,7 +46,6 @@ impl<'tcx> Cx<'tcx> {
|
|||
.enumerate()
|
||||
.filter_map(|(index, stmt)| {
|
||||
let hir_id = stmt.hir_id;
|
||||
let opt_dxn_ext = self.region_scope_tree.opt_destruction_scope(hir_id.local_id);
|
||||
match stmt.kind {
|
||||
hir::StmtKind::Expr(expr) | hir::StmtKind::Semi(expr) => {
|
||||
let stmt = Stmt {
|
||||
|
@ -60,7 +56,6 @@ impl<'tcx> Cx<'tcx> {
|
|||
},
|
||||
expr: self.mirror_expr(expr),
|
||||
},
|
||||
opt_destruction_scope: opt_dxn_ext,
|
||||
};
|
||||
Some(self.thir.stmts.push(stmt))
|
||||
}
|
||||
|
@ -122,7 +117,6 @@ impl<'tcx> Cx<'tcx> {
|
|||
lint_level: LintLevel::Explicit(local.hir_id),
|
||||
span,
|
||||
},
|
||||
opt_destruction_scope: opt_dxn_ext,
|
||||
};
|
||||
Some(self.thir.stmts.push(stmt))
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
|
||||
trace!(?expr.ty, "after adjustments");
|
||||
|
||||
// Next, wrap this up in the expr's scope.
|
||||
// Finally, wrap this up in the expr's scope.
|
||||
expr = Expr {
|
||||
temp_lifetime: expr.temp_lifetime,
|
||||
ty: expr.ty,
|
||||
|
@ -66,22 +66,6 @@ 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)
|
||||
{
|
||||
expr = Expr {
|
||||
temp_lifetime: expr.temp_lifetime,
|
||||
ty: expr.ty,
|
||||
span: hir_expr.span,
|
||||
kind: ExprKind::Scope {
|
||||
region_scope,
|
||||
value: self.thir.exprs.push(expr),
|
||||
lint_level: LintLevel::Inherited,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// OK, all done!
|
||||
self.thir.exprs.push(expr)
|
||||
}
|
||||
|
|
|
@ -91,23 +91,11 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn print_block(&mut self, block_id: BlockId, depth_lvl: usize) {
|
||||
let Block {
|
||||
targeted_by_break,
|
||||
opt_destruction_scope,
|
||||
span,
|
||||
region_scope,
|
||||
stmts,
|
||||
expr,
|
||||
safety_mode,
|
||||
} = &self.thir.blocks[block_id];
|
||||
let Block { targeted_by_break, span, region_scope, stmts, expr, safety_mode } =
|
||||
&self.thir.blocks[block_id];
|
||||
|
||||
print_indented!(self, "Block {", depth_lvl);
|
||||
print_indented!(self, format!("targeted_by_break: {}", targeted_by_break), depth_lvl + 1);
|
||||
print_indented!(
|
||||
self,
|
||||
format!("opt_destruction_scope: {:?}", opt_destruction_scope),
|
||||
depth_lvl + 1
|
||||
);
|
||||
print_indented!(self, format!("span: {:?}", span), depth_lvl + 1);
|
||||
print_indented!(self, format!("region_scope: {:?}", region_scope), depth_lvl + 1);
|
||||
print_indented!(self, format!("safety_mode: {:?}", safety_mode), depth_lvl + 1);
|
||||
|
@ -133,14 +121,9 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn print_stmt(&mut self, stmt_id: StmtId, depth_lvl: usize) {
|
||||
let Stmt { kind, opt_destruction_scope } = &self.thir.stmts[stmt_id];
|
||||
let Stmt { kind } = &self.thir.stmts[stmt_id];
|
||||
|
||||
print_indented!(self, "Stmt {", depth_lvl);
|
||||
print_indented!(
|
||||
self,
|
||||
format!("opt_destruction_scope: {:?}", opt_destruction_scope),
|
||||
depth_lvl + 1
|
||||
);
|
||||
|
||||
match kind {
|
||||
StmtKind::Expr { scope, expr } => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue