Skip to content

A module imported as source that a library it reaches holds is imported from that library - #770

Merged
ASDAlexander77 merged 3 commits into
mainfrom
fix-shared-nested-import-redefinition
Nov 5, 2026
Merged

ASDAlexander77 merged 3 commits into
mainfrom
fix-shared-nested-import-redefinition

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Problem

Under test-runner -shared every module except the program is linked into one library, named after the first module. With main -> m2 -> m1, the program imported m2 as source. It reached the library m1 only inside m2, and the library then declared m2 a second time while m2's source was already declaring it. The result was error: redefinition of symbol named 'f2' followed by module verification error. Plain test-runner passed.

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 place m2's definitions exist.

Fix (MLIRGenModule.cpp)

  • mlirGenInclude first 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.
  • A library never declares a module whose source is being generated around it (declSymbolsInProgress). That includes the program itself.
  • mlirGenImportSharedLib now reads a library the same way inside a declaration-mode source import. Before, its @dllimport function globals were made external and their symbol lookups were left at the module's top level (Global is referenced by parentless instruction).
  • importLibraryPath is split out of mlirGen(ImportDeclaration) so the scan resolves library paths the same way.

Tests

🤖 Generated with Claude Code

ASDAlexander77 and others added 3 commits November 5, 2026 19:03
…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>
@ASDAlexander77
ASDAlexander77 merged commit a96b0e4 into main Nov 5, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-shared-nested-import-redefinition branch November 5, 2026 19:42
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.

1 participant