rust/library/core/src
bors 7d65abfe80 Auto merge of #123948 - azhogin:azhogin/async-drop, r=oli-obk
Async drop codegen

Async drop implementation using templated coroutine for async drop glue generation.

Scopes changes to generate `async_drop_in_place()` awaits, when async droppable objects are out-of-scope in async context.

Implementation details:
https://github.com/azhogin/posts/blob/main/async-drop-impl.md

New fields in Drop terminator (drop & async_fut). Processing in codegen/miri must validate that those fields are empty (in full version async Drop terminator will be expanded at StateTransform pass or reverted to sync version). Changes in terminator visiting to consider possible new successor (drop field).

ResumedAfterDrop messages for panic when coroutine is resumed after it is started to be async drop'ed.

Lang item for generated coroutine for async function async_drop_in_place. `async fn async_drop_in_place<T>()::{{closure0}}`.

Scopes processing for generate async drop preparations. Async drop is a hidden Yield, so potentially async drops require the same dropline preparation as for Yield terminators.

Processing in StateTransform: async drops are expanded into yield-point. Generation of async drop of coroutine itself added.

Shims for AsyncDropGlueCtorShim, AsyncDropGlue and FutureDropPoll.

```rust
#[lang = "async_drop"]
pub trait AsyncDrop {
    #[allow(async_fn_in_trait)]
    async fn drop(self: Pin<&mut Self>);
}

impl Drop for Foo {
    fn drop(&mut self) {
        println!("Foo::drop({})", self.my_resource_handle);
    }
}

impl AsyncDrop for Foo {
    async fn drop(self: Pin<&mut Self>) {
        println!("Foo::async drop({})", self.my_resource_handle);
    }
}
```

First async drop glue implementation re-worked to use the same drop elaboration code as for sync drop.
`async_drop_in_place` changed to be `async fn`. So both `async_drop_in_place` ctor and produced coroutine have their lang items (`AsyncDropInPlace`/`AsyncDropInPlacePoll`) and shim instances (`AsyncDropGlueCtorShim`/`AsyncDropGlue`).
```
pub async unsafe fn async_drop_in_place<T: ?Sized>(_to_drop: *mut T) {
}
```
AsyncDropGlue shim generation uses `elaborate_drops::elaborate_drop` to produce drop ladder (in the similar way as for sync drop glue) and then `coroutine::StateTransform` to convert function into coroutine poll.

AsyncDropGlue coroutine's layout can't be calculated for generic T, it requires known final dropee type to be generated (in StateTransform). So, `templated coroutine` was introduced here (`templated_coroutine_layout(...)` etc).

Such approach overrides the first implementation using mixing language-level futures in https://github.com/rust-lang/rust/pull/121801.
2025-04-28 14:14:26 +00:00
..
alloc Pass Alignment for RawVecInner::new_in 2025-03-26 21:41:11 +00:00
array Auto merge of #139430 - scottmcm:polymorphic-array-into-iter, r=cuviper 2025-04-11 23:21:31 +00:00
ascii Add more precondition check tests 2024-10-09 19:34:27 -04:00
async_iter Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
bstr Replace colon with parentheses, add missing period 2025-04-21 10:48:46 -04:00
cell OnceCell & OnceLock docs: Using (un)initialized consistently 2025-02-03 17:48:39 +05:30
char Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc 2025-04-24 13:14:36 +07:00
clone CloneToUninit: use a private specialization trait 2024-07-29 20:44:43 +03:00
cmp Use generic NonZero everywhere in core. 2024-02-22 15:17:33 +01:00
convert Auto merge of #138363 - beetrees:f16-f128-integer-convert, r=Amanieu 2025-03-17 00:33:36 +00:00
ffi Rollup merge of #140297 - shepmaster:cstr-lossy, r=joboet 2025-04-27 11:54:58 +02:00
fmt Add comment 2025-04-15 07:25:42 +00:00
future AsyncDrop implementation using shim codegen of async_drop_in_place::{closure}, scoped async drop added. 2025-04-28 16:23:13 +07:00
hash library: Use size_of from the prelude instead of imported 2025-03-06 20:20:38 -08:00
intrinsics Rollup merge of #140172 - bjoernager:const-float-algebraic, r=RalfJung 2025-04-24 17:19:46 +02:00
io Add inherent versions of MaybeUninit methods for slices 2025-01-11 23:57:00 -05:00
iter Rollup merge of #139090 - yotamofek:pr/peekable-next-if-docs, r=tgross35 2025-04-27 11:54:58 +02:00
macros Deprecate the unstable concat_idents! 2025-04-24 22:14:23 +00:00
marker Make phantom variance markers transparent 2025-02-15 00:47:49 +00:00
mem Rollup merge of #135394 - clarfonthey:uninit-slices-part-2, r=tgross35 2025-03-19 16:52:52 +01:00
net replace version placeholder 2025-04-09 12:29:59 +01:00
num Rollup merge of #140172 - bjoernager:const-float-algebraic, r=RalfJung 2025-04-24 17:19:46 +02:00
ops Auto merge of #123948 - azhogin:azhogin/async-drop, r=oli-obk 2025-04-28 14:14:26 +00:00
panic Remove #[cfg(not(test))] gates in core 2025-03-06 13:21:59 -08:00
pin Initial UnsafePinned/UnsafeUnpin impl [Part 1: Libs] 2025-04-13 01:11:04 -04:00
prelude Deprecate the unstable concat_idents! 2025-04-24 22:14:23 +00:00
ptr Rollup merge of #139535 - ChrisDenton:default-ptr, r=tgross35 2025-04-19 14:01:37 +00:00
range Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
slice Auto merge of #123239 - Urgau:dangerous_implicit_autorefs, r=jdonszelmann,traviscross 2025-04-28 08:25:23 +00:00
str Auto merge of #123239 - Urgau:dangerous_implicit_autorefs, r=jdonszelmann,traviscross 2025-04-28 08:25:23 +00:00
sync Remove #[doc(hidden)] from AtomicPrimitive::AtomicInner 2025-04-27 02:18:08 +03:00
task Remove #[cfg(not(test))] gates in core 2025-03-06 13:21:59 -08:00
unicode Remove unneeded parentheses. 2025-03-08 12:56:00 +01:00
any.rs fix missing word in comment 2025-04-16 18:53:40 -07:00
arch.rs stabilize naked_functions 2025-04-20 11:18:38 +02:00
ascii.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
asserting.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
bool.rs Move select_unpredictable to the hint module 2025-04-13 01:34:25 +01:00
borrow.rs Suggest borrowing on fn argument that is impl AsRef 2024-05-09 23:25:31 +00:00
cell.rs Rollup merge of #134446 - tgross35:stabilize-cell_update, r=jhpratt 2025-04-24 08:12:56 +02:00
clone.rs Auto merge of #139279 - BoxyUwU:bump-boostrap, r=jieyouxu 2025-04-10 00:43:25 +00:00
cmp.rs Extend the chaining logic to slices too 2025-04-12 22:10:17 -07:00
contracts.rs Apply suggestions from code review 2025-04-10 16:32:56 -07:00
default.rs Remove #[cfg(not(test))] gates in core 2025-03-06 13:21:59 -08:00
error.md Mention core's PanicInfo in error.md. 2024-06-11 15:47:00 +02:00
error.rs Remove #[cfg(not(test))] gates in core 2025-03-06 13:21:59 -08:00
escape.rs core: add #![warn(unreachable_pub)] 2025-01-20 18:35:32 +01:00
hint.rs Fix drop handling in hint::select_unpredictable 2025-04-17 17:30:53 +02:00
internal_macros.rs Use cfg_match in core 2025-03-26 14:32:35 -04:00
lib.miri.rs add 'x.py miri', and make it work for 'library/{core,alloc,std}' 2024-04-03 20:27:20 +02:00
lib.rs Auto merge of #139632 - Darksonn:cfi-fmt, r=m-ou-se 2025-04-15 11:11:31 +00:00
marker.rs Initial UnsafePinned/UnsafeUnpin impl [Part 1: Libs] 2025-04-13 01:11:04 -04:00
option.rs add examples using .as_ref() for is_some_and and is_none_or 2025-04-24 10:22:49 +08:00
panic.rs update cfgs 2024-11-27 15:14:54 +00:00
panicking.rs AsyncDrop implementation using shim codegen of async_drop_in_place::{closure}, scoped async drop added. 2025-04-28 16:23:13 +07:00
pat.rs update cfgs 2025-04-09 12:29:59 +01:00
pin.rs Auto merge of #123239 - Urgau:dangerous_implicit_autorefs, r=jdonszelmann,traviscross 2025-04-28 08:25:23 +00:00
primitive.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
primitive_docs.rs Rollup merge of #138870 - beetrees:tier-2-nans, r=RalfJung 2025-04-20 14:05:33 +00:00
random.rs random: add tracking issue, address other comments 2024-09-23 10:36:16 +02:00
range.rs update cfg(bootstrap) 2025-02-18 09:32:44 -08:00
result.rs Solved suggestions 2025-04-25 11:06:53 +08:00
time.rs Rollup merge of #138082 - thaliaarchi:slice-cfg-not-test, r=thomcc 2025-03-16 09:40:05 +08:00
tuple.rs Extend the chaining logic to slices too 2025-04-12 22:10:17 -07:00
ub_checks.rs Make ub_check message clear that it's not an assert 2025-02-16 00:56:09 +00:00
unit.rs core: Make Debug impl of raw pointers print metadata if present 2025-02-15 17:27:55 +01:00
unsafe_binder.rs Add unwrap_unsafe_binder and wrap_unsafe_binder macro operators 2024-12-12 16:29:40 +00:00