-
Notifications
You must be signed in to change notification settings - Fork 385
Implement non-deterministc mode #683
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
Conversation
cb1a3cc
to
2e28498
Compare
Part of rust-lang#653 This allows us to properly implement getrandom(), which unlocks the default HashMap type (e.g. HashMap<K, V>) with RandomState) This commit adds a new '-Zmiri-seed=<seed>' option. When present, this option takes a 64-bit hex value, which is used as the seed to an internal PRNG. This PRNG is used to implement the 'getrandom()' syscall. When '-Zmiri-seed' is not passed, 'getrandom()' will be disabled.
2e28498
to
7323957
Compare
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.
Just some nits. This is awesome!
This is pretty cool! To make the test suite pass with your changes to the HashMap tests, you'd have to also implement this for macOS and Windows. Windows says
and macOS says
Alternatively, you could make the affected tests linux-only. Then we should open two issues to track the missing support for Windows and macOS. |
Implementing random number generation on OS X will require special-casing the 'openat' system call to special-case reading from /dev/urandom
I've implemented random number generation for Windows. For now, I've left the test disabled for OS X. Implementing random number generation on OS X will be trickier, since we'll need to handle attempted reads from |
Apparently 'ignore-' doesn't work with compiletest_rs
tests/run-pass/hashmap.rs
Outdated
let map_normal: HashMap<i32, i32> = HashMap::new(); | ||
test_map(map_normal); | ||
} else { | ||
test_map(_map); |
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 you move the let _map
into this conditional branch to avoid the unused variable on other platforms? Then you can also avoid the _
in the name.
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.
I wanted to test creation of both types of maps on all platforms, even though only one has the full set of tests run on it.
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.
TBH I don't see the point, this code just looks weird. Why test creation on both but not the rest of the test?
The purpose of this is mostly to test Miri, not to test the HashMap. For that, HashBrown actually runs its test suite in Miri. I don't see a good reason to use multiple different hash functions here.
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.
My intention was to ensure that Miri's test coverage didn't regress (e.g. ensure that we catch any regressions with creating a HashMap with a custom hasher).
I'll clean it up.
@RalfJung: I've addressed your comments |
just some nits then this looks ready to go to me |
@oli-obk Fixed |
Co-Authored-By: Aaron1011 <[email protected]>
@RalfJung Fixed |
Awesome, thanks for bearing with our nitpicking :) |
Part of #653
This allows us to properly implement getrandom(),
which unlocks the default HashMap type (e.g. HashMap<K, V>)
with RandomState)
This commit adds a new '-Zmiri-seed=' option. When present,
this option takes a 64-bit hex value, which is used as the seed
to an internal PRNG. This PRNG is used to implement the 'getrandom()'
syscall.
When '-Zmiri-seed' is not passed, 'getrandom()' will be disabled.