-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
debuginfo: Use TypeIdHasher for generating global debuginfo type IDs. #37336
Changes from 2 commits
6f3edb0
c52836c
7ef418b
025b27d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -402,17 +402,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { | |
// `isize` completely when hashing. To ensure that these don't leak in we use a | ||
// custom hasher implementation here which inflates the size of these to a `u64` | ||
// and `i64`. | ||
struct WidenUsizeHasher<H> { | ||
// | ||
// The same goes for endianess: We always convert multi-byte integers to little | ||
// endian before hashing. | ||
struct ArchIndependentHasher<H> { | ||
inner: H, | ||
} | ||
|
||
impl<H> WidenUsizeHasher<H> { | ||
fn new(inner: H) -> WidenUsizeHasher<H> { | ||
WidenUsizeHasher { inner: inner } | ||
impl<H> ArchIndependentHasher<H> { | ||
fn new(inner: H) -> ArchIndependentHasher<H> { | ||
ArchIndependentHasher { inner: inner } | ||
} | ||
} | ||
|
||
impl<H: Hasher> Hasher for WidenUsizeHasher<H> { | ||
impl<H: Hasher> Hasher for ArchIndependentHasher<H> { | ||
fn write(&mut self, bytes: &[u8]) { | ||
self.inner.write(bytes) | ||
} | ||
|
@@ -425,44 +428,44 @@ impl<H: Hasher> Hasher for WidenUsizeHasher<H> { | |
self.inner.write_u8(i) | ||
} | ||
fn write_u16(&mut self, i: u16) { | ||
self.inner.write_u16(i) | ||
self.inner.write_u16(i.to_le()) | ||
} | ||
fn write_u32(&mut self, i: u32) { | ||
self.inner.write_u32(i) | ||
self.inner.write_u32(i.to_le()) | ||
} | ||
fn write_u64(&mut self, i: u64) { | ||
self.inner.write_u64(i) | ||
self.inner.write_u64(i.to_le()) | ||
} | ||
fn write_usize(&mut self, i: usize) { | ||
self.inner.write_u64(i as u64) | ||
self.inner.write_u64((i as u64).to_le()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This, and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? That would be true if they were calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really? I'm not sure I follow why (they call the inner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhh, didn't read that code carefully enough 😞 I still remembered that |
||
} | ||
fn write_i8(&mut self, i: i8) { | ||
self.inner.write_i8(i) | ||
} | ||
fn write_i16(&mut self, i: i16) { | ||
self.inner.write_i16(i) | ||
self.inner.write_i16(i.to_le()) | ||
} | ||
fn write_i32(&mut self, i: i32) { | ||
self.inner.write_i32(i) | ||
self.inner.write_i32(i.to_le()) | ||
} | ||
fn write_i64(&mut self, i: i64) { | ||
self.inner.write_i64(i) | ||
self.inner.write_i64(i.to_le()) | ||
} | ||
fn write_isize(&mut self, i: isize) { | ||
self.inner.write_i64(i as i64) | ||
self.inner.write_i64((i as i64).to_le()) | ||
} | ||
} | ||
|
||
pub struct TypeIdHasher<'a, 'gcx: 'a+'tcx, 'tcx: 'a, H> { | ||
tcx: TyCtxt<'a, 'gcx, 'tcx>, | ||
state: WidenUsizeHasher<H>, | ||
state: ArchIndependentHasher<H>, | ||
} | ||
|
||
impl<'a, 'gcx, 'tcx, H: Hasher> TypeIdHasher<'a, 'gcx, 'tcx, H> { | ||
pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>, state: H) -> Self { | ||
TypeIdHasher { | ||
tcx: tcx, | ||
state: WidenUsizeHasher::new(state), | ||
state: ArchIndependentHasher::new(state), | ||
} | ||
} | ||
|
||
|
@@ -493,6 +496,10 @@ impl<'a, 'gcx, 'tcx, H: Hasher> TypeIdHasher<'a, 'gcx, 'tcx, H> { | |
pub fn def_path(&mut self, def_path: &ast_map::DefPath) { | ||
def_path.deterministic_hash_to(self.tcx, &mut self.state); | ||
} | ||
|
||
pub fn into_inner(self) -> H { | ||
self.state.inner | ||
} | ||
} | ||
|
||
impl<'a, 'gcx, 'tcx, H: Hasher> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tcx, H> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we turn this into a doc comment? Maybe even make it public, seems useful elsewhere.