crates/mimir-driver/tests/fixture-mir/app/src/lib.rs
pub fn helper(x: u64) -> u64 {
x.wrapping_mul(3)
}
/// An if, a loop and a call.
pub fn sample(n: u64) -> u64 {
let mut acc = 0;
let mut i = 0;
while i < n {
if i % 2 == 0 {
acc += helper(i);
} else {
acc += 1;
}
i += 1;
}
acc
}
/// The same body as `twin_b`, every local named differently.
pub fn twin_a(v: &[u64], k: u64) -> u64 {
let mut total = 0;
for x in v {
if *x > k {
total += helper(*x);
}
}
total
}
pub fn twin_b(items: &[u64], limit: u64) -> u64 {
let mut sum = 0;
for it in items {
if *it > limit {
sum += helper(*it);
}
}
sum
}
/// A macro site: its statements are positioned at the call site.
pub fn with_macro(v: &mut Vec<u64>) -> usize {
v.push(dep::weigh(4));
assert!(!v.is_empty(), "never empty");
v.len()
}
/// A closure body is folded into its fn.
pub fn with_closure(v: &[u64]) -> u64 {
v.iter().map(|x| helper(*x) + 1).sum()
}