Skip to content

Debugflag: -Z emit-end-regions #44249

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

Merged
merged 4 commits into from
Sep 7, 2017
Merged
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
@@ -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],
4 changes: 4 additions & 0 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
@@ -410,6 +410,10 @@ impl Session {
pub fn print_llvm_passes(&self) -> bool {
self.opts.debugging_opts.print_llvm_passes
}
pub fn emit_end_regions(&self) -> bool {
self.opts.debugging_opts.emit_end_regions ||
(self.opts.debugging_opts.mir_emit_validate > 0)
}
pub fn lto(&self) -> bool {
self.opts.cg.lto
}
20 changes: 12 additions & 8 deletions src/librustc_mir/build/cfg.rs
Original file line number Diff line number Diff line change
@@ -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.emit_end_regions() {
self.push(block, Statement {
source_info,
kind: StatementKind::EndRegion(region_scope),
});
}
}

pub fn push_assign(&mut self,
15 changes: 8 additions & 7 deletions src/librustc_mir/build/scope.rs
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 3 additions & 1 deletion src/librustc_mir/transform/clean_end_regions.rs
Original file line number Diff line number Diff line change
@@ -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.emit_end_regions() { return; }

let mut gather = GatherBorrowedRegions {
seen_regions: FxHashSet()
};
2 changes: 1 addition & 1 deletion src/test/mir-opt/end_region_1.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z identify_regions
// compile-flags: -Z identify_regions -Z emit-end-regions
// ignore-tidy-linelength

// This is just about the simplest program that exhibits an EndRegion.
2 changes: 1 addition & 1 deletion src/test/mir-opt/end_region_2.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z identify_regions
// compile-flags: -Z identify_regions -Z emit-end-regions
// ignore-tidy-linelength

// We will EndRegion for borrows in a loop that occur before break but
2 changes: 1 addition & 1 deletion src/test/mir-opt/end_region_3.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z identify_regions
// compile-flags: -Z identify_regions -Z emit-end-regions
// ignore-tidy-linelength

// Binding the borrow's subject outside the loop does not increase the
2 changes: 1 addition & 1 deletion src/test/mir-opt/end_region_4.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z identify_regions
// compile-flags: -Z identify_regions -Z emit-end-regions
// ignore-tidy-linelength

// Unwinding should EndRegion for in-scope borrows: Direct borrows.
2 changes: 1 addition & 1 deletion src/test/mir-opt/end_region_5.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z identify_regions -Z span_free_formats
// compile-flags: -Z identify_regions -Z span_free_formats -Z emit-end-regions
// ignore-tidy-linelength

// Unwinding should EndRegion for in-scope borrows: Borrowing via by-ref closure.
2 changes: 1 addition & 1 deletion src/test/mir-opt/end_region_6.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z identify_regions -Z span_free_formats
// compile-flags: -Z identify_regions -Z span_free_formats -Z emit-end-regions
// ignore-tidy-linelength

// Unwinding should EndRegion for in-scope borrows: 2nd borrow within by-ref closure.
2 changes: 1 addition & 1 deletion src/test/mir-opt/end_region_7.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z identify_regions -Z span_free_formats
// compile-flags: -Z identify_regions -Z span_free_formats -Z emit-end-regions
// ignore-tidy-linelength

// Unwinding should EndRegion for in-scope borrows: Borrow of moved data.
2 changes: 1 addition & 1 deletion src/test/mir-opt/end_region_8.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z identify_regions -Z span_free_formats
// compile-flags: -Z identify_regions -Z span_free_formats -Z emit-end-regions
// ignore-tidy-linelength

// Unwinding should EndRegion for in-scope borrows: Move of borrow into closure.
2 changes: 1 addition & 1 deletion src/test/mir-opt/end_region_9.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z identify_regions -Z span_free_formats
// compile-flags: -Z identify_regions -Z span_free_formats -Z emit-end-regions
// ignore-tidy-linelength

// This test models a scenario that arielb1 found during review.
2 changes: 1 addition & 1 deletion src/test/mir-opt/issue-43457.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z identify_regions -Z span_free_formats
// compile-flags: -Z identify_regions -Z span_free_formats -Z emit-end-regions
// ignore-tidy-linelength

// Regression test for #43457: an `EndRegion` was missing from output