On this page

0059. Bound emitted C nesting with flat control flow

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:

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

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.