From 768e7078785dd418968f26d79b1ff323403999ef Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 4 Apr 2017 11:08:52 -0400 Subject: [PATCH 1/6] kill the `CheckLoops` DepNode --- src/librustc/dep_graph/dep_node.rs | 2 -- src/librustc_passes/loops.rs | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 5aea2bcaa4f5c..5142fd3c028db 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -60,7 +60,6 @@ pub enum DepNode { CheckStaticRecursion, ResolveLifetimes, RegionResolveCrate, - CheckLoops, PluginRegistrar, StabilityIndex, CollectItem(D), @@ -219,7 +218,6 @@ impl DepNode { CheckStaticRecursion => Some(CheckStaticRecursion), ResolveLifetimes => Some(ResolveLifetimes), RegionResolveCrate => Some(RegionResolveCrate), - CheckLoops => Some(CheckLoops), PluginRegistrar => Some(PluginRegistrar), StabilityIndex => Some(StabilityIndex), Coherence => Some(Coherence), diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index 421181c68c4cd..2ea235af10378 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -11,7 +11,6 @@ use self::Context::*; use rustc::session::Session; -use rustc::dep_graph::DepNode; use rustc::hir::map::Map; use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap}; use rustc::hir; @@ -50,7 +49,6 @@ struct CheckLoopVisitor<'a, 'hir: 'a> { } pub fn check_crate(sess: &Session, map: &Map) { - let _task = map.dep_graph.in_task(DepNode::CheckLoops); let krate = map.krate(); krate.visit_all_item_likes(&mut CheckLoopVisitor { sess: sess, From f3b876c4b2dec93ead8ebdcbf5eb5a0be4fa46a0 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 4 Apr 2017 11:09:12 -0400 Subject: [PATCH 2/6] kill `CheckStaticRecursion` --- src/librustc/dep_graph/dep_node.rs | 2 -- src/librustc_passes/static_recursion.rs | 3 --- 2 files changed, 5 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 5142fd3c028db..0521b50df4d2d 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -57,7 +57,6 @@ pub enum DepNode { // Represents different phases in the compiler. CollectLanguageItems, - CheckStaticRecursion, ResolveLifetimes, RegionResolveCrate, PluginRegistrar, @@ -215,7 +214,6 @@ impl DepNode { MirKrate => Some(MirKrate), TypeckBodiesKrate => Some(TypeckBodiesKrate), CollectLanguageItems => Some(CollectLanguageItems), - CheckStaticRecursion => Some(CheckStaticRecursion), ResolveLifetimes => Some(ResolveLifetimes), RegionResolveCrate => Some(RegionResolveCrate), PluginRegistrar => Some(PluginRegistrar), diff --git a/src/librustc_passes/static_recursion.rs b/src/librustc_passes/static_recursion.rs index fc05471ead30b..d0bf49b7b337d 100644 --- a/src/librustc_passes/static_recursion.rs +++ b/src/librustc_passes/static_recursion.rs @@ -11,7 +11,6 @@ // This compiler pass detects constants that refer to themselves // recursively. -use rustc::dep_graph::DepNode; use rustc::hir::map as hir_map; use rustc::session::{CompileResult, Session}; use rustc::hir::def::{Def, CtorKind}; @@ -88,8 +87,6 @@ impl<'a, 'hir: 'a> Visitor<'hir> for CheckCrateVisitor<'a, 'hir> { } pub fn check_crate<'hir>(sess: &Session, hir_map: &hir_map::Map<'hir>) -> CompileResult { - let _task = hir_map.dep_graph.in_task(DepNode::CheckStaticRecursion); - let mut visitor = CheckCrateVisitor { sess: sess, hir_map: hir_map, From a83734dd96e303f484972dba9b446b3dda478f2e Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 4 Apr 2017 11:19:36 -0400 Subject: [PATCH 3/6] remove `EffectCheck` --- src/librustc/dep_graph/dep_node.rs | 2 -- src/librustc/middle/effect.rs | 3 --- 2 files changed, 5 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 0521b50df4d2d..b3878819378f7 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -64,7 +64,6 @@ pub enum DepNode { CollectItem(D), CollectItemSig(D), Coherence, - EffectCheck, Liveness, Resolve, EntryPoint, @@ -219,7 +218,6 @@ impl DepNode { PluginRegistrar => Some(PluginRegistrar), StabilityIndex => Some(StabilityIndex), Coherence => Some(Coherence), - EffectCheck => Some(EffectCheck), Liveness => Some(Liveness), Resolve => Some(Resolve), EntryPoint => Some(EntryPoint), diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index 5af8e7e52d888..d2b8ed8c29707 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -12,7 +12,6 @@ //! `unsafe`. use self::RootUnsafeContext::*; -use dep_graph::DepNode; use ty::{self, Ty, TyCtxt}; use ty::MethodCall; use lint; @@ -241,8 +240,6 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> { } pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { - let _task = tcx.dep_graph.in_task(DepNode::EffectCheck); - let mut visitor = EffectCheckVisitor { tcx: tcx, tables: &ty::TypeckTables::empty(), From a2a4fad6f787869bc3ae96e02082938e0a6dbef9 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 4 Apr 2017 11:28:48 -0400 Subject: [PATCH 4/6] kill `Liveness` --- src/librustc/dep_graph/dep_node.rs | 2 -- src/librustc/middle/liveness.rs | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index b3878819378f7..59d04ea8c771c 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -64,7 +64,6 @@ pub enum DepNode { CollectItem(D), CollectItemSig(D), Coherence, - Liveness, Resolve, EntryPoint, CheckEntryFn, @@ -218,7 +217,6 @@ impl DepNode { PluginRegistrar => Some(PluginRegistrar), StabilityIndex => Some(StabilityIndex), Coherence => Some(Coherence), - Liveness => Some(Liveness), Resolve => Some(Resolve), EntryPoint => Some(EntryPoint), CheckEntryFn => Some(CheckEntryFn), diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 7cae08efc0de0..b7da8480c1cef 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -109,7 +109,6 @@ use self::LoopKind::*; use self::LiveNodeKind::*; use self::VarKind::*; -use dep_graph::DepNode; use hir::def::*; use ty::{self, TyCtxt, ParameterEnvironment}; use traits::{self, Reveal}; @@ -196,7 +195,6 @@ impl<'a, 'tcx> Visitor<'tcx> for IrMaps<'a, 'tcx> { } pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { - let _task = tcx.dep_graph.in_task(DepNode::Liveness); tcx.hir.krate().visit_all_item_likes(&mut IrMaps::new(tcx).as_deep_visitor()); tcx.sess.abort_if_errors(); } From a4d7c1fec361219d237f39b5e32c09c72ca69fac Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 4 Apr 2017 12:06:35 -0400 Subject: [PATCH 5/6] push `borrowck` into its own task --- src/librustc/hir/map/mod.rs | 21 ++++++++++++++++++ src/librustc/ty/maps.rs | 2 ++ src/librustc_borrowck/borrowck/mod.rs | 32 +++++++++++++-------------- src/librustc_borrowck/lib.rs | 2 ++ src/librustc_driver/driver.rs | 1 + 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index d7aa36b24f942..cfafec00ae20d 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -442,6 +442,27 @@ impl<'hir> Map<'hir> { self.local_def_id(self.body_owner(id)) } + /// Given a body owner's id, returns the `BodyId` associated with it. + pub fn body_owned_by(&self, id: NodeId) -> BodyId { + if let Some(entry) = self.find_entry(id) { + if let Some(body_id) = entry.associated_body() { + // For item-like things and closures, the associated + // body has its own distinct id, and that is returned + // by `associated_body`. + body_id + } else { + // For some expressions, the expression is its own body. + if let EntryExpr(_, expr) = entry { + BodyId { node_id: expr.id } + } else { + span_bug!(self.span(id), "id `{}` has no associated body", id); + } + } + } else { + bug!("no entry for id `{}`", id) + } + } + pub fn ty_param_owner(&self, id: NodeId) -> NodeId { match self.get(id) { NodeItem(&Item { node: ItemTrait(..), .. }) => id, diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 4a183191cef29..219dbc4998e04 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -423,6 +423,8 @@ define_maps! { <'tcx> pub coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (), + pub borrowck: BorrowCheck(DefId) -> (), + /// Gets a complete map from all types to their inherent impls. /// Not meant to be used directly outside of coherence. /// (Defined only for LOCAL_CRATE) diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 0915c57b588eb..e0b4a23010d2f 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -22,7 +22,6 @@ pub use self::mir::elaborate_drops::ElaborateDrops; use self::InteriorKind::*; -use rustc::dep_graph::DepNode; use rustc::hir::map as hir_map; use rustc::hir::map::blocks::FnLikeNode; use rustc::cfg; @@ -37,12 +36,13 @@ use rustc::middle::mem_categorization::Categorization; use rustc::middle::mem_categorization::ImmutabilityBlame; use rustc::middle::region; use rustc::ty::{self, TyCtxt}; +use rustc::ty::maps::Providers; use std::fmt; use std::rc::Rc; use std::hash::{Hash, Hasher}; use syntax::ast; -use syntax_pos::{MultiSpan, Span}; +use syntax_pos::{DUMMY_SP, MultiSpan, Span}; use errors::DiagnosticBuilder; use rustc::hir; @@ -62,16 +62,16 @@ pub struct LoanDataFlowOperator; pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator>; pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { - tcx.dep_graph.with_task(DepNode::BorrowCheckKrate, tcx, (), check_crate_task); - - fn check_crate_task<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, (): ()) { - tcx.visit_all_bodies_in_krate(|body_owner_def_id, body_id| { - tcx.dep_graph.with_task(DepNode::BorrowCheck(body_owner_def_id), - tcx, - body_id, - borrowck_fn); - }); - } + tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| { + ty::queries::borrowck::get(tcx, DUMMY_SP, body_owner_def_id); + }); +} + +pub fn provide(providers: &mut Providers) { + *providers = Providers { + borrowck: borrowck, + ..*providers + }; } /// Collection of conclusions determined via borrow checker analyses. @@ -81,11 +81,11 @@ pub struct AnalysisData<'a, 'tcx: 'a> { pub move_data: move_data::FlowedMoveData<'a, 'tcx>, } -fn borrowck_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, body_id: hir::BodyId) { - debug!("borrowck_fn(body_id={:?})", body_id); +fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId) { + debug!("borrowck(body_owner_def_id={:?})", owner_def_id); - let owner_id = tcx.hir.body_owner(body_id); - let owner_def_id = tcx.hir.local_def_id(owner_id); + let owner_id = tcx.hir.as_local_node_id(owner_def_id).unwrap(); + let body_id = tcx.hir.body_owned_by(owner_id); let attributes = tcx.get_attrs(owner_def_id); let tables = tcx.item_tables(owner_def_id); diff --git a/src/librustc_borrowck/lib.rs b/src/librustc_borrowck/lib.rs index d3b22884a3d8c..a1d3357faf566 100644 --- a/src/librustc_borrowck/lib.rs +++ b/src/librustc_borrowck/lib.rs @@ -51,4 +51,6 @@ mod borrowck; pub mod graphviz; +pub use borrowck::provide; + __build_diagnostic_array! { librustc_borrowck, DIAGNOSTICS } diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 977382b33adf7..13486d898cff3 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -887,6 +887,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session, let mut local_providers = ty::maps::Providers::default(); mir::provide(&mut local_providers); rustc_privacy::provide(&mut local_providers); + borrowck::provide(&mut local_providers); typeck::provide(&mut local_providers); ty::provide(&mut local_providers); From 2e327a668e0f37fa9663ede580d354e28fc016bf Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 12 Apr 2017 05:42:02 -0400 Subject: [PATCH 6/6] fix nit --- src/librustc_borrowck/borrowck/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index e0b4a23010d2f..142286bd834d0 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -69,7 +69,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { pub fn provide(providers: &mut Providers) { *providers = Providers { - borrowck: borrowck, + borrowck, ..*providers }; }