cli: disambiguate block statement boundaries

This commit is contained in:
dev committed 2026-10-07 18:21:07 +03:00
1 parent 462ddd2c5c
commit 911982dd1c
33 files changed
+465 -7

No files matched your search

+8
View File
@@ -87,3 +87,11 @@ Reason: format 0 is frozen; features make it an extensible protocol without an o
AIR format 0 defines `max_value_size` = 1 048 576 bytes. Every materializable type in a module has an accounted size (spec 08 §7.1, a platform-independent metric, not a layout) of at most this value; violation, including overflow while computing a size, is `E5101`, checked during module validation. `max_local_frame` (1 MiB per function) is a separate guarantee. Neither depends on host memory.
Reason: a verified IR needs its own deterministic validity limits instead of inheriting host behavior; and large data should live in storage reached through borrows, not travel as SSA values. Total allocation is bounded separately in Phase 2, as fuel bounds execution.
## DD-016 — Explicit block statement boundaries
Spec 15 §4 and the grammar resolve Q-040 syntactically: leading bare `if`, `match` and `{…}` finish before outer expression operations in statement/tail position. A final construct remains a tail; `;` explicitly discards its value; without either, a value-producing block statement is E7006. Parentheses opt into continuation, while explicit expression contexts retain full expression parsing.
Reason: `if true { *p = 2u64; } *p = 3u64;` must denote two statements regardless of spacing. Greedy expression parsing consumed multiplication instead. Merely splitting would silently change `{2i64} -3i64` from −1 to −3; rejecting the undiscarded value avoids that change. Neither line-sensitive syntax nor assignment lookahead is needed. This is a small grammar decision, not a new AIR facility.
Compatibility: formerly accepted bare continuations in statement/tail position require parentheses around the initial construct. Formerly accepted value-producing bare block statements require explicit `;`, including mixed branches such as `if c { return 1u64; } else { 2u64 }` before another statement. Existing tails, explicit discards and initializer/return/argument/condition/expression-arm continuations retain their meanings. Ownership, lexical borrow ends, verifier transfers and deterministic runtime rules are unchanged. A borrow bound inside a preceding block remains inaccessible afterwards (E7002); aliasing and task rules still come from the existing verifier. No new diagnostic code, source syntax form, feature or verifier/runtime state is added. One frontend statement marker enforces the value guard and gives the formatter an explicit boundary; it never changes tokens or inserts separators. No empirical Model Capability Compression benefit is claimed; source documentation growth is measured in docs/agent/README.md.
+2
View File
@@ -295,3 +295,5 @@ General collections and algorithms need explicit typed hash/equality/order opera
## Q-040 — Block statements followed by unary-leading expressions
P6-8 review found an existing parser ambiguity: `if true { *p = 2u64; } *p = *p + 1u64;` is consumed as an expression continued by multiplication and then rejects E7006 at the assignment. The same failure is reproduced after a standalone block or `match`; `while` dispatches separately and is not affected. Source whitespace is insignificant; spec 15 §4 and the grammar admit both block statements and expressions beginning with block/control-flow forms. The intended disambiguation must be specified before changing which previously parsed expressions are accepted. Decide how a standalone block statement ends before a dereference/other unary-leading statement while preserving block-valued expressions in explicit expression contexts. Add positive/rejected parser and lowering cases for the chosen rule. The formatter preserves the current tokens/AST and MUST NOT insert semicolons or infer the intended statement boundary. This question is separate from P6-8.
**Resolved (DD-016, spec 15 §4):** leading bare `if`, `match` and `{…}` in statement/tail position stop before outer expression operations. The next `}` selects a tail, `;` an explicit discard, otherwise a block statement must yield `void` or diverge (E7006). Parentheses permit continuation; nested expression contexts retain ordinary parsing. The value guard prevents silent reinterpretation of former expressions such as `{2i64} -3i64`. Parser, lowering, formatter and source conformance cover the boundary and compatibility rules. This resolves one P6-1/P6-2 ambiguity, not the complete grammar tasks.