Skip to content

Commit 71e1c50

Browse files
committed
Removed use of TypeIdHasher in symbol hash generation and replaced it with StableHasher.
1 parent e7d7d91 commit 71e1c50

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/librustc_trans_utils/symbol_names.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,13 @@
9898
//! DefPaths which are much more robust in the face of changes to the code base.
9999
100100
use rustc::middle::weak_lang_items;
101+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
101102
use rustc_mir::monomorphize::Instance;
102103
use rustc_mir::monomorphize::item::{MonoItem, MonoItemExt, InstantiationMode};
103104
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
104105
use rustc::hir::map as hir_map;
106+
use rustc::ich::NodeIdHashingMode;
105107
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
106-
use rustc::ty::fold::TypeVisitor;
107108
use rustc::ty::item_path::{self, ItemPathBuffer, RootMode};
108109
use rustc::ty::maps::Providers;
109110
use rustc::ty::subst::Substs;
@@ -144,31 +145,29 @@ fn get_symbol_hash<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
144145
-> u64 {
145146
debug!("get_symbol_hash(def_id={:?}, parameters={:?})", def_id, substs);
146147

147-
let mut hasher = ty::util::TypeIdHasher::<u64>::new(tcx);
148+
let mut hasher = StableHasher::<u64>::new();
149+
let mut hcx = tcx.create_stable_hashing_context();
148150

149151
record_time(&tcx.sess.perf_stats.symbol_hash_time, || {
150152
// the main symbol name is not necessarily unique; hash in the
151153
// compiler's internal def-path, guaranteeing each symbol has a
152154
// truly unique path
153-
hasher.hash(tcx.def_path_hash(def_id));
155+
tcx.def_path_hash(def_id).hash_stable(&mut hcx, &mut hasher);
154156

155157
// Include the main item-type. Note that, in this case, the
156158
// assertions about `needs_subst` may not hold, but this item-type
157159
// ought to be the same for every reference anyway.
158160
assert!(!item_type.has_erasable_regions());
159-
hasher.visit_ty(item_type);
160-
161-
// If this is a function, we hash the signature as well.
162-
// This is not *strictly* needed, but it may help in some
163-
// situations, see the `run-make/a-b-a-linker-guard` test.
164-
if let ty::TyFnDef(..) = item_type.sty {
165-
item_type.fn_sig(tcx).visit_with(&mut hasher);
166-
}
161+
hcx.while_hashing_spans(false, |hcx| {
162+
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
163+
item_type.hash_stable(hcx, &mut hasher);
164+
});
165+
});
167166

168167
// also include any type parameters (for generic items)
169168
assert!(!substs.has_erasable_regions());
170169
assert!(!substs.needs_subst());
171-
substs.visit_with(&mut hasher);
170+
substs.hash_stable(&mut hcx, &mut hasher);
172171

173172
let is_generic = substs.types().next().is_some();
174173
let avoid_cross_crate_conflicts =
@@ -207,8 +206,8 @@ fn get_symbol_hash<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
207206
LOCAL_CRATE
208207
};
209208

210-
hasher.hash(&tcx.original_crate_name(instantiating_crate).as_str()[..]);
211-
hasher.hash(&tcx.crate_disambiguator(instantiating_crate));
209+
(&tcx.original_crate_name(instantiating_crate).as_str()[..]).hash_stable(&mut hcx, &mut hasher);
210+
(&tcx.crate_disambiguator(instantiating_crate)).hash_stable(&mut hcx, &mut hasher);
212211
}
213212
});
214213

0 commit comments

Comments
 (0)