Skip to content
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

remove rand as a public dependency + rollup and other cleanups #265

Merged
merged 8 commits into from
Dec 27, 2020

Conversation

BurntSushi
Copy link
Owner

@BurntSushi BurntSushi commented Dec 27, 2020

Part of this PR is meant to address #241, which was an unhappy reaction to how rand was evolving at the time. Since then, rand has slowed down its development and slimmed its dependency tree. It's still not quite as small as what quickcheck needs (which is really just a non-crypto PRNG), but it's closer.

One idea I and @matklad had was to just remove rand from the public API of QuickCheck. Doing this has a cost: it removes the ability to provide your own RNG to quickcheck and instead moves the use of the RNG to an implementation detail. My feeling is that providing one's own RNG to quickcheck was seldom-if-ever used, so I judged this to be an acceptable cost. In return, we are no longer pinned to rand's release cycle and we now have the freedom to switch out the RNG in the future if we want. For now, we upgrade to rand 0.8 and otherwise leave it alone for now.

In addition to losing the ability to provide your own RNG, we also lose a lot of the lower level RNG convenience routines provided by rand. I believe we can capture much of that by just exposing concrete routines on quickcheck::Gen, in addition to the various Arbitrary impls.

The reasons why the Gen trait existed in the first place were:

  1. I believe I copied the design as faithfully as possible from Haskell's QuickCheck, and IIRC, it is generic over the RNG.
  2. At the time I wrote QuickCheck, RNGs were part of the standard library. Once RNGs moved out into the crate ecosystem, the costs of making that crate a public dependency manifested itself.

Anywho, I've written all this out so that it's clear what has changed and why. In particular, if you find yourself at this PR because some functionality in quickcheck has been removed, then please open a new issue that includes the problem you're trying to solve and we'll try to figure out how to move forward.

BurntSushi and others added 8 commits December 27, 2020 12:59
The Send bound is a relic from the past. Indeed, the docs for the
Arbitrary trait have been outdated for quite some time. quickcheck
stopped running each test in a separate thread once
`std::panic::catch_unwind` was stabilized many moons ago. With
`catch_unwind`, the `Send` bound is no longer necessary.

We do need to retain the `'static` bound though. Without that,
implementing shrink seems implausible.

Fixes #262, Closes #263
This commit tweaks the Arbitrary impls of number types (integers,
floats) to use the full range with a small bias toward "problem" values.
This is a change from prior behavior that would use the `size` parameter
to control the range of integers.

In retrospect, using the `size` parameter this way was probably
misguided. Instead, it should only be used to control the sizes of data
structures instead of also constraining numeric ranges. By constraining
numeric ranges, we leave out a huge space of values that are never
tested.

Fixes #27, Fixes #119, Fixes #190, Fixes #233, Closes #240
We add a little sophistication here for whether the CString is
completely valid UTF-8 or whether it's just an arbitrary mix of bytes.
(Excluding NUL of course.)

Fixes #165, Closes #257
This removes the use of the rand_core crate as a public dependency. It
is now an implementation detail.

We achieve this primarily by turning the `Gen` trait into a concrete
type and fixing the fallout.

This does make it impossible for callers to use their own `Gen`
implementations, but it's unclear how often this was being used (if at
all). This does also limit the number of RNG utility routines that
callers have easy access to. However, it should be possible to use
rand's `SeedableRng::from_{rng,seed}` routines to get access to more
general RNGs.

Closes #241
This upgrades to the latest version of rand.

Closes #264
The next release will be a breaking change release anyway.

We update a few other things as well. The examples in particular.
@BurntSushi BurntSushi merged commit 282f146 into master Dec 27, 2020
@BurntSushi BurntSushi deleted the ag/work branch December 27, 2020 21:18
mxinden added a commit to paritytech/unsigned-varint that referenced this pull request Jan 11, 2021
With `quickcheck` `v1` `rand` is no longer part of `quickcheck`s public
API interface. More concretely `Gen` is now a `struct` with a minimal
API.  `Arbitrary` implementations should (/must) delegate to `Arbitrary`
implementations of primitives instead of making use the random number
generator directly.

See BurntSushi/quickcheck#265 for details.
mxinden added a commit to paritytech/unsigned-varint that referenced this pull request Jan 11, 2021
With `quickcheck` `v1` `rand` is no longer part of `quickcheck`s public
API interface. More concretely `Gen` is now a `struct` with a minimal
API.  `Arbitrary` implementations should (/must) delegate to `Arbitrary`
implementations of primitives instead of making use the random number
generator directly.

See BurntSushi/quickcheck#265 for details.

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Inden <[email protected]>
@jakoschiko jakoschiko mentioned this pull request Feb 9, 2021
@akesling akesling mentioned this pull request Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants