]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/ty/maps.rs
rustc: Move some attr methods to queries
[rust.git] / src / librustc / ty / maps.rs
index 48b92d101edb3f8e07ed1d3fbfc42e4f619ab217..75c20a25131ab0795b209662274268518c69ce6c 100644 (file)
@@ -12,7 +12,7 @@
 use errors::{Diagnostic, DiagnosticBuilder};
 use hir::def_id::{CrateNum, DefId, LOCAL_CRATE, DefIndex};
 use hir::def::{Def, Export};
-use hir::{self, TraitCandidate, HirId};
+use hir::{self, TraitCandidate, ItemLocalId};
 use hir::svh::Svh;
 use lint;
 use middle::const_val;
@@ -23,6 +23,8 @@
 use middle::resolve_lifetime::{Region, ObjectLifetimeDefault};
 use middle::stability::{self, DeprecationEntry};
 use middle::lang_items::{LanguageItems, LangItem};
+use middle::exported_symbols::ExportedSymbols;
+use middle::trans::{TransItem, CodegenUnit};
 use mir;
 use mir::transform::{MirSuite, MirPassIndex};
 use session::CompileResult;
@@ -39,7 +41,7 @@
 use rustc_data_structures::indexed_set::IdxSetBuf;
 use rustc_back::PanicStrategy;
 use rustc_data_structures::indexed_vec::IndexVec;
-use rustc_data_structures::fx::FxHashMap;
+use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 use std::cell::{RefCell, RefMut, Cell};
 use std::fmt::Debug;
 use std::hash::Hash;
@@ -48,6 +50,7 @@
 use std::collections::BTreeMap;
 use std::ops::Deref;
 use std::rc::Rc;
+use std::sync::Arc;
 use syntax_pos::{Span, DUMMY_SP};
 use syntax::attr;
 use syntax::ast;
@@ -87,7 +90,7 @@ fn default_span(&self, _: TyCtxt) -> Span {
     }
 }
 
-impl Key for HirId {
+impl Key for DefIndex {
     fn map_crate(&self) -> CrateNum {
         LOCAL_CRATE
     }
@@ -159,7 +162,7 @@ fn default_span(&self, tcx: TyCtxt) -> Span {
     }
 }
 
-impl<'tcx, T: Clone + Hash + Eq + Debug> Key for ty::ParamEnvAnd<'tcx, T> {
+impl<'tcx> Key for Ty<'tcx> {
     fn map_crate(&self) -> CrateNum {
         LOCAL_CRATE
     }
@@ -168,6 +171,15 @@ fn default_span(&self, _: TyCtxt) -> Span {
     }
 }
 
+impl<'tcx, T: Key> Key for ty::ParamEnvAnd<'tcx, T> {
+    fn map_crate(&self) -> CrateNum {
+        self.value.map_crate()
+    }
+    fn default_span(&self, tcx: TyCtxt) -> Span {
+        self.value.default_span(tcx)
+    }
+}
+
 trait Value<'tcx>: Sized {
     fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Self;
 }
@@ -556,15 +568,9 @@ fn describe(_tcx: TyCtxt, _: (DefId, DefId)) -> String {
     }
 }
 
-impl<'tcx> QueryDescription for queries::in_scope_traits<'tcx> {
-    fn describe(_tcx: TyCtxt, _: HirId) -> String {
-        format!("fetching the traits in scope at a particular ast node")
-    }
-}
-
-impl<'tcx> QueryDescription for queries::module_exports<'tcx> {
-    fn describe(_tcx: TyCtxt, _: HirId) -> String {
-        format!("fetching the exported items for a module")
+impl<'tcx> QueryDescription for queries::in_scope_traits_map<'tcx> {
+    fn describe(_tcx: TyCtxt, _: DefIndex) -> String {
+        format!("traits in scope at a block")
     }
 }
 
@@ -592,7 +598,7 @@ fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
     }
 }
 
-impl<'tcx> QueryDescription for queries::exported_symbols<'tcx> {
+impl<'tcx> QueryDescription for queries::exported_symbol_ids<'tcx> {
     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
         format!("looking up the exported symbols of a crate")
     }
@@ -652,21 +658,21 @@ fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
     }
 }
 
-impl<'tcx> QueryDescription for queries::named_region<'tcx> {
-    fn describe(_tcx: TyCtxt, _: HirId) -> String {
-        format!("fetching info about a named region")
+impl<'tcx> QueryDescription for queries::named_region_map<'tcx> {
+    fn describe(_tcx: TyCtxt, _: DefIndex) -> String {
+        format!("looking up a named region")
     }
 }
 
-impl<'tcx> QueryDescription for queries::is_late_bound<'tcx> {
-    fn describe(_tcx: TyCtxt, _: HirId) -> String {
-        format!("testing whether a lifetime is late bound")
+impl<'tcx> QueryDescription for queries::is_late_bound_map<'tcx> {
+    fn describe(_tcx: TyCtxt, _: DefIndex) -> String {
+        format!("testing if a region is late boudn")
     }
 }
 
-impl<'tcx> QueryDescription for queries::object_lifetime_defaults<'tcx> {
-    fn describe(_tcx: TyCtxt, _: HirId) -> String {
-        format!("fetching a list of ObjectLifetimeDefault for a lifetime")
+impl<'tcx> QueryDescription for queries::object_lifetime_defaults_map<'tcx> {
+    fn describe(_tcx: TyCtxt, _: DefIndex) -> String {
+        format!("looking up lifetime defaults for a region")
     }
 }
 
@@ -682,12 +688,6 @@ fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
     }
 }
 
-impl<'tcx> QueryDescription for queries::extern_mod_stmt_cnum<'tcx> {
-    fn describe(_tcx: TyCtxt, _: HirId) -> String {
-        format!("looking up the CrateNum for an `extern mod` statement")
-    }
-}
-
 impl<'tcx> QueryDescription for queries::get_lang_items<'tcx> {
     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
         format!("calculating the lang items map")
@@ -730,18 +730,6 @@ fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
     }
 }
 
-impl<'tcx> QueryDescription for queries::freevars<'tcx> {
-    fn describe(_tcx: TyCtxt, _: HirId) -> String {
-        format!("looking up free variables for a node")
-    }
-}
-
-impl<'tcx> QueryDescription for queries::maybe_unused_trait_import<'tcx> {
-    fn describe(_tcx: TyCtxt, _: HirId) -> String {
-        format!("testing if a trait import is unused")
-    }
-}
-
 impl<'tcx> QueryDescription for queries::maybe_unused_extern_crates<'tcx> {
     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
         format!("looking up all possibly unused extern crates")
@@ -760,6 +748,18 @@ fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
     }
 }
 
+impl<'tcx> QueryDescription for queries::exported_symbol_set<'tcx> {
+    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
+        format!("exported symbol set")
+    }
+}
+
+impl<'tcx> QueryDescription for queries::collect_and_partition_translation_items<'tcx> {
+    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
+        format!("collect_and_partition_translation_items")
+    }
+}
+
 // If enabled, send a message to the profile-queries thread
 macro_rules! profq_msg {
     ($tcx:expr, $msg:expr) => {
@@ -1331,12 +1331,13 @@ fn default() -> Self {
     [] fn extern_crate: ExternCrate(DefId) -> Rc<Option<ExternCrate>>,
 
     [] fn specializes: specializes_node((DefId, DefId)) -> bool,
-    [] fn in_scope_traits: InScopeTraits(HirId) -> Option<Rc<Vec<TraitCandidate>>>,
-    [] fn module_exports: ModuleExports(HirId) -> Option<Rc<Vec<Export>>>,
+    [] fn in_scope_traits_map: InScopeTraits(DefIndex)
+        -> Option<Rc<FxHashMap<ItemLocalId, Rc<Vec<TraitCandidate>>>>>,
+    [] fn module_exports: ModuleExports(DefId) -> Option<Rc<Vec<Export>>>,
     [] fn lint_levels: lint_levels_node(CrateNum) -> Rc<lint::LintLevelMap>,
 
     [] fn impl_defaultness: ImplDefaultness(DefId) -> hir::Defaultness,
-    [] fn exported_symbols: ExportedSymbols(CrateNum) -> Rc<Vec<DefId>>,
+    [] fn exported_symbol_ids: ExportedSymbolIds(CrateNum) -> Rc<Vec<DefId>>,
     [] fn native_libraries: NativeLibraries(CrateNum) -> Rc<Vec<NativeLibrary>>,
     [] fn plugin_registrar_fn: PluginRegistrarFn(CrateNum) -> Option<DefId>,
     [] fn derive_registrar_fn: DeriveRegistrarFn(CrateNum) -> Option<DefId>,
@@ -1355,16 +1356,18 @@ fn default() -> Self {
         -> Option<NativeLibraryKind>,
     [] fn link_args: link_args_node(CrateNum) -> Rc<Vec<String>>,
 
-    [] fn named_region: NamedRegion(HirId) -> Option<Region>,
-    [] fn is_late_bound: IsLateBound(HirId) -> bool,
-    [] fn object_lifetime_defaults: ObjectLifetimeDefaults(HirId)
-        -> Option<Rc<Vec<ObjectLifetimeDefault>>>,
+    [] fn named_region_map: NamedRegion(DefIndex) ->
+        Option<Rc<FxHashMap<ItemLocalId, Region>>>,
+    [] fn is_late_bound_map: IsLateBound(DefIndex) ->
+        Option<Rc<FxHashSet<ItemLocalId>>>,
+    [] fn object_lifetime_defaults_map: ObjectLifetimeDefaults(DefIndex)
+        -> Option<Rc<FxHashMap<ItemLocalId, Rc<Vec<ObjectLifetimeDefault>>>>>,
 
     [] fn visibility: Visibility(DefId) -> ty::Visibility,
     [] fn dep_kind: DepKind(CrateNum) -> DepKind,
     [] fn crate_name: CrateName(CrateNum) -> Symbol,
     [] fn item_children: ItemChildren(DefId) -> Rc<Vec<Export>>,
-    [] fn extern_mod_stmt_cnum: ExternModStmtCnum(HirId) -> Option<CrateNum>,
+    [] fn extern_mod_stmt_cnum: ExternModStmtCnum(DefId) -> Option<CrateNum>,
 
     [] fn get_lang_items: get_lang_items_node(CrateNum) -> Rc<LanguageItems>,
     [] fn defined_lang_items: DefinedLangItems(CrateNum) -> Rc<Vec<(DefIndex, usize)>>,
@@ -1376,13 +1379,21 @@ fn default() -> Self {
     [] fn used_crate_source: UsedCrateSource(CrateNum) -> Rc<CrateSource>,
     [] fn postorder_cnums: postorder_cnums_node(CrateNum) -> Rc<Vec<CrateNum>>,
 
-    [] fn freevars: Freevars(HirId) -> Option<Rc<Vec<hir::Freevar>>>,
-    [] fn maybe_unused_trait_import: MaybeUnusedTraitImport(HirId) -> bool,
+    [] fn freevars: Freevars(DefId) -> Option<Rc<Vec<hir::Freevar>>>,
+    [] fn maybe_unused_trait_import: MaybeUnusedTraitImport(DefId) -> bool,
     [] fn maybe_unused_extern_crates: maybe_unused_extern_crates_node(CrateNum)
-        -> Rc<Vec<(HirId, Span)>>,
+        -> Rc<Vec<(DefId, Span)>>,
 
     [] fn stability_index: stability_index_node(CrateNum) -> Rc<stability::Index<'tcx>>,
     [] fn all_crate_nums: all_crate_nums_node(CrateNum) -> Rc<Vec<CrateNum>>,
+
+    [] fn exported_symbol_set: exported_symbol_set_node(CrateNum)
+        -> Arc<ExportedSymbols>,
+    [] fn collect_and_partition_translation_items:
+        collect_and_partition_translation_items_node(CrateNum)
+        -> (Arc<FxHashSet<TransItem<'tcx>>>, Vec<Arc<CodegenUnit<'tcx>>>),
+    [] fn export_name: ExportName(DefId) -> Option<Symbol>,
+    [] fn contains_extern_indicator: ContainsExternIndicator(DefId) -> bool,
 }
 
 fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
@@ -1496,3 +1507,11 @@ fn stability_index_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
 fn all_crate_nums_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
     DepConstructor::AllCrateNums
 }
+
+fn exported_symbol_set_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
+    DepConstructor::ExportedSymbols
+}
+
+fn collect_and_partition_translation_items_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
+    DepConstructor::CollectAndPartitionTranslationItems
+}