Skip to content

Reapply "Fix open world public types" (#8802)#8810

Merged
tlively merged 8 commits into
mainfrom
reland-public-type-fix
Jun 15, 2026
Merged

Reapply "Fix open world public types" (#8802)#8810
tlively merged 8 commits into
mainfrom
reland-public-type-fix

Conversation

@tlively

@tlively tlively commented Jun 6, 2026

Copy link
Copy Markdown
Member

This reverts commit 9e3b947.

Beyond reapplying the original commit, this adds special handling when func is exposed so that function types used only to declare unreferenced functions or for control flow are not considered public. Type identity does not matter and does not need to be preserved in these cases. This avoids an assertion failure in MinimizeRecGroups when control flow types or unreferenced function types differ from public types only in exactness when custom descriptors is disabled. This can happen as a result of optimizations such as DAE, which are free to change the types of unreferenced functions.

Fixes #8718, #8798, #8799.

tlively added 2 commits June 5, 2026 17:50
This reverts commit 9e3b947.

Beyond reapplying the original commit, this adds special handling when `func` is exposed so that we avoid considering function types used only to declare unreferenced functions public. This avoids an assertion failure in MinimizeRecGroups when a previous pass like DAE optimizes an unreferenced function's type to differ from a public function type only by e.g. the exactness of a reference when custom descriptors is disabled. The assertion in MinimizeRecGroups is checking that all public types are distinguishable from each other given the enabled feature set. This is something we enforce when parsing input modules, so it makes sense to keep as an invariant of the IR. The change to consider types used only for unreferenced functions private lets us maintain that invariant without giving up optimization power unnecessarily.
@tlively tlively requested a review from a team as a code owner June 6, 2026 00:50
@tlively tlively requested review from stevenfontanella and removed request for a team June 6, 2026 00:50
@tlively

tlively commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

Still working through additional fuzz bugs on this. Marking as draft for now.

@tlively tlively marked this pull request as draft June 8, 2026 22:01
@tlively tlively marked this pull request as ready for review June 11, 2026 18:57
@tlively

tlively commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

Fuzzer seems happy enough now, although I'll continue running it to see if anything else turns up.

Comment thread src/ir/module-utils.cpp Outdated
// Find functions types that are used only in the declarations of
// unreferenced functions.
std::unordered_map<HeapType, Index> unreferencedCount;
for (auto& [func, referenced] : referencedFuncs) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: let's use const for these loop variables to make it clearer to read? ditto below

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done.

Comment thread src/ir/module-utils.cpp Outdated
bool newType = false;
if (auto it = seenSigs.find(sig); it != seenSigs.end()) {
info.info[it->second].useCount += count;
sigInfo = &info.info[it->second];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: it looks like we expect the lookup to succeed here, is that right? If so, let's use .at() instead to convey the intent better and fail loudly if the assumption is wrong?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done.

Comment thread src/ir/module-utils.cpp Outdated
// exposure is upgraded, we re-push it to the worklist to update the
// propagation to related types.
auto markPublic = [&](HeapType type, Exposure state) {
auto [it, inserted] = exposures.insert({type, state});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: looks like we can do try_emplace to avoid a move?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done.

@tlively tlively enabled auto-merge (squash) June 15, 2026 20:52
@tlively tlively merged commit 988db58 into main Jun 15, 2026
15 of 16 checks passed
@tlively tlively deleted the reland-public-type-fix branch June 15, 2026 21:15
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.

Open world --gufa bug

2 participants