Skip to content

Conversation

@tlively
Copy link
Member

@tlively tlively commented Dec 13, 2025

TypeSSA already had logic to detect and resolve inadvertent conflicts
between its newly constructed types and existing types. However, this
logic did not take into account the changes that the binary writer can
make when writing types, so it was still possible to construct a
situation where TypeSSA would produce types that would start conflicting
after binary writing.

Fix the problem by adding a new UniqueRecGroups utility to
wasm-type-shape.h. This utility uses the existing RecGroupShape utility,
which is aware of how the binary writer will modify types, to detect
conflicts. It uses the BrandTypeIterator, moved to wasm-type-shape.h
from MinimizeRecGroups.cpp, to create new types to differentiate rec
groups.

Make enough constructors of Type and Field constexpr that we can make
the fieldOptions array in BrandTypeIterator constexpr as well. This lets
us remove logic for initializing this array at runtime.
TypeSSA already had logic to detect and resolve inadvertent conflicts
between its newly constructed types and existing types. However, this
logic did not take into account the changes that the binary writer can
make when writing types, so it was still possible to construct a
situation where TypeSSA would produce types that would start conflicting
after binary writing.

Fix the problem by adding a new UniqueRecGroups utility to
wasm-type-shape.h. This utility uses the existing RecGroupShape utility,
which is aware of how the binary writer will modify types, to detect
conflicts. It uses the BrandTypeIterator, moved to wasm-type-shape.h
from MinimizeRecGroups.cpp, to create new types to differentiate rec
groups.
@tlively tlively requested review from aheejin and kripken December 13, 2025 03:40
Base automatically changed from constexpr-brand-fields to main December 13, 2025 20:51
}
};

struct UniqueRecGroups {
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps an overview comment?

// the group will be rebuilt with a brand at the end to make it unique.
// Returns the rebuilt types (including the brand) or the original types if no
// brand was necessary.
const std::vector<HeapType>& get(std::vector<HeapType> group);
Copy link
Member

Choose a reason for hiding this comment

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

This is called "get", but it adds a rec group - perhaps "add"?

I was confused by this API in the code, too, calls to get() seemed to have an effect that I couldn't figure out without reading this header.

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, you're right. I'll go with insert.

for (auto group : existing) {
std::vector<HeapType> types(group.begin(), group.end());
[[maybe_unused]] auto uniqueTypes = unique.get(std::move(types));
assert(uniqueTypes.size() == group.size() && "unexpected collision");
Copy link
Member Author

Choose a reason for hiding this comment

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

The fuzzer found a way to make this fail after about 80k iterations, so I'll investigate and fix that as well.

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.

3 participants