Commit 7355946
authored
fix(rt): remove mutability guard on local variable assignment (#948)
## Summary
Remove the `mutabilityOf(...) ==K mutabilityMut` guard from
`#setLocalValue` in `rt/data.md`. MIR's `LocalDecl::mutability` is a
source-level annotation, not an assignment constraint — the Rust
compiler validates legality before emitting MIR and may reuse immutable
locals across loop iterations.
- Remove mutability guard from the initialized-local `#setLocalValue`
rule
- Preserve original mutability on write (`mutabilityOf(...)`) instead of
forcing `mutabilityMut`
- Add regression test `immutable-local-reassign.rs` (loop variable with
`mutability: Not`)
Follow-up: #949 (remove mutability tracking entirely)
## Context
A `for i in 0..2` loop variable is bound via pattern matching
(`Some(i)`) on each iteration, so rustc marks it as `mutability: Not`.
However, rustc reuses the same MIR local across iterations, producing
repeated assignments to an immutable local. This is valid MIR —
confirmed via `rustc -Z unpretty=mir` and the [`LocalDecl`
documentation](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.LocalDecl.html).
Without this fix, proof execution gets stuck at step 693 on
`#setLocalValue(place(local(8), .ProjectionElems), Integer(1, 64,
false))` — the loop counter assignment that no rule can handle.
### Proof evidence
**Without fix (RED):**
```
APRProof: immutable-local-reassign.main
status: ProofStatus.FAILED
stuck: 1, failing: 1
Leaf <k>:
#setLocalValue(place(local(8), .ProjectionElems), Integer(1, 64, false))
function: repro
```
**With fix (GREEN):**
```
test_prove_rs[immutable-local-reassign] PASSED (53.31s)
```
## Test plan
- [x] `immutable-local-reassign.rs` passes with fix, fails (stuck)
without fix
- [x] Full integration test suite (`make test-integration`)1 parent e23e477 commit 7355946
3 files changed
Lines changed: 25 additions & 11 deletions
File tree
- kmir/src
- kmir/kdist/mir-semantics/rt
- tests/integration/data/prove-rs
- show
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
180 | | - | |
181 | 180 | | |
182 | 181 | | |
183 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
184 | 187 | | |
185 | 188 | | |
186 | 189 | | |
187 | 190 | | |
188 | 191 | | |
189 | 192 | | |
190 | | - | |
| 193 | + | |
191 | 194 | | |
192 | 195 | | |
193 | 196 | | |
194 | | - | |
195 | 197 | | |
196 | 198 | | |
197 | 199 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
Lines changed: 9 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
58 | 61 | | |
59 | | - | |
60 | | - | |
61 | 62 | | |
62 | 63 | | |
0 commit comments