Skip to main content

Module runtime_stack

Module runtime_stack 

Source
Expand description

The native stack contract for every thread that can run Harn code.

Harn has two independent stack hazards, each with its own owner:

  • Walking an arbitrarily deep value — x = [x] in a loop — is made stack-size independent by harn_vm::value::recursion, which grows the native stack on demand and tears values down iteratively.
  • Walking an arbitrarily deep program — parse, type-check, compile, and evaluate all recurse over nested syntax — is not. It relies on the thread simply having enough stack, and that is what RUNTIME_STACK_SIZE is.

This module owns the second contract because the parser is the lowest crate that recurses over a program: the module loader, the VM, and every host depend on it. A thread in any crate that can reach the parser or the VM is created here, through spawn, builder, or scope. Rust’s 2 MiB default is never the right answer for such a thread, and a stack overflow aborts the whole process rather than failing one request.

RUST_MIN_STACK does not substitute. Every CI test lane exports it, which makes an unsized thread large enough in CI and nowhere else, so a host that relies on it passes its own tests and aborts the first time a customer runs a deep enough script. harn_vm’s runtime_stack tests scan the workspace and refuse a thread created any other way.

Structs§

RuntimeScope
A scope whose threads hold RUNTIME_STACK_SIZE. See scope.

Constants§

PARSE_STACK_SIZE
Native stack a thread needs to parse any source the parser accepts.
RUNTIME_STACK_SIZE
Native stack size a thread needs in order to run Harn code.

Functions§

builder
A thread builder that already holds RUNTIME_STACK_SIZE.
on_vm_stack
Run body on a thread that holds the RUNTIME_STACK_SIZE contract.
scope
std::thread::scope whose spawned threads hold RUNTIME_STACK_SIZE.
spawn
std::thread::spawn with RUNTIME_STACK_SIZE.