Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async drop codegen #123948

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Prereq3 for async drop - LangItem registration for async_drop_in_plac…
…e<T>::{closure}
  • Loading branch information
azhogin committed Sep 8, 2024
commit 50aea7e98fa36beaeddd0e73a03b83890c6cad48
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ language_item_table! {
AsyncDrop, sym::async_drop, async_drop_trait, Target::Trait, GenericRequirement::Exact(0);
AsyncDestruct, sym::async_destruct, async_destruct_trait, Target::Trait, GenericRequirement::Exact(0);
AsyncDropInPlace, sym::async_drop_in_place, async_drop_in_place_fn, Target::Fn, GenericRequirement::Exact(1);
AsyncDropInPlacePoll, sym::async_drop_in_place_poll, async_drop_in_place_poll_fn, Target::Closure, GenericRequirement::Exact(1);
SurfaceAsyncDropInPlace, sym::surface_async_drop_in_place, surface_async_drop_in_place_fn, Target::Fn, GenericRequirement::Exact(1);
AsyncDropSurfaceDropInPlace, sym::async_drop_surface_drop_in_place, async_drop_surface_drop_in_place_fn, Target::Fn, GenericRequirement::Exact(1);
AsyncDropSlice, sym::async_drop_slice, async_drop_slice_fn, Target::Fn, GenericRequirement::Exact(1);
Expand Down
23 changes: 23 additions & 0 deletions compiler/rustc_passes/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> {
&mut self,
actual_target: Target,
def_id: LocalDefId,
cor_def_id: Option<LocalDefId>,
attrs: &'ast [ast::Attribute],
item_span: Span,
generics: Option<&'ast ast::Generics>,
Expand All @@ -74,6 +75,18 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> {
generics,
actual_target,
);
// We need to register LangItem::AsyncDropInPlacePoll
// for async_drop_in_place<T>::{closure}
if cor_def_id.is_some() && lang_item == LangItem::AsyncDropInPlace {
self.collect_item_extended(
LangItem::AsyncDropInPlacePoll,
cor_def_id.unwrap(),
item_span,
attr_span,
generics,
actual_target,
);
}
}
// Known lang item with attribute on incorrect target.
Some(lang_item) => {
Expand Down Expand Up @@ -289,10 +302,18 @@ impl<'ast, 'tcx> visit::Visitor<'ast> for LanguageItemCollector<'ast, 'tcx> {
unreachable!("macros should have been expanded")
}
};
let cor_def_id = if let ast::ItemKind::Fn(box ast::Fn { sig, .. }) = &i.kind
&& let Some(kind) = sig.header.coroutine_kind
{
self.resolver.node_id_to_def_id.get(&kind.closure_id()).copied()
} else {
None
};

self.check_for_lang(
target,
self.resolver.node_id_to_def_id[&i.id],
cor_def_id,
&i.attrs,
i.span,
i.opt_generics(),
Expand All @@ -308,6 +329,7 @@ impl<'ast, 'tcx> visit::Visitor<'ast> for LanguageItemCollector<'ast, 'tcx> {
self.check_for_lang(
Target::Variant,
self.resolver.node_id_to_def_id[&variant.id],
None,
&variant.attrs,
variant.span,
None,
Expand Down Expand Up @@ -350,6 +372,7 @@ impl<'ast, 'tcx> visit::Visitor<'ast> for LanguageItemCollector<'ast, 'tcx> {
self.check_for_lang(
target,
self.resolver.node_id_to_def_id[&i.id],
None,
&i.attrs,
i.span,
generics,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_passes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#![allow(internal_features)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
#![feature(box_patterns)]
#![feature(let_chains)]
#![feature(map_try_insert)]
#![feature(rustdoc_internals)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ symbols! {
async_drop_either,
async_drop_fuse,
async_drop_in_place,
async_drop_in_place_poll,
async_drop_noop,
async_drop_slice,
async_drop_surface_drop_in_place,
Expand Down
Loading