Skip to content

[analysis] Improve lattice fuzzer #6050

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

Merged
merged 3 commits into from
Oct 27, 2023
Merged

[analysis] Improve lattice fuzzer #6050

merged 3 commits into from
Oct 27, 2023

Conversation

tlively
Copy link
Member

@tlively tlively commented Oct 25, 2023

Implement new RandomLattice and RandomFullLattice utilities that are
lattices randomly created from other lattices. By recursively using themselves
as the parameter lattices for lattices like Inverted and Lift, these random
lattices can become arbitrarily nested.

Decouple the checking of lattice properties from the checking of transfer
function properties by creating a new, standalone checkLatticeProperties
function.

Base automatically changed from lift-lattice to main October 25, 2023 20:51
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

The diff here seems to show a lot of code I've already reviewed. Should this be rebased on that chain of PRs that is landing now?

Implement new `RandomLattice` and `RandomFullLattice` utilities that are
lattices randomly created from other lattices. By recursively using themselves
as the parameter lattices for lattices like `Inverted` and `Lift`, these random
lattices can become arbitrarily nested.

Decouple the checking of lattice properties from the checking of transfer
function properties by creating a new, standalone `checkLatticeProperties`
function.
@tlively
Copy link
Member Author

tlively commented Oct 25, 2023

@kripken, the diff should now be fixed.

// not allow concepts to depend on themselves. Also make the pointer copyable to
// satisfy that constraint on lattice elements.
template<typename L>
struct RandomElement : std::unique_ptr<void, void (*)(void*)> {
Copy link
Member

Choose a reason for hiding this comment

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

To be sure I follow, this is a unique pointer to a void (!), and also has a destructor of type void *(void*)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct!

: RandomElement([&]() {
auto copy = *other;
return copy;
}()) {}
Copy link
Member

Choose a reason for hiding this comment

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

Can't other be unallocated before the lambda here is called? The lambda doesn't keep it alive AFAIK.

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 lambda is only called immediately as part of the initialization expression, so other will definitely still be alive. The only reason we have a lambda here is that I don't know how to make a copy of a referenced value without assigning it to some lvalue. We need a copy of other in the first place because we can't pass other directly to the other constructor because we can't move out of it.

@tlively
Copy link
Member Author

tlively commented Oct 26, 2023

The test failure on alpine is unrelated and fixed by #6054.

// because they depend on `RandomFullLattice` satisfying `FullLattice`, but
// that requires the type to be complete.
struct L;
struct ElementImpl;
Copy link
Member

Choose a reason for hiding this comment

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

Wait, C++ lets you do a forward declaration in the struct definition, and you can define the forward-declared thing later outside? So you could even define it in another file..? How can that work?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, just like for a method. The type isn't complete until you define it, of course, which is why many of the methods below also have to be defined out of line, and after L and ElementImpl have been defined.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately you can't forward-declare a using statement, which is why these have to be expressed with structs and trivial inheritance.

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

lgtm but I worry about some day needing to debug this intricate C++ code my self 😄 but as it is in fuzzer code I worry less.

@tlively tlively merged commit 57e0b2f into main Oct 27, 2023
@tlively tlively deleted the fuzz-lattice branch October 27, 2023 20:48
radekdoulik pushed a commit to dotnet/binaryen that referenced this pull request Jul 12, 2024
Implement new `RandomLattice` and `RandomFullLattice` utilities that are
lattices randomly created from other lattices. By recursively using themselves
as the parameter lattices for lattices like `Inverted` and `Lift`, these random
lattices can become arbitrarily nested.

Decouple the checking of lattice properties from the checking of transfer
function properties by creating a new, standalone `checkLatticeProperties`
function.
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