Skip to content

Commit 30ea918

Browse files
committed
rustc: Move original_crate_name to a query
1 parent 2a5d89f commit 30ea918

File tree

8 files changed

+19
-21
lines changed

8 files changed

+19
-21
lines changed

Diff for: src/librustc/dep_graph/dep_node.rs

+1
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ define_dep_nodes!( <'tcx>
537537
[] DeriveRegistrarFn(CrateNum),
538538
[] CrateDisambiguator(CrateNum),
539539
[] CrateHash(CrateNum),
540+
[] OriginalCrateName(CrateNum),
540541
);
541542

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

Diff for: src/librustc/middle/cstore.rs

-5
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") }

Diff for: src/librustc/ty/context.rs

-8
Original file line numberDiff line numberDiff line change
@@ -923,14 +923,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
923923
}
924924
}
925925

926-
pub fn original_crate_name(self, cnum: CrateNum) -> Symbol {
927-
if cnum == LOCAL_CRATE {
928-
self.crate_name.clone()
929-
} else {
930-
self.sess.cstore.original_crate_name(cnum)
931-
}
932-
}
933-
934926
pub fn alloc_generics(self, generics: ty::Generics) -> &'gcx ty::Generics {
935927
self.global_arenas.generics.alloc(generics)
936928
}

Diff for: src/librustc/ty/maps.rs

+7
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,12 @@ impl<'tcx> QueryDescription for queries::crate_hash<'tcx> {
596596
}
597597
}
598598

599+
impl<'tcx> QueryDescription for queries::original_crate_name<'tcx> {
600+
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
601+
format!("looking up the original name a crate")
602+
}
603+
}
604+
599605
// If enabled, send a message to the profile-queries thread
600606
macro_rules! profq_msg {
601607
($tcx:expr, $msg:expr) => {
@@ -1175,6 +1181,7 @@ define_maps! { <'tcx>
11751181
[] derive_registrar_fn: DeriveRegistrarFn(CrateNum) -> Option<DefId>,
11761182
[] crate_disambiguator: CrateDisambiguator(CrateNum) -> Symbol,
11771183
[] crate_hash: CrateHash(CrateNum) -> Svh,
1184+
[] original_crate_name: OriginalCrateName(CrateNum) -> Symbol,
11781185
}
11791186

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

Diff for: src/librustc/ty/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
22112211
if let Some(id) = self.hir.as_local_node_id(id) {
22122212
self.hir.name(id)
22132213
} else if id.index == CRATE_DEF_INDEX {
2214-
self.sess.cstore.original_crate_name(id.krate)
2214+
self.original_crate_name(id.krate)
22152215
} else {
22162216
let def_key = self.sess.cstore.def_key(id);
22172217
// The name of a StructCtor is that of its struct parent.
@@ -2521,6 +2521,12 @@ fn crate_disambiguator<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
25212521
tcx.sess.local_crate_disambiguator()
25222522
}
25232523

2524+
fn original_crate_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
2525+
crate_num: CrateNum) -> Symbol {
2526+
assert_eq!(crate_num, LOCAL_CRATE);
2527+
tcx.crate_name.clone()
2528+
}
2529+
25242530
pub fn provide(providers: &mut ty::maps::Providers) {
25252531
util::provide(providers);
25262532
*providers = ty::maps::Providers {
@@ -2532,6 +2538,7 @@ pub fn provide(providers: &mut ty::maps::Providers) {
25322538
param_env,
25332539
trait_of_item,
25342540
crate_disambiguator,
2541+
original_crate_name,
25352542
trait_impls_of: trait_def::trait_impls_of_provider,
25362543
..*providers
25372544
};

Diff for: src/librustc_metadata/cstore_impl.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ provide! { <'tcx> tcx, def_id, cdata,
173173
}
174174
crate_disambiguator => { cdata.disambiguator() }
175175
crate_hash => { cdata.hash() }
176+
original_crate_name => { cdata.name() }
176177
}
177178

178179
pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
@@ -276,11 +277,6 @@ impl CrateStore for cstore::CStore {
276277
self.get_crate_data(cnum).name
277278
}
278279

279-
fn original_crate_name(&self, cnum: CrateNum) -> Symbol
280-
{
281-
self.get_crate_data(cnum).name()
282-
}
283-
284280
/// Returns the `DefKey` for a given `DefId`. This indicates the
285281
/// parent `DefId` as well as some idea of what kind of data the
286282
/// `DefId` refers to.

Diff for: src/librustc_metadata/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
12941294
.iter()
12951295
.map(|&cnum| {
12961296
let dep = CrateDep {
1297-
name: cstore.original_crate_name(cnum),
1297+
name: self.tcx.original_crate_name(cnum),
12981298
hash: self.tcx.crate_hash(cnum),
12991299
kind: cstore.dep_kind(cnum),
13001300
};

Diff for: src/librustdoc/visit_ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
206206
continue // These are `krate.exported_macros`, handled in `self.visit()`.
207207
}
208208

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

0 commit comments

Comments
 (0)