Skip to content

Commit

Permalink
Replace -Zborrowck-mir with -Zborrowck=mode
Browse files Browse the repository at this point in the history
where mode is one of {ast,mir,compare}.

This commit only implements the functionality.
The tests will be updated in a follow up commit.
  • Loading branch information
est31 committed Nov 26, 2017
1 parent 2ca00a9 commit c9af68e
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 53 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 borrowchk 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 c9af68e

Please sign in to comment.