Skip to content

Commit 4da2a88

Browse files
committed
Expose mir-borrowck via a query.
(A followup commit removes the mir::transform based entry point.)
1 parent 757b7ac commit 4da2a88

File tree

7 files changed

+44
-2
lines changed

7 files changed

+44
-2
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ define_dep_nodes!( <'tcx>
411411

412412
[] BorrowCheckKrate,
413413
[] BorrowCheck(DefId),
414+
[] MirBorrowCheck(DefId),
415+
414416
[] RvalueCheck(DefId),
415417
[] Reachability,
416418
[] MirKeys,

src/librustc/ty/maps.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,8 @@ define_maps! { <'tcx>
923923
[] coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
924924

925925
[] borrowck: BorrowCheck(DefId) -> (),
926+
// FIXME: shouldn't this return a `Result<(), BorrowckErrors>` instead?
927+
[] mir_borrowck: MirBorrowCheck(DefId) -> (),
926928

927929
/// Gets a complete map from all types to their inherent impls.
928930
/// Not meant to be used directly outside of coherence.

src/librustc_driver/driver.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,10 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
10751075
"borrow checking",
10761076
|| borrowck::check_crate(tcx));
10771077

1078+
time(time_passes,
1079+
"MIR borrow checking",
1080+
|| for def_id in tcx.body_owners() { tcx.mir_borrowck(def_id) });
1081+
10781082
// Avoid overwhelming user with errors if type checking failed.
10791083
// I'm not sure how helpful this is, to be honest, but it avoids
10801084
// a

src/librustc_mir/borrow_check.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use rustc::hir::def_id::{DefId};
12+
use rustc::mir::transform::{MirSource};
13+
use rustc::ty::{TyCtxt};
14+
use rustc::ty::maps::Providers;
15+
16+
pub fn provide(providers: &mut Providers) {
17+
*providers = Providers {
18+
mir_borrowck,
19+
..*providers
20+
};
21+
}
22+
23+
fn mir_borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
24+
let mir = tcx.mir_validated(def_id);
25+
let src = MirSource::from_local_def_id(tcx, def_id);
26+
debug!("run query mir_borrowck: {}", tcx.node_path_str(src.item_id()));
27+
28+
if tcx.has_attr(def_id, "rustc_mir_borrowck") || tcx.sess.opts.debugging_opts.borrowck_mir {
29+
::transform::borrow_check::borrowck_mir(tcx, src, &mir.borrow());
30+
}
31+
}

src/librustc_mir/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extern crate core; // for NonZero
4545

4646
mod diagnostics;
4747

48+
mod borrow_check;
4849
mod build;
4950
mod dataflow;
5051
mod hair;
@@ -55,6 +56,7 @@ pub mod util;
5556
use rustc::ty::maps::Providers;
5657

5758
pub fn provide(providers: &mut Providers) {
59+
borrow_check::provide(providers);
5860
shim::provide(providers);
5961
transform::provide(providers);
6062
}

src/librustc_mir/transform/borrow_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl MirPass for BorrowckMir {
5757
}
5858
}
5959

60-
fn borrowck_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource, mir: &Mir<'tcx>)
60+
pub(crate) fn borrowck_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource, mir: &Mir<'tcx>)
6161
{
6262
let id = src.item_id();
6363
let def_id = tcx.hir.local_def_id(id);

src/librustc_mir/transform/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
123123
}
124124

125125
fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Mir<'tcx> {
126-
// Borrowck uses `mir_validated`, so we have to force it to
126+
// (Mir-)Borrowck uses `mir_validated`, so we have to force it to
127127
// execute before we can steal.
128+
ty::queries::mir_borrowck::force(tcx, DUMMY_SP, def_id);
128129
ty::queries::borrowck::force(tcx, DUMMY_SP, def_id);
129130

130131
let mut mir = tcx.mir_validated(def_id).steal();

0 commit comments

Comments
 (0)