cli: parse nested expression contexts iteratively
This commit is contained in:
1 parent
371329f3f0
commit
bda43d2ecb
5 files changed
+1107
-221
No files matched your search
@@ -539,4 +539,6 @@ The [generic transformation increment](source-expression-depth-audit.md#generic-
|
||||
|
||||
The [parser constructor-path increment](source-expression-depth-audit.md#parser-qualified-constructor-paths) repairs Parser.exprPath independently of generic/lowering paths. Frozen baseline probes confirm enum and struct constructor aborts at 16,384 fields; the repaired CLI returns exact E7002 through 65,536. Named-root classification, spelling, type arguments, spans, syntax errors and host OOM propagation are preserved, with one complete string allocation. Q-061 remains open for the confirmed parenthesized/mixed-call parser failures and the remaining lowering/liveness inventory; no new acceptance limit or external review is claimed.
|
||||
|
||||
The [shared expression parser increment](source-expression-depth-audit.md#shared-expression-parser-continuations) removes native re-entry through grouping, call arguments, arrays, index bounds and struct fields, sharing binary/cast/unary/postfix/primary continuations. Token/AST/spans, grammar/error priority and scoped advice remain unchanged; host OOM propagates without diagnostics or partial AST. Reused work storage and stable driver frames retain caller-arena lifetime. Block/control callbacks still recurse outside the large dispatch frame; their bounded regression probes pass, without an arbitrary-depth claim. Grouped programs check through 65,536; mixed calls format through 65,536 but now abort in lowerer `call` at 1,024. Q-061 remains open for that confirmed path and remaining control/liveness traversal; no new limit or external review is claimed.
|
||||
|
||||
Audit these paths separately with finite public/generated source inputs before claiming whole-frontend bounded native-stack processing. Prefer explicit continuations preserving existing syntax, evaluation/query order, diagnostics and OOM behavior. A new depth rejection requires a normative decision; Q-059's type-traversal resolution does not authorize one.
|
||||
@@ -425,21 +425,90 @@ No normative, source/AIR format, feature, code, bundle, acceptance-limit or
|
||||
runtime/ownership rule changes. This repairs one callback; Q-061 remains open
|
||||
and no external review covers this increment yet.
|
||||
|
||||
## Shared expression parser continuations
|
||||
|
||||
Frozen pre-repair CLI production at 371329f (`aji-before-expression-parser`)
|
||||
aborts while formatting 1,024 grouped or mixed-call levels, with empty stdout.
|
||||
`expression-parser-probes.json` and `expression-parser-*.before.fmt.stdout/
|
||||
.stderr` hold the finite inputs/results. Debug stack excerpts reread current
|
||||
source files; use `parse-before-expression-driver.zig` for baseline line text.
|
||||
|
||||
Binary precedence/RHS, casts, unary prefixes, postfix and primary entry modes
|
||||
now share explicit continuations. Groups, ordinary/typed/variant call arguments,
|
||||
array lists/repetitions, index bounds and struct field expressions suspend on
|
||||
the same worklist, including alternating forms. Grammar, comparison rejection,
|
||||
`or trap`, borrowed-place boundaries, constructor classification, trailing
|
||||
commas, type-closer splitting, spans, argument advice and error priority are
|
||||
retained. Deferred call/advice restoration is separate from the formerly
|
||||
success-only group/index restoration. Host OOM propagates without syntax
|
||||
diagnostics or partial public AST.
|
||||
|
||||
The parser reuses its work buffer across entries. Native block/control callbacks
|
||||
save a base cursor; each re-entered driver processes/unwinds only entries above
|
||||
that base. Active driver results and current work live in stable, separately
|
||||
allocated frames reused by callback depth. No AST or queued pointer targets
|
||||
relocatable work storage or a driver result. Dispatch of block/if/match callbacks
|
||||
occurs outside the large per-step frame. An initial local-frame regression at
|
||||
256 block/if levels was caught and repaired before commit. Final probes preserve
|
||||
baseline formatted bytes at 64/256 block/if levels and 64 explicit-return levels;
|
||||
explicit-return block/if forms now also format at 256, where the baseline aborts
|
||||
(`expression-parser-control-final.json` and its raw outputs). This does not prove
|
||||
arbitrary callback depth safe.
|
||||
|
||||
Scratch deinit/destroy is logical cleanup for caller arenas. Work capacity,
|
||||
driver frames, AST nodes and partial outputs retain physical caller-arena
|
||||
lifetime. Work/driver buffers are reused rather than allocated independently
|
||||
for every scalar entry. Allocation requests/failure-index outcomes need not
|
||||
match the old recursive implementation. AST output ownership and host error
|
||||
handling are unchanged.
|
||||
|
||||
The copied shallow former descent compares 4,160 expression/form/context/entry
|
||||
combinations, including complete ASTs, failures, positions, token mutations and
|
||||
advice/scope state. Type, lexical/advice, block/control and path helpers are
|
||||
shared, outside the oracle's independence. Separate public parser tests cover
|
||||
32,768 mixed levels, every constructor span, siblings, type arguments and exact
|
||||
innermost E7001 advice. Re-entry/reuse tests poison scratch bytes before reading
|
||||
returned ASTs. Every recovering direct allocation failure checks host OOM,
|
||||
empty work, restored depth/advice/call scopes and no diagnostic; persistent
|
||||
backing failures through public parse check arena cleanup and no partial AST.
|
||||
|
||||
Final probes accept checks at 65,536 grouped levels and formatting at 65,536
|
||||
mixed-call levels. Full mixed-call checking still aborts at 1,024, now in lowerer
|
||||
`call` rather than parsing (`expression-parser-final-probes.json` and
|
||||
`expression-parser-*.after.final.*.stdout/.stderr`). Permanent CLI tests separate
|
||||
full accepted grouped/scalar programs with exact AIR/fuel from syntax-only
|
||||
mixed/call inputs, and retain complete rejection records across commands.
|
||||
|
||||
Build, unit and Zig format checks pass. All 1,793 ordinary conformance cases pass
|
||||
with terminal exit 0 and exact unique corpus coverage
|
||||
(`expression-parser-conformance.jsonl` and its audit). The depth, grammar and
|
||||
independent-error CLI suites pass 737/312/234 checks. The formatter passes 6,078
|
||||
checks over 1,469 files (1,414 parsed, 55 existing syntax errors, 782 identical
|
||||
AIR outputs). Frozen old/new CLIs retain exact exit/stdout/stderr on all 1,423
|
||||
public source checks and 506 accepted lowerings
|
||||
(`expression-parser-cli-compatibility.json`). These are compiler regressions,
|
||||
not a full per-step GC pass or a model-capability measurement.
|
||||
|
||||
No normative, source/AIR format, feature, code, bundle, acceptance-limit or
|
||||
ownership/runtime rule changes. Q-061 remains open for block/control parsing,
|
||||
non-scalar lowering and the remaining liveness/read/assignment inventory.
|
||||
This increment has no external review yet.
|
||||
|
||||
## Remaining work
|
||||
|
||||
Follow-up checks accept 16 parenthesized/mixed-call levels but abort
|
||||
with empty stdout at 1,024. A qualified enum variant returns E7002 at 16
|
||||
components but aborts in Parser.exprPath at 16,384. Raw evidence is
|
||||
`generic-followup-depth-probes.json` and `generic-followup-*.stdout/.stderr`.
|
||||
Generic transformation, its path callback and Parser.exprPath above are now
|
||||
repaired; the remaining inventory includes the other observed parser failures
|
||||
and inspection-only risks:
|
||||
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:
|
||||
|
||||
| Production path | Evidence and next scope |
|
||||
|---|---|
|
||||
| Parser `postfix`/`primary` through parenthesized `expr` | Confirmed failure at 1,024 levels; preserve grouping, precedence and spans. |
|
||||
| Parser `callArgs`, array/index/struct initializers, `ifExpr`, block/statement and match/arm expression entry | Mixed `1i64 + id(...)` calls have a confirmed parser abort at 1,024. Other callback depth behavior is unverified; include alternating forms, not only homogeneous spines. |
|
||||
| Lowerer non-scalar `expr` callbacks: calls, fields/indices/places, arrays/structs, if/match/arms and blocks/statements | Native re-entry remains outside the repaired scalar driver; deep behavior unverified, including alternating scalar/non-scalar expressions. |
|
||||
| Parser `ifExpr`, block/statement and match/arm expression entry | Native callback re-entry remains. Bounded block/if regression probes above pass; arbitrary and alternating control/statement depth is unverified. |
|
||||
| Lowerer non-scalar `expr` callbacks: calls, fields/indices/places, arrays/structs, if/match/arms and blocks/statements | Mixed scalar/call source now has a confirmed native abort in `call` at 1,024 after parsing succeeds. 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. |
|
||||
|
||||
The formatter's expression-marking traversal already uses a worklist, as
|
||||
|
||||
@@ -613,3 +613,26 @@ No normative/bundle/feature/code/acceptance-limit or runtime/ownership rule
|
||||
changes. Parenthesized and mixed-call parsing failures, remaining expression/
|
||||
statement walks, Q-060 validation and Phase 6 exit gates remain open. This
|
||||
increment has no external review yet.
|
||||
|
||||
## Source shared expression parsing (2026-10-10)
|
||||
|
||||
The [Q-061 parser increment](../design/source-expression-depth-audit.md#shared-expression-parser-continuations)
|
||||
shares explicit precedence/cast/unary/postfix/primary continuations with groups,
|
||||
call arguments, arrays, indices and struct fields. Grammar, spans, token/error
|
||||
order and call/advice scopes are preserved. Reused work storage and stable
|
||||
driver frames support native callback re-entry without retaining AST pointers
|
||||
into scratch; host OOM remains separate from source diagnostics. No normative/
|
||||
bundle/feature/code/acceptance-limit or ownership/runtime rule changes.
|
||||
|
||||
Independent shallow comparisons (4,160), 32,768 mixed levels with exact spans
|
||||
and leaf E7001 advice, poisoned scratch/re-entry and recovering/persistent OOM
|
||||
tests pass. Build/units/format checks, all 1,793 ordinary conformance cases with exact
|
||||
coverage and 737/312/234 depth/grammar/independent-error CLI checks pass. The
|
||||
formatter passes 6,078 checks; frozen old/new public checks/lowerings remain
|
||||
exact (1,423/506). Grouped source checks reach 65,536; mixed-call formatting reaches
|
||||
65,536. Block/if regression probes preserve accepted baseline output, including
|
||||
256 levels; explicit-return forms improve from baseline aborts to formatting
|
||||
at 256. These are bounded probes, not a whole-parser depth guarantee. Full
|
||||
mixed-call checking now confirms a lowerer `call` abort at 1,024; control/block
|
||||
parsing, remaining expression/statement/liveness walks, Q-060 validation and
|
||||
Phase 6 exit gates remain open. No external review covers this increment yet.
|
||||
+916
-214
File diff suppressed because it is too large.
Load diff
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Operand/generic depth, exact lowering/CFG/fuel and rejection positions (Q-061)."""
|
||||
"""Expression parsing/lowering depth, exact CFG/fuel and rejection positions (Q-061)."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
@@ -264,6 +264,96 @@ with tempfile.TemporaryDirectory(prefix='aji-expression-depth-') as directory:
|
||||
for command in ('lower', 'run', 'report', 'explore'):
|
||||
assert json.loads(cli(command, path, code=1)) == error
|
||||
|
||||
# Grouping is transparent in the AST; alternating binary/group frames
|
||||
# also reach ordinary lowering, with independently counted AIR and fuel.
|
||||
for depth in (0, 1, 16, 1024, 16384, 65536):
|
||||
for kind in ('group', 'grouped-add'):
|
||||
expression = ('(' * depth + '1i64' + ')' * depth if kind == 'group'
|
||||
else '1i64 + (' * depth + '1i64' + ')' * depth)
|
||||
instructions = 2 if kind == 'group' else 2 * depth + 2
|
||||
value = 1 if kind == 'group' else depth + 1
|
||||
path = root / f'{kind}-{depth}.aji'
|
||||
path.write_text('module depth\nfn main() -> i64 effects [] { return ' + expression + '; }\n')
|
||||
assert cli('check', path) == b''
|
||||
lowered = cli('lower', path)
|
||||
assert sum(b' = ' in line or line.strip().startswith(b'ret ') for line in lowered.splitlines()) == instructions
|
||||
if depth <= 1024:
|
||||
assert json.loads(cli('run', path, '--fuel', instructions)) == {'status': 'returned', 'value': value}
|
||||
assert json.loads(cli('run', path, '--fuel', instructions - 1, code=5)) == {
|
||||
'status': 'limit_exceeded', 'kind': 'fuel', 'limit': instructions - 1, 'steps': instructions - 1}
|
||||
formatted = path.with_suffix('.formatted.aji')
|
||||
output = cli('fmt', path)
|
||||
formatted.write_bytes(output)
|
||||
assert cli('fmt', formatted) == output
|
||||
assert json.loads(cli('fmt', formatted, '--check')) == {
|
||||
'file': str(formatted), 'status': 'formatted', 'changed': False}
|
||||
assert cli('lower', formatted) == lowered
|
||||
print(f'grouping depth: {kind} {depth}', flush=True)
|
||||
|
||||
forms = (
|
||||
('(', ')'), ('f(', ', 2u8)'), ('value[', ']'), ('value[0u8..', ']'),
|
||||
('[', ', 2u8]'), ('[', '; 1]'), ('Record { field: ', ', other: 2u8 }'),
|
||||
('channel.make<mut<ref<u8>>>(', ')'), ('ns.E::<u8>::A(', ')'),
|
||||
('not (', ')'), ('1u8 + (', ')'), ('(', ') as u8'), ('ref *(', ')'),
|
||||
)
|
||||
header = 'fn f() -> void effects [] { let x = '
|
||||
for depth in (16, 1024, 16384, 32768):
|
||||
prefix = ''.join(forms[i % len(forms)][0] for i in range(depth))
|
||||
suffix = ''.join(forms[i % len(forms)][1] for i in reversed(range(depth)))
|
||||
path = root / f'mixed-syntax-{depth}.aji'
|
||||
path.write_text('module depth\n' + header + prefix + 'leaf' + suffix + '; }\n')
|
||||
# Syntax/formatter coverage only: these synthetic expressions need not
|
||||
# have compatible types. Other non-scalar lowering remains Q-061 work.
|
||||
output = cli('fmt', path)
|
||||
formatted = path.with_suffix('.formatted.aji')
|
||||
formatted.write_bytes(output)
|
||||
assert cli('fmt', formatted) == output
|
||||
assert json.loads(cli('fmt', formatted, '--check')) == {
|
||||
'file': str(formatted), 'status': 'formatted', 'changed': False}
|
||||
path.write_text('module depth\n' + header + prefix + '!' + suffix + '; }\n')
|
||||
error = json.loads(cli('check', path, code=1))
|
||||
assert (error['code'], error['file'], error['line'], error['col']) == (
|
||||
'E7001', str(path), 2, len(header) + len(prefix) + 1), error
|
||||
assert error['repair_candidates'][0]['kind'] == 'boolean_negation', error
|
||||
for command in ('lower', 'run', 'report', 'explore', 'fmt'):
|
||||
assert json.loads(cli(command, path, code=1)) == error
|
||||
print(f'mixed syntax depth: {depth}', flush=True)
|
||||
|
||||
for depth in (16, 1024, 16384, 65536):
|
||||
path = root / f'nested-call-syntax-{depth}.aji'
|
||||
expression = '1i64 + id(' * depth + '1i64' + ')' * depth
|
||||
path.write_text('module depth\nfn id(x: i64) -> i64 effects [] { return x; }\n'
|
||||
'fn main() -> i64 effects [] { return ' + expression + '; }\n')
|
||||
output = cli('fmt', path)
|
||||
formatted = path.with_suffix('.formatted.aji')
|
||||
formatted.write_bytes(output)
|
||||
assert cli('fmt', formatted) == output
|
||||
assert json.loads(cli('fmt', formatted, '--check')) == {
|
||||
'file': str(formatted), 'status': 'formatted', 'changed': False}
|
||||
print(f'nested call syntax depth: {depth}', flush=True)
|
||||
|
||||
# Block/control callbacks remain native. Their existing shallow/deeper
|
||||
# syntax must retain its capacity while expression dispatch is moved out
|
||||
# of the native stack, including explicit-return callback re-entry.
|
||||
for depth in (64, 256):
|
||||
for kind in ('block', 'if', 'returned-block', 'returned-if'):
|
||||
if kind == 'block':
|
||||
expression = '{' * depth + '1i64' + '}' * depth
|
||||
elif kind == 'if':
|
||||
expression = 'if true {' * depth + '1i64' + '} else {1i64}' * depth
|
||||
elif kind == 'returned-block':
|
||||
expression = '{return ' * depth + '1i64' + ';}' * depth
|
||||
else:
|
||||
expression = 'if true {return ' * depth + '1i64' + ';} else {return 1i64;}' * depth
|
||||
path = root / f'control-syntax-{kind}-{depth}.aji'
|
||||
path.write_text('module depth\nfn main() -> i64 effects [] { return ' + expression + '; }\n')
|
||||
output = cli('fmt', path)
|
||||
formatted = path.with_suffix('.formatted.aji')
|
||||
formatted.write_bytes(output)
|
||||
assert cli('fmt', formatted) == output
|
||||
assert json.loads(cli('fmt', formatted, '--check')) == {
|
||||
'file': str(formatted), 'status': 'formatted', 'changed': False}
|
||||
|
||||
# Signed boundary literal remains one negative constant; the outer
|
||||
# checked negation traps rather than changing literal acceptance.
|
||||
minimum = root / 'minimum.aji'
|
||||
|
||||
Reference in new issue
Block a user