Skip to content

Fix determinism bug in type name updating#8359

Merged
tlively merged 2 commits intomainfrom
map-type-names-determinism-fix
Feb 23, 2026
Merged

Fix determinism bug in type name updating#8359
tlively merged 2 commits intomainfrom
map-type-names-determinism-fix

Conversation

@tlively
Copy link
Member

@tlively tlively commented Feb 21, 2026

There was previously a determinism bug where the result of updating type
names could depend on the iteration order of the oldToNewTypes map. The
bug occurred when the new types were a shuffling of the old types. The
update loop updated the module's type names in-place for the new types,
and those in-place updates could affect later results if the updated new
types were later visited as old types.

Fix the bug by collecting all changes to apply before applying them to the module's types and indices. This does not affect any existing tests,
but it will unbreak CI for #8217.

There was previously a determinism bug where the result of updating type
names could depend on the iteration order of the oldToNewTypes map. The
bug occurred when the new types were a shuffling of the old types. The
update loop updated the module's type names in-place for the new types,
and those in-place updates could affect later results if the updated new
types were later visited as old types.

Fix the bug by collecting all changes to apply before applying them to the module's types and indices. This does not affect any existing tests,
but it will unbreak CI for #8217.
@tlively tlively requested a review from kripken February 21, 2026 03:42
// Do not overwrite the entry for the old type if it has already appeared
// as a new type.
if (newTypeNames.insert({old, names}).second) {
seenTypeNames.insert(names.name);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it ok to unconditionally do this insert? I'm not sure what the comment is saying is dangerous to overwrite, as this is just a set of names - we can't overwrite a value for a key, given there are only keys?

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 comment is referring to the use of newTypeNames.insert({old, names}) rather than newTypeNames[old] = names.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, now i see, thanks...

Copy link
Member Author

Choose a reason for hiding this comment

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

Although looking at this again, I'm not sure that's even necessary. We're iterating over the old types, so they can only ever appear once as keys. I think this insert probably always succeeds.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh no, nevermind, because we already do newTypeNames[new_] = ... above.

@tlively tlively enabled auto-merge (squash) February 23, 2026 21:51
@tlively tlively disabled auto-merge February 23, 2026 22:46
@tlively tlively merged commit 69d6900 into main Feb 23, 2026
17 checks passed
@tlively tlively deleted the map-type-names-determinism-fix branch February 23, 2026 22: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