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 2 commits into
base: master
Choose a base branch
from

Conversation

neithernut
Copy link

Originally BurntSushi#294

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`.
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.

1 participant