-
Notifications
You must be signed in to change notification settings - Fork 39
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 function generation reproducability #240
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Apr 19, 2022
With a rewamped shrinker performance benchmark, below is the output of running it on this PR's fixed function generators. When added up all the timing this PR represents
|
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes #236
QCheck and QCheck2 generates functions by inhabiting (and side-effecting) an underlying
Hashtbl
, packaged asPoly_tbl
.A new function application then triggers a generator call and adds the new binding to the underlying table.
Overall, since the generator call side-effects the state of the underlying
Random.State
, the number of function applications may then unknowingly affect the output of another generator, e.g., if the function generator is part of a tuple as the example in #236:This side-effecting clearly breaks (what we tend to think of as) independence of the individual tuple entry generators.
The PR fixes the function generator by
split
ting theRandom.State
and lets the later function applications side-effect the split copy instead, thus restoring (some form of) independence. We do so for bothQCheck
andQCheck2
.The
RS.split
is part of theRandom.State
interface of the forth-coming OCaml 5.0 release - but we add a "poor man's"split
for backwards compatibility on <5.0.Finally the PR adds tests - with repeated reruns. Without the fix both of them gave rise to different prints when repeated. Both are fixed with the proposed patch.