Fix cross-module interface field/method vtable index mismatch#252
Merged
Conversation
Interface vtable slot numbers were assigned by two inconsistent algorithms: declaration-time assignment used raw interleaved declaration order, while cast-time assignment (getVirtualTable) always puts methods before fields. Whichever module performs an actual cast keeps the correct methods-first layout; a module that only reads an already-typed interface value it imported never runs the cast-time algorithm and keeps the stale declaration-order index, so a field read could land on a method's vtable slot (a function pointer misread as a byte offset) and crash the JIT with 0xC0000005. Add InterfaceInfo::assignCanonicalVirtualIndexes(), a pure function of the interface's own declaration, computed once when the declaration finishes resolving so all modules that re-parse it agree. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This was referenced Jul 19, 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.
Summary
InterfaceInfo::fields/methods'svirtualIndex) were assigned by two inconsistent algorithms: declaration-time assignment used raw interleaved declaration order, while cast-time assignment (getVirtualTable) always puts all methods before all fields.A.counter.countwhereA.counterisexported from another compiled module) never triggers the cast-time algorithm, so it kept the stale declaration-order index while the exporting module's real vtable used the methods-first layout - a field read could land on a method's vtable slot (a function pointer misread as athisVal-relative byte offset) and crash the JIT with0xC0000005.InterfaceInfo::assignCanonicalVirtualIndexes()computes the canonical (extends-offset, then methods in order, then fields in order) layout once when an interface declaration finishes resolving, independent of any cast - so every module that parses/re-parses the same interface declaration (including the@dllimporttextual redeclaration path used for-sharedimports) agrees on slot numbers.Counterinterface field/method regression coverage inexport_object_literal_with_interface.ts/import_object_literal_with_interface.tsthat was previously reverted (crashing) while this bug was still open.Test plan
ctest -R export-import-object-literal-with-interface(both AOT and JIT variants) now passctest -C Debug- 714/714 passed, no regressions🤖 Generated with Claude Code