Skip to content

Conversation

@kripken
Copy link
Member

@kripken kripken commented Dec 5, 2025

Mutation will find the necessary types of children, which can be more
general than the current child, and replace them. It did not handle
children with multiple constraints, however, like this:

(br_if $target
  (value)
  (condition)
)

The value here must be a subtype of the thing the br_if flows into,
and also of the block it targets - the value is sent twice, effectively,
so it has two subtyping constraints.

Add a GLBFinder utility for this, parallel to LUBFinder.

@kripken kripken requested a review from tlively December 9, 2025 23:51
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.

I wonder if it would be less new code to just use an element of the ValType lattice and use meet to update it: https://github.com/WebAssembly/binaryen/blob/main/src/analysis/lattices/valtype.h

private:
// The greatest lower bound. As we go this always contains the latest value
// based on everything we've seen so far.
Type glb = Type::unreachable;
Copy link
Member

Choose a reason for hiding this comment

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

We should use Type::none as the initial value, since it behaves very similarly to a top type whereas Type::unreachable is the bottom type. (This still requires some special casing, since Type::getGLB does not treat Type::none as top; we should consider fixing that to make Type::getLUB and Type::getGLB more consistent with each other.)

Copy link
Member Author

@kripken kripken Dec 10, 2025

Choose a reason for hiding this comment

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

Unreachable happens to be the bottom type in the lattice, but in this API, unreachable is the "uninitialized / we have seen no reachable data yet" marker. We ignore inputs of unreachable, and we start in that state.

That is, we want to ignore unreachable data - it does not constrain us - so GLBFinder.note(unreachable) should do nothing, not turn us into the bottom.

Avoiding that is consistent with LUBFinder and seems like the most intuitive API here to me.

(For similar reasons, using ValType's meet would be more work here, I found as I tried that now.)

Copy link
Member

Choose a reason for hiding this comment

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

But the GLB/meet of any type t with bottom (i.e. unreachable) is t, so you should get the "ignore unreachable" behavior for free, right? All you have to do is use none as the "uninitialized / we have seen no reachable data yet" marker.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wait, isn't it the opposite? Meet refines, towards the bottom, using the GLB. So the GLB/meet of any type t with bottom (i.e unreachable) is bottom (unreachable).

Here is that in the code:

if (!a.isRef() || !b.isRef()) {
return Type::unreachable;
}

Copy link
Member

Choose a reason for hiding this comment

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

Oh right, I was confused.


using namespace wasm;

TEST(GLBsTest, Basics) {
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to test the edge cases around Type::none and Type::unreachable as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added testing for one corner case, and assertions for others that it seems better to just disallow as invalid.

@kripken kripken merged commit 56f8f4f into WebAssembly:main Dec 12, 2025
17 checks passed
@kripken kripken deleted the fuzz.fix.extracted branch December 12, 2025 16:46
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