about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Woerister <michaelwoerister@posteo.net>2017-06-30 14:53:35 -0700
committerMichael Woerister <michaelwoerister@posteo.net>2017-07-10 12:20:56 +0200
commite00bec2dd4a8393213499c58312609c44112e8f7 (patch)
tree240519c0ed27a81f70b11bd6117cf69db4acc5f8
parent9808661b3d696c3f115b3dc3c68a8dc6cbc3bf72 (diff)
downloadrust-e00bec2dd4a8393213499c58312609c44112e8f7.tar.gz
rust-e00bec2dd4a8393213499c58312609c44112e8f7.zip
Allow 'tcx in define_dep_nodes! and deduplicate some DepNodes.
-rw-r--r--src/librustc/dep_graph/dep_node.rs32
-rw-r--r--src/librustc/ty/instance.rs22
-rw-r--r--src/librustc/ty/maps.rs72
-rw-r--r--src/librustc_metadata/cstore_impl.rs4
4 files changed, 58 insertions, 72 deletions
diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs
index 887a7a4fe04..1c30a19d2d9 100644
--- a/src/librustc/dep_graph/dep_node.rs
+++ b/src/librustc/dep_graph/dep_node.rs
@@ -64,7 +64,8 @@ use hir::def_id::{CrateNum, DefId};
 use hir::map::DefPathHash;
 
 use ich::Fingerprint;
-use ty::TyCtxt;
+use ty::fast_reject::SimplifiedType;
+use ty::{TyCtxt, Instance, InstanceDef};
 use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
 use ich::StableHashingContext;
 use std::fmt;
@@ -78,7 +79,8 @@ macro_rules! erase {
 }
 
 macro_rules! define_dep_nodes {
-    ($(
+    (<$tcx:tt>
+    $(
         $variant:ident $(( $($tuple_arg:tt),* ))*
                        $({ $($struct_arg_name:ident : $struct_arg_ty:ty),* })*
       ,)*
@@ -92,7 +94,7 @@ macro_rules! define_dep_nodes {
         impl DepKind {
             #[allow(unreachable_code)]
             #[inline]
-            pub fn can_reconstruct_query_key(&self) -> bool {
+            pub fn can_reconstruct_query_key<$tcx>(&self) -> bool {
                 match *self {
                     $(
                         DepKind :: $variant => {
@@ -139,7 +141,7 @@ macro_rules! define_dep_nodes {
             }
         }
 
-        pub enum DepConstructor {
+        pub enum DepConstructor<$tcx> {
             $(
                 $variant $(( $($tuple_arg),* ))*
                          $({ $($struct_arg_name : $struct_arg_ty),* })*
@@ -155,7 +157,7 @@ macro_rules! define_dep_nodes {
 
         impl DepNode {
             #[allow(unreachable_code, non_snake_case)]
-            pub fn new(tcx: TyCtxt, dep: DepConstructor) -> DepNode {
+            pub fn new<'a, 'gcx: 'a+'tcx, 'tcx: 'a>(tcx: TyCtxt<'a, 'gcx, 'tcx>, dep: DepConstructor<'gcx>) -> DepNode {
                 match dep {
                     $(
                         DepConstructor :: $variant $(( $($tuple_arg),* ))*
@@ -336,7 +338,7 @@ impl DefId {
     }
 }
 
-define_dep_nodes!(
+define_dep_nodes!( <'tcx>
     // Represents the `Krate` as a whole (the `hir::Krate` value) (as
     // distinct from the krate module). This is basically a hash of
     // the entire krate, so if you read from `Krate` (e.g., by calling
@@ -374,8 +376,11 @@ define_dep_nodes!(
 
     // Represents the MIR for a fn; also used as the task node for
     // things read/modify that MIR.
-    Mir(DefId),
-    MirShim(DefIdList),
+    MirConstQualif(DefId),
+    MirConst(DefId),
+    MirValidated(DefId),
+    MirOptimized(DefId),
+    MirShim { instance_def: InstanceDef<'tcx> },
 
     BorrowCheckKrate,
     BorrowCheck(DefId),
@@ -414,8 +419,10 @@ define_dep_nodes!(
     InherentImpls(DefId),
     TypeckBodiesKrate,
     TypeckTables(DefId),
+    HasTypeckTables(DefId),
     ConstEval(DefId),
     SymbolName(DefId),
+    InstanceSymbolName { instance: Instance<'tcx> },
     SpecializationGraph(DefId),
     ObjectSafety(DefId),
     IsCopy(DefId),
@@ -424,14 +431,9 @@ define_dep_nodes!(
     NeedsDrop(DefId),
     Layout(DefId),
 
-    // The set of impls for a given trait. Ultimately, it would be
-    // nice to get more fine-grained here (e.g., to include a
-    // simplified type), but we can't do that until we restructure the
-    // HIR to distinguish the *header* of an impl from its body.  This
-    // is because changes to the header may change the self-type of
-    // the impl and hence would require us to be more conservative
-    // than changes in the impl body.
+    // The set of impls for a given trait.
     TraitImpls(DefId),
+    RelevantTraitImpls(DefId, SimplifiedType),
 
     AllLocalTraitImpls,
 
diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs
index 76103148ec3..32063a2dda6 100644
--- a/src/librustc/ty/instance.rs
+++ b/src/librustc/ty/instance.rs
@@ -8,7 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use dep_graph::DepConstructor;
 use hir::def_id::DefId;
 use ty::{self, Ty, TypeFoldable, Substs};
 use util::ppaux;
@@ -59,27 +58,6 @@ impl<'tcx> InstanceDef<'tcx> {
     pub fn attrs<'a>(&self, tcx: ty::TyCtxt<'a, 'tcx, 'tcx>) -> ty::Attributes<'tcx> {
         tcx.get_attrs(self.def_id())
     }
-
-    pub //(crate)
-     fn dep_node(&self) -> DepConstructor {
-        // HACK: def-id binning, project-style; someone replace this with
-        // real on-demand.
-        let ty = match self {
-            &InstanceDef::FnPtrShim(_, ty) => Some(ty),
-            &InstanceDef::DropGlue(_, ty) => ty,
-            _ => None
-        }.into_iter();
-
-        DepConstructor::MirShim(
-            Some(self.def_id()).into_iter().chain(
-                ty.flat_map(|t| t.walk()).flat_map(|t| match t.sty {
-                   ty::TyAdt(adt_def, _) => Some(adt_def.did),
-                   ty::TyProjection(ref proj) => Some(proj.trait_ref.def_id),
-                   _ => None,
-               })
-            ).collect()
-        )
-    }
 }
 
 impl<'tcx> fmt::Display for Instance<'tcx> {
diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs
index b584143c527..2b91b13d725 100644
--- a/src/librustc/ty/maps.rs
+++ b/src/librustc/ty/maps.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use dep_graph::{DepConstructor, DepNode, DepTrackingMapConfig};
+use dep_graph::{DepConstructor, DepNode};
 use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
 use hir::def::Def;
 use hir;
@@ -261,11 +261,16 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
     }
 }
 
-trait QueryDescription: DepTrackingMapConfig {
+pub trait QueryConfig {
+    type Key: Eq + Hash + Clone;
+    type Value;
+}
+
+trait QueryDescription: QueryConfig {
     fn describe(tcx: TyCtxt, key: Self::Key) -> String;
 }
 
-impl<M: DepTrackingMapConfig<Key=DefId>> QueryDescription for M {
+impl<M: QueryConfig<Key=DefId>> QueryDescription for M {
     default fn describe(tcx: TyCtxt, def_id: DefId) -> String {
         format!("processing `{}`", tcx.item_path_str(def_id))
     }
@@ -550,18 +555,19 @@ macro_rules! define_maps {
             })*
         }
 
-        $(impl<$tcx> DepTrackingMapConfig for queries::$name<$tcx> {
+        $(impl<$tcx> QueryConfig for queries::$name<$tcx> {
             type Key = $K;
             type Value = $V;
+        }
 
+        impl<'a, $tcx, 'lcx> queries::$name<$tcx> {
             #[allow(unused)]
-            fn to_dep_node(tcx: TyCtxt, key: &$K) -> DepNode {
+            fn to_dep_node(tcx: TyCtxt<'a, $tcx, 'lcx>, key: &$K) -> DepNode {
                 use dep_graph::DepConstructor::*;
 
                 DepNode::new(tcx, $node(*key))
             }
-        }
-        impl<'a, $tcx, 'lcx> queries::$name<$tcx> {
+
             fn try_get_with<F, R>(tcx: TyCtxt<'a, $tcx, 'lcx>,
                                   mut span: Span,
                                   key: $K,
@@ -861,19 +867,19 @@ define_maps! { <'tcx>
     /// Maps DefId's that have an associated Mir to the result
     /// of the MIR qualify_consts pass. The actual meaning of
     /// the value isn't known except to the pass itself.
-    [] mir_const_qualif: Mir(DefId) -> u8,
+    [] mir_const_qualif: MirConstQualif(DefId) -> u8,
 
     /// Fetch the MIR for a given def-id up till the point where it is
     /// ready for const evaluation.
     ///
     /// See the README for the `mir` module for details.
-    [] mir_const: Mir(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
+    [] mir_const: MirConst(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
 
-    [] mir_validated: Mir(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
+    [] mir_validated: MirValidated(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
 
     /// MIR after our optimization passes have run. This is MIR that is ready
     /// for trans. This is also the only query that can fetch non-local MIR, at present.
-    [] optimized_mir: Mir(DefId) -> &'tcx mir::Mir<'tcx>,
+    [] optimized_mir: MirOptimized(DefId) -> &'tcx mir::Mir<'tcx>,
 
     /// Type of each closure. The def ID is the ID of the
     /// expression defining the closure.
@@ -890,7 +896,7 @@ define_maps! { <'tcx>
 
     [] typeck_tables_of: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
 
-    [] has_typeck_tables: TypeckTables(DefId) -> bool,
+    [] has_typeck_tables: HasTypeckTables(DefId) -> bool,
 
     [] coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
 
@@ -972,80 +978,80 @@ define_maps! { <'tcx>
     [] extern_crate: ExternCrate(DefId) -> Rc<Option<ExternCrate>>,
 }
 
-fn type_param_predicates((item_id, param_id): (DefId, DefId)) -> DepConstructor {
+fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
     DepConstructor::TypeParamPredicates {
         item_id,
         param_id
     }
 }
 
-fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepConstructor {
+fn coherent_trait_dep_node<'tcx>((_, def_id): (CrateNum, DefId)) -> DepConstructor<'tcx> {
     DepConstructor::CoherenceCheckTrait(def_id)
 }
 
-fn crate_inherent_impls_dep_node(_: CrateNum) -> DepConstructor {
+fn crate_inherent_impls_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
     DepConstructor::Coherence
 }
 
-fn reachability_dep_node(_: CrateNum) -> DepConstructor {
+fn reachability_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
     DepConstructor::Reachability
 }
 
-fn mir_shim_dep_node(instance: ty::InstanceDef) -> DepConstructor {
-    instance.dep_node()
+fn mir_shim_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>) -> DepConstructor<'tcx> {
+    DepConstructor::MirShim {
+        instance_def
+    }
 }
 
-fn symbol_name_dep_node(instance: ty::Instance) -> DepConstructor {
-    // symbol_name uses the substs only to traverse them to find the
-    // hash, and that does not create any new dep-nodes.
-    DepConstructor::SymbolName(instance.def.def_id())
+fn symbol_name_dep_node<'tcx>(instance: ty::Instance<'tcx>) -> DepConstructor<'tcx> {
+    DepConstructor::InstanceSymbolName { instance }
 }
 
-fn typeck_item_bodies_dep_node(_: CrateNum) -> DepConstructor {
+fn typeck_item_bodies_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
     DepConstructor::TypeckBodiesKrate
 }
 
-fn const_eval_dep_node((def_id, _): (DefId, &Substs)) -> DepConstructor {
+fn const_eval_dep_node<'tcx>((def_id, _): (DefId, &Substs)) -> DepConstructor<'tcx> {
     DepConstructor::ConstEval(def_id)
 }
 
-fn mir_keys(_: CrateNum) -> DepConstructor {
+fn mir_keys<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
     DepConstructor::MirKeys
 }
 
-fn crate_variances(_: CrateNum) -> DepConstructor {
+fn crate_variances<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
     DepConstructor::CrateVariances
 }
 
-fn relevant_trait_impls_for((def_id, _): (DefId, SimplifiedType)) -> DepConstructor {
-    DepConstructor::TraitImpls(def_id)
+fn relevant_trait_impls_for<'tcx>((def_id, t): (DefId, SimplifiedType)) -> DepConstructor<'tcx> {
+    DepConstructor::RelevantTraitImpls(def_id, t)
 }
 
-fn is_copy_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor {
+fn is_copy_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
     let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
         .unwrap_or(DefId::local(CRATE_DEF_INDEX));
     DepConstructor::IsCopy(def_id)
 }
 
-fn is_sized_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor {
+fn is_sized_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
     let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
         .unwrap_or(DefId::local(CRATE_DEF_INDEX));
     DepConstructor::IsSized(def_id)
 }
 
-fn is_freeze_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor {
+fn is_freeze_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
     let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
         .unwrap_or(DefId::local(CRATE_DEF_INDEX));
     DepConstructor::IsFreeze(def_id)
 }
 
-fn needs_drop_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor {
+fn needs_drop_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
     let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
         .unwrap_or(DefId::local(CRATE_DEF_INDEX));
     DepConstructor::NeedsDrop(def_id)
 }
 
-fn layout_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor {
+fn layout_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
     let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
         .unwrap_or(DefId::local(CRATE_DEF_INDEX));
     DepConstructor::Layout(def_id)
diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs
index 86db6fa1f90..4bdfdd51f65 100644
--- a/src/librustc_metadata/cstore_impl.rs
+++ b/src/librustc_metadata/cstore_impl.rs
@@ -12,7 +12,7 @@ use cstore;
 use encoder;
 use schema;
 
-use rustc::dep_graph::DepTrackingMapConfig;
+use rustc::ty::maps::QueryConfig;
 use rustc::middle::cstore::{CrateStore, CrateSource, LibSource, DepKind,
                             NativeLibrary, MetadataLoader, LinkMeta,
                             LinkagePreference, LoadedMacro, EncodedMetadata};
@@ -45,7 +45,7 @@ macro_rules! provide {
         pub fn provide<$lt>(providers: &mut Providers<$lt>) {
             $(fn $name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $def_id: DefId)
                                     -> <ty::queries::$name<$lt> as
-                                        DepTrackingMapConfig>::Value {
+                                        QueryConfig>::Value {
                 assert!(!$def_id.is_local());
 
                 let def_path_hash = $tcx.def_path_hash($def_id);