Skip to main content

Module stack

Module stack 

Source
Expand description

The stack a compiled program’s Main runs on.

A LOGOS program recurses as deep as its data: a tree of a million nodes is built and walked by recursion. A compiled program’s Main therefore runs on a stack of MAIN_STACK_BYTES mapped for it at start, on the thread that started it. Switching stacks rather than starting a thread keeps the process single-threaded, and that is worth having: once a second thread exists, even one only waiting for another to finish, the C library takes its locked, atomic path through every malloc and free, which doubled the time of an allocation-heavy program.

Recursion that runs past the end of the stack reaches an inaccessible guard page. The program then reports logicaffeine_data::failure::CALL_DEPTH_EXCEEDED, the sentence every tier reports for it, after writing out what it had shown, and ends with exit status 1. A native target whose stack the switch does not support runs Main on a thread of its own instead, and WebAssembly, which has one thread and a stack its module declares, runs it in place.

Constants§

MAIN_STACK_BYTES
The room a compiled program’s Main has for its calls.

Functions§

run_main
Run main, a compiled program’s Main, on a stack of MAIN_STACK_BYTES.