Skip to content

fix(ssa): reserve loop-local stack slots once per call - #243

Closed
cpunion wants to merge 3 commits into
codex/wasm-r4-main-base-20260907from
codex/fix-loop-local-stack-20260908
Closed

cpunion wants to merge 3 commits into
codex/wasm-r4-main-base-20260907from
codex/fix-loop-local-stack-20260908

Conversation

@cpunion

@cpunion cpunion commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Summary

Reserve a non-escaping Go local's stack slot in the LLVM entry block, while leaving zero-initialization at its declaration. The SSA local-allocation contract requires one slot per function call, including declarations inside a loop. Previously, an LLVM alloca inside the loop reserved more stack on every iteration.

This is independent of WebAssembly and is reproducible from the current main implementation. It was isolated while running the WASI poll acceptance tests in #235: every retry consumed another 96 bytes. At roughly 1,300 retries a 128 KiB Fiber stack crossed its lower boundary and corrupted adjacent state, before any GC had run. After this change about 7,000 observed suspend/resume operations used a constant stack pointer; no stack-size increase is included.

Coverage

  • Regression verifies that local reservations are in the entry block both with and without a compiler GC-root prologue, and that zero-initialization remains inside the loop.
  • LLVM module verification and large-local allocation policy tests.
  • Focused SSA tests pass on the main-based branch; full SSA tests pass on the integrating R4 branch.
  • R4 WASI readiness, deadline change, timeout, and close/wakeup acceptance passed locally after removing all diagnostic probes.

CI is pending. This PR contains only the compiler fix and its regression test; WASI poll support remains in #235.

@cpunion

cpunion commented Sep 8, 2026

Copy link
Copy Markdown
Owner Author

Moved to xgo-dev#2530 as requested. Remaining fork workflow runs are being cancelled; validation continues upstream. The branch includes the debug-location prerequisite tracked in xgo-dev#2529. Keeping the source branch for the upstream contribution.

@cpunion cpunion closed this Sep 8, 2026
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