std's mut imported under two names lends under both: no false missing-mut, no missed aliased-mut #150

Merged
sionzee merged 1 commit from mut-aliases into main 2026-11-24 01:15:37 +01:00
Owner

While checking whether mut(x) is inlined by the build (it is: the transform erases it), one case slipped through: a file that imports std's mut under two names, import { mut, mut as lend }. The loan collector kept only one local name, taken from a HashMap in no fixed order, and calls through the other name weren't loans at all:

  • they stayed as real calls in the emitted code;
  • aliased-mut didn't see them, so transfer(mut(account), lend(account)) passed;
  • depending on which name got picked, missing-mut reported a call that did lend and offered mut(mut(account)) as the fix.

Now the collector keeps every name for mut and for mutEach, sorted. Fixes still write mut when the file has that name.

Tests: new fixture mut_two_names (fails before this change with the false missing-mut and the missed aliased-mut), and mut_under_two_names_is_erased_by_both in tests/transform.rs. Fast profile: cargo nextest run --workspace 412/412 (the emit tests need the addon built first), npm run test:std 455/455, npm run test:soundness unchanged (16 of 110 escape).

Not in this PR: several other checks still match the callee by the literal name "mut" (lifetime.rs, superseded.rs, shifted.rs, left_behind.rs, borrow.rs:283), so a file whose only name for it is mut as lend skips those rules. Erasure and the loan checks are fine in that case. That needs its own change.

Created with Claude Opus 5.5 in Claude Code.

While checking whether `mut(x)` is inlined by the build (it is: the transform erases it), one case slipped through: a file that imports std's `mut` under two names, `import { mut, mut as lend }`. The loan collector kept only one local name, taken from a `HashMap` in no fixed order, and calls through the other name weren't loans at all: - they stayed as real calls in the emitted code; - `aliased-mut` didn't see them, so `transfer(mut(account), lend(account))` passed; - depending on which name got picked, `missing-mut` reported a call that did lend and offered `mut(mut(account))` as the fix. Now the collector keeps every name for `mut` and for `mutEach`, sorted. Fixes still write `mut` when the file has that name. Tests: new fixture `mut_two_names` (fails before this change with the false `missing-mut` and the missed `aliased-mut`), and `mut_under_two_names_is_erased_by_both` in `tests/transform.rs`. Fast profile: `cargo nextest run --workspace` 412/412 (the emit tests need the addon built first), `npm run test:std` 455/455, `npm run test:soundness` unchanged (16 of 110 escape). Not in this PR: several other checks still match the callee by the literal name `"mut"` (`lifetime.rs`, `superseded.rs`, `shifted.rs`, `left_behind.rs`, `borrow.rs:283`), so a file whose only name for it is `mut as lend` skips those rules. Erasure and the loan checks are fine in that case. That needs its own change. Created with Claude Opus 5.5 in Claude Code.
std's mut imported under two names lends under both
Some checks failed
Benchmarks / bench (pull_request) Successful in 3m18s
Tests / test (pull_request) Failing after 30m7s
1665c72e45
`import { mut, mut as lend }`: the loan collector kept one local name, picked from a HashMap
in no fixed order. The other name's calls were no loans: they stayed in the emitted code,
`aliased-mut` didn't see them, and `missing-mut` reported a call that did lend, offering
`mut(mut(account))`. It now keeps every name (sorted), for `mutEach` too; fixes write `mut`
when the file has it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sionzee deleted branch mut-aliases 2026-11-24 01:15:37 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Evobug/Safe-Ts!150
No description provided.