← board

Prune statements after a return at -O0

Split from [[feature-a-fold-the-consensus-dead-branch-core-at-every-level]], whose parts 1 (if/while), 2 (escape guard), 3 (-OO) and 4 (charter) are done. This is what its part 1 listed third and nothing has closed.

Measured, 2026-09-02, at the tree that landed the if/while prune

procedure P; begin Exit; WriteLn(NeverR); end;   { never_r_P declared, undefined }

-O0   rc=127  undefined symbol: never_r_P
-O2   alive
-O3   alive

IROptDeadCode catches it from -O1 up. -O0 is the only failing level.

Why it was NOT bolted onto the prune that landed

if False and while False are one question — is this condition a constant — answered by one helper (ASTConstCond) at two sites. This is a different question: which statements in a sequence are still reachable, which needs a notion of which node kinds TERMINATE a block (Exit, return, goto, Halt, a raise, a call to a noreturn), applied while walking AN_SEQ. Bolting it onto a constant-condition fold would have been the second path that stays broken (normalise-dont-special-case).

Constraints inherited from the parent, both non-negotiable

Acceptance

Log