提交 4da2a88a 编写于 作者: F Felix S. Klock II

Expose mir-borrowck via a query.

(A followup commit removes the mir::transform based entry point.)
上级 757b7ac2
......@@ -411,6 +411,8 @@ pub fn to_dep_node(self, tcx: TyCtxt, kind: DepKind) -> DepNode {
[] BorrowCheckKrate,
[] BorrowCheck(DefId),
[] MirBorrowCheck(DefId),
[] RvalueCheck(DefId),
[] Reachability,
[] MirKeys,
......
......@@ -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.
......
......@@ -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
......
// 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 @@
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);
}
......
......@@ -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);
......
......@@ -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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册