document and tweak the nll, use_mir, etc helpers

In particular, -Znll might as well imply -Zborrowck=mir by default,
just like `#![feature(nll)]` does.

Also, if NLL is in use, no reason to emit end regions. The NLL pass
just strips them out anyway.
This commit is contained in:
Niko Matsakis 2017-12-20 04:26:54 -05:00
parent e980fb8bef
commit cfa4ffa374
2 changed files with 28 additions and 7 deletions

View file

@ -437,25 +437,42 @@ impl Session {
pub fn print_llvm_passes(&self) -> bool {
self.opts.debugging_opts.print_llvm_passes
}
/// If true, we should use NLL-style region checking instead of
/// lexical style.
pub fn nll(&self) -> bool {
self.features.borrow().nll || self.opts.debugging_opts.nll
}
/// If true, we should use the MIR-based borrowck (we may *also* use
/// the AST-based borrowck).
pub fn use_mir(&self) -> bool {
self.features.borrow().nll || self.opts.borrowck_mode.use_mir()
self.borrowck_mode().use_mir()
}
/// If true, we should gather causal information during NLL
/// checking. This will eventually be the normal thing, but right
/// now it is too unoptimized.
pub fn nll_dump_cause(&self) -> bool {
self.opts.debugging_opts.nll_dump_cause
}
/// If true, we should enable two-phase borrows checks. This is
/// done with either `-Ztwo-phase-borrows` or with
/// `#![feature(nll)]`.
pub fn two_phase_borrows(&self) -> bool {
self.features.borrow().nll || self.opts.debugging_opts.two_phase_borrows
}
/// What mode(s) of borrowck should we run? AST? MIR? both?
/// (Also considers the `#![feature(nll)]` setting.)
pub fn borrowck_mode(&self) -> BorrowckMode {
match self.opts.borrowck_mode {
mode @ BorrowckMode::Mir |
mode @ BorrowckMode::Compare => mode,
mode @ BorrowckMode::Ast => {
if self.features.borrow().nll {
if self.nll() {
BorrowckMode::Mir
} else {
mode
@ -464,11 +481,18 @@ impl Session {
}
}
/// Should we emit EndRegion MIR statements? These are consumed by
/// MIR borrowck, but not when NLL is used. They are also consumed
/// by the validation stuff.
pub fn emit_end_regions(&self) -> bool {
// FIXME(#46875) -- we should not emit end regions when NLL is enabled,
// but for now we can't stop doing so because it causes false positives
self.opts.debugging_opts.emit_end_regions ||
(self.opts.debugging_opts.mir_emit_validate > 0) ||
self.opts.debugging_opts.mir_emit_validate > 0 ||
self.use_mir()
}
pub fn lto(&self) -> bool {
self.opts.cg.lto || self.target.target.options.requires_lto
}

View file

@ -72,10 +72,7 @@ fn mir_borrowck<'a, 'tcx>(
let input_mir = tcx.mir_validated(def_id);
debug!("run query mir_borrowck: {}", tcx.item_path_str(def_id));
if {
!tcx.has_attr(def_id, "rustc_mir_borrowck") && !tcx.sess.use_mir()
&& !tcx.sess.nll()
} {
if !tcx.has_attr(def_id, "rustc_mir_borrowck") && !tcx.sess.use_mir() {
return None;
}