-
Notifications
You must be signed in to change notification settings - Fork 830
Fix conflicting generalized types in TypeSSA #8119
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
base: main
Are you sure you want to change the base?
Conversation
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.
| } | ||
| }; | ||
|
|
||
| struct UniqueRecGroups { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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.
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.