Repository navigation
self-host P2 slice 3: invariant and bench blocks, byte-identical to gen-c #8011
Copy link
Copy link
Closed
Labels
Description
Part of #5980 (phase P2: "invariant blocks, bench blocks"). This is the third P2 slice; it follows #8000 (structs) and #8007 (enums).
Probed with t27c gen-c on master f2caa84 (t27c lab):
- gen-c writes an invariant whose checks it deems C-constant as
_Static_assert(pred, "invariant: NAME"), in an "Invariants" section after the functions. Any other invariant becomes a comment, or a function nothing calls (gen-c: an invariant it cannot write as _Static_assert becomes a comment or an uncalled function (hex/char literal, enum member, static const, call, statement), so C never checks it #8009). - A bench becomes
void bench_NAME(void) { /* bench: NAME */ ... }in a "Benchmarks" section after the tests. Nothing calls it, in C as in Zig.
Today the core refuses both keywords with E_LEX.
This slice
specs/compiler/core/t27core.t27accepts, byte-identical with gen-c:invariant NAME { CHECK; ... }andinvariant NAME: CHECK;. A CHECK is an expression, orassert(EXPR), over decimal numbers,true,falseand consts gen-c writes as#define, through operators andas. These are exactly the checks gen-c keeps as_Static_assert;- an empty invariant, which is a comment in C and unchecked in Zig;
bench NAME { STMT* }, including thebench_prefix rule and the empty-body TODO.
- New code E_INVARIANT (14) for an invariant gen-c does not check (gen-c: an invariant it cannot write as _Static_assert becomes a comment or an uncalled function (hex/char literal, enum member, static const, call, statement), so C never checks it #8009): a hex, binary or char literal, an enum member, a non-
#defineconst or a var, a call, or a statement. - A bench's top-level assignment follows the test rule. Zig binds an unbound name and gen-c leaves it undeclared, so the core refuses it with E_TESTASSIGN (gen-c: a bench body's first top-level assignment is written without a declaration, so cc rejects what the Zig route binds #8010).
- Fixtures: accept files that build and run, and one refusal per shape.
t27core_ddc.t27is repinned.
Gate: cargo test -p t27c --test core_selfhost on the t27c lab, with the fixpoint, the core tests, every fixture and the corpus differential. The DDC also passes under Zig and t27b.
User Scenarios
- Given a
.t27source file containinginvariant NAME { CHECK; ... }with constant-foldable checks, whent27ccompiles it in self-hosted mode, then the core accepts the syntax and produces diagnostics byte-identical togen-c(static-assert invariants pass, non-constant invariants yield E_INVARIANT 14). - Given a
.t27source file containingbench NAME { STMT* }including empty body andbench_prefix cases, whent27ccompiles it in self-hosted mode, then the core accepts the syntax and follows the test assignment rule (top-level assignment to unbound name yields E_TESTASSIGN). - Given the updated
t27core.t27and repinnedt27core_ddc.t27, when running the self-host test suite, then all core tests, fixtures (accept and one refusal per shape), and the corpus differential pass undercargo test -p t27c --test core_selfhost.
Requirements
- FR-001: The core spec
specs/compiler/core/t27core.t27MUST acceptinvariant NAME { CHECK; ... }andinvariant NAME: CHECK;where CHECK is an expression over decimal numbers,true,false,#defineconsts, operators, andas, and MUST emit E_INVARIANT (14) for checks containing hex/binary/char literals, enum members, non-#defineconsts, vars, calls, or statements. - FR-002: The core spec
specs/compiler/core/t27core.t27MUST accept emptyinvariant NAME { }(treated as comment/unchecked) andbench NAME { STMT* }withbench_prefix rule and empty-body TODO handling. - FR-003: The core spec
specs/compiler/core/t27core.t27MUST apply the test assignment rule to bench top-level assignments: unbound name assignment yields E_TESTASSIGN. - FR-004: The file
specs/compiler/core/t27core_ddc.t27MUST be repinned to match the updatedt27core.t27. - FR-005: Fixture files MUST exist for each accepted shape (build and run) and one refusal per shape (invariant and bench).
Success Criteria
cargo test -p t27c --test core_selfhostexits 0 on the t27c lab with the fixpoint, all core tests, every fixture, and the corpus differential passing.specs/compiler/core/t27core.t27compiles without E_LEX oninvariantandbenchkeywords.- Fixture verification: 5 accept fixtures (build and run) and 2 refusal fixtures (one invariant E_INVARIANT, one bench E_TESTASSIGN) all produce expected exit codes.
- DDC validation:
specs/compiler/core/t27core_ddc.t27repinned and passes under Zig and t27b.
Boundary
- specs/compiler/core/t27core.t27
- specs/compiler/core/t27core_ddc.t27
- specs/tools/trinity/tri/bench.t27
- cli/t27b/bench/bench.py
Reactions are currently unavailable
Activity
t27core: invariant and bench blocks, byte-identical to gen-c (Closes #…