diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 5b609f192e1c2b11d351febd6d23b72e3e99c2d6..9e5d40812311d992a35a47fec8087ecfdb5fd61d 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -411,6 +411,8 @@ pub fn to_dep_node(self, tcx: TyCtxt, kind: DepKind) -> DepNode { [] BorrowCheckKrate, [] BorrowCheck(DefId), + [] MirBorrowCheck(DefId), + [] RvalueCheck(DefId), [] Reachability, [] MirKeys, diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index a640da31eec257a08ff2d81a77e605970b1e714b..26b51630d93e0d1da168020e87fdf2ac56476864 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -923,6 +923,8 @@ fn default() -> Self { [] coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (), [] borrowck: BorrowCheck(DefId) -> (), + // FIXME: shouldn't this return a `Result<(), BorrowckErrors>` instead? + [] mir_borrowck: MirBorrowCheck(DefId) -> (), /// Gets a complete map from all types to their inherent impls. /// Not meant to be used directly outside of coherence. diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index c98f9c3d4660a2637612b5508ce7f6a84dc6cfe9..011c769519ad5fd03c44674f1a985a00ea48fba8 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -1075,6 +1075,10 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session, "borrow checking", || borrowck::check_crate(tcx)); + time(time_passes, + "MIR borrow checking", + || for def_id in tcx.body_owners() { tcx.mir_borrowck(def_id) }); + // Avoid overwhelming user with errors if type checking failed. // I'm not sure how helpful this is, to be honest, but it avoids // a diff --git a/src/librustc_mir/borrow_check.rs b/src/librustc_mir/borrow_check.rs new file mode 100644 index 0000000000000000000000000000000000000000..366608ac699954508f941152071112f06cb31f82 --- /dev/null +++ b/src/librustc_mir/borrow_check.rs @@ -0,0 +1,31 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use rustc::hir::def_id::{DefId}; +use rustc::mir::transform::{MirSource}; +use rustc::ty::{TyCtxt}; +use rustc::ty::maps::Providers; + +pub fn provide(providers: &mut Providers) { + *providers = Providers { + mir_borrowck, + ..*providers + }; +} + +fn mir_borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) { + let mir = tcx.mir_validated(def_id); + let src = MirSource::from_local_def_id(tcx, def_id); + debug!("run query mir_borrowck: {}", tcx.node_path_str(src.item_id())); + + if tcx.has_attr(def_id, "rustc_mir_borrowck") || tcx.sess.opts.debugging_opts.borrowck_mir { + ::transform::borrow_check::borrowck_mir(tcx, src, &mir.borrow()); + } +} diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 6b1fe0d2ca9f6b504f2bcceeac11ba6dc2d0a746..7aa4679992471fa436bd11324728b22f8ebc25ed 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -45,6 +45,7 @@ mod diagnostics; +mod borrow_check; mod build; mod dataflow; mod hair; @@ -55,6 +56,7 @@ use rustc::ty::maps::Providers; pub fn provide(providers: &mut Providers) { + borrow_check::provide(providers); shim::provide(providers); transform::provide(providers); } diff --git a/src/librustc_mir/transform/borrow_check.rs b/src/librustc_mir/transform/borrow_check.rs index 46e65d355a15baa5c692c304a066b1aa4c6d1962..c5333134a68618b05652df24e30b4672cdf99f84 100644 --- a/src/librustc_mir/transform/borrow_check.rs +++ b/src/librustc_mir/transform/borrow_check.rs @@ -57,7 +57,7 @@ fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource, mir: & } } -fn borrowck_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource, mir: &Mir<'tcx>) +pub(crate) fn borrowck_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource, mir: &Mir<'tcx>) { let id = src.item_id(); let def_id = tcx.hir.local_def_id(id); diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 25a156ea3fd97026347178ffb305a2e22f303f96..2536e4e576dd2b5169f5b9b967c68acfc0224aed 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -123,8 +123,9 @@ fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx } fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Mir<'tcx> { - // Borrowck uses `mir_validated`, so we have to force it to + // (Mir-)Borrowck uses `mir_validated`, so we have to force it to // execute before we can steal. + ty::queries::mir_borrowck::force(tcx, DUMMY_SP, def_id); ty::queries::borrowck::force(tcx, DUMMY_SP, def_id); let mut mir = tcx.mir_validated(def_id).steal();