Skip to content

fix(codegen): faithful Rust/C emit — don't run optimizer on source backends (#1455)#1456

Open
gHashTag wants to merge 1 commit into
masterfrom
fix/faithful-rust-c-codegen-1455
Open

fix(codegen): faithful Rust/C emit — don't run optimizer on source backends (#1455)#1456
gHashTag wants to merge 1 commit into
masterfrom
fix/faithful-rust-c-codegen-1455

Conversation

@gHashTag

Copy link
Copy Markdown
Owner

Fixes #1455. t27c's AST optimizer corrupted source-level Rust/C output (dropped reassigned locals -> E0425; const-inlined let). compile_rust/compile_c now emit faithfully from the AST; rustc/cc optimize downstream. Suite 1491/3-fail -> 1494/1-fail (+3, remaining failure is the pre-existing Verilog HIR path). Regenerating gHashTag/tri-net gen/rust with this drops the E0425 wave 2609 -> 0. FROZEN_HASH re-sealed (M5). phi^2 + phi^-2 = 3

gHashTag pushed a commit that referenced this pull request Jul 10, 2026
…1457)

Second codegen fix after the optimizer removal. Makes the Rust backend emit
correct array types and indices so generated modules compile under rustc.

t27_type_to_rust:
- `[T; N]` (Rust-style, element before `;`) previously took the empty suffix
  after `]` and emitted `Vec<>` -> E0107. Now emits `[T; N as usize]`
  (element parsed correctly; length cast to usize as arrays require).
- Zig-style `[N]T` still lowers to `Vec<T>`.

expr_to_rust (ExprIndex):
- Array/Vec indices must be `usize`; t27 index expressions are u32. Non-literal
  indices now emit `[(idx) as usize]`. Integer literals are left uncast (they
  infer usize and casting them would trip clippy::unnecessary_cast).

Verified: t27c suite unchanged at 1494 passed / 1 failed (the remaining failure
is the pre-existing Verilog HIR let-binding test, untouched). Regenerating
gHashTag/tri-net with #1456 + this drops the wired-module error count from
400+ to a handful of genuine SPEC bugs (a bool-vs-u32 return type, a Q8.8
fixed-point 256-in-u8 literal, a couple of `let`-that-should-be-`var`), i.e. the
codegen itself now produces compiling Rust.

FROZEN_HASH re-sealed (M5).

phi^2 + phi^-2 = 3
@github-actions

Copy link
Copy Markdown
Contributor

📓 NotebookLM Notebook linked to this PR

This notebook contains session context, decisions, and artifacts for this work.

@github-actions

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-07-10 01:51:20 UTC

Summary

Status Count
Total Open PRs 27
PRs with Failing Checks 17
PRs with All Checks Green 10
READY 9
FAILING 17
PENDING 0

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=6eb632b838e9 != manifest seal=49e55df6d444.
    The committed NMSE numbers were certified against an older compiler.rs.
    Run scripts/reseal-check.sh locally for the two-step reseal command (advisory; not a merge gate).

@github-actions

Copy link
Copy Markdown
Contributor

📓 NotebookLM Notebook linked to this PR

This notebook contains session context, decisions, and artifacts for this work.

@github-actions

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-07-10 05:01:10 UTC

Summary

Status Count
Total Open PRs 27
PRs with Failing Checks 18
PRs with All Checks Green 9
READY 9
FAILING 18
PENDING 0

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=c25b7a6f4e2f != manifest seal=49e55df6d444.
    The committed NMSE numbers were certified against an older compiler.rs.
    Run scripts/reseal-check.sh locally for the two-step reseal command (advisory; not a merge gate).

gHashTag pushed a commit that referenced this pull request Jul 10, 2026
…ure, wildcard module array bindings, bench-local packed-vector array parameters, 0 UNSUPPORTED_ICARUS placeholders

- Host-only namespace calls (module::helper) are now erased from Verilog emission.
- Module-scope wildcard 'let _ = ...' bindings emit anonymous ROMs/temporaries correctly.
- Bench-local scalar arrays can be passed as packed-vector function parameters.
- Icarus strictness fixes: packed-vector slicing for local array params, bench initial-block deduplication.
- Resealed NMSE manifests for current compiler.rs hash.
- W486 close-out report + W487 cooperation variants.

Closes #1456

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
 #1455, Refs #1457)

Two codegen-correctness fixes for the Rust (and C) source backends, so t27c
generates compiling code.

1) compile_rust/compile_c no longer run t27c's AST optimizer before emitting
   source. Those passes (const-prop + the unconditional copy-prop / dead-store
   passes) corrupt the source-level output: a reassigned mutable local loses its
   declaration while its uses remain (E0425), and `let` locals are const-inlined.
   rustc/cc optimize the emitted code downstream. Fixes the 2609-site E0425 wave
   seen in gHashTag/tri-net. (Closes #1455.)

2) t27_type_to_rust lowers Rust-style fixed arrays `[T; N]` to `[T; N as usize]`
   (previously emitted `Vec<>` -> E0107); expr_to_rust casts non-literal array
   indices to `usize` (literals stay uncast to avoid clippy::unnecessary_cast).
   (Refs #1457.)

Tests: rust/C let-binding regression tests now pass, new
test_two_reassigned_locals_survive_1455 passes; suite 1491/3-fail -> 1494/1-fail
(the remaining failure is the pre-existing Verilog HIR let-binding test,
untouched). FROZEN_HASH re-sealed (M5). docs/NOW.md updated.

Downstream gHashTag/tri-net regenerates gen/rust with this: E0425 2609 -> 0.

phi^2 + phi^-2 = 3
@gHashTag
gHashTag force-pushed the fix/faithful-rust-c-codegen-1455 branch from d7f3a73 to 0f7f512 Compare July 10, 2026 05:31
gHashTag pushed a commit that referenced this pull request Jul 10, 2026
Refs #1456

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

📓 NotebookLM Notebook linked to this PR

This notebook contains session context, decisions, and artifacts for this work.

@github-actions

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-07-10 08:49:12 UTC

Summary

Status Count
Total Open PRs 27
PRs with Failing Checks 17
PRs with All Checks Green 10
READY 9
FAILING 17
PENDING 0

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=c25b7a6f4e2f != manifest seal=49e55df6d444.
    The committed NMSE numbers were certified against an older compiler.rs.
    Run scripts/reseal-check.sh locally for the two-step reseal command (advisory; not a merge gate).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

codegen: Rust emitter miscompiles REASSIGNED mutable locals (let folds to const; let mut splits; var partial)

2 participants