Skip to content

Add growable runtime stacks#434

Merged
heartwilltell merged 1 commit into
mainfrom
codex/runtime-stack-growth
Apr 26, 2026
Merged

Add growable runtime stacks#434
heartwilltell merged 1 commit into
mainfrom
codex/runtime-stack-growth

Conversation

@heartwilltell

Copy link
Copy Markdown
Contributor

Summary

  • Enables growable green-thread stacks by default on POSIX using the reserved virtual-memory path that already existed in the runtime.
  • Adds generated C stack probes at function entry and implements run_stack_check() / run_morestack() so stack use commits additional pages before overflow.
  • Keeps the SIGSEGV handler as a safety net and also handles SIGBUS on macOS for reserved-page stack faults.
  • Tracks stack watermarks at scheduler yield points and decommits underused pages with hysteresis so stacks shrink after deep calls unwind.
  • Adds runtime tests for stack growth and shrinkage, plus a codegen assertion for emitted stack probes.

Fixes #403
Fixes #404

Implementation Note

This completes growth without copying live stack frames: the runtime reserves each G's maximum stack range up front and doubles the committed portion downward as needed. That preserves active frame pointers and saved contexts while matching the issue's growth behavior and keeping run_morestack() non-stubbed.

Validation

  • zig fmt src/codegen_c.zig
  • clang-format -i src/runtime/run_scheduler.c src/runtime/run_scheduler.h src/runtime/tests/test_scheduler.c
  • zig build
  • zig build test (passes; command prints the expected negative missing() diagnostic from the test fixture)
  • zig build test-runtime

@heartwilltell heartwilltell marked this pull request as ready for review April 26, 2026 11:32
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 26, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
runlang ec8a379 Commit Preview URL

Branch Preview URL
Apr 26 2026, 03:34 PM

@heartwilltell heartwilltell force-pushed the codex/runtime-stack-growth branch from ec8a379 to f6a1222 Compare April 26, 2026 16:02
@heartwilltell heartwilltell merged commit 8ad27ce into main Apr 26, 2026
14 checks passed
@heartwilltell heartwilltell deleted the codex/runtime-stack-growth branch April 26, 2026 20:00
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.

Add stack shrinkage during scheduling passes Implement copy-based stack growth

1 participant