Skip to content

feat(codegen): recursive reassignment + read scan in optimizer passes - #1465

Merged
gHashTag merged 2 commits into
masterfrom
feat/recursive-opt-scan-2026-07-13
Jul 13, 2026
Merged

gHashTag merged 2 commits into
masterfrom
feat/recursive-opt-scan-2026-07-13

Conversation

@gHashTag

Copy link
Copy Markdown
Owner

What

Three optimizer passes (const_propagate, copy_propagate, dead_store_elim) checked for reassignment/reads only at the top-level statement list, without recursing into if/while/for bodies. Locals reassigned inside conditionals had their let dropped or identifiers inlined, leaving dangling references (E0425).

Fixes #1464

How

Recursive reassignment and read scanning in all three passes:

  • const_propagate: uses assigns_to_recursive() instead of top-level scan
  • copy_propagate: same recursive check before inlining
  • dead_store_elim: collect_reads_in_stmts() recurses into control-flow bodies
  • New helper assigns_to_recursive(): mirrors collect_mutable_names pattern

Measured impact (tri-net, cross-env verified)

Before (#1461 merged, no #1462):  208 errors (E0384 fixed, E0425 remains)
After  (#1461+#1462):              26 errors (E0425 fixed, remaining = E0107 Vec generics)

Cross-env verified: 28 errors on linux, 26 on macOS arm64.

Files

bootstrap/src/compiler.rs — +50 lines (3 pass fixes + helper function)

Supersedes closed #1462 (base branch deleted by squash merge of #1461).

phi^2 + phi^-2 = 3

Perplexity Computer and others added 2 commits July 13, 2026 14:24
Three surgical fixes to the optimizer that together let mut-inference
(PR #1461) actually deliver clean gen/rust on downstream repos:

1. const_propagate: reassigned-check now uses collect_mutable_names,
   which already recurses into if/while/for/for-range bodies. Previously
   a `let X = <literal>` reassigned INSIDE a control-flow block was
   incorrectly considered non-reassigned, inlined, and its declaration
   dropped, leaving dangling `X = ...` reassignments in emit.

2. copy_propagate: same recursive reassigned-check guard added. A
   `let X = Y` where X is reassigned later (including inside
   control-flow) is no longer copy-propagated.

3. dead_store_elim: new helper collect_reads_in_stmts recurses into
   if/while/for/for-range bodies when building the `reads` set. Without
   this a `let i = 0;` that is only read inside a `while` body was
   seen as dead and eliminated. StmtAssign with a simple-identifier LHS
   still contributes only the RHS to `reads` (pre-existing dead-store
   semantics preserved).

Measured on tri-net specs (all 119 regenerated):
- baseline PR #1461 (SHA 6171697): cargo check --lib -> 208 errors
  (145x E0425 cannot-find-value, 26x E0107 Vec generics, misc)
- this PR: cargo check --lib -> 28 errors
  (26x E0107 Vec generics, 2x independent)
- delta: -180 errors, -87%. E0425 -> 0.

t27c own tests: 1491 passed / 3 failed. Same 3 pre-existing failures
(#1401 let_binding_is_lowered / test_let_binding_emitted_{c,rust}_1401)
that already fail on baseline 6171697; not a regression from this PR.

FROZEN_HASH re-sealed via bootstrap/stage0 ceremony.

Remaining 28 errors are independent bugs (Vec<> generics elision and
2 type-inference edge cases), not touched by this PR.

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-13 07:33:59 UTC

Summary

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

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=b4cb28350b49 != 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
gHashTag merged commit bd56aef into master Jul 13, 2026
18 of 19 checks passed
@gHashTag
gHashTag deleted the feat/recursive-opt-scan-2026-07-13 branch July 13, 2026 07:36
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: optimizer drops reassigned locals in control-flow bodies

1 participant