Repository navigation
Self-host: gen-c nests C comments in a nested repeat initializer and zeroes a repeated row #7353
Description
Profile (read first)
You are working as Gamma (Compiler Core) on epic #5980: rewrite t27c in t27 itself.
The self-hosted core (specs/compiler/core/t27core.t27) must write exactly the bytes
t27c gen-c writes, so every gen-c defect is a defect the core has to refuse instead of learn.
Rules for this task:
- Change gen-c only inside the Boundary below.
gen/is generated: never hand-edit it. - Build with
cargo build --release -p t27cand use./target/release/t27cfrom the repository
root, not at27con PATH. - Write the regression test first and watch it fail on the unfixed compiler. Then fix, and
revert the fix once to watch the test go red again. Say in the PR that you did both. - Any spec that stops compiling must be listed in the PR by path with its fix. A silent corpus
change is a failed task. - The PR body says
Closes #plus this issue's number andPart of #5980. ASCII only in source files.
Context
gen-c writes a repeat initializer as a C comment followed by {0}. For a nested repeat the
comment contains another comment:
var g: [2][3]u8 = [_][3]u8{ [_]u8{0} ** 3 } ** 2;
=> static uint8_t g[2][3] = /* repeat: { /* repeat: { 0 } ** 3 */ {0} } ** 2 */ {0};
The inner */ closes the outer comment, so the C does not compile (expected ',' or ';'). The
form is the one the corpus uses for 2-D globals ([16][16]u8, 6 uses). Two more losses on the same path:
- a repeated non-zero row,
[_][2]u8{ [_]u8{1, 2} } ** 2, becomes{0}and compiles: every element reads 0; - a non-zero inner repeat,
[_][K]i64{ [_]i64{7} ** K } ** R, puts the GNU range
{ [0 ... (K) - 1] = 7 }at the outer level ("array index range in initializer exceeds array bounds").
An explicit row list, [_][2]u8{ [_]u8{1, 2}, [_]u8{3, 4} }, is lowered correctly to
{ { 1, 2 }, { 3, 4 } }. The core (P1 slice 3) accepts that form and refuses an outer ** on a nested array with E_ARRAY.
Reproduce
cargo build --release -p t27c
printf 'module m;\nvar g: [2][2]u8 = [_][2]u8{ [_]u8{1, 2} } ** 2;\ntest t { assert(g[1][1] == 2); }\n' > /tmp/n.t27
./target/release/t27c gen-c /tmp/n.t27 > /tmp/n.c; echo "gen-c exit $?"
cc -std=c99 -DT27_TEST_MAIN /tmp/n.c -o /tmp/n && /tmp/n; echo "run exit $?"
Today: gen-c exit 0, then the run aborts on assert(g[1][1] == 2). With [_][3]u8{ [_]u8{0} ** 3 } ** 2 cc fails instead.
Acceptance criteria
-
- The Reproduce run prints
All 1 tests passed.and exits 0
- The Reproduce run prints
-
[_][3]u8{ [_]u8{0} ** 3 } ** 2and[_][K]i64{ [_]i64{7} ** K } ** Rcompile withcc -std=c99and hold the right values
-
cargo test --release -p t27c --test genc_nested_repeatpasses
Boundary
bootstrap/src/compiler.rsbootstrap/tests/genc_nested_repeat.rs
User Scenarios & Testing
- Given a global
var g: [16][16]u8 = [_][16]u8{ [_]u8{0} ** 16 } ** 16;,
when./target/release/t27c gen-clowers it,
then the C compiles and every element is 0; a repeated non-zero row keeps its values.
Requirements
- FR-001: gen-c MUST NOT nest a C comment inside a C comment.
- FR-002: a repeated row MUST keep its element values; a value MUST NOT become
{0}unless it is zero. - FR-900:
cargo test --release -p t27c --test genc_nested_repeatMUST pass, and MUST fail with the fix reverted. - FR-901:
cargo test --release -p t27c --test core_selfhostand the corpus suite MUST still pass.
Part of #5980
Activity
t27core: nested arrays and list initializers, byte-identical to gen-c (…
fix(gen-c): a #7353 repeat refusal names the line of its declaration
fix(gen-c): a #7353 repeat refusal names the declaration it initializes
fix(gen-c): a #7353 repeat of an enum member, struct literal or call …
gHashTag commentedon Oct 7, 2026
A fix is on branch
genc-repeat-pow(head db2c58f), but no PR is open because it is over the foreign-line budget (#7371). On top of #7406 it adds compiler.rs +292 and tests +304, against limits of 40 per file and 80 per PR, and #7406 is parked for the same reason.What the branch does:
**repeat is written as one comment, with the rows kept.a ** bbecomest27_pow/t27_ipow.On the t27c lab, 11/11 tests pass with the fix and 10/11 fail with it reverted.
The corpus diff on the previous head showed 16 specs change C, about 11 of them sealed. The branch is not resealed yet. Landing it needs the lowering written in .t27 or an owner decision.