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

Add "interposition" to the fuzzer's mutate() method #6427

Merged
merged 14 commits into from
Mar 26, 2024

Conversation

kripken
Copy link
Member

@kripken kripken commented Mar 22, 2024

Before this PR we only mutated by replacing an expression with another, which
replaced all the children. With this PR we also do these two patterns:

(A
  (B)
  (C)
)

=> ;; keep children, replace A

(block
  (drop (B))
  (drop (C))
  (NEW)
)

,

(D
  (A
    (B)
    (C)
  )
)

=> ;; keep A, replace it in the parent

(D
  (block
    (drop
      (A
        (B)
        (C)
      )
    )
    (NEW)
  )
)

Even better would be to reuse the children by the new ((NEW)) expression,
but that would take significantly more work.

@kripken kripken requested a review from tlively March 22, 2024 23:06
@@ -929,16 +930,15 @@ void TranslateToFuzzReader::mutate(Function* func) {
percentChance = std::max(percentChance, Index(3));

struct Modder : public PostWalker<Modder, UnifiedExpressionVisitor<Modder>> {
Module& wasm;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unused.

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can reuse children without significantly more work by walking the children of the replacement and randomly swapping them with the original children as long as the types are compatible.

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise, but it would be nice to put the ascii art from the PR description into the code comments.

@kripken
Copy link
Member Author

kripken commented Mar 25, 2024

Good ideas. I added the art and also to replace new children with old content.

// Only drop the child if we can't replace it as one of NEW's
// children. This does a linear scan of |rep| which is the reason
// for the above limit on the number of children.
if (!replaceChildWith(rep, child)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now this will always replace the first child of rep with compatible type. For example, if rep is an i32.add and the children are i32 expressions, the LHS of rep will always end up being the last original child and the RHS will never be replaced. Should we have replaceChildWith collect and randomly pick from all of the possible child locations to increase the number of possible outcomes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, but we do have recombine() which will mix around things that way. Though we could perhaps add more logic there to reorder the children of an expression, which seems useful. How about leaving that as a TODO?

@kripken kripken merged commit 19f8cc7 into WebAssembly:main Mar 26, 2024
14 checks passed
@kripken kripken deleted the fuzz.interpose branch March 26, 2024 18:01
@gkdn gkdn mentioned this pull request Aug 31, 2024
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.

2 participants