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.
Long-standing Hypothesis shrinking advice is that when you write
one_of(x, y)
then you should make sure thatx
is simpler thany
so as to get good shrinking behaviour.But, uh, what does "simpler" mean? Well it means "has smaller representations in the Hypothesis internal shrink order". Fair enough.
Well it turns out that this secretly means two different things:
Which of these do we mean?
Well, uh, unfortunately we mean both. The former is important to get good shrinking performance/behaviour, the latter is important to to get good results once fully shrunk.
Sure would be a shame if there were common pairs of strategies where these gave different answers, huh?
Anyway
one_of(integers(), text())
is such an example.integers()
are typically (and sortof logically should be) smaller than text, but0
is actually larger than''
in both the new and old representations.This PR adds a small-integer optimisation that fixes both. It gives us a single-byte representation of small integers in the old buffer-based implementation, and adds a special case for zero in the serialisation format of the new IR representation (non-zero integers don't need special casing here, because in the new representation this is only a problem for
0
. Any string of length > 0 will be at least two bytes, so the IR already handles the sizing of small non-zero integers correctly.