Skip to content

JIT: an import pointing to a .ts file is included with its bodies - #404

Merged
ASDAlexander77 merged 3 commits into
mainfrom
claude/vigilant-wozniak-6dh4ue
Sep 29, 2026
Merged

ASDAlexander77 merged 3 commits into
mainfrom
claude/vigilant-wozniak-6dh4ue

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Problem

Under the JIT, a program importing a class from another .ts file could not create an instance of it:

// main.ts
import './other'
print("Hello World", new S());

// other.ts
export class S { toString() { return "Hi"; } }

tslang main.ts failed with JIT session error: Symbols not found: [ S..new ]. mlirGenInclude always generated an imported .ts module as declarations only. Under the JIT nothing else provides the bodies, so S..new was only declared. S..new was just the first missing symbol; S.toString and the vtable had no bodies either.

Import rules after this change

import of a .ts file import of a .dll / .so
compile (--emit=obj/exe/dll) declarations only: each module is compiled to its own object and the objects are linked into one program declarations read from the library's embedded declarations; linked as for a .ts import (unchanged)
JIT (--emit=jit) included with its bodies declarations read from the library, which the program loads dynamically at run time

A .d.ts file is read as declarations either way.

Changes

  • MLIRGenModule.cpp (mlirGenInclude): declarationMode = !compileOptions.isJit.
  • test-runner.cpp: in -jit -shared mode on Linux, the imported library is no longer passed with --shared-libs. The import loads it at run time. This matches the Windows runner, which already did this.
  • New tests in test/tester/import-source/: the example above as a JIT test (test-jit-import-source-new-imported-class), plus compiled, -shared and -jit -shared variants in which the module is built separately.

Testing

Linux, Release build with the prebuilt LLVM 22.1.8: the full ctest suite passes (3121 passed, 0 failed, 1 test already disabled). Not built or tested on Windows.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VPAHhg8c9NEdoYNw52AtTg


Generated by Claude Code

mlirGenInclude generated an imported .ts module as declarations only, so a
program run on its own (tslang main.ts, JIT) found no bodies for what it
imported: 'Symbols not found: [ S..new ]' for new S() of an imported class.
An import pointing to a .ts file now includes it with its bodies, like a
referenced file; one pointing to a library (lib<name>.so / <name>.dll) still
takes them from the library. A .d.ts stays declarations only.

Known: test-runner still compiles each imported module into an object of its
own and links it beside the importer, so the multi-module export-import,
reference-path, shared-class-members and import-bindings tests now fail with
'multiple definition' link errors until the runner stops doing that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VPAHhg8c9NEdoYNw52AtTg
…t, not --shared-libs

A library an `import` points to is loaded by the program at run time; passing
it with --shared-libs as well is not how it is meant to be used (and matches
the Windows runner, which already did not). The 56 test-jit-shared tests pass,
including the reference-path diamond/cycle and shared-class-members ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VPAHhg8c9NEdoYNw52AtTg
…e JIT it is included

Compiled, each .ts module is an object of its own and the objects are linked
into one program, so an import pointing to a .ts file only declares what the
module has. Under the JIT there is no other object: the file is included with
its bodies. The import-source test now also runs compiled, with the module's
object linked beside the program.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VPAHhg8c9NEdoYNw52AtTg
@ASDAlexander77
ASDAlexander77 merged commit edaf802 into main Sep 29, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the claude/vigilant-wozniak-6dh4ue branch September 29, 2026 16:00
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.

2 participants