Skip to content

Commit

Permalink
rustc: Move original_crate_name to a query
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Aug 29, 2017
1 parent 2a5d89f commit 30ea918
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ define_dep_nodes!( <'tcx>
[] DeriveRegistrarFn(CrateNum),
[] CrateDisambiguator(CrateNum),
[] CrateHash(CrateNum),
[] OriginalCrateName(CrateNum),
);

trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
Expand Down
5 changes: 0 additions & 5 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ pub trait CrateStore {
/// The name of the crate as it is referred to in source code of the current
/// crate.
fn crate_name(&self, cnum: CrateNum) -> Symbol;
/// The name of the crate as it is stored in the crate's metadata.
fn original_crate_name(&self, cnum: CrateNum) -> Symbol;

// resolve
fn def_key(&self, def: DefId) -> DefKey;
Expand Down Expand Up @@ -349,9 +347,6 @@ impl CrateStore for DummyCrateStore {
fn dep_kind(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
fn export_macros(&self, cnum: CrateNum) { bug!("export_macros") }
fn crate_name(&self, cnum: CrateNum) -> Symbol { bug!("crate_name") }
fn original_crate_name(&self, cnum: CrateNum) -> Symbol {
bug!("original_crate_name")
}

// resolve
fn def_key(&self, def: DefId) -> DefKey { bug!("def_key") }
Expand Down
8 changes: 0 additions & 8 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,14 +923,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}
}

pub fn original_crate_name(self, cnum: CrateNum) -> Symbol {
if cnum == LOCAL_CRATE {
self.crate_name.clone()
} else {
self.sess.cstore.original_crate_name(cnum)
}
}

pub fn alloc_generics(self, generics: ty::Generics) -> &'gcx ty::Generics {
self.global_arenas.generics.alloc(generics)
}
Expand Down
7 changes: 7 additions & 0 deletions src/librustc/ty/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,12 @@ impl<'tcx> QueryDescription for queries::crate_hash<'tcx> {
}
}

impl<'tcx> QueryDescription for queries::original_crate_name<'tcx> {
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
format!("looking up the original name a crate")
}
}

// If enabled, send a message to the profile-queries thread
macro_rules! profq_msg {
($tcx:expr, $msg:expr) => {
Expand Down Expand Up @@ -1175,6 +1181,7 @@ define_maps! { <'tcx>
[] derive_registrar_fn: DeriveRegistrarFn(CrateNum) -> Option<DefId>,
[] crate_disambiguator: CrateDisambiguator(CrateNum) -> Symbol,
[] crate_hash: CrateHash(CrateNum) -> Svh,
[] original_crate_name: OriginalCrateName(CrateNum) -> Symbol,
}

fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
Expand Down
9 changes: 8 additions & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2211,7 +2211,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
if let Some(id) = self.hir.as_local_node_id(id) {
self.hir.name(id)
} else if id.index == CRATE_DEF_INDEX {
self.sess.cstore.original_crate_name(id.krate)
self.original_crate_name(id.krate)
} else {
let def_key = self.sess.cstore.def_key(id);
// The name of a StructCtor is that of its struct parent.
Expand Down Expand Up @@ -2521,6 +2521,12 @@ fn crate_disambiguator<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
tcx.sess.local_crate_disambiguator()
}

fn original_crate_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
crate_num: CrateNum) -> Symbol {
assert_eq!(crate_num, LOCAL_CRATE);
tcx.crate_name.clone()
}

pub fn provide(providers: &mut ty::maps::Providers) {
util::provide(providers);
*providers = ty::maps::Providers {
Expand All @@ -2532,6 +2538,7 @@ pub fn provide(providers: &mut ty::maps::Providers) {
param_env,
trait_of_item,
crate_disambiguator,
original_crate_name,
trait_impls_of: trait_def::trait_impls_of_provider,
..*providers
};
Expand Down
6 changes: 1 addition & 5 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ provide! { <'tcx> tcx, def_id, cdata,
}
crate_disambiguator => { cdata.disambiguator() }
crate_hash => { cdata.hash() }
original_crate_name => { cdata.name() }
}

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

fn original_crate_name(&self, cnum: CrateNum) -> Symbol
{
self.get_crate_data(cnum).name()
}

/// Returns the `DefKey` for a given `DefId`. This indicates the
/// parent `DefId` as well as some idea of what kind of data the
/// `DefId` refers to.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
.iter()
.map(|&cnum| {
let dep = CrateDep {
name: cstore.original_crate_name(cnum),
name: self.tcx.original_crate_name(cnum),
hash: self.tcx.crate_hash(cnum),
kind: cstore.dep_kind(cnum),
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
continue // These are `krate.exported_macros`, handled in `self.visit()`.
}

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

0 comments on commit 30ea918

Please sign in to comment.