Repository navigation
[WIP] improve canonicalization by using a hashing scheme - #51837
JaimeValdemoros wants to merge 4 commits into
Conversation
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @michaelwoerister (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
|
So this all seems good — I'm trying to remember what I had in mind. I know I considered going down this route (of adding There is also, however, a pre-existing "stable hash" thing we use for incremental. It may be that we can re-use some of that? But I guess we need to be able to have some kind of "hook" (precisely what this approach provides us), so that when we are hashing in the canonicalization code, we can identify that we're looking at an unbound inference variable and substitute the hash for the next index, etc. |
There was a problem hiding this comment.
I wonder if these impls can be moved to the macros -- I moved a bunch of stuff in preparation for this PR, but not everything. Trying to move as many things we can to use the macro -- before we make any changes to it! -- might indeed be a good first step.
There was a problem hiding this comment.
Ok, I've made a start on this - I've picked out a couple that seem to be trivially applicable to the macros. For a couple of the types, it seems that only some of the fields (in the case of structs) and components of variants (in the case of enums) are super_folded or super_visited. Would an approach be to somehow 'tag' these in the macro and extend the macro to understand the difference?
I'm imagining for example the impl for RValue, which does something like:
match *self {
Use(ref op) => Use(op.fold_with(folder)),
Repeat(ref op, len) => Repeat(op.fold_with(folder), len),
Ref(region, bk, ref place) =>
Ref(region.fold_with(folder), bk, place.fold_with(folder)),
Len(ref place) => Len(place.fold_with(folder)),
*snip*
match *self {
Use(ref op) => op.visit_with(visitor),
Repeat(ref op, _) => op.visit_with(visitor),
Ref(region, _, ref place) => region.visit_with(visitor) || place.visit_with(visitor),
Len(ref place) => place.visit_with(visitor),and the macro could be something like:
EnumTypeFoldableImpl! {
impl<'tcx, T> TypeFoldable<'tcx> for Rvalue<'tcx> {
(Rvalue::Use)(op),
(Rvalue::Repeat)(op, @clone len),
(Rvalue::Ref)(region, @clone bk, place),
(Rvalue::Len)(place),
...
}
}
There was a problem hiding this comment.
No, I've just implemented fold for those types that need it (e.g., bk) -- many of them already have it, I suspect.
There was a problem hiding this comment.
these hasher impls don't quite look right. We need to hash mem::discriminant(self) as well. Here is a good example:
rust/src/librustc/ich/impls_mir.rs
Lines 38 to 54 in ed0350e
There was a problem hiding this comment.
Ah, got it - was worrying about the fact that I was hashing a 'flattened' structure rather than the tree structure but I wasn't entirely sure how to resolve it. Presumably this is effectively adding in the enum 'position' to the hash
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
|
@JaimeValdemoros I'm starting to get worried that this will be a harder task than I originally imagined. =) I'd love to see if we can carve it up so that we can split the work a bit (this is why I was pinging you and @technicalguy about dropping in on zulip at some point over in #48417 -- but maybe we can chat a bit on the PR instead). The main thing I can see right now is to start by having someone try to do all the rote work of extracting and applying the macros. I could take a stab at that, for sure, or you — but it seems like work that can land independently. I suppose it may actually just be faster to do the |
|
Ping from triage @JaimeValdemoros, we haven't heard from you for a while, will you have time to look into this PR? |
|
Triage: @JaimeValdemoros I'm closing this as there's been no activity for the past 14 days. Thank you for this work and please do reopen this when you have time to come back to it. |
Attempting at #48417. This branch is a little bit behind so I think the first thing I need to do is rebase onto current master.