pub fn on_cove_stack<T: Send>(body: impl FnOnce() -> T + Send) -> Result<T>Expand description
Runs body on a thread the runtime sized, and hands back what it
produced.
This is how a host runs Cove on a stack MAX_CALL_DEPTH fits on. The
process main thread is not one: its size is the platform’s business, it is
1 MiB on Windows, and no main can change it after the fact. So every
path the toolchain has into a Cove program — cove run, cove test,
cove generate, cove replay, a cove build binary, and cove-bench —
does its whole run inside one of these, and Interpreter::spawn gives a
task thread the same size, so no thread this runtime evaluates Cove on has
a stack it did not choose.
The thread is scoped, so body may borrow, and everything Cove-shaped can
be built inside it: a Value is Rc-based and could not cross the
boundary in either direction. Only T crosses, which is why it is Send.
A panic inside body is resumed on the calling thread rather than
swallowed, so a bug reports itself exactly as it did when the same work
ran inline. The Err is the machine refusing a thread, which is the one
failure this adds.