-
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
Fix HashStable implementation on AllocId #93472
Conversation
Some changes occured to the CTFE / Miri engine cc @rust-lang/miri |
Ok this definitely doesn't work :^) Of course I should've checked the |
@rustbot author |
The easy solution here is to remove the HashStable impl entirely and instead add a manual impl for |
b522ee1
to
d778a62
Compare
@oli-obk, I took an initial stab at that suggestion of yours. In order to implement
I'm assuming some const eval code depends on that compare-alloc-by-id behavior, but I can't track it down. 🤷 |
This comment has been minimized.
This comment has been minimized.
@@ -634,7 +634,8 @@ fn check_const_value_eq<'tcx, R: TypeRelation<'tcx>>( | |||
ConstValue::Scalar(Scalar::Ptr(a_val, _a_size)), | |||
ConstValue::Scalar(Scalar::Ptr(b_val, _b_size)), | |||
) => { | |||
a_val == b_val | |||
// FIXME(compiler-errors): This is highly suspicious | |||
a_val.provenance.0 == b_val.provenance.0 |
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.
this is to preserve the old "equate AllocId by value" behavior.
edit: actually I don't need this change anymore, I'll revert it when I clean up this PR.
Alright, this definitely has to do with some code relying on -- As I learn more about this code, I think I was silly to think |
Well this is a rough set of working changes. I can clean it up tomorrow... |
Ah yes, sorry. I completely forgot about allocations themselves. Remove their HashStable impl and make it a free/inherent function. Then you can just keep calling it from ConstAlloc's impl |
Oh, my browser didn't refresh. Ignore the previous comment. Reading the impl now |
This comment has been minimized.
This comment has been minimized.
Looks like most of these manual impls will be gone when we get valtrees... so I am somewhat inclined to roll with the general idea. I was considering just swapping out the |
I am a bit worried about considering allocations equal when their contents are equal (but their ID is not) -- this might make sense for some allocations, but certainly not for all of them (e.g., |
we're def not going to do that :) I'm more than worried about something like this. Hash/Eq should just be plain derives on |
@oli-obk: yeah, I considered that too, especially because |
Yea, I agree it would kill perf, so let's keep doing what you were doing |
let (ptr, offset) = ptr.into_parts(); | ||
tcx.get_global_alloc(ptr).hash_stable(hcx, hasher); | ||
offset.hash_stable(hcx, hasher); | ||
size.hash_stable(hcx, hasher); |
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.
Is it really necessary to hash size
? This is the pointer size of the target, so identical for all pointers. Why would we need to hash this too?
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.
Good point, but I'd rather implement a correct implementation of HashStable than an optimized one first. I'll leave a FIXME and get back to it.
8ac75ce
to
0e1b142
Compare
0e1b142
to
50a22d9
Compare
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
Literally don't know what's going on with these tests. I don't even understand what these diagrams are trying to convey 😵💫. I guess something is hashing one of these types that I fixed in the example and using them for diagnostics? |
😄 these are normalized to hide the actual id, but that doesn't account for IDs with different number of digits. Also you need to bless tests with |
I'll try to take a stab at fixing these CI failures in a few days. @rustbot author |
Good. :) In that case I guess I don't understand what actually is being done here.
Should we have Hash/Eq at all on |
Well looks like CI is happy once I blessed the 32-bit tests, so @rustbot ready |
Is this PR still necessary with the realization in https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/valtrees/near/270830218 that we don't need to put alloc IDs into query keys? |
my understanding is that this PR mostly addresses hashing the structs that are returned by various queries, not the ones used as keys |
Right, but most of these will become obsolete with valtrees. The ones that don't, should actually be using alloc IDs by their identity, as otherwise static items may get the deduplication, too, and that is bad. We have existing bugs around this for mutable references in static mut (and probably interior mut ones in plain statics) |
I am not opposed to closing this PR in favor of waiting for valtrees to be the proper fix of representing stable const values returned by queries. Lemme know if that's what you mean and I can close this out. |
I do. Closing then, thanks for trying it out! |
(take 2:)
This PR removes the
HashStable
implementation fromAllocId
, and fixes theHashStable
implementation onConstValue
,ConstAlloc
, andAllocation
so that theirEq
andHashStable
implementations agree (as required byHashStable
).Fixes #93470
r? @oli-obk