Skip to content

Commit f1c721c

Browse files
committed
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.
1 parent 2f1ef9e commit f1c721c

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

src/librustc/session/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
919919
"when debug-printing compiler state, do not include spans"), // o/w tests have closure@path
920920
identify_regions: bool = (false, parse_bool, [UNTRACKED],
921921
"make unnamed regions display as '# (where # is some non-ident unique id)"),
922+
emit_end_regions: bool = (false, parse_bool, [UNTRACKED],
923+
"emit EndRegion as part of MIR; enable transforms that solely process EndRegion"),
922924
borrowck_mir: bool = (false, parse_bool, [UNTRACKED],
923925
"implicitly treat functions as if they have `#[rustc_mir_borrowck]` attribute"),
924926
time_passes: bool = (false, parse_bool, [UNTRACKED],

src/librustc_mir/build/cfg.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use build::CFG;
1717
use rustc::middle::region;
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-
region_scope: region::Scope) {
51-
self.push(block, Statement {
52-
source_info,
53-
kind: StatementKind::EndRegion(region_scope),
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+
region_scope: region::Scope) {
53+
if tcx.sess.opts.debugging_opts.emit_end_regions {
54+
self.push(block, Statement {
55+
source_info,
56+
kind: StatementKind::EndRegion(region_scope),
57+
});
58+
}
5559
}
5660

5761
pub fn push_assign(&mut self,

src/librustc_mir/build/scope.rs

Lines changed: 8 additions & 7 deletions
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;
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, region_scope.1, scope.region_scope);
362+
self.cfg.push_end_region(self.hir.tcx(), block, region_scope.1, scope.region_scope);
363363
block.unit()
364364
}
365365

@@ -414,7 +414,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
414414
false));
415415

416416
// End all regions for scopes out of which we are breaking.
417-
self.cfg.push_end_region(block, region_scope.1, scope.region_scope);
417+
self.cfg.push_end_region(self.hir.tcx(), block, region_scope.1, scope.region_scope);
418418
}
419419
}
420420
let scope = &self.scopes[len - scope_count];
@@ -463,7 +463,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
463463
true));
464464

465465
// End all regions for scopes out of which we are breaking.
466-
self.cfg.push_end_region(block, src_info, scope.region_scope);
466+
self.cfg.push_end_region(self.hir.tcx(), block, src_info, scope.region_scope);
467467
}
468468

469469
self.cfg.terminate(block, src_info, TerminatorKind::GeneratorDrop);
@@ -694,7 +694,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
694694
};
695695

696696
for scope in scopes.iter_mut() {
697-
target = build_diverge_scope(cfg, scope.region_scope_span,
697+
target = build_diverge_scope(self.hir.tcx(), cfg, scope.region_scope_span,
698698
scope, target, generator_drop);
699699
}
700700
Some(target)
@@ -831,7 +831,8 @@ fn build_scope_drops<'tcx>(cfg: &mut CFG<'tcx>,
831831
block.unit()
832832
}
833833

834-
fn build_diverge_scope<'a, 'gcx, 'tcx>(cfg: &mut CFG<'tcx>,
834+
fn build_diverge_scope<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
835+
cfg: &mut CFG<'tcx>,
835836
span: Span,
836837
scope: &mut Scope<'tcx>,
837838
mut target: BasicBlock,
@@ -893,7 +894,7 @@ fn build_diverge_scope<'a, 'gcx, 'tcx>(cfg: &mut CFG<'tcx>,
893894
// becomes trivial goto after pass that removes all EndRegions.)
894895
{
895896
let block = cfg.start_new_cleanup_block();
896-
cfg.push_end_region(block, source_info(span), scope.region_scope);
897+
cfg.push_end_region(tcx, block, source_info(span), scope.region_scope);
897898
cfg.terminate(block, source_info(span), TerminatorKind::Goto { target: target });
898899
target = block
899900
}

src/librustc_mir/transform/clean_end_regions.rs

Lines changed: 3 additions & 1 deletion
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.emit_end_regions { return; }
46+
4547
let mut gather = GatherBorrowedRegions {
4648
seen_regions: FxHashSet()
4749
};

0 commit comments

Comments
 (0)