]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Remove lang item methods from CrateStore
authorAlex Crichton <alex@alexcrichton.com>
Thu, 31 Aug 2017 16:19:33 +0000 (09:19 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 5 Sep 2017 14:37:58 +0000 (07:37 -0700)
Given the previous commit, these are now trivially representable as queries!

src/librustc/dep_graph/dep_node.rs
src/librustc/middle/cstore.rs
src/librustc/middle/lang_items.rs
src/librustc/middle/weak_lang_items.rs
src/librustc/ty/context.rs
src/librustc/ty/maps.rs
src/librustc_driver/test.rs
src/librustc_metadata/cstore_impl.rs
src/librustdoc/clean/inline.rs
src/librustdoc/clean/mod.rs
src/test/compile-fail/weak-lang-item.rs

index 3d003b96583884033e6b59e4d798c720be714266..1c52725c910593cc06589723707e896d019c84df 100644 (file)
@@ -561,6 +561,8 @@ pub fn to_dep_node(self, tcx: TyCtxt, kind: DepKind) -> DepNode {
     [] ItemChildren(DefId),
     [] ExternModStmtCnum(HirId),
     [] GetLangItems,
+    [] DefinedLangItems(CrateNum),
+    [] MissingLangItems(CrateNum),
 );
 
 trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
index 61a923a5954be86178bde37da84fcaf1311d7664..b7fdfe4a6359e648784b1fb8e02fa3ee378d7e92 100644 (file)
@@ -28,7 +28,6 @@
 use hir::map::definitions::{Definitions, DefKey, DefPathTable};
 use hir::svh::Svh;
 use ich;
-use middle::lang_items;
 use ty::{self, TyCtxt};
 use session::Session;
 use session::search_paths::PathKind;
@@ -243,10 +242,6 @@ pub trait CrateStore {
     // trait/impl-item info
     fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem;
 
-    // crate metadata
-    fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>;
-    fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>;
-
     // resolve
     fn def_key(&self, def: DefId) -> DefKey;
     fn def_path(&self, def: DefId) -> hir_map::DefPath;
@@ -332,10 +327,6 @@ fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem
         { bug!("associated_item_cloned") }
 
     // crate metadata
-    fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>
-        { bug!("lang_items") }
-    fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>
-        { bug!("missing_lang_items") }
     fn dep_kind_untracked(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
     fn export_macros_untracked(&self, cnum: CrateNum) { bug!("export_macros") }
     fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol { bug!("crate_name") }
index d08d7eb48b6231720296f3da2f56eda483b97aac..d7cc47f9ee78dfc1c8ede3407c6dc4a63e8da14f 100644 (file)
@@ -209,7 +209,7 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option<Symbol> {
 pub fn collect<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> LanguageItems {
     let mut collector = LanguageItemCollector::new(tcx);
     for cnum in tcx.sess.cstore.crates() {
-        for (index, item_index) in tcx.sess.cstore.lang_items(cnum) {
+        for &(index, item_index) in tcx.defined_lang_items(cnum).iter() {
             let def_id = DefId { krate: cnum, index: index };
             collector.collect_item(item_index, def_id);
         }
index 31114f8e302cf2719808ce13bb6aa3681eaaa6d4..ad6702ed21f8d0352662868714a5b9923accab27 100644 (file)
@@ -84,7 +84,7 @@ fn verify<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
 
     let mut missing = HashSet::new();
     for cnum in tcx.sess.cstore.crates() {
-        for item in tcx.sess.cstore.missing_lang_items(cnum) {
+        for &item in tcx.missing_lang_items(cnum).iter() {
             missing.insert(item);
         }
     }
index c40edff8ed71b8dc77b3bc1b8bec3bff1abb917f..0e02d5b992a52a79396ee4531bc23715e07280ec 100644 (file)
@@ -1097,7 +1097,17 @@ pub fn consider_optimizing<T: Fn() -> String>(&self, msg: T) -> bool {
     }
 
     pub fn lang_items(self) -> Rc<middle::lang_items::LanguageItems> {
-        self.get_lang_items(LOCAL_CRATE)
+        // Right now we insert a `with_ignore` node in the dep graph here to
+        // ignore the fact that `get_lang_items` below depends on the entire
+        // crate.  For now this'll prevent false positives of recompiling too
+        // much when anything changes.
+        //
+        // Once red/green incremental compilation lands we should be able to
+        // remove this because while the crate changes often the lint level map
+        // will change rarely.
+        self.dep_graph.with_ignore(|| {
+            self.get_lang_items(LOCAL_CRATE)
+        })
     }
 }
 
index 163645007906977022dcb4fad27be5b811ca48a2..fc7dcb16ea05784515f414c54e494a039f97afb1 100644 (file)
@@ -10,7 +10,7 @@
 
 use dep_graph::{DepConstructor, DepNode, DepNodeIndex};
 use errors::{Diagnostic, DiagnosticBuilder};
-use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
+use hir::def_id::{CrateNum, DefId, LOCAL_CRATE, DefIndex};
 use hir::def::{Def, Export};
 use hir::{self, TraitCandidate, HirId};
 use hir::svh::Svh;
@@ -22,7 +22,7 @@
 use middle::region;
 use middle::region::RegionMaps;
 use middle::resolve_lifetime::{Region, ObjectLifetimeDefault};
-use middle::lang_items::LanguageItems;
+use middle::lang_items::{LanguageItems, LangItem};
 use mir;
 use mir::transform::{MirSuite, MirPassIndex};
 use session::CompileResult;
@@ -694,6 +694,18 @@ fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
     }
 }
 
+impl<'tcx> QueryDescription for queries::defined_lang_items<'tcx> {
+    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
+        format!("calculating the lang items defined in a crate")
+    }
+}
+
+impl<'tcx> QueryDescription for queries::missing_lang_items<'tcx> {
+    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
+        format!("calculating the missing lang items in a crate")
+    }
+}
+
 // If enabled, send a message to the profile-queries thread
 macro_rules! profq_msg {
     ($tcx:expr, $msg:expr) => {
@@ -1301,6 +1313,8 @@ fn default() -> Self {
     [] extern_mod_stmt_cnum: ExternModStmtCnum(HirId) -> Option<CrateNum>,
 
     [] get_lang_items: get_lang_items_node(CrateNum) -> Rc<LanguageItems>,
+    [] defined_lang_items: DefinedLangItems(CrateNum) -> Rc<Vec<(DefIndex, usize)>>,
+    [] missing_lang_items: MissingLangItems(CrateNum) -> Rc<Vec<LangItem>>,
 }
 
 fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
index 552130e8a4703dab1c7e0e7333892751a6d89b2b..567c8b7e3f73df1b8d6d5968e4d8445818d06c93 100644 (file)
@@ -15,7 +15,6 @@
 use rustc_lint;
 use rustc_resolve::MakeGlobMap;
 use rustc_trans;
-use rustc::middle::lang_items;
 use rustc::middle::free_region::FreeRegionMap;
 use rustc::middle::region;
 use rustc::middle::resolve_lifetime;
@@ -140,7 +139,6 @@ fn test_env<F>(source_string: &str,
     let hir_map = hir_map::map_crate(&mut hir_forest, defs);
 
     // run just enough stuff to build a tcx:
-    let lang_items = lang_items::collect_language_items(&sess, &hir_map);
     let named_region_map = resolve_lifetime::krate(&sess, &hir_map);
     let index = stability::Index::new(&sess);
     TyCtxt::create_and_enter(&sess,
@@ -152,7 +150,6 @@ fn test_env<F>(source_string: &str,
                              resolutions,
                              named_region_map.unwrap(),
                              hir_map,
-                             lang_items,
                              index,
                              "test_crate",
                              |tcx| {
index 326ec8398080375220b49abd5a7048e8d64ffb6c..16cbc52ced98fb1f275cbbbded69dec2fa56599e 100644 (file)
                             LinkagePreference, LoadedMacro, EncodedMetadata,
                             EncodedMetadataHashes, NativeLibraryKind};
 use rustc::hir::def;
-use rustc::middle::lang_items;
 use rustc::session::Session;
 use rustc::ty::{self, TyCtxt};
 use rustc::ty::maps::Providers;
-use rustc::hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, CRATE_DEF_INDEX};
+use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, CRATE_DEF_INDEX};
 use rustc::hir::map::{DefKey, DefPath, DefPathHash};
 use rustc::hir::map::blocks::FnLikeNode;
 use rustc::hir::map::definitions::{DefPathTable, GlobalMetaDataKind};
@@ -213,6 +212,8 @@ fn into_args(self) -> (DefId, DefId) { (self.0.as_def_id(), self.1) }
         cdata.each_child_of_item(def_id.index, |child| result.push(child), tcx.sess);
         Rc::new(result)
     }
+    defined_lang_items => { Rc::new(cdata.get_lang_items(&tcx.dep_graph)) }
+    missing_lang_items => { Rc::new(cdata.get_missing_lang_items(&tcx.dep_graph)) }
 }
 
 pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
@@ -305,17 +306,6 @@ fn export_macros_untracked(&self, cnum: CrateNum) {
         }
     }
 
-    fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>
-    {
-        self.get_crate_data(cnum).get_lang_items(&self.dep_graph)
-    }
-
-    fn missing_lang_items(&self, cnum: CrateNum)
-                          -> Vec<lang_items::LangItem>
-    {
-        self.get_crate_data(cnum).get_missing_lang_items(&self.dep_graph)
-    }
-
     fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol
     {
         self.get_crate_data(cnum).name
index e9c6c0ce02a2711fe41491f516ffd5a5a041f063..fcd0e58a985528007d7eb45da21273e44fe54b43 100644 (file)
@@ -243,26 +243,27 @@ pub fn build_impls(cx: &DocContext, did: DefId) -> Vec<clean::Item> {
     }
 
     // Also try to inline primitive impls from other crates.
+    let lang_items = tcx.lang_items();
     let primitive_impls = [
-        tcx.lang_items.isize_impl(),
-        tcx.lang_items.i8_impl(),
-        tcx.lang_items.i16_impl(),
-        tcx.lang_items.i32_impl(),
-        tcx.lang_items.i64_impl(),
-        tcx.lang_items.i128_impl(),
-        tcx.lang_items.usize_impl(),
-        tcx.lang_items.u8_impl(),
-        tcx.lang_items.u16_impl(),
-        tcx.lang_items.u32_impl(),
-        tcx.lang_items.u64_impl(),
-        tcx.lang_items.u128_impl(),
-        tcx.lang_items.f32_impl(),
-        tcx.lang_items.f64_impl(),
-        tcx.lang_items.char_impl(),
-        tcx.lang_items.str_impl(),
-        tcx.lang_items.slice_impl(),
-        tcx.lang_items.const_ptr_impl(),
-        tcx.lang_items.mut_ptr_impl(),
+        lang_items.isize_impl(),
+        lang_items.i8_impl(),
+        lang_items.i16_impl(),
+        lang_items.i32_impl(),
+        lang_items.i64_impl(),
+        lang_items.i128_impl(),
+        lang_items.usize_impl(),
+        lang_items.u8_impl(),
+        lang_items.u16_impl(),
+        lang_items.u32_impl(),
+        lang_items.u64_impl(),
+        lang_items.u128_impl(),
+        lang_items.f32_impl(),
+        lang_items.f64_impl(),
+        lang_items.char_impl(),
+        lang_items.str_impl(),
+        lang_items.slice_impl(),
+        lang_items.const_ptr_impl(),
+        lang_items.mut_ptr_impl(),
     ];
 
     for def_id in primitive_impls.iter().filter_map(|&def_id| def_id) {
@@ -401,7 +402,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
             clean::RegionBound(..) => unreachable!(),
         }
     });
-    if trait_.def_id() == tcx.lang_items.deref_trait() {
+    if trait_.def_id() == tcx.lang_items().deref_trait() {
         super::build_deref_target_impls(cx, &trait_items, ret);
     }
 
index 0a9583278c6d0d56fd16b405015865a96d780037..9d61bc2fa5aab341e22669f8b95e3c11cb75d549 100644 (file)
@@ -125,9 +125,9 @@ fn clean(&self, cx: &DocContext) -> Crate {
 
         {
             let mut r = cx.renderinfo.borrow_mut();
-            r.deref_trait_did = cx.tcx.lang_items.deref_trait();
-            r.deref_mut_trait_did = cx.tcx.lang_items.deref_mut_trait();
-            r.owned_box_did = cx.tcx.lang_items.owned_box();
+            r.deref_trait_did = cx.tcx.lang_items().deref_trait();
+            r.deref_mut_trait_did = cx.tcx.lang_items().deref_mut_trait();
+            r.owned_box_did = cx.tcx.lang_items().owned_box();
         }
 
         let mut externs = Vec::new();
@@ -689,7 +689,7 @@ fn maybe_sized(cx: &DocContext) -> TyParamBound {
     fn is_sized_bound(&self, cx: &DocContext) -> bool {
         use rustc::hir::TraitBoundModifier as TBM;
         if let TyParamBound::TraitBound(PolyTrait { ref trait_, .. }, TBM::None) = *self {
-            if trait_.def_id() == cx.tcx.lang_items.sized_trait() {
+            if trait_.def_id() == cx.tcx.lang_items().sized_trait() {
                 return true;
             }
         }
@@ -713,7 +713,7 @@ fn external_path_params(cx: &DocContext, trait_did: Option<DefId>, has_self: boo
 
     match trait_did {
         // Attempt to sugar an external path like Fn<(A, B,), C> to Fn(A, B) -> C
-        Some(did) if cx.tcx.lang_items.fn_trait_kind(did).is_some() => {
+        Some(did) if cx.tcx.lang_items().fn_trait_kind(did).is_some() => {
             assert_eq!(types.len(), 1);
             let inputs = match types[0].sty {
                 ty::TyTuple(ref tys, _) => tys.iter().map(|t| t.clean(cx)).collect(),
@@ -2526,7 +2526,7 @@ fn clean(&self, cx: &DocContext) -> Vec<Item> {
 
         // If this impl block is an implementation of the Deref trait, then we
         // need to try inlining the target's inherent impl blocks as well.
-        if trait_.def_id() == cx.tcx.lang_items.deref_trait() {
+        if trait_.def_id() == cx.tcx.lang_items().deref_trait() {
             build_deref_target_impls(cx, &items, &mut ret);
         }
 
@@ -2582,27 +2582,27 @@ fn build_deref_target_impls(cx: &DocContext,
             }
         };
         let did = match primitive {
-            Isize => tcx.lang_items.isize_impl(),
-            I8 => tcx.lang_items.i8_impl(),
-            I16 => tcx.lang_items.i16_impl(),
-            I32 => tcx.lang_items.i32_impl(),
-            I64 => tcx.lang_items.i64_impl(),
-            I128 => tcx.lang_items.i128_impl(),
-            Usize => tcx.lang_items.usize_impl(),
-            U8 => tcx.lang_items.u8_impl(),
-            U16 => tcx.lang_items.u16_impl(),
-            U32 => tcx.lang_items.u32_impl(),
-            U64 => tcx.lang_items.u64_impl(),
-            U128 => tcx.lang_items.u128_impl(),
-            F32 => tcx.lang_items.f32_impl(),
-            F64 => tcx.lang_items.f64_impl(),
-            Char => tcx.lang_items.char_impl(),
+            Isize => tcx.lang_items().isize_impl(),
+            I8 => tcx.lang_items().i8_impl(),
+            I16 => tcx.lang_items().i16_impl(),
+            I32 => tcx.lang_items().i32_impl(),
+            I64 => tcx.lang_items().i64_impl(),
+            I128 => tcx.lang_items().i128_impl(),
+            Usize => tcx.lang_items().usize_impl(),
+            U8 => tcx.lang_items().u8_impl(),
+            U16 => tcx.lang_items().u16_impl(),
+            U32 => tcx.lang_items().u32_impl(),
+            U64 => tcx.lang_items().u64_impl(),
+            U128 => tcx.lang_items().u128_impl(),
+            F32 => tcx.lang_items().f32_impl(),
+            F64 => tcx.lang_items().f64_impl(),
+            Char => tcx.lang_items().char_impl(),
             Bool => None,
-            Str => tcx.lang_items.str_impl(),
-            Slice => tcx.lang_items.slice_impl(),
-            Array => tcx.lang_items.slice_impl(),
+            Str => tcx.lang_items().str_impl(),
+            Slice => tcx.lang_items().slice_impl(),
+            Array => tcx.lang_items().slice_impl(),
             Tuple => None,
-            RawPointer => tcx.lang_items.const_ptr_impl(),
+            RawPointer => tcx.lang_items().const_ptr_impl(),
             Reference => None,
             Fn => None,
         };
index fdf50c27bf4cf2c8176b61d278de0e31458b15da..8eac959fc1e900c0f574397526afc322c966f980 100644 (file)
@@ -16,3 +16,5 @@
 
 extern crate core;
 extern crate weak_lang_items;
+
+fn main() {}