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

Do recursive shrinking without recursive function calls #1

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

neithernut
Copy link

Originally BurntSushi#294

BurntSushi and others added 25 commits May 23, 2023 12:44
... so that memchr builds. Sigh.
* Shut up non_fmt_panic warning

Like a few other macros, `panic!` accepts a format string and arguments.
The format string is meant to be static and calling it with a message
string will generate a warning. Currently, the warning also indicates
that `rustc` will generate an error instead in the near future.

* Eliminate redundant format! in panic!

The `panic!` matro itself does take a foramt string. In fact, the
redundant format generated a warning.
… crates.io badge (BurntSushi#309)

* Use SPDX license format and remove outdated Travis CI reference

* Fix crates.io badge
Currently https://docs.rs/quickcheck doesn't say much about what this crate does. I think having most info in the README is OK, but probably there should be some info in the crate docs root as well.
Required by `env_logger` crate
We try to shrink values recursively, i.e. when a shrunk value witnesses
a failure, we'd shrink that value further. Previously, this recursion
would be implemented via actual control flow recursion, i.e. a function
calling itself. Since the recursion could not be unrolled by the
compiler, this could result in stack overflows in some situations.

Albeit such an overflow would often hint at a faulty shrinker (e.g. a
shrinker yielding the original value), the stack overflow could also
occur in other situations.

This change switches from a recursive control flow to explicitly
swapping out the shrinking iterator during the iteration.
In the past, shrinking was implemented using recursion in the control
flow. `shrink_failure` would call itself. That function was introduced
originally in

        5b19e7c

presumably in order to implement recursive shrinking. However, we
recently choose an approach which would not rely on recursive control
flow but on swapping out an iterator. Thus, the reason why
`shrink_failure` existed in the first place doesn't exist any more.
This change moves the logic in its original place, but also replaces the
`match` which enclosed the call to `shrink_failure` with an `if`.
@neithernut neithernut force-pushed the non-recursive-shrinking branch from 61ae277 to d930487 Compare March 10, 2025 09:37
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.