cli: disambiguate block statement boundaries
This commit is contained in:
1 parent
462ddd2c5c
commit
911982dd1c
33 files changed
+465
-7
No files matched your search
@@ -142,3 +142,5 @@ RFC 0036 (Proposed), explicit source borrow returns (cl100k, relative to paths):
|
||||
RFC 0036 review fixes clarify reserved task borrow returns and known array bounds in unused generic signatures. These rules add 54 cl100k tokens: other source docs 64,160 → 64,214, full source 72,848 → 72,902 (+0.07%); Quick Reference stays 8,688. o200k groups are 8,723 / 64,413 / 73,136; Qwen2.5 8,954 / 65,794 / 74,748. language/ownership.md is 1,873 cl100k tokens; AIR and library/std.md stay unchanged. The additions make source rejection predictable without adding a semantic feature.
|
||||
|
||||
P6-8 source formatter (cl100k): Quick Reference 8,688 → 8,728 (+40), other source docs 64,214 → 64,677 (+463), full source 72,902 → 73,405 (+0.69%). language/tooling.md is 3,051 tokens. o200k groups are 8,763 / 64,876 / 73,639; Qwen2.5 8,994 / 66,259 / 75,253. AIR stays 179,282 bytes / 46,300 cl100k tokens, and library/std.md stays unchanged. One command with check/write modes reduces whitespace repair and diff noise while preserving tokens, comments and canonical AIR; it adds no language concept, feature, verifier/runtime state or diagnostic code. No empirical MCC benefit is claimed.
|
||||
|
||||
Q-040 block boundaries (DD-016, cl100k): Quick Reference 8,728 → 8,769 (+41), other source docs 64,677 → 65,012 (+335), full source 73,405 → 73,781 (+0.51%). o200k groups are 8,805 / 65,212 / 74,017; Qwen2.5 9,037 / 66,603 / 75,640. AIR and library/std.md are unchanged. One syntactic boundary rule and an explicit-discard guard replace an ambiguity; there is no new syntax form, diagnostic code or verifier/runtime state. No empirical MCC benefit is claimed.
|
||||
@@ -23,7 +23,7 @@ effects [io.read, io.write]
|
||||
|
||||
- `main`'s parameters are capabilities, granted by name: `aji run --grant input=io.read --grant out=io.write --stdin 'hi' main.aji`.
|
||||
- Every function lists its effects after the signature. A missing effect is `E3101`, whose `suggested_effects` field is the full list to write.
|
||||
- Statements end with `;`; `if`/`while`/`for`/`loop`/`match`/`select`/`scope`/`shield`/`lock` blocks do not.
|
||||
- Statements end with `;`; block statements do not require one. A bare `if`, `match` or `{…}` at statement/tail start ends at its final `}`. Parenthesize it to continue with an operator. Before another statement it must yield `void` or diverge; use `;` to explicitly discard a value (`E7006` otherwise). Initializers, returns and arguments use ordinary expression parsing.
|
||||
|
||||
## 2. Types
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
+1
-1
@@ -141,7 +141,7 @@ Targets for Phase 6A, measured on dev tasks:
|
||||
|
||||
## Standard library track
|
||||
|
||||
At the owner’s request (2026-10-06), reusable std APIs were implemented in a separate work branch. On 2026-10-07 the owner requested adoption/merge of the completed STD-0..7 intermediate foundation and resumption of source-language work; Q-034/P6-11 is implemented for review (RFC 0036 Proposed), and P6-8 implements the source formatter. The existing block-statement ambiguity Q-040 is recorded for P6-1/P6-2; larger syntax/contracts work retains its separate spec gate. Remaining std milestones stay in the backlog. [Standard library plan](standard-library.md) defines the bootstrap, prerequisites (`linear_aggregates`, general modules and generics), Std 0.1/0.2/0.3 and the public integration gate. P7/P8 remain on hold pending B1 analysis; this track does not change frozen evaluation inputs.
|
||||
At the owner’s request (2026-10-06), reusable std APIs were implemented in a separate work branch. On 2026-10-07 the owner requested adoption/merge of the completed STD-0..7 intermediate foundation and resumption of source-language work; Q-034/P6-11 is implemented for review (RFC 0036 Proposed), and P6-8 implements the source formatter. Q-040 is resolved by explicit block statement boundaries (DD-016, spec 15 §4), one P6-1/P6-2 ambiguity; larger syntax/contracts work retains its separate spec gate. Remaining std milestones stay in the backlog. [Standard library plan](standard-library.md) defines the bootstrap, prerequisites (`linear_aggregates`, general modules and generics), Std 0.1/0.2/0.3 and the public integration gate. P7/P8 remain on hold pending B1 analysis; this track does not change frozen evaluation inputs.
|
||||
|
||||
## Task conventions
|
||||
|
||||
|
||||
@@ -156,3 +156,9 @@ Validation: full conformance 1,135/1,135 with no failures or pending tests; 56 f
|
||||
`aji fmt` formats one source file without linking, specializing, verifying or running it; `--check` emits a JSON status, and explicit `--write` atomically replaces a regular file while preserving permissions. Libraries and semantically rejected programs remain formattable. Original token spellings, comments and declaration order are retained; output is re-tokenized before exposure, and layout traversal is iterative. No syntax, AIR feature, verifier/runtime state or diagnostic code is added. Invalid syntax reports the existing E7001. The CLI contract and layout are spec 15 §11; the public-corpus/CLI script runs in CI.
|
||||
|
||||
Validation: unit tests and Zig formatting pass, including 10,000-term expressions, comments/CRLF, continuation indentation and statement groups. The formatter CLI suite passes 3,146 checks over 853 public files: 844 parse and format idempotently, nine existing syntax-error fixtures report E7001, and 548 successful lowerings retain byte-identical AIR. The suite also checks explicit writes, unchanged inode/mtime, permissions, symbolic/hard links, FIFO rejection, JSON/exit codes and a source run. Full conformance remains 1,135/1,135. Independent read-only review by Claude identified layout/comment handling defects; fixes were independently rechecked and covered by unit cases. Original source files are not rewritten. Documentation budgets are recorded in docs/agent/README.md. Review found the separate existing block-statement ambiguity Q-040; resolving its syntax belongs to P6-1/P6-2 and is not inferred by the formatter. This increment does not complete Phase 6.
|
||||
|
||||
## P6-1/P6-2 block boundary increment (2026-10-07)
|
||||
|
||||
Q-040 is resolved in spec 15 §4 and the grammar (DD-016): leading bare `if`, `match` and `{…}` finish before outer expression operations in statement/tail position. The enclosing `}` selects a tail, `;` an explicit discard, otherwise a block statement must yield `void` or diverge. This E7006 guard prevents silent reinterpretation of former expressions such as `{2i64} -3i64`; parenthesized continuations and nested expression contexts remain available. The parser marks block statements, ordinary/generic lowering checks the guard, and the formatter derives line boundaries from statement spans. No AIR feature, diagnostic code or verifier/runtime state is added. P6-1/P6-2 remain open for the rest of their grammar work.
|
||||
|
||||
Validation: full conformance passes 1,154/1,154 with no failures or pending tests, including 19 focused source cases covering stores, other unary starts, tails, explicit contexts/discards, generic bodies, mixed diverging/value branches and lexical borrow ends. Unit tests, Zig formatting, bundle/example checks and 120/120 construct coverage pass. The formatter/CLI suite passes 3,267 checks over 872 public files: 860 parse idempotently, 12 syntax-error fixtures reject with E7001, and 557 successful lowerings preserve byte-identical AIR. A before/after comparison over the original 853 public files finds no exit-code changes and identical AIR for all 548 successful lowerings. Independent read-only review by Claude found the silent value-discard risk in the initial design; the guard fixes it, and final review found no remaining issues. Budgets are recorded in docs/agent/README.md; frozen evaluation inputs are unchanged.
|
||||
@@ -52,6 +52,13 @@ int_type = "u8" | "u16" | "u32" | "u64" | "u128" | "usize"
|
||||
(* A built-in operation is a call whose callee is a dotted path:
|
||||
`own.new(v, mem)`, `region.new(arena, v)`, `cap.narrow.budget(c, n)`. *)
|
||||
|
||||
(* Statement/tail disambiguation (spec 15 §4): leading bare if_expr,
|
||||
match_expr or block is consumed whole before choosing the production.
|
||||
Next `}` makes it the tail, `;` explicitly discards its result, otherwise
|
||||
it is a block_stmt whose result must be void or divergence (E7006).
|
||||
No outer postfix/cast/binary continuation is consumed here; parenthesize
|
||||
the construct for continuation. Nested expr contexts are unrestricted.
|
||||
Other block_stmt forms end at their final `}`. Whitespace is irrelevant. *)
|
||||
block = "{" { statement } [ expr ] "}" ; (* optional tail expression: the block's value *)
|
||||
statement = "let" binding [ ":" type ] "=" expr ";"
|
||||
| "var" ident ":" type "=" ( expr | "zero" ) ";"
|
||||
|
||||
@@ -86,7 +86,11 @@ Arrays are written `[T; N]`. `scope`, `shield` and `guard<T>` are not source typ
|
||||
|
||||
## 4. Statements and control flow
|
||||
|
||||
Statements end with `;`. Block constructs (`if`, `while`, `for`, `loop`, `match`, `select`, `scope`, `shield`, `lock`, `{ … }`) do not take one.
|
||||
Statements end with `;`. Block constructs (`if`, `while`, `for`, `loop`, `match`, `select`, `scope`, `shield`, `lock`, `{ … }`) do not require one.
|
||||
|
||||
**Block boundary.** At a statement or block-tail start, an unparenthesized `if`, `match` or `{ … }` MUST be parsed as one complete construct, including its `else` chain or arms, without consuming subsequent postfix, cast or binary operations. Immediately before the enclosing `}`, it is the tail expression; followed by `;`, it is an expression statement that explicitly discards its result; otherwise it is a block statement and MUST yield `void` or diverge (`E7006` for a value). This prevents an old value-producing expression from silently becoming two statements. Other block statements likewise end at their final `}`. Whitespace and comments MUST NOT affect these boundaries.
|
||||
|
||||
To continue such an expression in statement/tail position, parenthesize the complete construct: `({ 2u64 }) * 3u64`. Expression contexts (initializers, assignment right-hand sides, returns, arguments, conditions and expression arms) retain ordinary expression parsing: `return { 2u64 } * 3u64;` needs no extra parentheses.
|
||||
|
||||
| Source | Meaning |
|
||||
|---|---|
|
||||
|
||||
Reference in new issue
Block a user