Skip to content

Commit c5be649

Browse files
authored
fix(rt): repair closure callee setup for iter-eq repro (#957)
## Summary - adds `iter-eq-copied-take-dereftruncate` as a regression - fixes `setupCalleeClosure2` by initializing callee `_1` with the closure env before tuple unpacking - removes temporary show tracking after the repro reaches `#EndProgram` ## Why This Fix - Red commit frontier: after `1947` steps the new repro stopped at: - `#traverseProjection(toLocal(1), thunk(operandCopy(place(... local: local(1) ...))))` - Root cause: `setupCalleeClosure2` reserved `NEWLOCALS` and unpacked the tuple argument into `_2..`, but never wrote the closure receiver/env into `_1`. The std closure body later dereferenced `local(1)`, so execution walked a bad projection path instead of the closure env. - Fix: write `#incrementRef(getValue(LOCALS, CLOSURE))` into `local(1)` before `#setTupleArgs(2, ...)`. - Effect: the same repro moves from the stuck `1947`-step leaf to `#EndProgram` after `5601` steps. The cleanup commit then deletes only the temporary show artifact.
1 parent caa5994 commit c5be649

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

kmir/src/kmir/kdist/mir-semantics/kmir.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,8 @@ Therefore a heuristics is used here:
562562
_SPAN
563563
)
564564
=>
565-
#setTupleArgs(2, getValue(LOCALS, TUPLE)) ~> #execBlock(FIRST)
565+
#setLocalValue(place(local(1), .ProjectionElems), #incrementRef(getValue(LOCALS, CLOSURE)))
566+
~> #setTupleArgs(2, getValue(LOCALS, TUPLE)) ~> #execBlock(FIRST)
566567
// arguments are tuple components, stored as _2 .. _n
567568
...
568569
</k>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
fn main() {
2+
let _keep: fn() -> bool = repro;
3+
}
4+
5+
#[inline(never)]
6+
#[no_mangle]
7+
pub fn repro() -> bool {
8+
let k0 = Pubkey([1; 32]);
9+
let k1 = Pubkey([2; 32]);
10+
let k2 = Pubkey([3; 32]);
11+
let n = 2usize;
12+
13+
let accounts = [
14+
AccountInfo { key: &k0 },
15+
AccountInfo { key: &k1 },
16+
AccountInfo { key: &k2 },
17+
];
18+
let signers = [k1, k2, k0];
19+
20+
accounts[1..]
21+
.iter()
22+
.map(|signer| *signer.key)
23+
.eq(signers.iter().take(n).copied())
24+
}
25+
26+
#[derive(Clone)]
27+
struct AccountInfo<'a> {
28+
key: &'a Pubkey,
29+
}
30+
31+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
32+
struct Pubkey([u8; 32]);

kmir/src/tests/integration/test_integration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
'assume-cheatcode-conflict-fail': ['check_assume_conflict'],
3939
'transmute-bytes': ['bytes_to_u64', 'u64_to_bytes'],
4040
'test_offset_from-fail': ['testing'],
41+
'iter-eq-copied-take-dereftruncate': ['repro'],
4142
}
4243
PROVE_RS_SHOW_SPECS = [
4344
'local-raw-fail',

0 commit comments

Comments
 (0)