Skip to content

fix(ssa): preserve truncating cast chain boundary - #13388

Open
1sgtpepper wants to merge 1 commit into
noir-lang:masterfrom
1sgtpepper:fix-cast-chain-boundary
Open

fix(ssa): preserve truncating cast chain boundary#13388
1sgtpepper wants to merge 1 commit into
noir-lang:masterfrom
1sgtpepper:fix-cast-chain-boundary

Conversation

@1sgtpepper

@1sgtpepper 1sgtpepper commented Jul 22, 2026

Copy link
Copy Markdown

Problem Resolved

Resolves #12844

Summary of Changes

Preserves an intermediate cast whenever collapsing it would change truncation or extension behavior. For -1i8 as u8 as i16, the u8 boundary must produce 255; replacing the chain with direct i8 -> i16 widening would produce -1.

The legality check compares all three widths and signedness roles, and collapses only cast chains that compose exactly. The behavior test covers the reported case, the opposite unsigned→signed boundary, narrow-then-widen chains, and a wider unsigned intermediate. Two existing SSA snapshots retain their proven intermediate casts.

User Documentation

Check one:

  • No user documentation needed.
  • Documented in docs/.
  • [For Experimental Features] Documentation tracking issue created:

PR Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

Validation:

  • cargo test -p noirc_evaluator --lib
  • cargo clippy -p noirc_evaluator --lib -- -D warnings
  • cargo fmt --check

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution to the Noir language.

Please do not force push to this branch after the Noir team have started review of this PR. Doing so will only delay us merging your PR as we will need to start the review process from scratch.

Thanks for your understanding.

@1sgtpepper
1sgtpepper force-pushed the fix-cast-chain-boundary branch from a96b0cf to 45b611c Compare July 22, 2026 13:08
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.

SSA cast-chain simplification drops observable unsigned truncation boundary

1 participant