Skip to content

Commit 051601e

Browse files
committed
Add -Z skip-end-regions as way to side-step EndRegion emission.
The main intent is to investigate cases where EndRegion emission is believed to be causing excess peak memory pressure. It may also be of use to people inspecting the MIR output who find the EndRegions to be a distraction. ---- (commit is now updated to thread the tcx down instead of consulting thread-local storage for it.)
1 parent 890c87b commit 051601e

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

Diff for: src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
918918
"when debug-printing compiler state, do not include spans"), // o/w tests have closure@path
919919
identify_regions: bool = (false, parse_bool, [UNTRACKED],
920920
"make unnamed regions display as '# (where # is some non-ident unique id)"),
921+
skip_end_regions: bool = (false, parse_bool, [UNTRACKED],
922+
"skip EndRegion emission in MIR, skip transforms that solely process EndRegion"),
921923
borrowck_mir: bool = (false, parse_bool, [UNTRACKED],
922924
"implicitly treat functions as if they have `#[rustc_mir_borrowck]` attribute"),
923925
time_passes: bool = (false, parse_bool, [UNTRACKED],

Diff for: src/librustc_mir/build/cfg.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use build::CFG;
1717
use rustc::middle::region::CodeExtent;
1818
use rustc::mir::*;
19+
use rustc::ty;
1920

2021
impl<'tcx> CFG<'tcx> {
2122
pub fn block_data(&self, blk: BasicBlock) -> &BasicBlockData<'tcx> {
@@ -44,14 +45,17 @@ impl<'tcx> CFG<'tcx> {
4445
self.block_data_mut(block).statements.push(statement);
4546
}
4647

47-
pub fn push_end_region(&mut self,
48-
block: BasicBlock,
49-
source_info: SourceInfo,
50-
extent: CodeExtent) {
51-
self.push(block, Statement {
52-
source_info,
53-
kind: StatementKind::EndRegion(extent),
54-
});
48+
pub fn push_end_region<'a, 'gcx:'a+'tcx>(&mut self,
49+
tcx: ty::TyCtxt<'a, 'gcx, 'tcx>,
50+
block: BasicBlock,
51+
source_info: SourceInfo,
52+
extent: CodeExtent) {
53+
if !tcx.sess.opts.debugging_opts.skip_end_regions {
54+
self.push(block, Statement {
55+
source_info,
56+
kind: StatementKind::EndRegion(extent),
57+
});
58+
}
5559
}
5660

5761
pub fn push_assign(&mut self,

Diff for: src/librustc_mir/build/scope.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ should go to.
8989

9090
use build::{BlockAnd, BlockAndExtension, Builder, CFG};
9191
use rustc::middle::region::CodeExtent;
92-
use rustc::ty::Ty;
92+
use rustc::ty::{Ty, TyCtxt};
9393
use rustc::mir::*;
9494
use rustc::mir::transform::MirSource;
9595
use syntax_pos::{Span};
@@ -359,7 +359,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
359359
self.arg_count,
360360
false));
361361

362-
self.cfg.push_end_region(block, extent.1, scope.extent);
362+
self.cfg.push_end_region(self.hir.tcx(), block, extent.1, scope.extent);
363363
block.unit()
364364
}
365365

@@ -412,7 +412,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
412412
false));
413413

414414
// End all regions for scopes out of which we are breaking.
415-
self.cfg.push_end_region(block, extent.1, scope.extent);
415+
self.cfg.push_end_region(self.hir.tcx(), block, extent.1, scope.extent);
416416
}
417417
}
418418
let scope = &self.scopes[len - scope_count];
@@ -461,7 +461,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
461461
true));
462462

463463
// End all regions for scopes out of which we are breaking.
464-
self.cfg.push_end_region(block, src_info, scope.extent);
464+
self.cfg.push_end_region(self.hir.tcx(), block, src_info, scope.extent);
465465
}
466466

467467
self.cfg.terminate(block, src_info, TerminatorKind::GeneratorDrop);
@@ -692,7 +692,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
692692
};
693693

694694
for scope in scopes.iter_mut() {
695-
target = build_diverge_scope(cfg, scope.extent_span, scope, target, generator_drop);
695+
target = build_diverge_scope(
696+
self.hir.tcx(), cfg, scope.extent_span, scope, target, generator_drop);
696697
}
697698
Some(target)
698699
}
@@ -828,7 +829,8 @@ fn build_scope_drops<'tcx>(cfg: &mut CFG<'tcx>,
828829
block.unit()
829830
}
830831

831-
fn build_diverge_scope<'a, 'gcx, 'tcx>(cfg: &mut CFG<'tcx>,
832+
fn build_diverge_scope<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
833+
cfg: &mut CFG<'tcx>,
832834
span: Span,
833835
scope: &mut Scope<'tcx>,
834836
mut target: BasicBlock,
@@ -890,7 +892,7 @@ fn build_diverge_scope<'a, 'gcx, 'tcx>(cfg: &mut CFG<'tcx>,
890892
// becomes trivial goto after pass that removes all EndRegions.)
891893
{
892894
let block = cfg.start_new_cleanup_block();
893-
cfg.push_end_region(block, source_info(span), scope.extent);
895+
cfg.push_end_region(tcx, block, source_info(span), scope.extent);
894896
cfg.terminate(block, source_info(span), TerminatorKind::Goto { target: target });
895897
target = block
896898
}

Diff for: src/librustc_mir/transform/clean_end_regions.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ struct DeleteTrivialEndRegions<'a> {
3939

4040
impl MirPass for CleanEndRegions {
4141
fn run_pass<'a, 'tcx>(&self,
42-
_tcx: TyCtxt<'a, 'tcx, 'tcx>,
42+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
4343
_source: MirSource,
4444
mir: &mut Mir<'tcx>) {
45+
if tcx.sess.opts.debugging_opts.skip_end_regions { return; }
46+
4547
let mut gather = GatherBorrowedRegions {
4648
seen_regions: FxHashSet()
4749
};

0 commit comments

Comments
 (0)