Skip to content

Commit a4d7c1f

Browse files
committed
push borrowck into its own task
1 parent a2a4fad commit a4d7c1f

File tree

5 files changed

+42
-16
lines changed

5 files changed

+42
-16
lines changed

src/librustc/hir/map/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,27 @@ impl<'hir> Map<'hir> {
442442
self.local_def_id(self.body_owner(id))
443443
}
444444

445+
/// Given a body owner's id, returns the `BodyId` associated with it.
446+
pub fn body_owned_by(&self, id: NodeId) -> BodyId {
447+
if let Some(entry) = self.find_entry(id) {
448+
if let Some(body_id) = entry.associated_body() {
449+
// For item-like things and closures, the associated
450+
// body has its own distinct id, and that is returned
451+
// by `associated_body`.
452+
body_id
453+
} else {
454+
// For some expressions, the expression is its own body.
455+
if let EntryExpr(_, expr) = entry {
456+
BodyId { node_id: expr.id }
457+
} else {
458+
span_bug!(self.span(id), "id `{}` has no associated body", id);
459+
}
460+
}
461+
} else {
462+
bug!("no entry for id `{}`", id)
463+
}
464+
}
465+
445466
pub fn ty_param_owner(&self, id: NodeId) -> NodeId {
446467
match self.get(id) {
447468
NodeItem(&Item { node: ItemTrait(..), .. }) => id,

src/librustc/ty/maps.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ define_maps! { <'tcx>
423423

424424
pub coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
425425

426+
pub borrowck: BorrowCheck(DefId) -> (),
427+
426428
/// Gets a complete map from all types to their inherent impls.
427429
/// Not meant to be used directly outside of coherence.
428430
/// (Defined only for LOCAL_CRATE)

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub use self::mir::elaborate_drops::ElaborateDrops;
2222

2323
use self::InteriorKind::*;
2424

25-
use rustc::dep_graph::DepNode;
2625
use rustc::hir::map as hir_map;
2726
use rustc::hir::map::blocks::FnLikeNode;
2827
use rustc::cfg;
@@ -37,12 +36,13 @@ use rustc::middle::mem_categorization::Categorization;
3736
use rustc::middle::mem_categorization::ImmutabilityBlame;
3837
use rustc::middle::region;
3938
use rustc::ty::{self, TyCtxt};
39+
use rustc::ty::maps::Providers;
4040

4141
use std::fmt;
4242
use std::rc::Rc;
4343
use std::hash::{Hash, Hasher};
4444
use syntax::ast;
45-
use syntax_pos::{MultiSpan, Span};
45+
use syntax_pos::{DUMMY_SP, MultiSpan, Span};
4646
use errors::DiagnosticBuilder;
4747

4848
use rustc::hir;
@@ -62,16 +62,16 @@ pub struct LoanDataFlowOperator;
6262
pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator>;
6363

6464
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
65-
tcx.dep_graph.with_task(DepNode::BorrowCheckKrate, tcx, (), check_crate_task);
66-
67-
fn check_crate_task<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, (): ()) {
68-
tcx.visit_all_bodies_in_krate(|body_owner_def_id, body_id| {
69-
tcx.dep_graph.with_task(DepNode::BorrowCheck(body_owner_def_id),
70-
tcx,
71-
body_id,
72-
borrowck_fn);
73-
});
74-
}
65+
tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| {
66+
ty::queries::borrowck::get(tcx, DUMMY_SP, body_owner_def_id);
67+
});
68+
}
69+
70+
pub fn provide(providers: &mut Providers) {
71+
*providers = Providers {
72+
borrowck: borrowck,
73+
..*providers
74+
};
7575
}
7676

7777
/// Collection of conclusions determined via borrow checker analyses.
@@ -81,11 +81,11 @@ pub struct AnalysisData<'a, 'tcx: 'a> {
8181
pub move_data: move_data::FlowedMoveData<'a, 'tcx>,
8282
}
8383

84-
fn borrowck_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, body_id: hir::BodyId) {
85-
debug!("borrowck_fn(body_id={:?})", body_id);
84+
fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId) {
85+
debug!("borrowck(body_owner_def_id={:?})", owner_def_id);
8686

87-
let owner_id = tcx.hir.body_owner(body_id);
88-
let owner_def_id = tcx.hir.local_def_id(owner_id);
87+
let owner_id = tcx.hir.as_local_node_id(owner_def_id).unwrap();
88+
let body_id = tcx.hir.body_owned_by(owner_id);
8989
let attributes = tcx.get_attrs(owner_def_id);
9090
let tables = tcx.item_tables(owner_def_id);
9191

src/librustc_borrowck/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ mod borrowck;
5151

5252
pub mod graphviz;
5353

54+
pub use borrowck::provide;
55+
5456
__build_diagnostic_array! { librustc_borrowck, DIAGNOSTICS }

src/librustc_driver/driver.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
887887
let mut local_providers = ty::maps::Providers::default();
888888
mir::provide(&mut local_providers);
889889
rustc_privacy::provide(&mut local_providers);
890+
borrowck::provide(&mut local_providers);
890891
typeck::provide(&mut local_providers);
891892
ty::provide(&mut local_providers);
892893

0 commit comments

Comments
 (0)