Store hashes in special types so they aren't accidentally encoded as numbers
This commit is contained in:
parent
de96f3d873
commit
0445fbdd83
38 changed files with 274 additions and 138 deletions
|
@ -1,4 +1,4 @@
|
|||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher};
|
||||
use rustc_hir::def_id::CrateNum;
|
||||
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
|
||||
use rustc_middle::ty::print::{PrettyPrinter, Print, Printer};
|
||||
|
@ -93,7 +93,7 @@ fn get_symbol_hash<'tcx>(
|
|||
item_type: Ty<'tcx>,
|
||||
|
||||
instantiating_crate: Option<CrateNum>,
|
||||
) -> u64 {
|
||||
) -> Hash64 {
|
||||
let def_id = instance.def_id();
|
||||
let substs = instance.substs;
|
||||
debug!("get_symbol_hash(def_id={:?}, parameters={:?})", def_id, substs);
|
||||
|
@ -138,7 +138,7 @@ fn get_symbol_hash<'tcx>(
|
|||
});
|
||||
|
||||
// 64 bits should be enough to avoid collisions.
|
||||
hasher.finish::<u64>()
|
||||
hasher.finish::<Hash64>()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ impl SymbolPath {
|
|||
}
|
||||
}
|
||||
|
||||
fn finish(mut self, hash: u64) -> String {
|
||||
fn finish(mut self, hash: Hash64) -> String {
|
||||
self.finalize_pending_component();
|
||||
// E = end name-sequence
|
||||
let _ = write!(self.result, "17h{hash:016x}E");
|
||||
|
|
|
@ -406,7 +406,7 @@ fn encode_ty_name(tcx: TyCtxt<'_>, def_id: DefId) -> String {
|
|||
|
||||
// Crate disambiguator and name
|
||||
s.push('C');
|
||||
s.push_str(&to_disambiguator(tcx.stable_crate_id(def_path.krate).to_u64()));
|
||||
s.push_str(&to_disambiguator(tcx.stable_crate_id(def_path.krate).as_u64()));
|
||||
let crate_name = tcx.crate_name(def_path.krate).to_string();
|
||||
let _ = write!(s, "{}{}", crate_name.len(), &crate_name);
|
||||
|
||||
|
|
|
@ -731,7 +731,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
|
|||
fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
|
||||
self.push("C");
|
||||
let stable_crate_id = self.tcx.def_path_hash(cnum.as_def_id()).stable_crate_id();
|
||||
self.push_disambiguator(stable_crate_id.to_u64());
|
||||
self.push_disambiguator(stable_crate_id.as_u64());
|
||||
let name = self.tcx.crate_name(cnum);
|
||||
self.push_ident(name.as_str());
|
||||
Ok(self)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue