Skip to content

Commit d6c88f4

Browse files
committed
rustc: Move crate_hash to a query
1 parent ebc1fd3 commit d6c88f4

File tree

8 files changed

+12
-15
lines changed

8 files changed

+12
-15
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ define_dep_nodes!( <'tcx>
540540
[] PluginRegistrarFn(CrateNum),
541541
[] DeriveRegistrarFn(CrateNum),
542542
[] CrateDisambiguator(CrateNum),
543+
[] CrateHash(CrateNum),
543544
);
544545

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

src/librustc/middle/cstore.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ pub trait CrateStore {
253253
fn crate_name(&self, cnum: CrateNum) -> Symbol;
254254
/// The name of the crate as it is stored in the crate's metadata.
255255
fn original_crate_name(&self, cnum: CrateNum) -> Symbol;
256-
fn crate_hash(&self, cnum: CrateNum) -> Svh;
257256

258257
// resolve
259258
fn def_key(&self, def: DefId) -> DefKey;
@@ -353,7 +352,6 @@ impl CrateStore for DummyCrateStore {
353352
fn original_crate_name(&self, cnum: CrateNum) -> Symbol {
354353
bug!("original_crate_name")
355354
}
356-
fn crate_hash(&self, cnum: CrateNum) -> Svh { bug!("crate_hash") }
357355

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

src/librustc/ty/maps.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use errors::{Diagnostic, DiagnosticBuilder};
1313
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
1414
use hir::def::{Def, Export};
1515
use hir::{self, TraitCandidate, HirId};
16+
use hir::svh::Svh;
1617
use lint;
1718
use middle::const_val;
1819
use middle::cstore::{ExternCrate, LinkagePreference, NativeLibrary};
@@ -617,6 +618,12 @@ impl<'tcx> QueryDescription for queries::crate_disambiguator<'tcx> {
617618
}
618619
}
619620

621+
impl<'tcx> QueryDescription for queries::crate_hash<'tcx> {
622+
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
623+
format!("looking up the hash a crate")
624+
}
625+
}
626+
620627
// If enabled, send a message to the profile-queries thread
621628
macro_rules! profq_msg {
622629
($tcx:expr, $msg:expr) => {
@@ -1198,6 +1205,7 @@ define_maps! { <'tcx>
11981205
[] fn plugin_registrar_fn: PluginRegistrarFn(CrateNum) -> Option<DefId>,
11991206
[] fn derive_registrar_fn: DeriveRegistrarFn(CrateNum) -> Option<DefId>,
12001207
[] fn crate_disambiguator: CrateDisambiguator(CrateNum) -> Symbol,
1208+
[] fn crate_hash: CrateHash(CrateNum) -> Svh,
12011209
}
12021210

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

src/librustc_incremental/persist/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ pub fn find_metadata_hashes_for(tcx: TyCtxt, cnum: CrateNum) -> Option<PathBuf>
632632
}
633633
};
634634

635-
let target_svh = tcx.sess.cstore.crate_hash(cnum);
635+
let target_svh = tcx.crate_hash(cnum);
636636
let target_svh = base_n::encode(target_svh.as_u64(), INT_ENCODE_BASE);
637637

638638
let sub_dir = find_metadata_hashes_iter(&target_svh, dir_entries.filter_map(|e| {

src/librustc_incremental/persist/hash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'a, 'tcx> HashContext<'a, 'tcx> {
133133
fn load_data(&mut self, cnum: CrateNum) {
134134
debug!("load_data(cnum={})", cnum);
135135

136-
let svh = self.tcx.sess.cstore.crate_hash(cnum);
136+
let svh = self.tcx.crate_hash(cnum);
137137
let old = self.crate_hashes.insert(cnum, svh);
138138
debug!("load_data: svh={}", svh);
139139
assert!(old.is_none(), "loaded data for crate {:?} twice", cnum);

src/librustc_metadata/cstore.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ impl CStore {
126126
self.metas.borrow().get(&cnum).unwrap().clone()
127127
}
128128

129-
pub fn get_crate_hash(&self, cnum: CrateNum) -> Svh {
130-
self.get_crate_data(cnum).hash()
131-
}
132-
133129
pub fn set_crate_data(&self, cnum: CrateNum, data: Rc<CrateMetadata>) {
134130
self.metas.borrow_mut().insert(cnum, data);
135131
}

src/librustc_metadata/cstore_impl.rs

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

183182
pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
@@ -286,11 +285,6 @@ impl CrateStore for cstore::CStore {
286285
self.get_crate_data(cnum).name()
287286
}
288287

289-
fn crate_hash(&self, cnum: CrateNum) -> Svh
290-
{
291-
self.get_crate_hash(cnum)
292-
}
293-
294288
/// Returns the `DefKey` for a given `DefId`. This indicates the
295289
/// parent `DefId` as well as some idea of what kind of data the
296290
/// `DefId` refers to.

src/librustc_metadata/encoder.rs

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

0 commit comments

Comments
 (0)