You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tests: check that each value a task takes in a loop is dropped exactly once #4543
#4356 makes each spawn copy the values that its task moves or copies into the task's own memory. Its test checks the value that each task sees, but not the drops. If the copy at the spawn made a value drop twice, or never, no test would fail.
This program moves a Drop value, and one field of a struct, into tasks in a loop. Each value must print its dropped line exactly once:
import core::ops;
const PASSES : i64 = 3;
struct Loud {
id : i64,
}
impl Drop for Loud {
fn drop(self : &mut Loud) -> void {
println!("dropped {}", self.id);
}
}
struct Two {
a : Loud,
b : Loud,
}
fn take(l : Loud) -> void {
println!("task has {}", l.id);
}
fn take_a(a : Loud, b_id : i64) -> void {
println!("task has {} and reads {}", a.id, b_id);
}
fn moved_whole() -> void {
tasks {
for i in 0i64..PASSES {
let l = Loud {
id : i
};
spawn {
take(l);
};
}
};
}
fn one_field_moved() -> void {
tasks {
for i in 0i64..PASSES {
let t = Two {
a : Loud {
id : 10i64 + i
}, b : Loud {
id : 20i64 + i
}
};
spawn {
take_a(t.a, t.b.id);
};
}
};
}
fn main() -> i32 {
moved_whole();
println!("--");
one_field_moved();
return 0;
}
On main today, each of the 9 dropped lines prints once, with both code generators, and with VX_TASK_RUNTIME unset, threads and shared. Each task also sees the value of its own pass. So the test guards against a regression, and it should pass with #4356 too.
The tasks can end in any order, so the drops can print in any order. The RUN line can sort the output before FileCheck. Then one CHECK-NEXT line for each id checks that it prints exactly once.
Activity
tests: add a task that moves a struct with a Receiver to the drop test
tests: check that each value a task moves in a loop is dropped once (v…