Skip to content

Commit

Permalink
Auto merge of #46106 - est31:master, r=nikomatsakis
Browse files Browse the repository at this point in the history
Add a MIR-borrowck-only output mode

Removes the `-Z borrowck-mir` flag in favour of a `-Z borrowck=mode` flag where mode can be `mir`, `ast`, or `compare`.

* The `ast` mode represents the current default, passing `-Z borrowck=ast` is equivalent to not passing it at all.
* The `compare` mode outputs both the output of the MIR borrow checker and the AST borrow checker, each error with `(Ast)` and `(Mir)` appended. This mode has the same behaviour as `-Z borrowck-mir` had before this commit.
* The `mir` mode only outputs the results of the MIR borrow checker, while suppressing the errors of the ast borrow checker

The PR also updates the tests to use the new flags.

closes  #46097
  • Loading branch information
bors committed Nov 26, 2017
2 parents 71b21ed + d791798 commit 827cb0d
Show file tree
Hide file tree
Showing 62 changed files with 354 additions and 373 deletions.
44 changes: 42 additions & 2 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ top_level_options!(

debugging_opts: DebuggingOptions [TRACKED],
prints: Vec<PrintRequest> [UNTRACKED],
// Determines which borrow checker(s) to run. This is the parsed, sanitized
// version of `debugging_opts.borrowck`, which is just a plain string.
borrowck_mode: BorrowckMode [UNTRACKED],
cg: CodegenOptions [TRACKED],
// FIXME(mw): We track this for now but it actually doesn't make too
// much sense: The value of this option can stay the same
Expand Down Expand Up @@ -401,6 +404,32 @@ pub enum PrintRequest {
NativeStaticLibs,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum BorrowckMode {
Ast,
Mir,
Compare,
}

impl BorrowckMode {
/// Should we emit the AST-based borrow checker errors?
pub fn use_ast(self) -> bool {
match self {
BorrowckMode::Ast => true,
BorrowckMode::Compare => true,
BorrowckMode::Mir => false,
}
}
/// Should we emit the MIR-based borrow checker errors?
pub fn use_mir(self) -> bool {
match self {
BorrowckMode::Ast => false,
BorrowckMode::Compare => true,
BorrowckMode::Mir => true,
}
}
}

pub enum Input {
/// Load source from file
File(PathBuf),
Expand Down Expand Up @@ -526,6 +555,7 @@ pub fn basic_options() -> Options {
incremental: None,
debugging_opts: basic_debugging_options(),
prints: Vec::new(),
borrowck_mode: BorrowckMode::Ast,
cg: basic_codegen_options(),
error_format: ErrorOutputType::default(),
externs: Externs(BTreeMap::new()),
Expand Down Expand Up @@ -973,8 +1003,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"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"),
borrowck: Option<String> = (None, parse_opt_string, [UNTRACKED],
"select which borrowck is used (`ast`, `mir`, or `compare`)"),
time_passes: bool = (false, parse_bool, [UNTRACKED],
"measure time of each rustc pass"),
count_llvm_insns: bool = (false, parse_bool,
Expand Down Expand Up @@ -1743,6 +1773,15 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
}
}));

let borrowck_mode = match debugging_opts.borrowck.as_ref().map(|s| &s[..]) {
None | Some("ast") => BorrowckMode::Ast,
Some("mir") => BorrowckMode::Mir,
Some("compare") => BorrowckMode::Compare,
Some(m) => {
early_error(error_format, &format!("unknown borrowck mode `{}`", m))
},
};

if !cg.remark.is_empty() && debuginfo == NoDebugInfo {
early_warn(error_format, "-C remark will not show source locations without \
--debuginfo");
Expand Down Expand Up @@ -1784,6 +1823,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
incremental,
debugging_opts,
prints,
borrowck_mode,
cg,
error_format,
externs: Externs(externs),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ impl Session {
pub fn emit_end_regions(&self) -> bool {
self.opts.debugging_opts.emit_end_regions ||
(self.opts.debugging_opts.mir_emit_validate > 0) ||
self.opts.debugging_opts.borrowck_mir
self.opts.borrowck_mode.use_mir()
}
pub fn lto(&self) -> bool {
self.opts.cg.lto || self.target.target.options.requires_lto
Expand Down
11 changes: 11 additions & 0 deletions src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,17 @@ impl<'b, 'tcx: 'b> BorrowckErrors for BorrowckCtxt<'b, 'tcx> {
{
self.tcx.sess.struct_span_err(sp, msg)
}

fn cancel_if_wrong_origin<'a>(&'a self,
mut diag: DiagnosticBuilder<'a>,
o: Origin)
-> DiagnosticBuilder<'a>
{
if !o.should_emit_errors(self.tcx.sess.opts.borrowck_mode) {
self.tcx.sess.diagnostic().cancel(&mut diag);
}
diag
}
}

///////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn mir_borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {

if {
!tcx.has_attr(def_id, "rustc_mir_borrowck") &&
!tcx.sess.opts.debugging_opts.borrowck_mir &&
!tcx.sess.opts.borrowck_mode.use_mir() &&
!tcx.sess.opts.debugging_opts.nll
} {
return;
Expand Down
Loading

0 comments on commit 827cb0d

Please sign in to comment.