Skip to content

Commit

Permalink
Subpart12 for async drop - tests
Browse files Browse the repository at this point in the history
  • Loading branch information
azhogin committed Aug 30, 2024
1 parent 33841e6 commit a3433a5
Show file tree
Hide file tree
Showing 29 changed files with 1,371 additions and 118 deletions.
108 changes: 64 additions & 44 deletions src/tools/miri/tests/pass/async-drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// WARNING: If you would ever want to modify this test,
// please consider modifying rustc's async drop test at
// `tests/ui/async-await/async-drop.rs`.
// `tests/ui/async-await/async-drop/async-drop-initial.rs`.

#![feature(async_drop, impl_trait_in_assoc_type, noop_waker, async_closure)]
#![allow(incomplete_features, dead_code)]
Expand Down Expand Up @@ -68,7 +68,8 @@ fn main() {
test_async_drop(SyncThenAsync { i: 15, a: AsyncInt(16), b: SyncInt(17), c: AsyncInt(18) })
.await;

let async_drop_fut = pin!(core::future::async_drop(AsyncInt(19)));
let mut ptr19 = mem::MaybeUninit::new(AsyncInt(19));
let async_drop_fut = pin!(unsafe { async_drop_in_place(ptr19.as_mut_ptr()) });
test_idempotency(async_drop_fut).await;

let foo = AsyncInt(20);
Expand All @@ -89,13 +90,14 @@ fn main() {

struct AsyncInt(i32);

impl Drop for AsyncInt {
fn drop(&mut self) {
println!("AsyncInt::drop: {}", self.0);
}
}
impl AsyncDrop for AsyncInt {
type Dropper<'a> = impl Future<Output = ()>;

fn async_drop(self: Pin<&mut Self>) -> Self::Dropper<'_> {
async move {
println!("AsyncInt::Dropper::poll: {}", self.0);
}
async fn drop(self: Pin<&mut Self>) {
println!("AsyncInt::async_drop: {}", self.0);
}
}

Expand Down Expand Up @@ -124,13 +126,14 @@ struct AsyncReference<'a> {
foo: &'a AsyncInt,
}

impl Drop for AsyncReference<'_> {
fn drop(&mut self) {
println!("AsyncReference::drop: {}", self.foo.0);
}
}
impl AsyncDrop for AsyncReference<'_> {
type Dropper<'a> = impl Future<Output = ()> where Self: 'a;

fn async_drop(self: Pin<&mut Self>) -> Self::Dropper<'_> {
async move {
println!("AsyncReference::Dropper::poll: {}", self.foo.0);
}
async fn drop(self: Pin<&mut Self>) {
println!("AsyncReference::async_drop: {}", self.foo.0);
}
}

Expand All @@ -142,13 +145,14 @@ struct AsyncStruct {
b: AsyncInt,
}

impl Drop for AsyncStruct {
fn drop(&mut self) {
println!("AsyncStruct::drop: {}", self.i);
}
}
impl AsyncDrop for AsyncStruct {
type Dropper<'a> = impl Future<Output = ()>;

fn async_drop(self: Pin<&mut Self>) -> Self::Dropper<'_> {
async move {
println!("AsyncStruct::Dropper::poll: {}", self.i);
}
async fn drop(self: Pin<&mut Self>) {
println!("AsyncStruct::async_drop: {}", self.i);
}
}

Expand All @@ -157,23 +161,34 @@ enum AsyncEnum {
B(SyncInt),
}

impl Drop for AsyncEnum {
fn drop(&mut self) {
let new_self = match self {
AsyncEnum::A(foo) => {
println!("AsyncEnum(A)::drop: {}", foo.0);
AsyncEnum::B(SyncInt(foo.0))
}
AsyncEnum::B(foo) => {
println!("AsyncEnum(B)::drop: {}", foo.0);
AsyncEnum::A(AsyncInt(foo.0))
}
};
mem::forget(mem::replace(&mut *self, new_self));
}
}
impl AsyncDrop for AsyncEnum {
type Dropper<'a> = impl Future<Output = ()>;

fn async_drop(mut self: Pin<&mut Self>) -> Self::Dropper<'_> {
async move {
let new_self = match &*self {
AsyncEnum::A(foo) => {
println!("AsyncEnum(A)::Dropper::poll: {}", foo.0);
AsyncEnum::B(SyncInt(foo.0))
}
AsyncEnum::B(foo) => {
println!("AsyncEnum(B)::Dropper::poll: {}", foo.0);
AsyncEnum::A(AsyncInt(foo.0))
}
};
mem::forget(mem::replace(&mut *self, new_self));
}
async fn drop(mut self: Pin<&mut Self>) {
let new_self = match &*self {
AsyncEnum::A(foo) => {
println!("AsyncEnum(A)::async_drop: {}", foo.0);
AsyncEnum::B(SyncInt(foo.0))
}
AsyncEnum::B(foo) => {
println!("AsyncEnum(B)::async_drop: {}", foo.0);
AsyncEnum::A(AsyncInt(foo.0))
}
};
mem::forget(mem::replace(&mut *self, new_self));
}
}

Expand All @@ -183,14 +198,19 @@ union AsyncUnion {
unsigned: u32,
}

impl Drop for AsyncUnion {
fn drop(&mut self) {
println!(
"AsyncUnion::drop: {}, {}",
unsafe { self.signed },
unsafe { self.unsigned },
);
}
}
impl AsyncDrop for AsyncUnion {
type Dropper<'a> = impl Future<Output = ()>;

fn async_drop(self: Pin<&mut Self>) -> Self::Dropper<'_> {
async move {
println!("AsyncUnion::Dropper::poll: {}, {}", unsafe { self.signed }, unsafe {
self.unsigned
});
}
async fn drop(self: Pin<&mut Self>) {
println!("AsyncUnion::async_drop: {}, {}", unsafe { self.signed }, unsafe {
self.unsigned
});
}
}
37 changes: 19 additions & 18 deletions src/tools/miri/tests/pass/async-drop.stack.stdout
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
AsyncInt::Dropper::poll: 0
AsyncInt::Dropper::poll: 1
AsyncInt::Dropper::poll: 2
AsyncInt::Dropper::poll: 3
AsyncInt::Dropper::poll: 4
AsyncStruct::Dropper::poll: 6
AsyncInt::Dropper::poll: 7
AsyncInt::Dropper::poll: 8
AsyncReference::Dropper::poll: 10
AsyncInt::Dropper::poll: 11
AsyncEnum(A)::Dropper::poll: 12
AsyncInt::async_drop: 0
AsyncInt::async_drop: 1
AsyncInt::async_drop: 2
AsyncInt::async_drop: 3
AsyncInt::async_drop: 4
AsyncStruct::async_drop: 6
AsyncInt::async_drop: 7
AsyncInt::async_drop: 8
AsyncReference::async_drop: 10
AsyncInt::async_drop: 11
AsyncEnum(A)::async_drop: 12
SyncInt::drop: 12
AsyncEnum(B)::Dropper::poll: 13
AsyncInt::Dropper::poll: 13
AsyncEnum(B)::async_drop: 13
AsyncInt::async_drop: 13
SyncInt::drop: 14
SyncThenAsync::drop: 15
AsyncInt::Dropper::poll: 16
AsyncInt::async_drop: 16
SyncInt::drop: 17
AsyncInt::Dropper::poll: 18
AsyncInt::Dropper::poll: 19
AsyncInt::Dropper::poll: 20
AsyncUnion::Dropper::poll: 21, 21
AsyncInt::async_drop: 18
AsyncInt::async_drop: 19
AsyncInt::async_drop: 20
AsyncUnion::async_drop: 21, 21
AsyncInt::async_drop: 10
37 changes: 19 additions & 18 deletions src/tools/miri/tests/pass/async-drop.tree.stdout
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
AsyncInt::Dropper::poll: 0
AsyncInt::Dropper::poll: 1
AsyncInt::Dropper::poll: 2
AsyncInt::Dropper::poll: 3
AsyncInt::Dropper::poll: 4
AsyncStruct::Dropper::poll: 6
AsyncInt::Dropper::poll: 7
AsyncInt::Dropper::poll: 8
AsyncReference::Dropper::poll: 10
AsyncInt::Dropper::poll: 11
AsyncEnum(A)::Dropper::poll: 12
AsyncInt::async_drop: 0
AsyncInt::async_drop: 1
AsyncInt::async_drop: 2
AsyncInt::async_drop: 3
AsyncInt::async_drop: 4
AsyncStruct::async_drop: 6
AsyncInt::async_drop: 7
AsyncInt::async_drop: 8
AsyncReference::async_drop: 10
AsyncInt::async_drop: 11
AsyncEnum(A)::async_drop: 12
SyncInt::drop: 12
AsyncEnum(B)::Dropper::poll: 13
AsyncInt::Dropper::poll: 13
AsyncEnum(B)::async_drop: 13
AsyncInt::async_drop: 13
SyncInt::drop: 14
SyncThenAsync::drop: 15
AsyncInt::Dropper::poll: 16
AsyncInt::async_drop: 16
SyncInt::drop: 17
AsyncInt::Dropper::poll: 18
AsyncInt::Dropper::poll: 19
AsyncInt::Dropper::poll: 20
AsyncUnion::Dropper::poll: 21, 21
AsyncInt::async_drop: 18
AsyncInt::async_drop: 19
AsyncInt::async_drop: 20
AsyncUnion::async_drop: 21, 21
AsyncInt::async_drop: 10
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ yields ()
StorageDead(_5);
StorageDead(_4);
StorageDead(_3);
drop(_1) -> [return: bb1, unwind: bb2];
drop(_1) -> [return: bb1, unwind: bb3, drop: bb2];
}

bb1: {
return;
}

bb2 (cleanup): {
bb2: {
coroutine_drop;
}

bb3 (cleanup): {
resume;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ yields ()
StorageDead(_5);
StorageDead(_4);
StorageDead(_3);
drop(_1) -> [return: bb1, unwind: bb2];
drop(_1) -> [return: bb1, unwind: bb3, drop: bb2];
}

bb1: {
return;
}

bb2 (cleanup): {
bb2: {
coroutine_drop;
}

bb3 (cleanup): {
resume;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ yields ()
StorageDead(_5);
StorageDead(_4);
StorageDead(_3);
drop(_1) -> [return: bb1, unwind: bb2];
drop(_1) -> [return: bb1, unwind: bb3, drop: bb2];
}

bb1: {
return;
}

bb2 (cleanup): {
bb2: {
coroutine_drop;
}

bb3 (cleanup): {
resume;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ yields ()
StorageDead(_5);
StorageDead(_4);
StorageDead(_3);
drop(_1) -> [return: bb1, unwind: bb2];
drop(_1) -> [return: bb1, unwind: bb3, drop: bb2];
}

bb1: {
return;
}

bb2 (cleanup): {
bb2: {
coroutine_drop;
}

bb3 (cleanup): {
resume;
}
}
27 changes: 6 additions & 21 deletions tests/mir-opt/inline/issue_78442.bar.RevealAll.panic-abort.diff
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,39 @@
debug _baz => _1;
let mut _0: ();
let _2: ();
- let mut _3: &impl Fn();
- let _4: impl Fn();
+ let mut _3: &fn() {foo};
+ let _4: fn() {foo};
let mut _3: &fn() {foo};
let _4: fn() {foo};
let mut _5: ();

bb0: {
StorageLive(_2);
StorageLive(_3);
StorageLive(_4);
_4 = hide_foo() -> [return: bb1, unwind: bb6];
_4 = hide_foo() -> [return: bb1, unwind unreachable];
}

bb1: {
_3 = &_4;
StorageLive(_5);
_5 = ();
- _2 = <impl Fn() as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb5];
+ _2 = <fn() {foo} as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb5];
_2 = <fn() {foo} as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind unreachable];
}

bb2: {
StorageDead(_5);
StorageDead(_3);
drop(_4) -> [return: bb3, unwind: bb6];
goto -> bb3;
}

bb3: {
StorageDead(_4);
StorageDead(_2);
_0 = const ();
drop(_1) -> [return: bb4, unwind: bb7];
drop(_1) -> [return: bb4, unwind unreachable];
}

bb4: {
return;
}

bb5 (cleanup): {
drop(_4) -> [return: bb6, unwind terminate(cleanup)];
}

bb6 (cleanup): {
drop(_1) -> [return: bb7, unwind terminate(cleanup)];
}

bb7 (cleanup): {
resume;
}
}

Loading

0 comments on commit a3433a5

Please sign in to comment.