1
Fork 0
rust/compiler/rustc_mir_transform/src
bors aca749eefc Auto merge of #121801 - zetanumbers:async_drop_glue, r=oli-obk
Add simple async drop glue generation

This is a prototype of the async drop glue generation for some simple types. Async drop glue is intended to behave very similar to the regular drop glue except for being asynchronous. Currently it does not execute synchronous drops but only calls user implementations of `AsyncDrop::async_drop` associative function and awaits the returned future. It is not complete as it only recurses into arrays, slices, tuples, and structs and does not have same sensible restrictions as the old `Drop` trait implementation like having the same bounds as the type definition, while code assumes their existence (requires a future work).

This current design uses a workaround as it does not create any custom async destructor state machine types for ADTs, but instead uses types defined in the std library called future combinators (deferred_async_drop, chain, ready_unit).

Also I recommend reading my [explainer](https://zetanumbers.github.io/book/async-drop-design.html).

This is a part of the [MCP: Low level components for async drop](https://github.com/rust-lang/compiler-team/issues/727) work.

Feature completeness:

 - [x] `AsyncDrop` trait
 - [ ] `async_drop_in_place_raw`/async drop glue generation support for
   - [x] Trivially destructible types (integers, bools, floats, string slices, pointers, references, etc.)
   - [x] Arrays and slices (array pointer is unsized into slice pointer)
   - [x] ADTs (enums, structs, unions)
   - [x] tuple-like types (tuples, closures)
   - [ ] Dynamic types (`dyn Trait`, see explainer's [proposed design](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#async-drop-glue-for-dyn-trait))
   - [ ] coroutines (https://github.com/rust-lang/rust/pull/123948)
 - [x] Async drop glue includes sync drop glue code
 - [x] Cleanup branch generation for `async_drop_in_place_raw`
 - [ ] Union rejects non-trivially async destructible fields
 - [ ] `AsyncDrop` implementation requires same bounds as type definition
 - [ ] Skip trivially destructible fields (optimization)
 - [ ] New [`TyKind::AdtAsyncDestructor`](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#adt-async-destructor-types) and get rid of combinators
 - [ ] [Synchronously undroppable types](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#exclusively-async-drop)
 - [ ] Automatic async drop at the end of the scope in async context
2024-04-23 02:10:23 +00:00
..
coroutine Use a helper to zip together parent and child captures for coroutine-closures 2024-04-10 13:39:52 -04:00
coverage coverage: Separate branch pairs from other mapping kinds 2024-04-22 21:55:34 +10:00
inline Add simple async drop glue generation 2024-04-16 20:45:07 +03:00
shim Fix disabling the export of noop async_drop_in_place_raw 2024-04-18 15:19:05 +03:00
abort_unwinding_calls.rs Fix mir pass ICE in the presence of other errors 2024-02-08 14:49:27 +00:00
add_call_guards.rs remove redundant imports 2023-12-10 10:56:22 +08:00
add_moves_for_packed_drops.rs remove redundant imports 2023-12-10 10:56:22 +08:00
add_retag.rs add_retag: ensure box-to-raw-ptr casts are preserved for Miri 2024-03-18 10:32:25 +01:00
add_subtyping_projections.rs remove redundant imports 2023-12-10 10:56:22 +08:00
check_alignment.rs Put checks that detect UB under their own flag below debug_assertions 2024-04-06 11:21:47 -04:00
check_const_item_mutation.rs Rename TyCtxt::emit_spanned_lint as TyCtxt::emit_node_span_lint. 2024-01-23 08:09:05 +11:00
check_packed_ref.rs Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
cleanup_post_borrowck.rs Unbox and unwrap the contents of StatementKind::Coverage 2024-03-23 22:05:11 +11:00
const_debuginfo.rs
copy_prop.rs remove redundant imports 2023-12-10 10:56:22 +08:00
coroutine.rs rustc_index: Add a ZERO constant to index types 2024-04-03 19:06:22 +03:00
cost_checker.rs Make is_intrinsic query return the intrinsic name 2024-02-12 09:33:52 +00:00
cross_crate_inline.rs Remove all checks of IntrinsicDef::must_be_overridden except for the actual overrides in codegen 2024-03-19 09:19:58 +00:00
ctfe_limit.rs
dataflow_const_prop.rs Actually create ranged int types in the type system. 2024-04-08 12:02:19 +00:00
dead_store_elimination.rs Auto merge of #116520 - Enselic:large-copy-into-fn, r=oli-obk 2024-01-16 19:33:14 +00:00
deduce_param_attrs.rs Dejargnonize subst 2024-02-12 15:46:35 +09:00
deduplicate_blocks.rs Merge dead bb pruning and unreachable bb deduplication. 2024-01-07 15:12:10 +00:00
deref_separator.rs remove redundant imports 2023-12-10 10:56:22 +08:00
dest_prop.rs Implement asm goto in MIR and MIR lowering 2024-02-24 18:50:09 +00:00
dump_mir.rs
early_otherwise_branch.rs Don't change the otherwise of the switch 2024-04-08 19:20:07 +08:00
elaborate_box_derefs.rs rustc_index: Add a ZERO constant to index types 2024-04-03 19:06:22 +03:00
elaborate_drops.rs Convert delayed_bugs to bugs. 2024-02-21 10:20:05 +11:00
errors.rs Remove MIR unsafe check 2024-04-03 08:50:12 +00:00
ffi_unwind_calls.rs Rename mir_const query to mir_built 2024-03-20 09:05:22 +00:00
function_item_references.rs Make RawPtr take Ty and Mutbl separately 2024-03-22 11:13:29 -04:00
gvn.rs Add AggregateKind::RawPtr and enough support to compile 2024-04-21 11:08:37 -07:00
inline.rs Auto merge of #121801 - zetanumbers:async_drop_glue, r=oli-obk 2024-04-23 02:10:23 +00:00
instsimplify.rs Address more PR feedback 2024-04-21 11:08:38 -07:00
jump_threading.rs Rollup merge of #122784 - jswrenn:tag_for_variant, r=compiler-errors 2024-03-22 20:31:29 +01:00
known_panics_lint.rs Add AggregateKind::RawPtr and enough support to compile 2024-04-21 11:08:37 -07:00
large_enums.rs Fix some comments 2023-12-28 12:23:14 +08:00
lib.rs Remove MIR unsafe check 2024-04-03 08:50:12 +00:00
lint.rs compiler: Lower fn call arg spans down to MIR 2024-01-15 19:07:11 +01:00
lower_intrinsics.rs Add an intrinsic that lowers to AggregateKind::RawPtr 2024-04-21 11:08:37 -07:00
lower_slice_len.rs compiler: Lower fn call arg spans down to MIR 2024-01-15 19:07:11 +01:00
match_branches.rs Auto merge of #124156 - DianQK:disable-match_branches, r=RalfJung 2024-04-20 08:47:07 +00:00
mentioned_items.rs mentioned_items: avoid adding str/slice unsizing casts 2024-03-20 11:16:11 +01:00
multiple_return_terminators.rs remove redundant imports 2023-12-10 10:56:22 +08:00
normalize_array_len.rs remove redundant imports 2023-12-10 10:56:22 +08:00
nrvo.rs and more 2024-03-28 17:19:15 +03:00
pass_manager.rs Only split by-ref/by-move futures for async closures 2024-03-19 16:59:23 -04:00
prettify.rs remove redundant imports 2023-12-10 10:56:22 +08:00
promote_consts.rs ScalarInt: add methods to assert being a (u)int of given size 2024-04-19 13:51:52 +02:00
ref_prop.rs Dejargnonize subst 2024-02-12 15:46:35 +09:00
remove_noop_landing_pads.rs Avoid debug logging entire MIR body 2024-02-15 15:54:28 +01:00
remove_place_mention.rs remove redundant imports 2023-12-10 10:56:22 +08:00
remove_storage_markers.rs Move condition enabling the pass to is_enabled 2024-01-23 20:58:44 +01:00
remove_uninit_drops.rs remove redundant imports 2023-12-10 10:56:22 +08:00
remove_unneeded_drops.rs Merge dead bb pruning and unreachable bb deduplication. 2024-01-07 15:12:10 +00:00
remove_zsts.rs Add CoroutineClosure to TyKind, AggregateKind, UpvarArgs 2024-02-06 02:22:58 +00:00
required_consts.rs
reveal_all.rs remove redundant imports 2023-12-10 10:56:22 +08:00
shim.rs Add simple async drop glue generation 2024-04-16 20:45:07 +03:00
simplify.rs rustc_index: Add a ZERO constant to index types 2024-04-03 19:06:22 +03:00
simplify_branches.rs simplify_branches: add comment 2024-03-24 12:53:03 +01:00
simplify_comparison_integral.rs
sroa.rs remove redundant imports 2023-12-10 10:56:22 +08:00
ssa.rs Remove unused fields in some structures 2024-03-12 10:59:40 +01:00
unreachable_enum_branching.rs Remove restrictions on small enum statements such as Order, Option or Result 2024-03-13 22:35:11 +08:00
unreachable_prop.rs coverage: Re-enable UnreachablePropagation for coverage builds 2024-03-26 11:46:04 +11:00