Improve the generation of fuzz functions#243
Merged
cfallin merged 4 commits intobytecodealliance:mainfrom Sep 23, 2025
Merged
Conversation
Previously, the ranges of the knobs for generating components of a functions were hard-coded in `Func::arbitrary_with_options`. This change extracts some of them to `Options` to (a) allow for more control from outside and (b) to explain what these parameters are doing. The one functional change here is that `num_clobbers_per_inst = 0..=10` is used both times clobbers are created (callsite-ish arm and clobbers arm); previously the clobbers arm only clobbered `0..=5` registers. It seemed possible that this was just an oversight (?).
This change avoids iterating over the blocks twice--once will do fine. It is unclear, though, whether this loop should even exist: it seems like it is re-doing the "connect block successors and predecessors" work that `Func::add_edge` is already doing (TODO).
This is simply a readability refactor: the internal logic of `Func::arbitrary_with_options` is quite complex already, so moving some of the smaller pieces out into separate functions makes things clearer.
cfallin
approved these changes
Sep 23, 2025
Member
cfallin
left a comment
There was a problem hiding this comment.
Thanks for all of these cleanups!
This file contains hidden or 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
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 is intended as a non-functional refactor (with one caveat below). The generation of functions is quite tricky:
regalloc2must always generate test case functions that are allocatable. But the complex logic ofFunc::arbitrary_with_optionsmakes this more difficult than it already is. This change attempts to simplify, document, and allow users of theFunc::arbitrary_with_optionsmore control over the generated test cases.The one caveat is the number of clobbers. Previously, we generated different amounts of clobbers if
opts.fixed_regs && opts.callsite_ish_constraintsand ifopts.clobbers:0..=10versus0..=5. I suspect this is an oversight (?) so I just used the sameopts.num_clobbers_per_instin both cases. This does change the fuzzing DNA, invalidating the corpus, but this will happen soon anyways if we start fuzzingOperandConstraint::Limit.