Commit 4a4af13
committed
fix(codegen): emit faithful Rust/C, don't run t27c optimizer on source backends (#1455)
t27c's AST optimizer corrupts the SOURCE-LEVEL output of the Rust and C
backends: a reassigned mutable local (`var x = 0; ... x = a;`) loses its
declaration while its uses remain (E0425), and `let` locals are const-inlined.
This is the 2609-site E0425 wave observed downstream in gHashTag/tri-net.
Root cause: compile_rust / compile_c ran `optimize(&mut ast, default)` (const
prop + the unconditional copy-prop / dead-store passes) before emitting SOURCE
code. Those passes are meant for a lowering target, not for human/rustc-facing
source; rustc and the C compiler optimize the emitted code far more reliably.
Fix: drop the `optimize()` call from compile_rust and compile_c and emit
faithfully from the parsed AST. Verilog/Zig keep their own pipelines.
Effect on the test suite (was 1491 passed / 3 failed at HEAD):
- test_let_binding_emitted_rust_1401 now PASSES (was failing)
- test_let_binding_emitted_c_1401 now PASSES (was failing)
- new test_two_reassigned_locals_survive_1455 PASSES
- 1494 passed / 1 failed; the remaining failure (let_binding_is_lowered_1401,
Verilog HIR path, does not call optimize) is pre-existing and untouched here.
Downstream (gHashTag/tri-net): regenerating gen/rust with this t27c drops the
E0425 wave from 2609 to 0; residual errors there are separate codegen bugs
(bare `Vec<>` without a generic arg, a few type mismatches) tracked separately.
FROZEN_HASH re-sealed (M5) for the compiler.rs change.
phi^2 + phi^-2 = 31 parent 4832ec6 commit 4a4af13
2 files changed
Lines changed: 29 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6183 | 6183 | | |
6184 | 6184 | | |
6185 | 6185 | | |
6186 | | - | |
6187 | | - | |
| 6186 | + | |
| 6187 | + | |
| 6188 | + | |
| 6189 | + | |
6188 | 6190 | | |
6189 | 6191 | | |
6190 | 6192 | | |
| |||
6193 | 6195 | | |
6194 | 6196 | | |
6195 | 6197 | | |
6196 | | - | |
6197 | | - | |
| 6198 | + | |
| 6199 | + | |
| 6200 | + | |
| 6201 | + | |
| 6202 | + | |
| 6203 | + | |
| 6204 | + | |
| 6205 | + | |
| 6206 | + | |
6198 | 6207 | | |
6199 | 6208 | | |
6200 | 6209 | | |
| |||
22530 | 22539 | | |
22531 | 22540 | | |
22532 | 22541 | | |
| 22542 | + | |
| 22543 | + | |
| 22544 | + | |
| 22545 | + | |
| 22546 | + | |
| 22547 | + | |
| 22548 | + | |
| 22549 | + | |
| 22550 | + | |
| 22551 | + | |
| 22552 | + | |
| 22553 | + | |
| 22554 | + | |
| 22555 | + | |
| 22556 | + | |
22533 | 22557 | | |
22534 | 22558 | | |
22535 | 22559 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
0 commit comments