-
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
Deterministic FxHashSet
wrapper
#94188
Conversation
r? @nagisa (rust-highfive has picked a reviewer for you, use r? to override) |
Right now it seems that |
I had a couple of questions:
|
This comment has been minimized.
This comment has been minimized.
FxHashSet is just an alias for the regular HashSet (with a different hash algorithm), so it should not implement HashStable either.
It's not a problem for a type to implement both |
Ah, since it was a wrapper I assumed we wanted to drop some methods and traits, but wasn't sure which ones. |
718f98f
to
55d7ac1
Compare
This comment has been minimized.
This comment has been minimized.
The current problem is that some places require
For point 2, I have a question: Where does one create or acquire |
Using either |
55d7ac1
to
c13de89
Compare
This comment has been minimized.
This comment has been minimized.
I have tried in vain to grok through the layers of macros here, I'm not entirely sure where the last compilation error is coming from. I've tried to grep for |
You are probably looking for https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/query/mod.rs |
Yeah, those errors are really hard to decipher. @bjorn3 is right: https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/query/mod.rs defines all queries in the compiler. All query keys and results must implement HashStable -- and HashSet (which includes FxHashSet) doesn't anymore. So all occurrences of those must be replaced with StableSet in that file. Likewise, the "query prodivers" (i.e. the actual implementations of the queries defined in that file) must be update accordingly. |
In some cases I've seen, Also, adding |
c13de89
to
05d1db9
Compare
This comment has been minimized.
This comment has been minimized.
05d1db9
to
75a8132
Compare
The current compilation problem is that we need an implementation of |
This comment has been minimized.
This comment has been minimized.
Another open question: Which one to use where? I could avoid compilation errors with either but I don't want to code in something that won't pass tests, or worse, cause silent bugs. |
☔ The latest upstream changes (presumably #94129) made this pull request unmergeable. Please resolve the merge conflicts. |
Aren't we using pointers as keys in a number of places? |
Looks like we do for |
I think the safe way to compare them would be to simply compare the contents of the pointers. Maybe what we need isn't really a wrapper -- But instead just to:
|
That doesn't fix the iteration order problem. |
Let me clarify: The argument for making the serialized version independent of iteration order is only about deterministic builds, not about incremental compilation. That is, if we have two compilation sessions that both serialize a set
I agree. There's an interesting (but not immediately relevant) subtlety there: As far as I know, FxHashSet, and SwissTable-based hash maps in general, do not give a guarantee that |
I did some experimentation, and this is what I came up with: It basically adds an unordered version of let mut src: StableMap<u32, u32> = Default::default();
src.insert(1, 2);
let mut dst: StableMap<u64, u64> = Default::default();
dst.extend(src.items().map(|(&k, &v)| (k as u64 + 1, v as u64 + 1))) The hope is that this allows us to avoid unnecessarily sorting things if they end up in an unsorted context afterwards anyway. Does that make sense? |
Yes! |
Okay, I've rebased and added the suggested API. I'm attempting to mirror parts of the API as I need them, but I have to change over some occurrences first. |
The job Click to see the possible cause of the failure (guessed by this bot)
|
@@ -910,17 +910,14 @@ pub fn provide(providers: &mut Providers) { | |||
}; | |||
|
|||
let (defids, _) = tcx.collect_and_partition_mono_items(cratenum); | |||
for id in &*defids { | |||
if defids.any(|x| { |
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.
if defids.any(|x| { | |
if defids.any(|id| { |
☔ The latest upstream changes (presumably #95524) made this pull request unmergeable. Please resolve the merge conflicts. |
Based on this comment, I'll switch to waiting on author to implement suggested changes. Please feel free to request a review when ready, thanks! @rustbot -S-waiting-on-review +S-waiting-on-author |
@hameerabbasi any updates on this? |
I think it's okay if someone else takes over after this weekend. I'll try to resolve the comments already posted. |
It seems |
Hi, after we recently ran into a critical issue that could have been prevented by this, I decided to try and make some progress more quickly. I opened rust-lang/compiler-team#533, which suggests a replacement for StableMap and StableSet, very much like I proposed above (#94188 (comment)). This is mostly implemented in michaelwoerister@694136d (although I'm going to rename If you are still interested in this topic, @hameerabbasi, I can ping you when the new collection types have been merged. Then we can start using them in more cases. But I would suggest doing it in smaller pieces at a time. I suggest closing this particular PR -- although I do think the work that has been done here was very important in exploring the design space! |
@michaelwoerister Feel free to cc me when the PR is ready! I'll follow along from the sidelines, and probably leave a question/comment here and there. Just so you're aware, my time to work on FOSS in general is limited to about 4-6 hours a week, due to a day job, a move to another country and the procedures surrounding that. If you feel slow progress is still useful progress, I'd like to spend time on this. |
Sounds good, @hameerabbasi! |
Closing this based on the comments above |
FYI, the replacement PR is up at #102698. |
xref #63713
r? @michaelwoerister