Skip to content

Commit

Permalink
Optimize async drop glue for some old types
Browse files Browse the repository at this point in the history
  • Loading branch information
zetanumbers committed May 29, 2024
1 parent 1aaf0a9 commit c8b699c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/src/future/async_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ async unsafe fn surface_drop_in_place<T: Drop + ?Sized>(ptr: *mut T) {
/// wrapped future completes by returning `Poll::Ready(())` on poll. This
/// is useful for constructing async destructors to guarantee this
/// "fuse" property
//
// FIXME: Consider optimizing combinators to not have to use fuse in majority
// of cases, perhaps by adding `#[(rustc_)idempotent(_future)]` attribute for
// async functions and blocks with the unit return type. However current layout
// optimizations currently encode `None` case into the async block's discriminant.
struct Fuse<T> {
inner: Option<T>,
}
Expand Down Expand Up @@ -251,6 +256,12 @@ async unsafe fn either<O: IntoFuture<Output = ()>, M: IntoFuture<Output = ()>, T
}
}

#[cfg(not(bootstrap))]
#[lang = "async_drop_deferred_drop_in_place"]
async unsafe fn deferred_drop_in_place<T>(to_drop: *mut T) {
unsafe { crate::ptr::drop_in_place(to_drop) }
}

/// Used for noop async destructors. We don't use [`core::future::Ready`]
/// because it panics after its second poll, which could be potentially
/// bad if that would happen during the cleanup.
Expand Down

0 comments on commit c8b699c

Please sign in to comment.