Skip to content

Commit 953490d

Browse files
committed
rustc: Remove lang item methods from CrateStore
Given the previous commit, these are now trivially representable as queries!
1 parent a2e2aba commit 953490d

File tree

11 files changed

+82
-75
lines changed

11 files changed

+82
-75
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ define_dep_nodes!( <'tcx>
561561
[] ItemChildren(DefId),
562562
[] ExternModStmtCnum(HirId),
563563
[] GetLangItems,
564+
[] DefinedLangItems(CrateNum),
565+
[] MissingLangItems(CrateNum),
564566
);
565567

566568
trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {

src/librustc/middle/cstore.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use hir::map as hir_map;
2828
use hir::map::definitions::{Definitions, DefKey, DefPathTable};
2929
use hir::svh::Svh;
3030
use ich;
31-
use middle::lang_items;
3231
use ty::{self, TyCtxt};
3332
use session::Session;
3433
use session::search_paths::PathKind;
@@ -243,10 +242,6 @@ pub trait CrateStore {
243242
// trait/impl-item info
244243
fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem;
245244

246-
// crate metadata
247-
fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>;
248-
fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>;
249-
250245
// resolve
251246
fn def_key(&self, def: DefId) -> DefKey;
252247
fn def_path(&self, def: DefId) -> hir_map::DefPath;
@@ -332,10 +327,6 @@ impl CrateStore for DummyCrateStore {
332327
{ bug!("associated_item_cloned") }
333328

334329
// crate metadata
335-
fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>
336-
{ bug!("lang_items") }
337-
fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>
338-
{ bug!("missing_lang_items") }
339330
fn dep_kind_untracked(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
340331
fn export_macros_untracked(&self, cnum: CrateNum) { bug!("export_macros") }
341332
fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol { bug!("crate_name") }

src/librustc/middle/lang_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option<Symbol> {
209209
pub fn collect<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> LanguageItems {
210210
let mut collector = LanguageItemCollector::new(tcx);
211211
for cnum in tcx.sess.cstore.crates() {
212-
for (index, item_index) in tcx.sess.cstore.lang_items(cnum) {
212+
for &(index, item_index) in tcx.defined_lang_items(cnum).iter() {
213213
let def_id = DefId { krate: cnum, index: index };
214214
collector.collect_item(item_index, def_id);
215215
}

src/librustc/middle/weak_lang_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn verify<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
8484

8585
let mut missing = HashSet::new();
8686
for cnum in tcx.sess.cstore.crates() {
87-
for item in tcx.sess.cstore.missing_lang_items(cnum) {
87+
for &item in tcx.missing_lang_items(cnum).iter() {
8888
missing.insert(item);
8989
}
9090
}

src/librustc/ty/context.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,17 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
10971097
}
10981098

10991099
pub fn lang_items(self) -> Rc<middle::lang_items::LanguageItems> {
1100-
self.get_lang_items(LOCAL_CRATE)
1100+
// Right now we insert a `with_ignore` node in the dep graph here to
1101+
// ignore the fact that `get_lang_items` below depends on the entire
1102+
// crate. For now this'll prevent false positives of recompiling too
1103+
// much when anything changes.
1104+
//
1105+
// Once red/green incremental compilation lands we should be able to
1106+
// remove this because while the crate changes often the lint level map
1107+
// will change rarely.
1108+
self.dep_graph.with_ignore(|| {
1109+
self.get_lang_items(LOCAL_CRATE)
1110+
})
11011111
}
11021112
}
11031113

src/librustc/ty/maps.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use dep_graph::{DepConstructor, DepNode, DepNodeIndex};
1212
use errors::{Diagnostic, DiagnosticBuilder};
13-
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
13+
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE, DefIndex};
1414
use hir::def::{Def, Export};
1515
use hir::{self, TraitCandidate, HirId};
1616
use hir::svh::Svh;
@@ -22,7 +22,7 @@ use middle::privacy::AccessLevels;
2222
use middle::region;
2323
use middle::region::RegionMaps;
2424
use middle::resolve_lifetime::{Region, ObjectLifetimeDefault};
25-
use middle::lang_items::LanguageItems;
25+
use middle::lang_items::{LanguageItems, LangItem};
2626
use mir;
2727
use mir::transform::{MirSuite, MirPassIndex};
2828
use session::CompileResult;
@@ -694,6 +694,18 @@ impl<'tcx> QueryDescription for queries::get_lang_items<'tcx> {
694694
}
695695
}
696696

697+
impl<'tcx> QueryDescription for queries::defined_lang_items<'tcx> {
698+
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
699+
format!("calculating the lang items defined in a crate")
700+
}
701+
}
702+
703+
impl<'tcx> QueryDescription for queries::missing_lang_items<'tcx> {
704+
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
705+
format!("calculating the missing lang items in a crate")
706+
}
707+
}
708+
697709
// If enabled, send a message to the profile-queries thread
698710
macro_rules! profq_msg {
699711
($tcx:expr, $msg:expr) => {
@@ -1301,6 +1313,8 @@ define_maps! { <'tcx>
13011313
[] extern_mod_stmt_cnum: ExternModStmtCnum(HirId) -> Option<CrateNum>,
13021314

13031315
[] get_lang_items: get_lang_items_node(CrateNum) -> Rc<LanguageItems>,
1316+
[] defined_lang_items: DefinedLangItems(CrateNum) -> Rc<Vec<(DefIndex, usize)>>,
1317+
[] missing_lang_items: MissingLangItems(CrateNum) -> Rc<Vec<LangItem>>,
13041318
}
13051319

13061320
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {

src/librustc_driver/test.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc::dep_graph::DepGraph;
1515
use rustc_lint;
1616
use rustc_resolve::MakeGlobMap;
1717
use rustc_trans;
18-
use rustc::middle::lang_items;
1918
use rustc::middle::free_region::FreeRegionMap;
2019
use rustc::middle::region;
2120
use rustc::middle::resolve_lifetime;
@@ -140,7 +139,6 @@ fn test_env<F>(source_string: &str,
140139
let hir_map = hir_map::map_crate(&mut hir_forest, defs);
141140

142141
// run just enough stuff to build a tcx:
143-
let lang_items = lang_items::collect_language_items(&sess, &hir_map);
144142
let named_region_map = resolve_lifetime::krate(&sess, &hir_map);
145143
let index = stability::Index::new(&sess);
146144
TyCtxt::create_and_enter(&sess,
@@ -152,7 +150,6 @@ fn test_env<F>(source_string: &str,
152150
resolutions,
153151
named_region_map.unwrap(),
154152
hir_map,
155-
lang_items,
156153
index,
157154
"test_crate",
158155
|tcx| {

src/librustc_metadata/cstore_impl.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ use rustc::middle::cstore::{CrateStore, CrateSource, LibSource, DepKind,
2020
LinkagePreference, LoadedMacro, EncodedMetadata,
2121
EncodedMetadataHashes, NativeLibraryKind};
2222
use rustc::hir::def;
23-
use rustc::middle::lang_items;
2423
use rustc::session::Session;
2524
use rustc::ty::{self, TyCtxt};
2625
use rustc::ty::maps::Providers;
27-
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, CRATE_DEF_INDEX};
26+
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, CRATE_DEF_INDEX};
2827
use rustc::hir::map::{DefKey, DefPath, DefPathHash};
2928
use rustc::hir::map::blocks::FnLikeNode;
3029
use rustc::hir::map::definitions::{DefPathTable, GlobalMetaDataKind};
@@ -213,6 +212,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
213212
cdata.each_child_of_item(def_id.index, |child| result.push(child), tcx.sess);
214213
Rc::new(result)
215214
}
215+
defined_lang_items => { Rc::new(cdata.get_lang_items(&tcx.dep_graph)) }
216+
missing_lang_items => { Rc::new(cdata.get_missing_lang_items(&tcx.dep_graph)) }
216217
}
217218

218219
pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
@@ -305,17 +306,6 @@ impl CrateStore for cstore::CStore {
305306
}
306307
}
307308

308-
fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>
309-
{
310-
self.get_crate_data(cnum).get_lang_items(&self.dep_graph)
311-
}
312-
313-
fn missing_lang_items(&self, cnum: CrateNum)
314-
-> Vec<lang_items::LangItem>
315-
{
316-
self.get_crate_data(cnum).get_missing_lang_items(&self.dep_graph)
317-
}
318-
319309
fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol
320310
{
321311
self.get_crate_data(cnum).name

src/librustdoc/clean/inline.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -243,26 +243,27 @@ pub fn build_impls(cx: &DocContext, did: DefId) -> Vec<clean::Item> {
243243
}
244244

245245
// Also try to inline primitive impls from other crates.
246+
let lang_items = tcx.lang_items();
246247
let primitive_impls = [
247-
tcx.lang_items.isize_impl(),
248-
tcx.lang_items.i8_impl(),
249-
tcx.lang_items.i16_impl(),
250-
tcx.lang_items.i32_impl(),
251-
tcx.lang_items.i64_impl(),
252-
tcx.lang_items.i128_impl(),
253-
tcx.lang_items.usize_impl(),
254-
tcx.lang_items.u8_impl(),
255-
tcx.lang_items.u16_impl(),
256-
tcx.lang_items.u32_impl(),
257-
tcx.lang_items.u64_impl(),
258-
tcx.lang_items.u128_impl(),
259-
tcx.lang_items.f32_impl(),
260-
tcx.lang_items.f64_impl(),
261-
tcx.lang_items.char_impl(),
262-
tcx.lang_items.str_impl(),
263-
tcx.lang_items.slice_impl(),
264-
tcx.lang_items.const_ptr_impl(),
265-
tcx.lang_items.mut_ptr_impl(),
248+
lang_items.isize_impl(),
249+
lang_items.i8_impl(),
250+
lang_items.i16_impl(),
251+
lang_items.i32_impl(),
252+
lang_items.i64_impl(),
253+
lang_items.i128_impl(),
254+
lang_items.usize_impl(),
255+
lang_items.u8_impl(),
256+
lang_items.u16_impl(),
257+
lang_items.u32_impl(),
258+
lang_items.u64_impl(),
259+
lang_items.u128_impl(),
260+
lang_items.f32_impl(),
261+
lang_items.f64_impl(),
262+
lang_items.char_impl(),
263+
lang_items.str_impl(),
264+
lang_items.slice_impl(),
265+
lang_items.const_ptr_impl(),
266+
lang_items.mut_ptr_impl(),
266267
];
267268

268269
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>) {
401402
clean::RegionBound(..) => unreachable!(),
402403
}
403404
});
404-
if trait_.def_id() == tcx.lang_items.deref_trait() {
405+
if trait_.def_id() == tcx.lang_items().deref_trait() {
405406
super::build_deref_target_impls(cx, &trait_items, ret);
406407
}
407408

src/librustdoc/clean/mod.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
125125

126126
{
127127
let mut r = cx.renderinfo.borrow_mut();
128-
r.deref_trait_did = cx.tcx.lang_items.deref_trait();
129-
r.deref_mut_trait_did = cx.tcx.lang_items.deref_mut_trait();
130-
r.owned_box_did = cx.tcx.lang_items.owned_box();
128+
r.deref_trait_did = cx.tcx.lang_items().deref_trait();
129+
r.deref_mut_trait_did = cx.tcx.lang_items().deref_mut_trait();
130+
r.owned_box_did = cx.tcx.lang_items().owned_box();
131131
}
132132

133133
let mut externs = Vec::new();
@@ -689,7 +689,7 @@ impl TyParamBound {
689689
fn is_sized_bound(&self, cx: &DocContext) -> bool {
690690
use rustc::hir::TraitBoundModifier as TBM;
691691
if let TyParamBound::TraitBound(PolyTrait { ref trait_, .. }, TBM::None) = *self {
692-
if trait_.def_id() == cx.tcx.lang_items.sized_trait() {
692+
if trait_.def_id() == cx.tcx.lang_items().sized_trait() {
693693
return true;
694694
}
695695
}
@@ -713,7 +713,7 @@ fn external_path_params(cx: &DocContext, trait_did: Option<DefId>, has_self: boo
713713

714714
match trait_did {
715715
// Attempt to sugar an external path like Fn<(A, B,), C> to Fn(A, B) -> C
716-
Some(did) if cx.tcx.lang_items.fn_trait_kind(did).is_some() => {
716+
Some(did) if cx.tcx.lang_items().fn_trait_kind(did).is_some() => {
717717
assert_eq!(types.len(), 1);
718718
let inputs = match types[0].sty {
719719
ty::TyTuple(ref tys, _) => tys.iter().map(|t| t.clean(cx)).collect(),
@@ -2526,7 +2526,7 @@ impl Clean<Vec<Item>> for doctree::Impl {
25262526

25272527
// If this impl block is an implementation of the Deref trait, then we
25282528
// need to try inlining the target's inherent impl blocks as well.
2529-
if trait_.def_id() == cx.tcx.lang_items.deref_trait() {
2529+
if trait_.def_id() == cx.tcx.lang_items().deref_trait() {
25302530
build_deref_target_impls(cx, &items, &mut ret);
25312531
}
25322532

@@ -2582,27 +2582,27 @@ fn build_deref_target_impls(cx: &DocContext,
25822582
}
25832583
};
25842584
let did = match primitive {
2585-
Isize => tcx.lang_items.isize_impl(),
2586-
I8 => tcx.lang_items.i8_impl(),
2587-
I16 => tcx.lang_items.i16_impl(),
2588-
I32 => tcx.lang_items.i32_impl(),
2589-
I64 => tcx.lang_items.i64_impl(),
2590-
I128 => tcx.lang_items.i128_impl(),
2591-
Usize => tcx.lang_items.usize_impl(),
2592-
U8 => tcx.lang_items.u8_impl(),
2593-
U16 => tcx.lang_items.u16_impl(),
2594-
U32 => tcx.lang_items.u32_impl(),
2595-
U64 => tcx.lang_items.u64_impl(),
2596-
U128 => tcx.lang_items.u128_impl(),
2597-
F32 => tcx.lang_items.f32_impl(),
2598-
F64 => tcx.lang_items.f64_impl(),
2599-
Char => tcx.lang_items.char_impl(),
2585+
Isize => tcx.lang_items().isize_impl(),
2586+
I8 => tcx.lang_items().i8_impl(),
2587+
I16 => tcx.lang_items().i16_impl(),
2588+
I32 => tcx.lang_items().i32_impl(),
2589+
I64 => tcx.lang_items().i64_impl(),
2590+
I128 => tcx.lang_items().i128_impl(),
2591+
Usize => tcx.lang_items().usize_impl(),
2592+
U8 => tcx.lang_items().u8_impl(),
2593+
U16 => tcx.lang_items().u16_impl(),
2594+
U32 => tcx.lang_items().u32_impl(),
2595+
U64 => tcx.lang_items().u64_impl(),
2596+
U128 => tcx.lang_items().u128_impl(),
2597+
F32 => tcx.lang_items().f32_impl(),
2598+
F64 => tcx.lang_items().f64_impl(),
2599+
Char => tcx.lang_items().char_impl(),
26002600
Bool => None,
2601-
Str => tcx.lang_items.str_impl(),
2602-
Slice => tcx.lang_items.slice_impl(),
2603-
Array => tcx.lang_items.slice_impl(),
2601+
Str => tcx.lang_items().str_impl(),
2602+
Slice => tcx.lang_items().slice_impl(),
2603+
Array => tcx.lang_items().slice_impl(),
26042604
Tuple => None,
2605-
RawPointer => tcx.lang_items.const_ptr_impl(),
2605+
RawPointer => tcx.lang_items().const_ptr_impl(),
26062606
Reference => None,
26072607
Fn => None,
26082608
};

0 commit comments

Comments
 (0)