Skip to content

fix(codegen): lower Rust +% to wrapping_add (R7) - #1660

Closed
gHashTag wants to merge 1 commit into
masterfrom
fix/r7-rust-wrapping-ops
Closed

gHashTag wants to merge 1 commit into
masterfrom
fix/r7-rust-wrapping-ops

Conversation

@gHashTag

@gHashTag gHashTag commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Problem

t27c gen-rust emitted the wrapping-add operator +% literally (a +% b), which is not valid Rust and fails to compile.

Fix

Lower +% → (lhs).wrapping_add(rhs) in Compiler::expr_to_rust. Checked +/* deliberately stay infix — the Zig backend keeps them checked (overflow-panic in debug), and the two backends must agree. Blanket backend-wrapping (as the R7 backlog line suggested) would break that parity; see #1659 for the real hash-mixer story (missing *%/-%/<<% operators).

Verification

  • New test test_wrapping_add_op_lowered_rust: +% → wrapping_add, no literal +% leak, plain + NOT wrapped.
  • Full compiler suite 1495 passed / 0 failed. (bitnet_pipeline::sequencer_idle_arms_on_start fails identically on pristine master — pre-existing, unrelated.)
  • End-to-end: gen-rust output now compiles under rustc --edition 2021.

Constitution

  • L2: emitter change, not a gen/ edit.
  • L4: regression test added.
  • M5: FROZEN_HASH re-sealed (93cc42e3…).

Closes #1658
Relates #1659

🤖 Generated with Claude Code

The wrapping-add operator +% (Zig-style, TokenKind::PlusPercent) was passed
through literally by the Rust emitter, producing `a +% b` — not valid Rust,
fails to compile. Lower it to (lhs).wrapping_add(rhs) in Compiler::expr_to_rust.

Checked + / * stay infix so the Rust backend keeps the same overflow-panic
semantics as the Zig backend (which emits checked +/* and native +%).

Adds regression test test_wrapping_add_op_lowered_rust (L4) and re-seals the
FROZEN_HASH (M5). Full compiler suite: 1495 passed / 0 failed. Generated code
now compiles under rustc --edition 2021.

Closes #1658

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

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-08-05 08:10:23 UTC

Summary

Status Count
Total Open PRs 50
PRs with Failing Checks 7
PRs with All Checks Green 43
READY 0
FAILING 7
PENDING 0

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=93cc42e3597c != manifest seal=87e5cbd3ad94.
    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

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

📓 NotebookLM Notebook linked to this PR

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

@gHashTag

gHashTag commented Aug 5, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #1674, which folds in this exact +%→wrapping_add change and adds the rest of the family (-%/*% across lexer, parser, and the Rust/Verilog/C backends). Closing in favor of the complete version.

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: gen-rust emits literal +% (invalid Rust) — lower to wrapping_add (R7)

1 participant