Expose mir-borrowck via a query.
(A followup commit removes the mir::transform based entry point.)
This commit is contained in:
parent
757b7ac2ab
commit
4da2a88abc
@ -411,6 +411,8 @@ define_dep_nodes!( <'tcx>
|
||||
|
||||
[] BorrowCheckKrate,
|
||||
[] BorrowCheck(DefId),
|
||||
[] MirBorrowCheck(DefId),
|
||||
|
||||
[] RvalueCheck(DefId),
|
||||
[] Reachability,
|
||||
[] MirKeys,
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
31
src/librustc_mir/borrow_check.rs
Normal file
31
src/librustc_mir/borrow_check.rs
Normal file
@ -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());
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user