[GTO] Update struct field indices after localizing operands - #9108
Merged
Merged
Conversation
PR #9043 ("Avoid newly exposing prototypes in GTO") introduced prepending an i8 placeholder field at index 0 of exposed no-proto descriptors when their first field becomes prototype-exposing. When all fields of such a descriptor are kept, the new index of the last field equals the old struct's `fields.size()`. Because `updateInstructions` runs before `updateTypes` (so expression heap types still refer to the pre-optimization `Struct` definitions), and `FieldRemover` is a `PostWalker`, child `struct.get`, `struct.rmw`, and `struct.cmpxchg` instructions had their `index` mutated in-place to the new index before an enclosing `struct.new` or `struct.set` ran `ChildLocalizer` or `getResultOfFirst`. When `EffectAnalyzer` subsequently inspected those child instructions, `readsStruct` accessed `type.getStruct().fields[index]` using the old `HeapType` and the new `index`, causing an out-of-bounds assertion failure (`__n < this->size()`) or reading the wrong field's mutability. Fix this by splitting instruction updating into two passes executed in a single nested `PassRunner` invocation (`FieldRemover` followed by `IndexUpdater`), along with sequential `runOnModuleCode` runs. `FieldRemover` removes/reorders `struct.new` operands and replaces removed `struct.set`s while all struct instructions still have their old field indices matching their old `HeapType`s, and `IndexUpdater` then updates the field indices on all remaining struct instructions.
tlively
requested review from
stevenfontanella
and removed request for
a team
September 16, 2026 15:30
stevenfontanella
approved these changes
Sep 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR #9043 ("Avoid newly exposing prototypes in GTO") introduced prepending
an i8 placeholder field at index 0 of exposed no-proto descriptors when
their first field becomes prototype-exposing. When all fields of such a
descriptor are kept, the new index of the last field equals the old
struct's
fields.size().Because
updateInstructionsruns beforeupdateTypes(so expressionheap types still refer to the pre-optimization
Structdefinitions), andFieldRemoveris aPostWalker, childstruct.get,struct.rmw, andstruct.cmpxchginstructions had theirindexmutated in-place to thenew index before an enclosing
struct.neworstruct.setranChildLocalizerorgetResultOfFirst. WhenEffectAnalyzersubsequentlyinspected those child instructions,
readsStructaccessedtype.getStruct().fields[index]using the oldHeapTypeand the newindex, causing an out-of-bounds assertion failure (__n < this->size())or reading the wrong field's mutability.
Fix this by splitting instruction updating into two passes executed in a
single nested
PassRunnerinvocation (FieldRemoverfollowed byIndexUpdater), along with sequentialrunOnModuleCoderuns.FieldRemoverremoves/reordersstruct.newoperands and replacesremoved
struct.sets while all struct instructions still have their oldfield indices matching their old
HeapTypes, andIndexUpdaterthenupdates the field indices on all remaining struct instructions.