This commit is contained in:
The Miri Cronjob Bot 2024-04-25 05:05:41 +00:00
parent ff6fc75781
commit 258e5043a1
3 changed files with 150 additions and 81 deletions

View File

@ -7,7 +7,8 @@ use std::{
};
fn firstn() -> impl Coroutine<Yield = u64, Return = ()> {
#[coroutine] static move || {
#[coroutine]
static move || {
let mut num = 0;
let num = &mut num;
*num += 0;

View File

@ -43,94 +43,144 @@ fn basic() {
panic!()
}
finish(1, false, #[coroutine] || yield 1);
finish(
1,
false,
#[coroutine]
|| yield 1,
);
finish(3, false, #[coroutine] || {
let mut x = 0;
yield 1;
x += 1;
yield 1;
x += 1;
yield 1;
assert_eq!(x, 2);
});
finish(7 * 8 / 2, false, #[coroutine] || {
for i in 0..8 {
yield i;
}
});
finish(1, false, #[coroutine] || {
if true {
finish(
3,
false,
#[coroutine]
|| {
let mut x = 0;
yield 1;
} else {
}
});
x += 1;
yield 1;
x += 1;
yield 1;
assert_eq!(x, 2);
},
);
finish(1, false, #[coroutine] || {
if false {
} else {
yield 1;
}
});
finish(
7 * 8 / 2,
false,
#[coroutine]
|| {
for i in 0..8 {
yield i;
}
},
);
finish(2, false, #[coroutine] || {
if {
finish(
1,
false,
#[coroutine]
|| {
if true {
yield 1;
} else {
}
},
);
finish(
1,
false,
#[coroutine]
|| {
if false {
} else {
yield 1;
}
},
);
finish(
2,
false,
#[coroutine]
|| {
if {
yield 1;
false
} {
yield 1;
panic!()
}
yield 1;
false
} {
yield 1;
panic!()
}
yield 1;
});
},
);
// also test self-referential coroutines
assert_eq!(
finish(5, true, #[coroutine] static || {
let mut x = 5;
let y = &mut x;
*y = 5;
yield *y;
*y = 10;
x
}),
finish(
5,
true,
#[coroutine]
static || {
let mut x = 5;
let y = &mut x;
*y = 5;
yield *y;
*y = 10;
x
}
),
10
);
assert_eq!(
finish(5, true, #[coroutine] || {
let mut x = Box::new(5);
let y = &mut *x;
*y = 5;
yield *y;
*y = 10;
*x
}),
finish(
5,
true,
#[coroutine]
|| {
let mut x = Box::new(5);
let y = &mut *x;
*y = 5;
yield *y;
*y = 10;
*x
}
),
10
);
let b = true;
finish(1, false, #[coroutine] || {
yield 1;
if b {
return;
}
#[allow(unused)]
let x = never();
#[allow(unreachable_code)]
yield 2;
drop(x);
});
finish(3, false, #[coroutine] || {
yield 1;
#[allow(unreachable_code)]
let _x: (String, !) = (String::new(), {
finish(
1,
false,
#[coroutine]
|| {
yield 1;
if b {
return;
}
#[allow(unused)]
let x = never();
#[allow(unreachable_code)]
yield 2;
return;
});
});
drop(x);
},
);
finish(
3,
false,
#[coroutine]
|| {
yield 1;
#[allow(unreachable_code)]
let _x: (String, !) = (String::new(), {
yield 2;
return;
});
},
);
}
fn smoke_resume_arg() {
@ -172,7 +222,8 @@ fn smoke_resume_arg() {
}
drain(
&mut #[coroutine] |mut b| {
&mut #[coroutine]
|mut b| {
while b != 0 {
b = yield (b + 1);
}
@ -181,21 +232,35 @@ fn smoke_resume_arg() {
vec![(1, Yielded(2)), (-45, Yielded(-44)), (500, Yielded(501)), (0, Complete(-1))],
);
expect_drops(2, || drain(&mut #[coroutine] |a| yield a, vec![(DropMe, Yielded(DropMe))]));
expect_drops(2, || {
drain(
&mut #[coroutine]
|a| yield a,
vec![(DropMe, Yielded(DropMe))],
)
});
expect_drops(6, || {
drain(
&mut #[coroutine] |a| yield yield a,
&mut #[coroutine]
|a| yield yield a,
vec![(DropMe, Yielded(DropMe)), (DropMe, Yielded(DropMe)), (DropMe, Complete(DropMe))],
)
});
#[allow(unreachable_code)]
expect_drops(2, || drain(&mut #[coroutine] |a| yield return a, vec![(DropMe, Complete(DropMe))]));
expect_drops(2, || {
drain(
&mut #[coroutine]
|a| yield return a,
vec![(DropMe, Complete(DropMe))],
)
});
expect_drops(2, || {
drain(
&mut #[coroutine] |a: DropMe| {
&mut #[coroutine]
|a: DropMe| {
if false { yield () } else { a }
},
vec![(DropMe, Complete(DropMe))],
@ -205,7 +270,8 @@ fn smoke_resume_arg() {
expect_drops(4, || {
drain(
#[allow(unused_assignments, unused_variables)]
&mut #[coroutine] |mut a: DropMe| {
&mut #[coroutine]
|mut a: DropMe| {
a = yield;
a = yield;
a = yield;
@ -228,7 +294,8 @@ fn uninit_fields() {
}
fn run<T>(x: bool, y: bool) {
let mut c = #[coroutine] || {
let mut c = #[coroutine]
|| {
if x {
let _a: T;
if y {

View File

@ -8,7 +8,8 @@ use std::{
};
fn firstn() -> impl Coroutine<Yield = u64, Return = ()> {
#[coroutine] static move || {
#[coroutine]
static move || {
let mut num = 0;
let num = &mut num;