Skip EndRegion emission by default. Use -Z emit-end-regions to reenable it.
The main intent is to fix cases where EndRegion emission is believed to be causing excess peak memory pressure. It may also be a welcome change to people inspecting the MIR output who find the EndRegions to be a distraction.
This commit is contained in:
parent
2f1ef9ef11
commit
f1c721caa7
4 changed files with 25 additions and 16 deletions
|
|
@ -919,6 +919,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
|
|||
"when debug-printing compiler state, do not include spans"), // o/w tests have closure@path
|
||||
identify_regions: bool = (false, parse_bool, [UNTRACKED],
|
||||
"make unnamed regions display as '# (where # is some non-ident unique id)"),
|
||||
emit_end_regions: bool = (false, parse_bool, [UNTRACKED],
|
||||
"emit EndRegion as part of MIR; enable transforms that solely process EndRegion"),
|
||||
borrowck_mir: bool = (false, parse_bool, [UNTRACKED],
|
||||
"implicitly treat functions as if they have `#[rustc_mir_borrowck]` attribute"),
|
||||
time_passes: bool = (false, parse_bool, [UNTRACKED],
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
use build::CFG;
|
||||
use rustc::middle::region;
|
||||
use rustc::mir::*;
|
||||
use rustc::ty;
|
||||
|
||||
impl<'tcx> CFG<'tcx> {
|
||||
pub fn block_data(&self, blk: BasicBlock) -> &BasicBlockData<'tcx> {
|
||||
|
|
@ -44,14 +45,17 @@ impl<'tcx> CFG<'tcx> {
|
|||
self.block_data_mut(block).statements.push(statement);
|
||||
}
|
||||
|
||||
pub fn push_end_region(&mut self,
|
||||
block: BasicBlock,
|
||||
source_info: SourceInfo,
|
||||
region_scope: region::Scope) {
|
||||
self.push(block, Statement {
|
||||
source_info,
|
||||
kind: StatementKind::EndRegion(region_scope),
|
||||
});
|
||||
pub fn push_end_region<'a, 'gcx:'a+'tcx>(&mut self,
|
||||
tcx: ty::TyCtxt<'a, 'gcx, 'tcx>,
|
||||
block: BasicBlock,
|
||||
source_info: SourceInfo,
|
||||
region_scope: region::Scope) {
|
||||
if tcx.sess.opts.debugging_opts.emit_end_regions {
|
||||
self.push(block, Statement {
|
||||
source_info,
|
||||
kind: StatementKind::EndRegion(region_scope),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push_assign(&mut self,
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ should go to.
|
|||
|
||||
use build::{BlockAnd, BlockAndExtension, Builder, CFG};
|
||||
use rustc::middle::region;
|
||||
use rustc::ty::Ty;
|
||||
use rustc::ty::{Ty, TyCtxt};
|
||||
use rustc::mir::*;
|
||||
use rustc::mir::transform::MirSource;
|
||||
use syntax_pos::{Span};
|
||||
|
|
@ -359,7 +359,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
self.arg_count,
|
||||
false));
|
||||
|
||||
self.cfg.push_end_region(block, region_scope.1, scope.region_scope);
|
||||
self.cfg.push_end_region(self.hir.tcx(), block, region_scope.1, scope.region_scope);
|
||||
block.unit()
|
||||
}
|
||||
|
||||
|
|
@ -414,7 +414,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
false));
|
||||
|
||||
// End all regions for scopes out of which we are breaking.
|
||||
self.cfg.push_end_region(block, region_scope.1, scope.region_scope);
|
||||
self.cfg.push_end_region(self.hir.tcx(), block, region_scope.1, scope.region_scope);
|
||||
}
|
||||
}
|
||||
let scope = &self.scopes[len - scope_count];
|
||||
|
|
@ -463,7 +463,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
true));
|
||||
|
||||
// End all regions for scopes out of which we are breaking.
|
||||
self.cfg.push_end_region(block, src_info, scope.region_scope);
|
||||
self.cfg.push_end_region(self.hir.tcx(), block, src_info, scope.region_scope);
|
||||
}
|
||||
|
||||
self.cfg.terminate(block, src_info, TerminatorKind::GeneratorDrop);
|
||||
|
|
@ -694,7 +694,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
};
|
||||
|
||||
for scope in scopes.iter_mut() {
|
||||
target = build_diverge_scope(cfg, scope.region_scope_span,
|
||||
target = build_diverge_scope(self.hir.tcx(), cfg, scope.region_scope_span,
|
||||
scope, target, generator_drop);
|
||||
}
|
||||
Some(target)
|
||||
|
|
@ -831,7 +831,8 @@ fn build_scope_drops<'tcx>(cfg: &mut CFG<'tcx>,
|
|||
block.unit()
|
||||
}
|
||||
|
||||
fn build_diverge_scope<'a, 'gcx, 'tcx>(cfg: &mut CFG<'tcx>,
|
||||
fn build_diverge_scope<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
cfg: &mut CFG<'tcx>,
|
||||
span: Span,
|
||||
scope: &mut Scope<'tcx>,
|
||||
mut target: BasicBlock,
|
||||
|
|
@ -893,7 +894,7 @@ fn build_diverge_scope<'a, 'gcx, 'tcx>(cfg: &mut CFG<'tcx>,
|
|||
// becomes trivial goto after pass that removes all EndRegions.)
|
||||
{
|
||||
let block = cfg.start_new_cleanup_block();
|
||||
cfg.push_end_region(block, source_info(span), scope.region_scope);
|
||||
cfg.push_end_region(tcx, block, source_info(span), scope.region_scope);
|
||||
cfg.terminate(block, source_info(span), TerminatorKind::Goto { target: target });
|
||||
target = block
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,9 +39,11 @@ struct DeleteTrivialEndRegions<'a> {
|
|||
|
||||
impl MirPass for CleanEndRegions {
|
||||
fn run_pass<'a, 'tcx>(&self,
|
||||
_tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
_source: MirSource,
|
||||
mir: &mut Mir<'tcx>) {
|
||||
if !tcx.sess.opts.debugging_opts.emit_end_regions { return; }
|
||||
|
||||
let mut gather = GatherBorrowedRegions {
|
||||
seen_regions: FxHashSet()
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue