about summary refs log tree commit diff
path: root/library/core
diff options
context:
space:
mode:
authorArpad Borsos <swatinem@swatinem.de>2022-12-20 15:15:29 +0100
committerArpad Borsos <swatinem@swatinem.de>2023-01-19 09:03:05 +0100
commit96931a787abaac7d720fc415780037fc63bee98d (patch)
tree66f88274150177d17c4f110d599d4348bce591a7 /library/core
parent6ba6d22bdf5348e566dedc77a7dfee3f3804f2fb (diff)
downloadrust-96931a787abaac7d720fc415780037fc63bee98d.tar.gz
rust-96931a787abaac7d720fc415780037fc63bee98d.zip
Transform async ResumeTy in generator transform
- Eliminates all the `get_context` calls that async lowering created.
- Replace all `Local` `ResumeTy` types with `&mut Context<'_>`.

The `Local`s that have their types replaced are:
- The `resume` argument itself.
- The argument to `get_context`.
- The yielded value of a `yield`.

The `ResumeTy` hides a `&mut Context<'_>` behind an unsafe raw pointer, and the
`get_context` function is being used to convert that back to a `&mut Context<'_>`.

Ideally the async lowering would not use the `ResumeTy`/`get_context` indirection,
but rather directly use `&mut Context<'_>`, however that would currently
lead to higher-kinded lifetime errors.
See <https://github.com/rust-lang/rust/issues/105501>.

The async lowering step and the type / lifetime inference / checking are
still using the `ResumeTy` indirection for the time being, and that indirection
is removed here. After this transform, the generator body only knows about `&mut Context<'_>`.
Diffstat (limited to 'library/core')
-rw-r--r--library/core/src/future/mod.rs4
-rw-r--r--library/core/src/task/wake.rs1
2 files changed, 5 insertions, 0 deletions
diff --git a/library/core/src/future/mod.rs b/library/core/src/future/mod.rs
index 5bfe001de46..c4fb3620946 100644
--- a/library/core/src/future/mod.rs
+++ b/library/core/src/future/mod.rs
@@ -112,6 +112,10 @@ pub unsafe fn get_context<'a, 'b>(cx: ResumeTy) -> &'a mut Context<'b> {
     unsafe { &mut *cx.0.as_ptr().cast() }
 }
 
+// FIXME(swatinem): This fn is currently needed to work around shortcomings
+// in type and lifetime inference.
+// See the comment at the bottom of `LoweringContext::make_async_expr` and
+// <https://github.com/rust-lang/rust/issues/104826>.
 #[doc(hidden)]
 #[unstable(feature = "gen_future", issue = "50547")]
 #[inline]
diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs
index a4425fd234a..89adfccd901 100644
--- a/library/core/src/task/wake.rs
+++ b/library/core/src/task/wake.rs
@@ -174,6 +174,7 @@ impl RawWakerVTable {
 /// Currently, `Context` only serves to provide access to a [`&Waker`](Waker)
 /// which can be used to wake the current task.
 #[stable(feature = "futures_api", since = "1.36.0")]
+#[cfg_attr(not(bootstrap), lang = "Context")]
 pub struct Context<'a> {
     waker: &'a Waker,
     // Ensure we future-proof against variance changes by forcing