Skip to content

Commit 74d37ac

Browse files
committed
Removed TypeIdHasher.
1 parent 71e1c50 commit 74d37ac

File tree

1 file changed

+0
-145
lines changed

1 file changed

+0
-145
lines changed

src/librustc/ty/util.rs

Lines changed: 0 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -606,151 +606,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
606606
}
607607
}
608608

609-
pub struct TypeIdHasher<'a, 'gcx: 'a+'tcx, 'tcx: 'a, W> {
610-
tcx: TyCtxt<'a, 'gcx, 'tcx>,
611-
state: StableHasher<W>,
612-
}
613-
614-
impl<'a, 'gcx, 'tcx, W> TypeIdHasher<'a, 'gcx, 'tcx, W>
615-
where W: StableHasherResult
616-
{
617-
pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Self {
618-
TypeIdHasher { tcx: tcx, state: StableHasher::new() }
619-
}
620-
621-
pub fn finish(self) -> W {
622-
self.state.finish()
623-
}
624-
625-
pub fn hash<T: Hash>(&mut self, x: T) {
626-
x.hash(&mut self.state);
627-
}
628-
629-
fn hash_discriminant_u8<T>(&mut self, x: &T) {
630-
let v = unsafe {
631-
intrinsics::discriminant_value(x)
632-
};
633-
let b = v as u8;
634-
assert_eq!(v, b as u64);
635-
self.hash(b)
636-
}
637-
638-
fn def_id(&mut self, did: DefId) {
639-
// Hash the DefPath corresponding to the DefId, which is independent
640-
// of compiler internal state. We already have a stable hash value of
641-
// all DefPaths available via tcx.def_path_hash(), so we just feed that
642-
// into the hasher.
643-
let hash = self.tcx.def_path_hash(did);
644-
self.hash(hash);
645-
}
646-
}
647-
648-
impl<'a, 'gcx, 'tcx, W> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tcx, W>
649-
where W: StableHasherResult
650-
{
651-
fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool {
652-
// Distinguish between the Ty variants uniformly.
653-
self.hash_discriminant_u8(&ty.sty);
654-
655-
match ty.sty {
656-
TyInt(i) => self.hash(i),
657-
TyUint(u) => self.hash(u),
658-
TyFloat(f) => self.hash(f),
659-
TyArray(_, n) => {
660-
self.hash_discriminant_u8(&n.val);
661-
match n.val {
662-
ConstVal::Value(Value::ByVal(PrimVal::Bytes(b))) => self.hash(b),
663-
ConstVal::Unevaluated(def_id, _) => self.def_id(def_id),
664-
_ => bug!("arrays should not have {:?} as length", n)
665-
}
666-
}
667-
TyRawPtr(m) |
668-
TyRef(_, m) => self.hash(m.mutbl),
669-
TyClosure(def_id, _) |
670-
TyGenerator(def_id, _, _) |
671-
TyAnon(def_id, _) |
672-
TyFnDef(def_id, _) => self.def_id(def_id),
673-
TyAdt(d, _) => self.def_id(d.did),
674-
TyForeign(def_id) => self.def_id(def_id),
675-
TyFnPtr(f) => {
676-
self.hash(f.unsafety());
677-
self.hash(f.abi());
678-
self.hash(f.variadic());
679-
self.hash(f.inputs().skip_binder().len());
680-
}
681-
TyDynamic(ref data, ..) => {
682-
if let Some(p) = data.principal() {
683-
self.def_id(p.def_id());
684-
}
685-
for d in data.auto_traits() {
686-
self.def_id(d);
687-
}
688-
}
689-
TyGeneratorWitness(tys) => {
690-
self.hash(tys.skip_binder().len());
691-
}
692-
TyTuple(tys) => {
693-
self.hash(tys.len());
694-
}
695-
TyParam(p) => {
696-
self.hash(p.idx);
697-
self.hash(p.name);
698-
}
699-
TyProjection(ref data) => {
700-
self.def_id(data.item_def_id);
701-
}
702-
TyNever |
703-
TyBool |
704-
TyChar |
705-
TyStr |
706-
TySlice(_) => {}
707-
708-
TyError |
709-
TyInfer(_) => bug!("TypeIdHasher: unexpected type {}", ty)
710-
}
711-
712-
ty.super_visit_with(self)
713-
}
714-
715-
fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
716-
self.hash_discriminant_u8(r);
717-
match *r {
718-
ty::ReErased |
719-
ty::ReStatic |
720-
ty::ReEmpty => {
721-
// No variant fields to hash for these ...
722-
}
723-
ty::ReCanonical(c) => {
724-
self.hash(c);
725-
}
726-
ty::ReLateBound(db, ty::BrAnon(i)) => {
727-
self.hash(db.depth);
728-
self.hash(i);
729-
}
730-
ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, .. }) => {
731-
self.def_id(def_id);
732-
}
733-
734-
ty::ReClosureBound(..) |
735-
ty::ReLateBound(..) |
736-
ty::ReFree(..) |
737-
ty::ReScope(..) |
738-
ty::ReVar(..) |
739-
ty::ReSkolemized(..) => {
740-
bug!("TypeIdHasher: unexpected region {:?}", r)
741-
}
742-
}
743-
false
744-
}
745-
746-
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, x: &ty::Binder<T>) -> bool {
747-
// Anonymize late-bound regions so that, for example:
748-
// `for<'a, b> fn(&'a &'b T)` and `for<'a, b> fn(&'b &'a T)`
749-
// result in the same TypeId (the two types are equivalent).
750-
self.tcx.anonymize_late_bound_regions(x).super_visit_with(self)
751-
}
752-
}
753-
754609
impl<'a, 'tcx> ty::TyS<'tcx> {
755610
pub fn moves_by_default(&'tcx self,
756611
tcx: TyCtxt<'a, 'tcx, 'tcx>,

0 commit comments

Comments
 (0)