Skip to content

Commit 52b67f9

Browse files
committed
rustc: Move original_crate_name to a query
1 parent d6c88f4 commit 52b67f9

File tree

8 files changed

+19
-21
lines changed

8 files changed

+19
-21
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ define_dep_nodes!( <'tcx>
541541
[] DeriveRegistrarFn(CrateNum),
542542
[] CrateDisambiguator(CrateNum),
543543
[] CrateHash(CrateNum),
544+
[] OriginalCrateName(CrateNum),
544545
);
545546

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

src/librustc/middle/cstore.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,6 @@ pub trait CrateStore {
251251
/// The name of the crate as it is referred to in source code of the current
252252
/// crate.
253253
fn crate_name(&self, cnum: CrateNum) -> Symbol;
254-
/// The name of the crate as it is stored in the crate's metadata.
255-
fn original_crate_name(&self, cnum: CrateNum) -> Symbol;
256254

257255
// resolve
258256
fn def_key(&self, def: DefId) -> DefKey;
@@ -349,9 +347,6 @@ impl CrateStore for DummyCrateStore {
349347
fn dep_kind(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
350348
fn export_macros(&self, cnum: CrateNum) { bug!("export_macros") }
351349
fn crate_name(&self, cnum: CrateNum) -> Symbol { bug!("crate_name") }
352-
fn original_crate_name(&self, cnum: CrateNum) -> Symbol {
353-
bug!("original_crate_name")
354-
}
355350

356351
// resolve
357352
fn def_key(&self, def: DefId) -> DefKey { bug!("def_key") }

src/librustc/ty/context.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -917,14 +917,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
917917
}
918918
}
919919

920-
pub fn original_crate_name(self, cnum: CrateNum) -> Symbol {
921-
if cnum == LOCAL_CRATE {
922-
self.crate_name.clone()
923-
} else {
924-
self.sess.cstore.original_crate_name(cnum)
925-
}
926-
}
927-
928920
pub fn alloc_generics(self, generics: ty::Generics) -> &'gcx ty::Generics {
929921
self.global_arenas.generics.alloc(generics)
930922
}

src/librustc/ty/maps.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,12 @@ impl<'tcx> QueryDescription for queries::crate_hash<'tcx> {
624624
}
625625
}
626626

627+
impl<'tcx> QueryDescription for queries::original_crate_name<'tcx> {
628+
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
629+
format!("looking up the original name a crate")
630+
}
631+
}
632+
627633
// If enabled, send a message to the profile-queries thread
628634
macro_rules! profq_msg {
629635
($tcx:expr, $msg:expr) => {
@@ -1206,6 +1212,7 @@ define_maps! { <'tcx>
12061212
[] fn derive_registrar_fn: DeriveRegistrarFn(CrateNum) -> Option<DefId>,
12071213
[] fn crate_disambiguator: CrateDisambiguator(CrateNum) -> Symbol,
12081214
[] fn crate_hash: CrateHash(CrateNum) -> Svh,
1215+
[] fn original_crate_name: OriginalCrateName(CrateNum) -> Symbol,
12091216
}
12101217

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

src/librustc/ty/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
22102210
if let Some(id) = self.hir.as_local_node_id(id) {
22112211
self.hir.name(id)
22122212
} else if id.index == CRATE_DEF_INDEX {
2213-
self.sess.cstore.original_crate_name(id.krate)
2213+
self.original_crate_name(id.krate)
22142214
} else {
22152215
let def_key = self.sess.cstore.def_key(id);
22162216
// The name of a StructCtor is that of its struct parent.
@@ -2516,6 +2516,12 @@ fn crate_disambiguator<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
25162516
tcx.sess.local_crate_disambiguator()
25172517
}
25182518

2519+
fn original_crate_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
2520+
crate_num: CrateNum) -> Symbol {
2521+
assert_eq!(crate_num, LOCAL_CRATE);
2522+
tcx.crate_name.clone()
2523+
}
2524+
25192525
pub fn provide(providers: &mut ty::maps::Providers) {
25202526
util::provide(providers);
25212527
context::provide(providers);
@@ -2528,6 +2534,7 @@ pub fn provide(providers: &mut ty::maps::Providers) {
25282534
param_env,
25292535
trait_of_item,
25302536
crate_disambiguator,
2537+
original_crate_name,
25312538
trait_impls_of: trait_def::trait_impls_of_provider,
25322539
..*providers
25332540
};

src/librustc_metadata/cstore_impl.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ provide! { <'tcx> tcx, def_id, cdata,
177177
}
178178
crate_disambiguator => { cdata.disambiguator() }
179179
crate_hash => { cdata.hash() }
180+
original_crate_name => { cdata.name() }
180181
}
181182

182183
pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
@@ -280,11 +281,6 @@ impl CrateStore for cstore::CStore {
280281
self.get_crate_data(cnum).name
281282
}
282283

283-
fn original_crate_name(&self, cnum: CrateNum) -> Symbol
284-
{
285-
self.get_crate_data(cnum).name()
286-
}
287-
288284
/// Returns the `DefKey` for a given `DefId`. This indicates the
289285
/// parent `DefId` as well as some idea of what kind of data the
290286
/// `DefId` refers to.

src/librustc_metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
12951295
.iter()
12961296
.map(|&cnum| {
12971297
let dep = CrateDep {
1298-
name: cstore.original_crate_name(cnum),
1298+
name: self.tcx.original_crate_name(cnum),
12991299
hash: self.tcx.crate_hash(cnum),
13001300
kind: cstore.dep_kind(cnum),
13011301
};

src/librustdoc/visit_ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
207207
continue // These are `krate.exported_macros`, handled in `self.visit()`.
208208
}
209209

210-
let imported_from = self.cx.sess().cstore.original_crate_name(def_id.krate);
210+
let imported_from = self.cx.tcx.original_crate_name(def_id.krate);
211211
let def = match self.cx.sess().cstore.load_macro(def_id, self.cx.sess()) {
212212
LoadedMacro::MacroDef(macro_def) => macro_def,
213213
// FIXME(jseyfried): document proc macro reexports

0 commit comments

Comments
 (0)