0059. Bound emitted C nesting with flat control flow
- Status: Accepted
- Date: 2026-10-31
- Plan: M8.4
- Review: Compiler and backend
Context
A legal 255-deep match produces C bracket nesting 510 with braced switch arms. Clang defaults to a combined parentheses/braces/brackets limit of 256, so valid Harness input fails downstream. GCC does not expose this portability failure.
Decision
Keep structured Core IR and shallow C unchanged. Once 24 structured statements are open, emit further control flow without recursively opening C blocks:
- Switch dispatch jumps to arm labels after the switch closes; reaching arms jump past their siblings. Emit an end label only when a jump references it.
- If branches jump to else/end labels.
- Loops use top/continue/break labels, preserving arena marks and resets.
Use analysis and emission share the same threshold and real C loop stack. Only still-open C switches push sentinels; flat loops always use labeled exits. IR local/scope IDs already make declarations unique without lexical C blocks; rvalue operands are atoms, so source calls/records do not add recursive brackets. At most 24 structured layers remain (at most two braces each), leaving ample room for bounded rvalue syntax below Clang's limit.
This supersedes ADR-0023's unconditional braced C arms/sentinel rule only for deeply nested emission. All other IR, coverage and interpreter decisions remain in force.
Alternatives considered
- Detect Clang and raise -fbracket-depth — hides the failure only through the driver; independently compiling emit-c output would still fail.
- Flatten every function — unnecessary C/digest churn for shallow programs and reduced readability where structured C works well.
Consequences
Deep legal programs compile without compiler-specific flags. Scalar depth tests and mixed allocating control-flow tests guard bracket growth, label warnings, evaluation order and cleanup; all existing goldens remain byte-identical. Backend control-flow use analysis must stay synchronized with emission.