Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -Z skip-end-regions as way to side-step EndRegion emission. #44219

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,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)"),
skip_end_regions: bool = (false, parse_bool, [UNTRACKED],
"skip EndRegion emission in MIR, skip 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],
Expand Down
20 changes: 12 additions & 8 deletions src/librustc_mir/build/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use build::CFG;
use rustc::middle::region::CodeExtent;
use rustc::mir::*;
use rustc::ty;

impl<'tcx> CFG<'tcx> {
pub fn block_data(&self, blk: BasicBlock) -> &BasicBlockData<'tcx> {
Expand Down Expand Up @@ -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,
extent: CodeExtent) {
self.push(block, Statement {
source_info,
kind: StatementKind::EndRegion(extent),
});
pub fn push_end_region<'a, 'gcx:'a+'tcx>(&mut self,
tcx: ty::TyCtxt<'a, 'gcx, 'tcx>,
block: BasicBlock,
source_info: SourceInfo,
extent: CodeExtent) {
if !tcx.sess.opts.debugging_opts.skip_end_regions {
self.push(block, Statement {
source_info,
kind: StatementKind::EndRegion(extent),
});
}
}

pub fn push_assign(&mut self,
Expand Down
16 changes: 9 additions & 7 deletions src/librustc_mir/build/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ should go to.

use build::{BlockAnd, BlockAndExtension, Builder, CFG};
use rustc::middle::region::CodeExtent;
use rustc::ty::Ty;
use rustc::ty::{Ty, TyCtxt};
use rustc::mir::*;
use rustc::mir::transform::MirSource;
use syntax_pos::{Span};
Expand Down Expand Up @@ -359,7 +359,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
self.arg_count,
false));

self.cfg.push_end_region(block, extent.1, scope.extent);
self.cfg.push_end_region(self.hir.tcx(), block, extent.1, scope.extent);
block.unit()
}

Expand Down Expand Up @@ -412,7 +412,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, extent.1, scope.extent);
self.cfg.push_end_region(self.hir.tcx(), block, extent.1, scope.extent);
}
}
let scope = &self.scopes[len - scope_count];
Expand Down Expand Up @@ -461,7 +461,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.extent);
self.cfg.push_end_region(self.hir.tcx(), block, src_info, scope.extent);
}

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

for scope in scopes.iter_mut() {
target = build_diverge_scope(cfg, scope.extent_span, scope, target, generator_drop);
target = build_diverge_scope(
self.hir.tcx(), cfg, scope.extent_span, scope, target, generator_drop);
}
Some(target)
}
Expand Down Expand Up @@ -828,7 +829,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,
Expand Down Expand Up @@ -890,7 +892,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.extent);
cfg.push_end_region(tcx, block, source_info(span), scope.extent);
cfg.terminate(block, source_info(span), TerminatorKind::Goto { target: target });
target = block
}
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_mir/transform/clean_end_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.skip_end_regions { return; }

let mut gather = GatherBorrowedRegions {
seen_regions: FxHashSet()
};
Expand Down