cli: parse control flow with shared continuations

This commit is contained in:
dev committed 2026-10-11 22:18:21 +03:00
1 parent 9534359595
commit b2c551047c
5 files changed
+1442 -345

No files matched your search

+82 -2
View File
@@ -1162,6 +1162,86 @@ Control parsing/lowering, multi-result/graph callbacks and liveness/read/
assignment scans keep Q-061 open. Q-060's full GC validation and Phase 6 exit
review remain independent open gates.
## Shared control parser continuations
At HEAD `9534359`, nested block/if expressions parse and check at 16/256
levels but abort in the parser at 1,024; a separate else-if chain formats at
1,024 but aborts at 16,384. The shared parser driver now queues block,
statement, condition, if/else-if, match/arm, select, loop, scope, shield and
lock children alongside expression continuations. All use one stable result
frame; the expression-returning entry API cannot select control-only outputs.
Unused recursive-entry wrappers and multi-frame machinery are removed.
This is a traversal repair: tokens, AST/spans, statement/tail/discard boundaries,
`block_statement`, arm-kind selection, error priority and borrow advice retain
their existing rules. Conditions/call advice restore on all exits; for/lock
prefix and group/index restoration remains success-only, as before. Host OOM
propagates without diagnostic conversion or a public partial AST. Work buffers
and AST allocation retain caller-arena lifetime; `deinit` does not promise
physical early release of arena storage. Spec/reference, AIR, verifier,
ownership/concurrency/runtime, diagnostic codes, bundles and acceptance limits
are unchanged. The existing grouped-statement discrepancy is logged separately
as Q-062, with old/new accepted CLI evidence.
An independent copy of the former mutually recursive control/expression
parser compares shallow ASTs, mutated token buffers, position/end/failure and
scope state. Token/type/pattern helpers remain shared, an explicit oracle
limitation. Added checks cover per-token EOF/deletion sweeps with outer borrow
advice; every control child form's invalid leaf; 32,768 mixed/block and
ungrouped-condition levels; 32,768 statements, match/select arms and else-if
links; control-heavy scratch poisoning; recovering and sticky per-call OOM
above the arena, including grown queues and late failures. A physical backing
tracker measures scalar, block and mixed parsing and verifies complete backing
release after arena teardown. Expanded and final follow-up units pass,
including both OOM modes with resize/remap disabled to inject every growth.
The fixed failure-sweep guards are test bounds, not language limits.
At 32,768 levels, measured live arena backing allocations peak at:
| Input | Source bytes | Peak backing bytes |
|---|---:|---:|
| Scalar `not` chain | 131,126 | 89,887,292 |
| Nested blocks | 131,127 | 139,565,186 |
| Mixed 17-form tree | 805,722 | 692,273,454 |
Work items are 448 bytes, compared with the reconstructed former
expression-only union's 424 bytes; the single frame is 1,992 bytes. The former
payload layouts were checked unchanged, but this is not a before/after peak
measurement. The 24-byte item growth does not justify boxing control payloads
and adding allocation/aliasing paths in this repair. The large stress peaks
are informational, not evidence of efficient memory use or a portable bound.
They include tokenization, owned token duplication, AST, retained work buffers
and arena slack; they exclude source text, allocator overhead and downstream
passes. Backing allocation lengths are distinct from resident process memory.
The separate 12-form, 32,768-depth hosted rejection source is 857,464 bytes;
one Linux/Debug `check` measured 350,804 KiB max child RSS. Its six-command
comparisons run sequentially. This does not bound other environments.
The focused standalone CLI block passes 127 calls: block/if formatting and
fixed points through 1,024; else-if through 65,536; bounded check/lower through
256 and source/AIR runtime through 16; syntax-only control contexts at 256;
and exact E7001/boolean-negation records for six public commands through
32,768 with CRLF/UTF-8 source. It is an exact extraction of the new block in
`tests/hosted/source_expression_depth.py`, not a run of that whole accumulating
suite. Build/format, frozen public check/lower byte parity (1,423/506), grammar
(312), formatter (6,078), independent-error (234) and repair-advice (299)
checks pass. All 1,793 ordinary conformance files pass with exact unique
coverage; no file is omitted or counted twice.
Claude's core read-only review found no demonstrated production divergence;
its API/dead-path, mutation, deep/wide, scratch and OOM suggestions are addressed
above. Read-only follow-up/final reviews also found no production defect
within their recorded scope; they ran no tests. Final review clarifications:
peak measurements are informational and the historical work-size reconstruction
is explicit; the hosted memory-heavy scope is documented. Its counter concern
does not reproduce: `cli` increments the global counter and the standalone
extraction records all 127 calls. Current frame/queue poisoning does not cover
abandoned arena buffers, a retained test limitation.
The new parser exposes the next confirmed failure: full checking still aborts
at 1,024 nested block/if levels in `blockBodyWant`/`ifExpr`, with empty stdout.
Lowering/control/liveness, Q-060 full GC validation and Phase 6 exit gates stay
open.
## Remaining work
Follow-up checks accept 16 parenthesized/mixed-call levels but abort
@@ -1171,11 +1251,11 @@ components but aborts in Parser.exprPath at 16,384. Raw evidence is
Generic transformation, its path callback, Parser.exprPath and the shared
expression parser above are now repaired. The preceding follow-up records are
historical checkpoints, not current parser failures. The remaining inventory
includes a confirmed lowerer failure and inspection-only risks:
includes confirmed block/if lowerer failures and inspection-only risks:
| Production path | Evidence and next scope |
|---|---|
| Parser `ifExpr`, block/statement and match/arm expression entry | Finite block/if probes above confirm parser aborts at 1,024 before/after the raw-place repair; 16/256 accept. Alternating control/statement combinations still need audit. |
| Parser block/statement/condition and if/match/select expression entry | Shared control/expression continuations are repaired above. Historical parser aborts no longer describe the candidate; parser-only deep coverage does not prove downstream AST traversal. |
| Lowerer non-scalar `expr` callbacks: builtin/variant calls, fields/indices/places, arrays/structs, if/match/arms and blocks/statements | Ordinary calls, struct/value-field, array and enum-payload descent are repaired above. Boolean, consuming own/region, atomic, task.join and spawn operands are repaired above. Mutex make/take operands are repaired above. Scalar index operands use continuations above; the recorded nested-array base-index failure is repaired by the raw-place increment above. Dereference/bound expression callbacks and graph/control combinations still need audit. Multi-result task.join_cancel inputs and other graph/place/control callbacks retain native entry. Other callback depth remains unverified; include alternating scalar/non-scalar expressions. |
| Lowerer use-after-region/liveness and assignment scans (`After`, first-use/read scans, `blockAssigns`/`stmtAssigns`/`exprAssigns`, match/select helpers) | Recursive AST walks inspected; audit their callers and finite deep inputs separately. |