Skip to content

Commit

Permalink
rustc: Move crate_hash to a query
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Aug 29, 2017
1 parent f75be96 commit 2a5d89f
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 16 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 @@ -536,6 +536,7 @@ define_dep_nodes!( <'tcx>
[] PluginRegistrarFn(CrateNum),
[] DeriveRegistrarFn(CrateNum),
[] CrateDisambiguator(CrateNum),
[] CrateHash(CrateNum),
);

trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ pub trait CrateStore {
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;
fn crate_hash(&self, cnum: CrateNum) -> Svh;

// resolve
fn def_key(&self, def: DefId) -> DefKey;
Expand Down Expand Up @@ -353,7 +352,6 @@ impl CrateStore for DummyCrateStore {
fn original_crate_name(&self, cnum: CrateNum) -> Symbol {
bug!("original_crate_name")
}
fn crate_hash(&self, cnum: CrateNum) -> Svh { bug!("crate_hash") }

// resolve
fn def_key(&self, def: DefId) -> DefKey { bug!("def_key") }
Expand Down
8 changes: 8 additions & 0 deletions src/librustc/ty/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use dep_graph::{DepConstructor, DepNode, DepNodeIndex};
use errors::{Diagnostic, DiagnosticBuilder};
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use hir::def::Def;
use hir::svh::Svh;
use hir;
use lint;
use middle::const_val;
Expand Down Expand Up @@ -589,6 +590,12 @@ impl<'tcx> QueryDescription for queries::crate_disambiguator<'tcx> {
}
}

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

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

fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ pub fn find_metadata_hashes_for(tcx: TyCtxt, cnum: CrateNum) -> Option<PathBuf>
}
};

let target_svh = tcx.sess.cstore.crate_hash(cnum);
let target_svh = tcx.crate_hash(cnum);
let target_svh = base_n::encode(target_svh.as_u64(), INT_ENCODE_BASE);

let sub_dir = find_metadata_hashes_iter(&target_svh, dir_entries.filter_map(|e| {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<'a, 'tcx> HashContext<'a, 'tcx> {
fn load_data(&mut self, cnum: CrateNum) {
debug!("load_data(cnum={})", cnum);

let svh = self.tcx.sess.cstore.crate_hash(cnum);
let svh = self.tcx.crate_hash(cnum);
let old = self.crate_hashes.insert(cnum, svh);
debug!("load_data: svh={}", svh);
assert!(old.is_none(), "loaded data for crate {:?} twice", cnum);
Expand Down
4 changes: 0 additions & 4 deletions src/librustc_metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ impl CStore {
self.metas.borrow().get(&cnum).unwrap().clone()
}

pub fn get_crate_hash(&self, cnum: CrateNum) -> Svh {
self.get_crate_data(cnum).hash()
}

pub fn set_crate_data(&self, cnum: CrateNum, data: Rc<CrateMetadata>) {
self.metas.borrow_mut().insert(cnum, data);
}
Expand Down
7 changes: 0 additions & 7 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ use syntax::ext::base::SyntaxExtension;
use syntax::parse::filemap_to_stream;
use syntax::symbol::Symbol;
use syntax_pos::{Span, NO_EXPANSION};
use rustc::hir::svh::Svh;
use rustc::hir;

macro_rules! provide {
Expand Down Expand Up @@ -174,7 +173,6 @@ 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 @@ -283,11 +281,6 @@ impl CrateStore for cstore::CStore {
self.get_crate_data(cnum).name()
}

fn crate_hash(&self, cnum: CrateNum) -> Svh
{
self.get_crate_hash(cnum)
}

/// 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 @@ -1295,7 +1295,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
.map(|&cnum| {
let dep = CrateDep {
name: cstore.original_crate_name(cnum),
hash: cstore.crate_hash(cnum),
hash: self.tcx.crate_hash(cnum),
kind: cstore.dep_kind(cnum),
};
(cnum, dep)
Expand Down

0 comments on commit 2a5d89f

Please sign in to comment.