Skip to content

Fix bug in UniqueRecGroups - #8202

Merged
tlively merged 4 commits into
mainfrom
unique-rec-group-fix
Jan 15, 2026
Merged

tlively merged 4 commits into
mainfrom
unique-rec-group-fix

Conversation

@tlively

@tlively tlively commented Jan 14, 2026

Copy link
Copy Markdown
Member

UniqueRecGroups compares the shapes of rec groups after considering how
types will be written in the final binary for a particular feature set.
Previously its interface dealt in arbitrary vectors of types, but it
turns out that it could sometimes be subtly incorrect to pass vectors of
types that were not already all in the same rec group.

The problem is that the base case for the RecGroupShape utility that
hashes rec group shapes is either hashing the index in the group for
recursive references to types in the group or the type ID for
non-recursive references. When the type vector contains types from
different rec groups, non-recursive references across groups can
inadvertently appear and be hashed as recursive references.

Fix the problem for UniqueRecGroups by changing the interface to take
RecGroups rather than arbitrary vectors of heap types.

A regression test for this bug will be included in an upcoming PR. It
cannot be included here because it depends on running a pass that does
not exist yet.

UniqueRecGroups compares the shapes of rec groups after considering how
types will be written in the final binary for a particular feature set.
Previously its interface dealt in arbitrary vectors of types, but it
turns out that it could sometimes be subtly incorrect to pass vectors of
types that were not already all in the same rec group.

The problem is that the base case for the RecGroupShape utility that
hashes rec group shapes is either hashing the index in the group for
recursive references to types in the group or the type ID for
non-recursive references. When the type vector contains types from
different rec groups, non-recursive references across groups can
inadvertently appear and be hashed as recursive references.

Fix the problem for UniqueRecGroups by changing the interface to take
RecGroups rather than arbitrary vectors of heap types.

A regression test for this bug will be included in an upcoming PR. It
cannot be included here because it depends on running a pass that does
not exist yet.
@tlively
tlively requested a review from kripken January 14, 2026 05:04
@kripken

kripken commented Jan 14, 2026

Copy link
Copy Markdown
Member

be hashed as recursive references.

Why is this a bug? I would expect an unlucky hash collision to slow things down, but then there is an equality check after it, ensuring correctness (as in the typical hashing data structures).

@tlively

tlively commented Jan 14, 2026

Copy link
Copy Markdown
Member Author

The equality check only happens when the hashes accidentally collide. When they are accidentally different, you're out of luck.

@kripken

kripken commented Jan 14, 2026

Copy link
Copy Markdown
Member

I see, thanks.

Comment thread src/passes/TypeSSA.cpp Outdated
@@ -63,29 +63,27 @@ namespace {

// Ensure there are no conflicts between the newly built types and any existing

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.

Suggested change
// Ensure there are no conflicts between the newly built types and any existing
// Ensure there are no conflicts between the newly built types in the given RecGroup and any existing

@tlively
tlively enabled auto-merge (squash) January 15, 2026 01:52
@tlively
tlively merged commit a2ba43f into main Jan 15, 2026
17 checks passed
@tlively
tlively deleted the unique-rec-group-fix branch January 15, 2026 02:28
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