Fix wasm dev list mutation and short string concat#9666
Draft
lukewilliamboswell wants to merge 5 commits into
Draft
Fix wasm dev list mutation and short string concat#9666lukewilliamboswell wants to merge 5 commits into
lukewilliamboswell wants to merge 5 commits into
Conversation
The wasm dev backend hand-rolled `list_set` to always allocate a fresh element buffer, copy every element, and return a new list without ever freeing the input allocation, checking uniqueness, or running element refcount callbacks. In a loop (e.g. a WASM-4 frame callback) this leaks one buffer per call until the platform allocator is exhausted, which is why `basic.roc --opt=dev` booted and then trapped with `roc_alloc: out of memory`. `list_replace_unsafe` and `list_swap` were `unreachable` traps. Route all three through the shared `roc_builtins_list_replace`/ `roc_builtins_list_swap` builtins, threading the statically-proven uniqueness mask so they mutate in place when the list is unique and copy-on-write otherwise, matching the dev x86, LLVM, and interpreter backends. `host_imports` mode (used only by the wasm eval-test runner) gains matching compact host functions. Separately, the join-point bookkeeping maps were module-lifetime and never scoped to a proc. Join ids from lowering are globally unique, but TRMC mints a fresh id from a per-proc `max_join_id + 1`, which collides with another proc's id; the colliding proc's `put` then overwrote and leaked the earlier proc's `param_locals` array (the DebugAllocator leak in `generateCFStmtNode` while building `sound.roc`). Retire each join's entries at its `.join_close`, mirroring the lexical push/pop discipline the loop-target stacks already use, so entries live exactly as long as their join is in scope and a jump to an out-of-scope join surfaces the existing invariant violation instead of silently miscompiling.
…oin-leak' into wasm4-patches
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.
Summary
i32count on wasm32Str.concatresults as inline smallRocStrvalues instead of heap stringsValidation
zig fmt build.zig test/wasm/main.zig src/backend/wasm/WasmCodeGen.ziggit diff --checkzig build run-test-wasm-static-libzig build roczig build run-test-zig-module-backendzig build miniciroc-wasm4 validation
/home/lbw/Documents/Github/roc/zig-out/bin/roc build examples/sound.roc --opt=dev --output=/tmp/sound-dev-9667-fixed.wasm/home/lbw/Documents/Github/roc/zig-out/bin/roc build examples/basic.roc --opt=dev --output=/tmp/basic-dev-9667-fixed.wasmtimeout 8s w4 run-native /tmp/basic-dev-9667-fixed.wasmbasic.rocreached the timeout with no trap output, which matches the expected non-OOM behavior for the previous immediate WASM-4 reproduction.