# Appendix I: Computing the maximum stack size for a function

The maximum stack size for a function is determined by modelling the stack operations of each
operation as described in the section 4.4.

Computing the maximum stack size of instructions that enclose sequences of instructions to form a
block (`block`, `if`, `else`, etc.) must additionally account for the following requirmements:

1. `if..else..end` encloses two distinct instruction sequences with potentially different stack
   capacity requirements. The greater of the two must be considered the stack requirement of the
   entire `if..else..end` instruction.
2. When modelling conditional branches, the greater stack size requirement must always be chosen.
3. After a stack-polymorphic instruction is executed, the maximum stack size for the enclosing
   block is frozen and can no longer be affected by any of the instructions that follow.

## The reduction rule exception

Execution of an intermediate reduction of the aggregate instructions may require more stack space
than occuppied by strictly the input/output operands to the instruction. The implementations are
responsible for reserving sufficient red-zone stack space required by these aggregate instructions
as they are not modelled by the maximum stack size computation.
