Issue 139 - #141
Draft
andreaTP wants to merge 3 commits into
Draft
Conversation
…#139) computeMaxTempSlots was missing STRUCT_NEW, THROW, ARRAY_NEW_FIXED, and CALL (hasTooManyParameters). When these instructions appeared inside a try_table body, their temp slot usage overflowed into the try-save area, corrupting saved GC ref values. In the Kotlin/Wasm reproducer, struct.new inside a try_table overwrote the try-save slot holding a String literal with an RTTI struct, causing String.plus to receive the wrong reference and eventually array.len to trap on a null array.
…itters Replace the manually-maintained computeMaxTempSlots switch in WasmAnalyzer with a data-driven approach. Each emitter that uses temp slots now declares a TempSlotCalculator at registration time in EmitterMap. This makes it impossible to add a new temp-slot-using opcode without also declaring its slot requirement. - Add TempSlotCalculator interface to Emitters - Extend Builder.intrinsic() with a 3-arg overload - Move all slot calculations from WasmAnalyzer switch to EmitterMap - Replace 140-line switch with 10-line generic loop - Keep assertTempSlotInRange runtime guard as safety net
The Kotlin/Wasm module uses non-canonical LEB128 size encodings from the Kotlin compiler, similar to main.go.wasm.
andreaTP
commented
Aug 6, 2026
andreaTP
left a comment
Contributor
Author
There was a problem hiding this comment.
Almost ready, the testing is solid but the implementation needs a little tweak for human(and machine) readability.
| .intrinsic( | ||
| CompilerOpCode.DROP_KEEP, | ||
| Emitters::DROP_KEEP, | ||
| (ins, module) -> { |
Contributor
Author
There was a problem hiding this comment.
Counting temp slots in lambdas and inline clutter readability and seems to mix concerns
| .intrinsic( | ||
| CompilerOpCode.BR_ON_CAST_FAIL_CHECK, Emitters::BR_ON_CAST_FAIL_CHECK) | ||
| .build(); | ||
| private static FunctionType resolveTagType(int tagIdx, WasmModule module) { |
Contributor
Author
There was a problem hiding this comment.
do we have something similar somewhere else in the codebase?
| return ValType.builder().fromId(id).build().resolve(ctx.typeSection()); | ||
| } | ||
|
|
||
| private static void assertTempSlotInRange(Context ctx, int slotsNeeded) { |
Contributor
Author
There was a problem hiding this comment.
This is a clear indication for developers, we should make sure this doesn't spill to user land in absence of bugs.
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.
Fix #139
to be reviewed