Fix Kotlin/Wasm bindgen runtime compilation on Kotlin 2.3.21 - #8
Merged
Conversation
The KSP-generated guest runtime emitted references to kotlin.wasm.unsafe.componentModelRealloc, freeAllComponentModelReallocAllocatedMemory, and the ComponentModelInternalApi opt-in. These symbols only exist in Kotlin 2.4.0+, so the compiler-compatibility gate failed to build the wasmWasi fixture pinned to Kotlin 2.3.21: e: KwasmWasmGuestRuntime.kt:5:24 Unresolved reference 'ComponentModelInternalApi' e: KwasmWasmGuestRuntime.kt:20:27 Unresolved reference 'componentModelRealloc' e: KwasmWasmGuestRuntime.kt:21:27 Unresolved reference 'freeAllComponentModelReallocAllocatedMemory' > Task :bindgen-api:compileTestKotlinWasmWasi FAILED Replace the Component Model realloc allocator with an equivalent bump allocator built on withScopedMemoryAllocator, which is present in both Kotlin 2.4.0 and 2.3.21. The guest allocator now tracks live regions in a map and replays the live prefix before each new allocation so returned pointers stay disjoint from regions the host still owns. The free path drops the freeAllComponentModelReallocAllocatedMemory reset accordingly. Add a regression assertion that the rendered runtime uses withScopedMemoryAllocator and no longer references componentModelRealloc. Verified locally with scripts/verify-kotlin-wasm-compiler-compatibility.sh on both Kotlin 2.4.0 and 2.3.21 rows, plus :bindgen-ksp:test.
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
The
Kotlin/Wasm 2 compilers × 2 EH encodingsCI job fails when building the wasmWasi compatibility fixture pinned to Kotlin 2.3.21:```
e: KwasmWasmGuestRuntime.kt:5:24 Unresolved reference 'ComponentModelInternalApi'
e: KwasmWasmGuestRuntime.kt:20:27 Unresolved reference 'componentModelRealloc'
e: KwasmWasmGuestRuntime.kt:21:27 Unresolved reference 'freeAllComponentModelReallocAllocatedMemory'
Root cause
WasmGuestRuntimeRendereremits a generated guest runtime that referencedkotlin.wasm.unsafe.componentModelRealloc,freeAllComponentModelReallocAllocatedMemory, and theComponentModelInternalApiopt-in. These symbols only exist in Kotlin 2.4.0+, so the compatibility gate — which deliberately builds the fixture on the previous stable compiler (2.3.21) — could not compile it.Fix
Replace the Component Model realloc allocator with an equivalent bump allocator built on
withScopedMemoryAllocator(present in both 2.4.0 and 2.3.21). The guest allocator now tracks live regions in a map and replays the live prefix before each new allocation so returned pointers stay disjoint from regions the host still owns. The free path drops thefreeAllComponentModelReallocAllocatedMemoryreset.Adds a regression assertion that the rendered runtime uses
withScopedMemoryAllocatorand no longer referencescomponentModelRealloc.Verification
scripts/verify-kotlin-wasm-compiler-compatibility.sh— BUILD SUCCESSFUL on both rows:Verified Kotlin/Wasm compiler rows: 2.4.0, 2.3.21:bindgen-ksp:test(incl.BindingSourceRendererTest) — greenNote
This addresses only the compiler-compatibility failure. A separate, independent CI failure (
Unknown host target: linux aarch64on theLinux arm64 testsmatrix entry) will be handled in a follow-up PR — Konan does not support linux aarch64 as a host, so that matrix entry needs restructuring regardless of this fix.