Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9fe1803

Browse files
committed
Auto merge ofrust-lang#124662 - zetanumbers:needs_async_drop, r=oli-obk
Implement `needs_async_drop` in rustc and optimize async drop glueThis PR expands onrust-lang#121801 and implements `Ty::needs_async_drop` which works almost exactly the same as `Ty::needs_drop`, which is needed forrust-lang#123948.Also made compiler's async drop code to look more like compiler's regular drop code, which enabled me to write an optimization where types which do not use `AsyncDrop` can simply forward async drop glue to `drop_in_place`. This made size of the async block from the [async_drop test](https://github.com/zetanumbers/rust/blob/67980dd6fb11917d23d01a19c2cf4cfc3978aac8/tests/ui/async-await/async-drop.rs) to decrease by 12%.
2 parentsba98164 +bb6d4eb commit9fe1803

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎core/src/future/async_drop.rs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ async unsafe fn surface_drop_in_place<T: Drop + ?Sized>(ptr: *mut T) {
161161
/// wrapped future completes by returning `Poll::Ready(())` on poll. This
162162
/// is useful for constructing async destructors to guarantee this
163163
/// "fuse" property
164+
//
165+
// FIXME: Consider optimizing combinators to not have to use fuse in majority
166+
// of cases, perhaps by adding `#[(rustc_)idempotent(_future)]` attribute for
167+
// async functions and blocks with the unit return type. However current layout
168+
// optimizations currently encode `None` case into the async block's discriminant.
164169
structFuse<T>{
165170
inner:Option<T>,
166171
}
@@ -251,6 +256,14 @@ async unsafe fn either<O: IntoFuture<Output = ()>, M: IntoFuture<Output = ()>, T
251256
}
252257
}
253258

259+
#[cfg(not(bootstrap))]
260+
#[lang ="async_drop_deferred_drop_in_place"]
261+
asyncunsafefndeferred_drop_in_place<T>(to_drop:*mutT){
262+
// SAFETY: same safety requirements as with drop_in_place (implied by
263+
// function's name)
264+
unsafe{crate::ptr::drop_in_place(to_drop)}
265+
}
266+
254267
/// Used for noop async destructors. We don't use [`core::future::Ready`]
255268
/// because it panics after its second poll, which could be potentially
256269
/// bad if that would happen during the cleanup.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp