From cfa4ffa374f264cad971b8177e8d3a9cdd8152b3 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 20 Dec 2017 04:26:54 -0500 Subject: [PATCH] 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. --- src/librustc/session/mod.rs | 30 +++++++++++++++++++++++++--- src/librustc_mir/borrow_check/mod.rs | 5 +---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 903bfc44c1d..60a218500ca 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -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 } diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 7a6c2c25bf1..c907c97d6d3 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -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; }