Repository navigation
self-host: gen-c emits nothing for a char-literal const #6049
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
const Q: u8 = 'a'; produces no #define Q and no error, so every use of Q fails to compile later. The self-hosted core refuses it (E_CONST).
Reproduce
cargo build --release -p t27c
printf 'module m;\nconst Q: u8 = '\''a'\'';\n' > /tmp/charc.t27
./target/release/t27c gen-c /tmp/charc.t27
Today the relevant output is:
(the Constants banner, then nothing)
Acceptance criteria
-
./target/release/t27c gen-c /tmp/charc.t27 | grep -c '#define Q'prints1(today0)
-
./target/release/t27c gen-c /tmp/charc.t27 > /tmp/charc.c && printf '#include "charc.c"\nint main(void){return Q==97?0:1;}\n' > /tmp/charcm.c && cc -w -o /tmp/charcm /tmp/charcm.c && /tmp/charcm; echo $?prints0
-
cargo test --release -p t27c --test genc_char_constpasses
Boundary
bootstrap/src/compiler.rsbootstrap/tests/genc_char_const.rs
User Scenarios & Testing
- Given
/tmp/charc.t27written by the Reproduce block,
when./target/release/t27c gen-c /tmp/charc.t27runs and its output is compiled withcc,
thenQ == 97, and escapes'\n'and'\''keep their values (10 and 39).
Requirements
- FR-001: a char-literal const MUST lower to its byte value with the declared type.
- FR-900:
cargo test --release -p t27c --test genc_char_constMUST 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): emit a char const instead of dropping it (Closes #6049)
fix(gen-c): emit a char const instead of dropping it (Closes #6049)
fix(gen-c): emit a char const instead of dropping it (Closes #6049)