diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2017-08-21 10:24:12 +0200 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2017-08-21 12:49:18 +0200 |
| commit | 4da2a88abc99eebbc5bdbfd8aada728982a262d7 (patch) | |
| tree | 05e05afa4a99c577d333c0831089563fca31688c /src | |
| parent | 757b7ac2abd69d97ba196b76f0bbf78c377aaea9 (diff) | |
| download | rust-4da2a88abc99eebbc5bdbfd8aada728982a262d7.tar.gz rust-4da2a88abc99eebbc5bdbfd8aada728982a262d7.zip | |
Expose mir-borrowck via a query.
(A followup commit removes the mir::transform based entry point.)
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/dep_graph/dep_node.rs | 2 | ||||
| -rw-r--r-- | src/librustc/ty/maps.rs | 2 | ||||
| -rw-r--r-- | src/librustc_driver/driver.rs | 4 | ||||
| -rw-r--r-- | src/librustc_mir/borrow_check.rs | 31 | ||||
| -rw-r--r-- | src/librustc_mir/lib.rs | 2 | ||||
| -rw-r--r-- | src/librustc_mir/transform/borrow_check.rs | 2 | ||||
| -rw-r--r-- | src/librustc_mir/transform/mod.rs | 3 |
7 files changed, 44 insertions, 2 deletions
diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 5b609f192e1..9e5d4081231 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -411,6 +411,8 @@ define_dep_nodes!( <'tcx> [] BorrowCheckKrate, [] BorrowCheck(DefId), + [] MirBorrowCheck(DefId), + [] RvalueCheck(DefId), [] Reachability, [] MirKeys, diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index a640da31eec..26b51630d93 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -923,6 +923,8 @@ define_maps! { <'tcx> [] 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 c98f9c3d466..011c769519a 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 00000000000..366608ac699 --- /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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 6b1fe0d2ca9..7aa46799924 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -45,6 +45,7 @@ extern crate core; // for NonZero mod diagnostics; +mod borrow_check; mod build; mod dataflow; mod hair; @@ -55,6 +56,7 @@ pub mod util; 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 46e65d355a1..c5333134a68 100644 --- a/src/librustc_mir/transform/borrow_check.rs +++ b/src/librustc_mir/transform/borrow_check.rs @@ -57,7 +57,7 @@ impl MirPass for BorrowckMir { } } -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 25a156ea3fd..2536e4e576d 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(); |
