Repository navigation
Done
Labels
Milestone
Description
Summary
Track the roadmap item for running selected FFI-heavy code on an OS-thread-sized stack. This is separate from the multi-worker fiber scheduler work in #455: stack switching is about avoiding small fiber-stack overflow at FFI boundaries and honoring the reserved @[ffi_stack] mode.
Current Evidence
docs/with-specification.mdsays FFI stack switching is roadmap / implementation-defined.- §14.19 describes switching from the fiber stack to a pre-allocated OS-thread stack at FFI boundaries.
- The spec reserves
@[ffi_stack]for forcing an entire function to run on an OS-thread stack. - The current runtime supports configurable fiber stack sizes via
[runtime] fiber_stack_size, but no FFI boundary stack-switch mode is implemented. docs/requirements.mdmarks the roadmap text as inventoried, not as evidence that runtime implementation exists.
Why This Exists
The fixed-size fiber stack baseline is acceptable for normal C calls when users can raise fiber_stack_size. The roadmap feature is still useful for deep C call trees and FFI-heavy code where making every fiber large would waste memory.
Design Constraints
@[ffi_stack]must be explicit. Hidden stack switching should not make suspension or stack behavior unpredictable.- The compiler must keep
may_suspendand FFI callback restrictions intact; stack switching is not permission to yield through C frames. - If a platform lacks the required low-level support, the compiler/runtime should reject the mode loudly rather than silently ignoring it.
- Keep the baseline fixed-size fiber path working and simple.
Implementation Sketch
- Parse/validate
@[ffi_stack]as a real function attribute rather than only a reserved spelling. - Add sema/codegen metadata so marked functions enter through an OS-stack trampoline.
- Add runtime support for an OS-thread-sized stack pool per scheduler/worker thread.
- At marked function entry, save the fiber stack context, switch to the OS stack, run the body, then restore the fiber stack.
- Audit panic/unwind/error-return paths so stack restoration is guaranteed.
- Add platform-specific implementations for Darwin and Windows, or emit a hard diagnostic for unsupported targets.
Acceptance Criteria
@[ffi_stack]has executable tests proving a marked function uses the OS-stack path.- Deep FFI-call smoke tests can run without requiring globally huge fiber stacks.
- The mode is explicit and rejected on unsupported platforms.
may_suspendrestrictions remain enforced for callbacks and C-frame boundaries.- Existing async/fiber tests continue to pass in baseline mode.
Activity
ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): still open.@[ffi_stack]is reserved and nothing implements it:post-release: a runtime feature the spec marks roadmap.
Wave 3: @[ffi_stack] (#583), List.new_in(allocator) (#570), float Min…