Skip to content

fix: don't consider &mut x as a last use in a call if x is used in another argument - #13446

Open
asterite wants to merge 5 commits into
masterfrom
ab/ownership-call-arg-and-same-arg-mut-ref
Open

fix: don't consider &mut x as a last use in a call if x is used in another argument#13446
asterite wants to merge 5 commits into
masterfrom
ab/ownership-call-arg-and-same-arg-mut-ref

Conversation

@asterite

@asterite asterite commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Problem Resolved

Resolves https://github.com/noir-lang/noir-claude/issues/1553
Resolves https://github.com/noir-lang/noir-claude/issues/1563

Summary of Changes

This fixes a real bug where passing &mut x, x to a call didn't produce a clone on x so a mutation via &mut x (in the called method) ended up affecting x. That said, this is unlikely to happen in real code as there's probably no use in passing the same variable both as a mutable reference and as itself.

Then, a fix to rc_invariant had to be done to account for this case. This is a check that runs in debug builds.

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.

@asterite asterite changed the title Ab/ownership call arg and same arg mut ref fix: don't consider &mut x as a last use in a call if x is used in another argument Aug 3, 2026
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Changes to Brillig bytecode sizes

Generated at commit: 2033ac4d3bb0e45bfb1567e44770c07ad726b13c, compared to commit: 54386dfcd6449707ec737e416d90825c0872e96b

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
array_sort_inliner_max +3 ❌ +0.74%
array_sort_inliner_min +3 ❌ +0.74%
array_sort_inliner_zero +3 ❌ +0.74%

Full diff report 👇
Program Brillig opcodes (+/-) %
array_sort_inliner_max 408 (+3) +0.74%
array_sort_inliner_min 408 (+3) +0.74%
array_sort_inliner_zero 408 (+3) +0.74%
uhashmap_inliner_zero 7,150 (+18) +0.25%
uhashmap_inliner_min 7,326 (+18) +0.25%
uhashmap_inliner_max 9,152 (+18) +0.20%

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Changes to number of Brillig opcodes executed

Generated at commit: 2033ac4d3bb0e45bfb1567e44770c07ad726b13c, compared to commit: 54386dfcd6449707ec737e416d90825c0872e96b

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
array_sort_inliner_max +3 ❌ +0.36%
array_sort_inliner_min +3 ❌ +0.36%
array_sort_inliner_zero +3 ❌ +0.36%

Full diff report 👇
Program Brillig opcodes (+/-) %
array_sort_inliner_max 843 (+3) +0.36%
array_sort_inliner_min 843 (+3) +0.36%
array_sort_inliner_zero 843 (+3) +0.36%
uhashmap_inliner_max 68,560 (+18) +0.03%
uhashmap_inliner_min 87,103 (+18) +0.02%
uhashmap_inliner_zero 87,194 (+18) +0.02%

@asterite
asterite requested a review from TomAFrench August 3, 2026 21: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.

1 participant