Attach resolvable source to IR-generated hint files (wasmJs/JS KLIB)#56
Merged
Conversation
…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).
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
After the duplicate-signature fix (#55), wasmJs/JS still failed KLIB metadata serialization:
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 ioFile(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 syntheticbuildFilesites, via shared helpersyntheticHintSourceFile().Verification
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-moduledefinition_*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.sourceFilehas no setter). Guidance: use Kotlin 2.4.0 for annotation-based wasmJs.Refs #40
🤖 Generated with Claude Code