Skip to content

Attach resolvable source to IR-generated hint files (wasmJs/JS KLIB)#56

Merged
arnaudgiuliani merged 3 commits into
1.0.1from
arnaud/ktz-wall2-wasm-null-source
Jun 9, 2026
Merged

Attach resolvable source to IR-generated hint files (wasmJs/JS KLIB)#56
arnaudgiuliani merged 3 commits into
1.0.1from
arnaud/ktz-wall2-wasm-null-source

Conversation

@arnaudgiuliani

Copy link
Copy Markdown
Member

Problem

After the duplicate-signature fix (#55), wasmJs/JS still failed KLIB metadata serialization:

IllegalStateException: No file found for source null   (serializeModuleIntoKlib)

The plugin's synthetic hint files (injectedparams, DSL, call-site, annotation batch) were built with no FirFile.sourceFile. KLIB metadata serialization resolves every file to an io File (KtSourceFile.toIoFileOrNull()); a null source is tolerated by the Native backend but rejected by the JS/Wasm serializer.

Fix

Attach a resolvable KtIoFileSourceFile (the hint file's own deterministic path) to all four synthetic buildFile sites, via shared helper syntheticHintSourceFile().

Verification

  • Pure-DSL module now compiles to wasmJs (was the serialization error).
  • Box suite unchanged (IR text dumps don't include source paths — no golden drift).
  • Adds playground-apps/app-kmp-klib, a KLIB-target (wasmJs/iosArm64) regression sample.

Scope note — annotation-based wasmJs

A separate path remains for annotation modules: the FIR-generated module() and cross-module definition_* discovery hints are placed in a compiler-framework-created file with no settable source. This is a Kotlin 2.3.20 wasm/js serializer bug (KT-82395) — fixed in Kotlin 2.4.0 (verified: annotation-based wasmJs builds on 2.4.0, fails on 2.3.20). Not fixable in-plugin (FirFile.sourceFile has no setter). Guidance: use Kotlin 2.4.0 for annotation-based wasmJs.

Refs #40

Stacked on #55#52. Merge those first; this PR's diff narrows afterward.

🤖 Generated with Claude Code

…ed by multiple modules

A target type collected by more than one @componentscan module (getAllKnownDefinitions
flat-maps definitions across modules) emitted the injectedparams_<fqName> hint function
once per definition. Identical signatures are tolerated on JVM but a hard KLIB
serialization failure on Native/JS/Wasm (compiler#40, #44).

Emit the hint exactly once per target FqName (gate on localSlots.putIfAbsent). Since
only non-ambiguous targets reach this point, they share an identical shape, so a single
hint is correct.

Adds box regression test injected_param_dual_definition_single_hint (two @componentscan
modules over the same @InjectedParam target): asserts a single injectedparams_ function
(was 2 pre-fix). Full box suite green.

Refs #40, #44
… KLIB)

KCP's synthetic hint files (injectedparams, DSL, call-site, annotation batch) were
built with no FirFile.sourceFile. KLIB metadata serialization resolves every file to
an io File (serializeModuleIntoKlib -> KtSourceFile.toIoFileOrNull()); a null source is
tolerated by the Native backend but fails the JS/Wasm serializer with
'No file found for source null' (KT-82395).

Set sourceFile = KtIoFileSourceFile(<hint file path>) on all four synthetic buildFile
sites via shared helper syntheticHintSourceFile(). Verified: a pure-DSL module compiles
to wasmJs (was KT-82395). Box suite unchanged (IR dumps don't include source paths).

Note: annotation modules also generate a FIR top-level module() file whose source is
created by the compiler framework from a name-only containingFileName; that file (2b)
is not fixable in-plugin (FirFile.sourceFile has no setter) and is tracked under KT-82395.

Refs #40, KT-82395
Minimal KMP app reproducing compiler#40 (wasmJs) and #44 (iOS): the same
@InjectedParam target collected by two @componentscan modules. Exercises the
KLIB-serialized targets that JVM box tests cannot cover.

README documents the expected matrix: iOS + wasmJs-DSL pass on both Kotlin
2.3.20 and 2.4.0; wasmJs + annotations passes on 2.4.0 and is blocked on 2.3.20
by KT-82395 (a Kotlin compiler bug, not the plugin). Build artifacts gitignored;
not wired as a CI gate (the wasmJs-annotation cell is Kotlin-version-dependent).
@arnaudgiuliani arnaudgiuliani merged commit 238743a into 1.0.1 Jun 9, 2026
2 checks passed
@arnaudgiuliani arnaudgiuliani deleted the arnaud/ktz-wall2-wasm-null-source branch July 10, 2026 12:53
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