Skip to content

Add simple async drop glue generation#121801

Merged
bors merged 6 commits intorust-lang:masterfrom
zetanumbers:async_drop_glue
Apr 23, 2024
Merged

Add simple async drop glue generation#121801
bors merged 6 commits intorust-lang:masterfrom
zetanumbers:async_drop_glue

Conversation

@zetanumbers
Copy link
Copy Markdown
Contributor

@zetanumbers zetanumbers commented Feb 29, 2024

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.

This is a part of the MCP: Low level components for async drop work.

Feature completeness:

  • AsyncDrop trait
  • async_drop_in_place_raw/async drop glue generation support for
    • Trivially destructible types (integers, bools, floats, string slices, pointers, references, etc.)
    • Arrays and slices (array pointer is unsized into slice pointer)
    • ADTs (enums, structs, unions)
    • tuple-like types (tuples, closures)
    • Dynamic types (dyn Trait, see explainer's proposed design)
    • coroutines (Async drop codegen #123948)
  • Async drop glue includes sync drop glue code
  • 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 and get rid of combinators
  • Synchronously undroppable types
  • Automatic async drop at the end of the scope in async context

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-async-await Area: Async & Await AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. F-async_drop `#![feature(async_drop)]` merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-async Working group: Async & await WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.