Skip to content
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

Dont run ast borrowck on mir mode #52083

Merged
merged 2 commits into from
Jul 7, 2018
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
!self.sess.opts.debugging_opts.disable_ast_check_for_mutation_in_guard
}

/// If true, we should use the AST-based borrowck (we may *also* use
/// the MIR-based borrowck).
pub fn use_ast_borrowck(self) -> bool {
self.borrowck_mode().use_ast()
}

/// If true, we should use the MIR-based borrowck (we may *also* use
/// the AST-based borrowck).
pub fn use_mir_borrowck(self) -> bool {
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ pub struct AnalysisData<'a, 'tcx: 'a> {
fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId)
-> Lrc<BorrowCheckResult>
{
assert!(tcx.use_ast_borrowck());

debug!("borrowck(body_owner_def_id={:?})", owner_def_id);

let owner_id = tcx.hir.as_local_node_id(owner_def_id).unwrap();
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,11 @@ where
middle::liveness::check_crate(tcx)
});

time(sess, "borrow checking", || borrowck::check_crate(tcx));
time(sess, "borrow checking", || {
if tcx.use_ast_borrowck() {
borrowck::check_crate(tcx);
}
});

time(sess,
"MIR borrow checking",
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn mir_borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> BorrowC
let mut return_early;

// Return early if we are not supposed to use MIR borrow checker for this function.
return_early = !tcx.has_attr(def_id, "rustc_mir_borrowck") && !tcx.use_mir_borrowck();
return_early = !tcx.has_attr(def_id, "rustc_mir") && !tcx.use_mir_borrowck();

if tcx.is_struct_constructor(def_id) {
// We are not borrow checking the automatically generated struct constructors
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_mir/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
// (Mir-)Borrowck uses `mir_validated`, so we have to force it to
// execute before we can steal.
let _ = tcx.mir_borrowck(def_id);
let _ = tcx.borrowck(def_id);

if tcx.use_ast_borrowck() {
let _ = tcx.borrowck(def_id);
}

let mut mir = tcx.mir_validated(def_id).steal();
run_passes![tcx, mir, def_id, 2;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/rustc_peek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl MirPass for SanityCheck {
src: MirSource, mir: &mut Mir<'tcx>) {
let def_id = src.def_id;
let id = tcx.hir.as_local_node_id(def_id).unwrap();
if !tcx.has_attr(def_id, "rustc_mir_borrowck") {
if !tcx.has_attr(def_id, "rustc_mir") {
debug!("skipping rustc_peek::SanityCheck on {}", tcx.item_path_str(def_id));
return;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/mir-dataflow/def-inits-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

// General test of maybe_uninits state computed by MIR dataflow.

#![feature(nll)]
#![feature(core_intrinsics, rustc_attrs)]

use std::intrinsics::rustc_peek;
use std::mem::{drop, replace};

struct S(i32);

#[rustc_mir_borrowck]
#[rustc_mir(rustc_peek_definite_init,stop_after_dataflow)]
fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
let ret;
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/mir-dataflow/inits-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

// General test of maybe_inits state computed by MIR dataflow.

#![feature(nll)]
#![feature(core_intrinsics, rustc_attrs)]

use std::intrinsics::rustc_peek;
use std::mem::{drop, replace};

struct S(i32);

#[rustc_mir_borrowck]
#[rustc_mir(rustc_peek_maybe_init,stop_after_dataflow)]
fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
let ret;
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/mir-dataflow/uninits-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

// General test of maybe_uninits state computed by MIR dataflow.

#![feature(nll)]
#![feature(core_intrinsics, rustc_attrs)]

use std::intrinsics::rustc_peek;
use std::mem::{drop, replace};

struct S(i32);

#[rustc_mir_borrowck]
#[rustc_mir(rustc_peek_maybe_uninit,stop_after_dataflow)]
fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
let ret;
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/mir-dataflow/uninits-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

// General test of maybe_uninits state computed by MIR dataflow.

#![feature(nll)]
#![feature(core_intrinsics, rustc_attrs)]

use std::intrinsics::rustc_peek;
use std::mem::{drop, replace};

struct S(i32);

#[rustc_mir_borrowck]
#[rustc_mir(rustc_peek_maybe_uninit,stop_after_dataflow)]
fn foo(x: &mut S) {
// `x` is initialized here, so maybe-uninit bit is 0.
Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/error-codes/E0017.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ error[E0017]: references in statics may only refer to immutable values
LL | static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
| ^^^^^^ statics require immutable values

error[E0017]: references in statics may only refer to immutable values
--> $DIR/E0017.rs:17:38
|
LL | static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
| ^^^^^^ statics require immutable values

error[E0596]: cannot borrow immutable item `X` as mutable
--> $DIR/E0017.rs:15:39
|
LL | static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
| ^^^^^^ cannot borrow as mutable

error[E0017]: references in statics may only refer to immutable values
--> $DIR/E0017.rs:17:38
|
LL | static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
| ^^^^^^ statics require immutable values

error: aborting due to 4 previous errors

Some errors occurred: E0017, E0596.
Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/error-codes/E0388.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ error[E0017]: references in statics may only refer to immutable values
LL | static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
| ^^^^^^ statics require immutable values

error[E0017]: references in statics may only refer to immutable values
--> $DIR/E0388.rs:17:38
|
LL | static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
| ^^^^^^ statics require immutable values

error[E0596]: cannot borrow immutable item `X` as mutable
--> $DIR/E0388.rs:15:39
|
LL | static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
| ^^^^^^ cannot borrow as mutable

error[E0017]: references in statics may only refer to immutable values
--> $DIR/E0388.rs:17:38
|
LL | static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
| ^^^^^^ statics require immutable values

error: aborting due to 4 previous errors

Some errors occurred: E0017, E0596.
Expand Down