Home / Docs / Specification / 27. Tasks and time
27.4 Stacks and memory
Release v0.4.0
- Stacks. A task's stack is sized from the depth it may still use, as spec/19 §8 rule 2 sizes it, and is mapped with an inaccessible guard region below it, so running past its end faults instead of writing other memory. Stacks come from a pool and are reused. In a run that filled the pool before
main(§1 rule 4), every stack is mapped at the size the largest task asks for, while each task's budget stays the one its depth gives. (ADR 0117, amendment of 2026-11-09, accepted; #1152.) In an executable, the stack of a task that may still usedlevels of depth hasmin(16 MiB + d × F, S(d))usable bytes, whereS(d)is the size of spec/19 §8 rule 2, which the interpreter keeps, andFis the program's frame bound: the largest frame the code generator laid out for any function compiled into the executable (its functions, lambdas, handler operations and entry wrappers, a superset of those a task can run), plus 16 bytes of call linkage and 16 of alignment, rounded up to 16 bytes.Fcomes from the program's text and--max-depthfrom the run's flags, so the size is public and the same for every input: it never depends onsecretdata, and the pool of §1 rule 4 still holds stacks of one size. A program for which the code generator cannot state some frame's size, or whose largest frame exceeds the 64 KiB of the guard region, keepsS(d). Every call between compiled functions, direct, through a function value or to a handler's operation, passes the check of rule 2, and the runtime calls compiled code only at a task's base, so a level of depth holds at most one compiled frame; the 16 MiB hold the runtime's own work above the deepest call, a signal handler's frame and the task's base. A bound that were still too small would only stop the task sooner, with U6003 at the call by rule 2, never past its stack. - Depth. Every call checks the stack against its budget before it proceeds, so a task stops with U6003 at the call, as spec/11 §7 says, well before its guard region. Reaching the guard region is a defect of the runtime, which ends the process by the signal.
- Memory. The stack each task has used counts toward
--max-memory, together with the heaps of the run (spec/11 §7, ADR 0061 amendment of 2026-10-18). It is measured at each call's depth check as the highest point the task's stack has reached, rounded up to 16 KiB, and released when the task ends. In native code this coversmain's stack too.