-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add simple async drop glue generation #121801
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
Changes from 1 commit
24a24ec
80c0b7e
e239e73
0881e3e
a9c7465
67980dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1306,8 +1306,7 @@ impl<'tcx> Ty<'tcx> { | |
/// Checks whether values of this type `T` implements the `AsyncDrop` | ||
/// trait. | ||
pub fn has_surface_async_drop(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool { | ||
self.trivially_has_surface_async_drop() | ||
&& tcx.has_surface_async_drop_raw(param_env.and(self)) | ||
self.could_have_surface_async_drop() && tcx.has_surface_async_drop_raw(param_env.and(self)) | ||
} | ||
|
||
/// Fast path helper for testing if a type has `AsyncDrop` | ||
|
@@ -1316,52 +1315,68 @@ impl<'tcx> Ty<'tcx> { | |
/// Returning `false` means the type is known to not have `AsyncDrop` | ||
/// implementation. Returning `true` means nothing -- could be | ||
/// `AsyncDrop`, might not be. | ||
fn trivially_has_surface_async_drop(self) -> bool { | ||
match self.kind() { | ||
ty::Int(_) | ||
| ty::Uint(_) | ||
| ty::Float(_) | ||
| ty::Bool | ||
| ty::Char | ||
| ty::Str | ||
| ty::Never | ||
| ty::Ref(..) | ||
| ty::RawPtr(_, _) | ||
| ty::FnDef(..) | ||
| ty::FnPtr(_) | ||
| ty::Error(_) | ||
| ty::Tuple(_) | ||
| ty::Slice(_) | ||
| ty::Array(_, _) | ||
| ty::Closure(..) | ||
| ty::CoroutineClosure(..) | ||
| ty::Coroutine(..) | ||
| ty::CoroutineWitness(..) | ||
| ty::Pat(..) => false, | ||
ty::Adt(..) | ||
| ty::Bound(..) | ||
| ty::Dynamic(..) | ||
| ty::Foreign(_) | ||
| ty::Infer(_) | ||
| ty::Alias(..) | ||
| ty::Param(_) | ||
| ty::Placeholder(_) => true, | ||
} | ||
fn could_have_surface_async_drop(self) -> bool { | ||
!self.is_async_destructor_trivially_noop() | ||
&& !matches!( | ||
self.kind(), | ||
ty::Tuple(_) | ||
| ty::Slice(_) | ||
| ty::Array(_, _) | ||
| ty::Closure(..) | ||
| ty::CoroutineClosure(..) | ||
| ty::Coroutine(..) | ||
) | ||
} | ||
|
||
/// Checks whether values of this type `T` implements the `AsyncDrop` | ||
zetanumbers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// trait. | ||
pub fn has_surface_drop(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool { | ||
self.trivially_has_surface_drop() && tcx.has_surface_drop_raw(param_env.and(self)) | ||
self.could_have_surface_drop() && tcx.has_surface_drop_raw(param_env.and(self)) | ||
} | ||
|
||
/// Fast path helper for testing if a type has `AsyncDrop` | ||
/// implementation. | ||
/// Fast path helper for testing if a type has `Drop` implementation. | ||
/// | ||
/// Returning `false` means the type is known to not have `AsyncDrop` | ||
/// Returning `false` means the type is known to not have `Drop` | ||
/// implementation. Returning `true` means nothing -- could be | ||
/// `AsyncDrop`, might not be. | ||
fn trivially_has_surface_drop(self) -> bool { | ||
/// `Drop`, might not be. | ||
fn could_have_surface_drop(self) -> bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how does this relate to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, in contrast |
||
self.is_async_destructor_trivially_noop() | ||
&& !matches!( | ||
self.kind(), | ||
ty::Tuple(_) | ||
| ty::Slice(_) | ||
| ty::Array(_, _) | ||
| ty::Closure(..) | ||
| ty::CoroutineClosure(..) | ||
| ty::Coroutine(..) | ||
) | ||
} | ||
|
||
/// Checks whether values of this type `T` implement has noop async destructor. | ||
// | ||
// FIXME: implement optimization to make ADTs, which do not need drop, | ||
// to skip fields or to have noop async destructor. | ||
pub fn is_async_destructor_noop( | ||
self, | ||
tcx: TyCtxt<'tcx>, | ||
param_env: ty::ParamEnv<'tcx>, | ||
) -> bool { | ||
self.is_async_destructor_trivially_noop() | ||
|| if let ty::Adt(adt_def, _) = self.kind() { | ||
(adt_def.is_union() || adt_def.is_payloadfree()) | ||
&& !self.has_surface_async_drop(tcx, param_env) | ||
&& !self.has_surface_drop(tcx, param_env) | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
/// Fast path helper for testing if a type has noop async destructor. | ||
/// | ||
/// Returning `true` means the type is known to have noop async destructor | ||
/// implementation. Returning `true` means nothing -- could be | ||
/// `Drop`, might not be. | ||
fn is_async_destructor_trivially_noop(self) -> bool { | ||
match self.kind() { | ||
ty::Int(_) | ||
| ty::Uint(_) | ||
|
@@ -1371,26 +1386,12 @@ impl<'tcx> Ty<'tcx> { | |
| ty::Str | ||
| ty::Never | ||
| ty::Ref(..) | ||
| ty::RawPtr(_, _) | ||
| ty::RawPtr(..) | ||
| ty::FnDef(..) | ||
| ty::FnPtr(_) | ||
| ty::Error(_) | ||
| ty::Tuple(_) | ||
| ty::Slice(_) | ||
| ty::Array(_, _) | ||
| ty::Closure(..) | ||
| ty::CoroutineClosure(..) | ||
| ty::Coroutine(..) | ||
| ty::CoroutineWitness(..) | ||
| ty::Pat(..) => false, | ||
ty::Adt(..) | ||
| ty::Bound(..) | ||
| ty::Dynamic(..) | ||
| ty::Foreign(_) | ||
| ty::Infer(_) | ||
| ty::Alias(..) | ||
| ty::Param(_) | ||
| ty::Placeholder(_) => true, | ||
| ty::FnPtr(_) => true, | ||
ty::Tuple(tys) => tys.is_empty(), | ||
ty::Adt(adt_def, _) => adt_def.is_manually_drop(), | ||
_ => false, | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer
self.references_error()
over matching forty::Error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neither drop glue nor discriminant kind do this. I will have to switch every match on
ty::Error
otherwise compiler may emit type errors.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I cannot add this case to be a part of
is_async_destructor_noop
because of this line, which differs from other similar types like ints:rust/compiler/rustc_trait_selection/src/traits/project.rs
Line 1111 in e239e73
But I'm not sure, maybe I should include it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... I guess we can look if there's a general thing to improve here everywhere