Repository navigation
self-host: gen-c silently drops every declaration after endmodule #6047
Copy link
Copy link
Closed
Labels
owner-approved-foreignOwner-approved exception to the only-t27 rule: hand-written foreign code allowed in this PROwner-approved exception to the only-t27 rule: hand-written foreign code allowed in this PR
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, PR #6041) 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. Fixing it here is what lets the core grow. Rules for this task:
- Change the Rust emitter 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 other spec whose generated C changes must be listed in the PR by path, with one line on
why the new bytes are right. 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
endmodule ends the parse, and anything after it vanishes from the output with exit code 0: the function lost below is never emitted and nothing says so. The self-hosted core refuses a declaration after endmodule (E_SYNTAX). The fix is the same refusal, unless a corpus spec relies on text after endmodule, in which case list them in the PR and stop for a decision.
Reproduce
cargo build --release -p t27c
printf 'module m;\nendmodule\nfn lost() -> i64 {\n return 1;\n}\n' > /tmp/endm.t27
./target/release/t27c gen-c /tmp/endm.t27
Today the relevant output is:
(header comment only: no prototype, no body for lost, exit 0)
Acceptance criteria
-
./target/release/t27c gen-c /tmp/endm.t27 > /dev/null 2>/tmp/endm.err; echo $?prints a non-zero code (today0)
-
grep -c 'endmodule' /tmp/endm.errprints at least1: the message names what was refused
-
printf 'module m;\nfn kept() -> i64 {\n return 1;\n}\nendmodule\n' > /tmp/endm2.t27 && ./target/release/t27c gen-c /tmp/endm2.t27 | grep -c 'kept('prints at least1:endmoduleat the end still works
-
cargo test --release -p t27c --test genc_after_endmodulepasses
Boundary
bootstrap/src/compiler.rsbootstrap/tests/genc_after_endmodule.rs
User Scenarios & Testing
- Given
/tmp/endm.t27written by the Reproduce block,
when./target/release/t27c gen-c /tmp/endm.t27runs and its output is compiled withcc,
then the compiler refuses the file with a message namingendmodule, and a file whoseendmoduleis last compiles as before.
Requirements
- FR-001: a token after
endmoduleother than comments and whitespace MUST be refused, never dropped. - FR-002: list every file under
specs/that has a token afterendmodulein the PR (expected: none). - FR-900:
cargo test --release -p t27c --test genc_after_endmoduleMUST pass, and MUST fail with the fix reverted. - FR-901: if
bootstrap/tests/core_selfhost.rsexists on your base,cargo test --release -p t27c --test core_selfhostMUST still pass.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
owner-approved-foreignOwner-approved exception to the only-t27 rule: hand-written foreign code allowed in this PROwner-approved exception to the only-t27 rule: hand-written foreign code allowed in this PR
Activity
fix(gen-c): refuse text after `endmodule` instead of dropping it (Closes
fix(gen-c): refuse text after `endmodule` instead of dropping it (Closes
fix(gen-c): refuse text after `endmodule` instead of dropping it (Closes