Repository navigation
A module imported as source that a library it reaches holds is imported from that library - #770
Merged
Merged
Conversation
…ed from that library
Under test-runner -shared every module but the program is linked into one library, named
after the first module. With main -> m2 -> m1 the program imported m2 as source, met the
library m1 only inside m2, and the library declared m2 again while m2's source was declaring
it: "redefinition of symbol named 'f2'". Skipping it there was not enough - linked with the
library alone, the program has no other definition of what m2's source declares.
mlirGenInclude now follows the module's imports (and theirs), read once per file, and when a
library they reach holds the module itself, imports the library in its place. A library never
declares a module whose source is being generated around it (declSymbolsInProgress), the
program's own included. And a library is read the same inside a declaration-mode source
import: its function globals were made external, their symbol lookups left at the module's
top ("Global is referenced by parentless instruction").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nto fix-shared-nested-import-redefinition # Conflicts: # tslang/lib/TypeScript/MLIRGenImpl.h
Left out while a module imported as source was declared twice when the library it reached held it as well; with that fixed the library chain_01 holds every link and chain_20 is imported from it. 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.
Problem
Under
test-runner -sharedevery module except the program is linked into one library, named after the first module. Withmain -> m2 -> m1, the program importedm2as source. It reached the librarym1only insidem2, and the library then declaredm2a second time whilem2's source was already declaring it. The result waserror: redefinition of symbol named 'f2'followed bymodule verification error. Plaintest-runnerpassed.Skipping the library's copy there doesn't work either. The program is linked against the library alone (
lld: undefined symbol: f2), so the library is the only placem2's definitions exist.Fix (
MLIRGenModule.cpp)mlirGenIncludefirst follows the module's imports, and theirs. Each file is parsed once and the result is cached (libraryHoldingModule). If a library reached that way holds the module itself (it exports its__decls_<suffix>), that library is imported in place of the source. This happens before the source is read, because once the source has been generated, even by discovery, its declarations would sit beside the library's.declSymbolsInProgress). That includes the program itself.mlirGenImportSharedLibnow reads a library the same way inside a declaration-mode source import. Before, its@dllimportfunction globals were made external and their symbol lookups were left at the module's top level (Global is referenced by parentless instruction).importLibraryPathis split out ofmlirGen(ImportDeclaration)so the scan resolves library paths the same way.Tests
New
reference-path-import-nested(compile,-shared,-jit -shared):nested_import -> nested_middle -> nested_bottom, with the library named afternested_bottom.Full
ctest -C Releasebefore the merge: 6632/6632 passed.import-chain/deep_chain.tsnow also runs under-sharedand-jit -shared(added by An import is discovered once: nested imports were generated 2^depth times #769, merged into this branch). The librarychain_01holds every link, andchain_20is imported from it. Each variant takes about 1.4 s.After merging main (-mm=own: a thrown parameter is kept; an awaited borrowed string is copied #768, An import is discovered once: nested imports were generated 2^depth times #769), the full
ctest -C Releasepassed 6644/6644.🤖 Generated with Claude Code