I have a fairly simple test here, which seems to output an impossible call stack when profiled with perf:
use std::collections::HashMap;
#[inline(never)]
#[no_mangle]
fn merge(lhs: &mut HashMap<i32, f32>, rhs: &HashMap<i32, f32>) {
for (k, v) in rhs {
lhs.insert(*k, *v);
}
}
#[no_mangle]
#[inline(never)]
fn merge_all(inputs: Vec<(HashMap<i32, f32>, HashMap<i32, f32>)>) {
for (mut lhs, rhs) in inputs {
merge(&mut lhs, &rhs);
std::mem::forget(core::hint::black_box((lhs, rhs)));
}
}
pub fn main() {
for _ in 0..1000 {
let mut a = HashMap::<i32, f32>::default();
for key in 0..100 {
a.insert(key, key as f32);
}
let mut b = HashMap::default();
b.insert(-1, -1.0);
let inputs = std::iter::from_fn(|| Some((a.clone(), b.clone())))
.take(1000)
.collect::<Vec<_>>();
merge_all(inputs);
}
}
[continuing in thread...]