Repository navigation
A generic specialization made during an import's discovery is regenerated - #380
Merged
Merged
Conversation
…ated An import met during a file's discovery pass is generated in full, into the discovery module, which is then erased. A generic class specialized there (Array<Node> for an imported `childNodes: Array<Node>`) was marked processed, and the real pass returned early for it, so its members never reached the module that used them. Indexing the field failed to lower: "failed to legalize operation 'ts.SymbolCallInternal'" (BrowserLib's Document.ts, #231). ClassInfo now records the module its processing state was reached in, and a specialization is only skipped in that same module. A specialization is also generated in full while an imported file is being declared: its members are linkonce_odr and belong to every module that uses them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Indexing a generic-class field of an imported class failed to lower. Found in
Document.tsof the BrowserLib sources attached to #231. It is theSymbolCallInternalerror listed there.Cause
When a file's discovery pass meets an
importof a source file,mlirGenIncludecompiles the imported file in full, both its discovery and its real pass. At that pointtheModuleis the importer's discovery module, which is erased afterwards.A generic class specialized there (
Array<Node>, the type ofchildNodes) had its members generated into that throwaway module, but itsprocessingstate stayed set. When the importer's real pass reachedArray<Node>,mlirGen(ClassLikeDeclaration)saw it as already processed and returned early. The module that used the class never got any of its members. The index access became a call toArray<Node>.get, a symbol the module did not have.Temporary tracing showed the sequence. The specialization's real-pass generation (
allowPartialResolve=0) ran insidemodule=discovery_module, and the later pass in the importer's own module foundprocessing=11and skipped it.Non-generic classes never hit this, because they are regenerated every time. Only specializations have the early return.
Fix
ClassInforecords the module itsprocessingstate was reached in (processingModule). A specialization is skipped only when it was processed in the current module; in another module it is generated again. Discovery (allowPartialResolve) keeps its own state, which is unchanged.instantiateSpecializedClassType(both overloads) turnsdeclarationModeoff while it generates the specialization. The members arelinkonce_odrand belong to every module that uses them. An importer should not rely on the imported module's object happening to keep the members it needs.Tests
test-compile-import-specialization: aTreeclass with achildren: Box<Tree>field, whereBox<T>has an indexer, imported and walked recursively throughchildren[i]. It uses a user-defined generic because the suite runs without the default lib. It fails onmainwith the sameSymbolCallInternalerror.Not in this PR
The same test through a
-sharedlibrary (test-compile-shared-…/test-jit-shared-…) fails onmainwithgeneric type Box can't be found. The importer cannot name a generic class declared in the library it imports. That is a separate gap, so only the static variant is registered.🤖 Generated with Claude Code