Skip to content

Commit 7bda637

Browse files
committed
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 <rust-lang/rust#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<'_>`.
1 parent 613d5d1 commit 7bda637

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

core/src/future/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ pub unsafe fn get_context<'a, 'b>(cx: ResumeTy) -> &'a mut Context<'b> {
112112
unsafe { &mut *cx.0.as_ptr().cast() }
113113
}
114114

115+
// FIXME(swatinem): This fn is currently needed to work around shortcomings
116+
// in type and lifetime inference.
117+
// See the comment at the bottom of `LoweringContext::make_async_expr` and
118+
// <https://github.com/rust-lang/rust/issues/104826>.
115119
#[doc(hidden)]
116120
#[unstable(feature = "gen_future", issue = "50547")]
117121
#[inline]

core/src/task/wake.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ impl RawWakerVTable {
174174
/// Currently, `Context` only serves to provide access to a [`&Waker`](Waker)
175175
/// which can be used to wake the current task.
176176
#[stable(feature = "futures_api", since = "1.36.0")]
177+
#[cfg_attr(not(bootstrap), lang = "Context")]
177178
pub struct Context<'a> {
178179
waker: &'a Waker,
179180
// Ensure we future-proof against variance changes by forcing

0 commit comments

Comments
 (0)