Skip to content

Commit 575b2a2

Browse files
authored
Rollup merge of #105915 - andrewpollack:revert-105250-async-rm-resumety, r=tmandry
Revert "Replace usage of `ResumeTy` in async lowering with `Context`" Reverts #105250 Fixes: #105501 Following instructions from [forge](https://forge.rust-lang.org/compiler/reviews.html#reverts). This change introduced a breaking change that is not actionable nor relevant, and is blocking updates to our toolchain. Along with other comments on the CL marking issues that are fixed by reverts, reverting is best until these issues can be resolved cc. `@Swatinem`
2 parents d90658d + 8441ca5 commit 575b2a2

14 files changed

+43
-70
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+21-36
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_hir::def::Res;
1616
use rustc_hir::definitions::DefPathData;
1717
use rustc_session::errors::report_lit_error;
1818
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
19-
use rustc_span::symbol::{kw, sym, Ident};
19+
use rustc_span::symbol::{sym, Ident};
2020
use rustc_span::DUMMY_SP;
2121
use thin_vec::thin_vec;
2222

@@ -596,38 +596,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
596596
) -> hir::ExprKind<'hir> {
597597
let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span)));
598598

599-
// Resume argument type, which should be `&mut Context<'_>`.
600-
// NOTE: Using the `'static` lifetime here is technically cheating.
601-
// The `Future::poll` argument really is `&'a mut Context<'b>`, but we cannot
602-
// express the fact that we are not storing it across yield-points yet,
603-
// and we would thus run into lifetime errors.
604-
// See <https://github.com/rust-lang/rust/issues/68923>.
605-
// Our lowering makes sure we are not mis-using the `_task_context` input type
606-
// in the sense that we are indeed not using it across yield points. We
607-
// get a fresh `&mut Context` for each resume / call of `Future::poll`.
608-
// This "cheating" was previously done with a `ResumeTy` that contained a raw
609-
// pointer, and a `get_context` accessor that pulled the `Context` lifetimes
610-
// out of thin air.
611-
let context_lifetime_ident = Ident::with_dummy_span(kw::StaticLifetime);
612-
let context_lifetime = self.arena.alloc(hir::Lifetime {
613-
hir_id: self.next_id(),
614-
ident: context_lifetime_ident,
615-
res: hir::LifetimeName::Static,
616-
});
617-
let context_path =
618-
hir::QPath::LangItem(hir::LangItem::Context, self.lower_span(span), None);
619-
let context_ty = hir::MutTy {
620-
ty: self.arena.alloc(hir::Ty {
621-
hir_id: self.next_id(),
622-
kind: hir::TyKind::Path(context_path),
623-
span: self.lower_span(span),
624-
}),
625-
mutbl: hir::Mutability::Mut,
626-
};
599+
// Resume argument type: `ResumeTy`
600+
let unstable_span =
601+
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
602+
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span, None);
627603
let input_ty = hir::Ty {
628604
hir_id: self.next_id(),
629-
kind: hir::TyKind::Rptr(context_lifetime, context_ty),
630-
span: self.lower_span(span),
605+
kind: hir::TyKind::Path(resume_ty),
606+
span: unstable_span,
631607
};
632608

633609
// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
@@ -686,9 +662,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
686662
.map_or(false, |attrs| attrs.into_iter().any(|attr| attr.has_name(sym::track_caller)));
687663

688664
let hir_id = self.lower_node_id(closure_node_id);
689-
let unstable_span =
690-
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
691665
if track_caller {
666+
let unstable_span = self.mark_span_with_reason(
667+
DesugaringKind::Async,
668+
span,
669+
self.allow_gen_future.clone(),
670+
);
692671
self.lower_attrs(
693672
hir_id,
694673
&[Attribute {
@@ -731,7 +710,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
731710
/// mut __awaitee => loop {
732711
/// match unsafe { ::std::future::Future::poll(
733712
/// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
734-
/// task_context,
713+
/// ::std::future::get_context(task_context),
735714
/// ) } {
736715
/// ::std::task::Poll::Ready(result) => break result,
737716
/// ::std::task::Poll::Pending => {}
@@ -772,7 +751,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
772751
// unsafe {
773752
// ::std::future::Future::poll(
774753
// ::std::pin::Pin::new_unchecked(&mut __awaitee),
775-
// task_context,
754+
// ::std::future::get_context(task_context),
776755
// )
777756
// }
778757
let poll_expr = {
@@ -790,10 +769,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
790769
arena_vec![self; ref_mut_awaitee],
791770
Some(expr_hir_id),
792771
);
772+
let get_context = self.expr_call_lang_item_fn_mut(
773+
gen_future_span,
774+
hir::LangItem::GetContext,
775+
arena_vec![self; task_context],
776+
Some(expr_hir_id),
777+
);
793778
let call = self.expr_call_lang_item_fn(
794779
span,
795780
hir::LangItem::FuturePoll,
796-
arena_vec![self; new_unchecked, task_context],
781+
arena_vec![self; new_unchecked, get_context],
797782
Some(expr_hir_id),
798783
);
799784
self.arena.alloc(self.expr_unsafe(call))

compiler/rustc_hir/src/lang_items.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,10 @@ language_item_table! {
286286

287287
// FIXME(swatinem): the following lang items are used for async lowering and
288288
// should become obsolete eventually.
289+
ResumeTy, sym::ResumeTy, resume_ty, Target::Struct, GenericRequirement::None;
289290
IdentityFuture, sym::identity_future, identity_future_fn, Target::Fn, GenericRequirement::None;
291+
GetContext, sym::get_context, get_context_fn, Target::Fn, GenericRequirement::None;
290292

291-
Context, sym::Context, context, Target::Struct, GenericRequirement::None;
292293
FuturePoll, sym::poll, future_poll_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
293294

294295
FromFrom, sym::from, from_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;

compiler/rustc_span/src/symbol.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ symbols! {
164164
Capture,
165165
Center,
166166
Clone,
167-
Context,
168167
Continue,
169168
Copy,
170169
Count,
@@ -264,6 +263,7 @@ symbols! {
264263
Relaxed,
265264
Release,
266265
Result,
266+
ResumeTy,
267267
Return,
268268
Right,
269269
Rust,
@@ -753,6 +753,7 @@ symbols! {
753753
generic_associated_types_extended,
754754
generic_const_exprs,
755755
generic_param_attrs,
756+
get_context,
756757
global_allocator,
757758
global_asm,
758759
globs,

library/core/src/future/mod.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub use poll_fn::{poll_fn, PollFn};
4444
/// non-Send/Sync as well, and we don't want that.
4545
///
4646
/// It also simplifies the HIR lowering of `.await`.
47-
// FIXME(swatinem): This type can be removed when bumping the bootstrap compiler
47+
#[cfg_attr(not(bootstrap), lang = "ResumeTy")]
4848
#[doc(hidden)]
4949
#[unstable(feature = "gen_future", issue = "50547")]
5050
#[derive(Debug, Copy, Clone)]
@@ -61,7 +61,6 @@ unsafe impl Sync for ResumeTy {}
6161
/// This function returns a `GenFuture` underneath, but hides it in `impl Trait` to give
6262
/// better error messages (`impl Future` rather than `GenFuture<[closure.....]>`).
6363
// This is `const` to avoid extra errors after we recover from `const async fn`
64-
// FIXME(swatinem): This fn can be removed when bumping the bootstrap compiler
6564
#[cfg_attr(bootstrap, lang = "from_generator")]
6665
#[doc(hidden)]
6766
#[unstable(feature = "gen_future", issue = "50547")]
@@ -103,8 +102,7 @@ where
103102
GenFuture(gen)
104103
}
105104

106-
// FIXME(swatinem): This fn can be removed when bumping the bootstrap compiler
107-
#[cfg_attr(bootstrap, lang = "get_context")]
105+
#[lang = "get_context"]
108106
#[doc(hidden)]
109107
#[unstable(feature = "gen_future", issue = "50547")]
110108
#[must_use]
@@ -115,10 +113,6 @@ pub unsafe fn get_context<'a, 'b>(cx: ResumeTy) -> &'a mut Context<'b> {
115113
unsafe { &mut *cx.0.as_ptr().cast() }
116114
}
117115

118-
// FIXME(swatinem): This fn is currently needed to work around shortcomings
119-
// in type and lifetime inference.
120-
// See the comment at the bottom of `LoweringContext::make_async_expr` and
121-
// <https://github.com/rust-lang/rust/issues/104826>.
122116
#[cfg_attr(not(bootstrap), lang = "identity_future")]
123117
#[doc(hidden)]
124118
#[unstable(feature = "gen_future", issue = "50547")]

library/core/src/task/wake.rs

-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ 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")]
178177
pub struct Context<'a> {
179178
waker: &'a Waker,
180179
// Ensure we future-proof against variance changes by forcing

src/test/ui/async-await/async-await-let-else.drop-tracking.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ LL | async fn bar2<T>(_: T) -> ! {
4040
LL | | panic!()
4141
LL | | }
4242
| |_^
43-
= note: required because it captures the following types: `&mut Context<'_>`, `Option<bool>`, `impl Future<Output = !>`, `()`
43+
= note: required because it captures the following types: `ResumeTy`, `Option<bool>`, `impl Future<Output = !>`, `()`
4444
note: required because it's used within this `async fn` body
4545
--> $DIR/async-await-let-else.rs:21:32
4646
|

src/test/ui/async-await/issue-68112.drop_tracking.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ note: required because it appears within the type `impl Future<Output = Arc<RefC
5757
|
5858
LL | fn make_non_send_future2() -> impl Future<Output = Arc<RefCell<i32>>> {
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60-
= note: required because it captures the following types: `&mut Context<'_>`, `impl Future<Output = Arc<RefCell<i32>>>`, `()`, `Ready<i32>`
60+
= note: required because it captures the following types: `ResumeTy`, `impl Future<Output = Arc<RefCell<i32>>>`, `()`, `Ready<i32>`
6161
note: required because it's used within this `async` block
6262
--> $DIR/issue-68112.rs:60:20
6363
|

src/test/ui/async-await/issue-68112.no_drop_tracking.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ note: required because it appears within the type `impl Future<Output = Arc<RefC
5757
|
5858
LL | fn make_non_send_future2() -> impl Future<Output = Arc<RefCell<i32>>> {
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60-
= note: required because it captures the following types: `&mut Context<'_>`, `impl Future<Output = Arc<RefCell<i32>>>`, `()`, `i32`, `Ready<i32>`
60+
= note: required because it captures the following types: `ResumeTy`, `impl Future<Output = Arc<RefCell<i32>>>`, `()`, `i32`, `Ready<i32>`
6161
note: required because it's used within this `async` block
6262
--> $DIR/issue-68112.rs:60:20
6363
|

src/test/ui/async-await/issue-69446-fnmut-capture.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ LL | | });
1414
|
1515
= note: `FnMut` closures only have access to their captured variables while they are executing...
1616
= note: ...therefore, they cannot allow references to captured variables to escape
17-
= note: requirement occurs because of a mutable reference to `Context<'_>`
18-
= note: mutable references are invariant over their type parameter
19-
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
2017

2118
error: aborting due to previous error
2219

src/test/ui/async-await/issue-70935-complex-spans.drop_tracking.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LL | async fn baz<T>(_c: impl FnMut() -> T) where T: Future<Output=()> {
1818
| ___________________________________________________________________^
1919
LL | | }
2020
| |_^
21-
= note: required because it captures the following types: `&mut Context<'_>`, `impl Future<Output = ()>`, `()`
21+
= note: required because it captures the following types: `ResumeTy`, `impl Future<Output = ()>`, `()`
2222
note: required because it's used within this `async` block
2323
--> $DIR/issue-70935-complex-spans.rs:16:5
2424
|

src/test/ui/async-await/partial-drop-partial-reinit.drop_tracking.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | async fn foo() {
1111
|
1212
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `NotSend`
1313
= note: required because it appears within the type `(NotSend,)`
14-
= note: required because it captures the following types: `&mut Context<'_>`, `(NotSend,)`, `()`, `impl Future<Output = ()>`
14+
= note: required because it captures the following types: `ResumeTy`, `(NotSend,)`, `()`, `impl Future<Output = ()>`
1515
note: required because it's used within this `async fn` body
1616
--> $DIR/partial-drop-partial-reinit.rs:31:16
1717
|

src/test/ui/async-await/partial-drop-partial-reinit.no_drop_tracking.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | async fn foo() {
1111
|
1212
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `NotSend`
1313
= note: required because it appears within the type `(NotSend,)`
14-
= note: required because it captures the following types: `&mut Context<'_>`, `(NotSend,)`, `impl Future<Output = ()>`, `()`
14+
= note: required because it captures the following types: `ResumeTy`, `(NotSend,)`, `impl Future<Output = ()>`, `()`
1515
note: required because it's used within this `async fn` body
1616
--> $DIR/partial-drop-partial-reinit.rs:31:16
1717
|

src/test/ui/regions/closure-in-projection-issue-97405.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ fn good_generic_fn<T>() {
2222
// This should fail because `T` ends up in the upvars of the closure.
2323
fn bad_generic_fn<T: Copy>(t: T) {
2424
assert_static(opaque(async move { t; }).next());
25-
//~^ ERROR the parameter type `T` may not live long enough
25+
//~^ ERROR the associated type `<impl Iterator as Iterator>::Item` may not live long enough
2626
assert_static(opaque(move || { t; }).next());
2727
//~^ ERROR the associated type `<impl Iterator as Iterator>::Item` may not live long enough
2828
assert_static(opaque(opaque(async move { t; }).next()).next());
29-
//~^ ERROR the parameter type `T` may not live long enough
29+
//~^ ERROR the associated type `<impl Iterator as Iterator>::Item` may not live long enough
3030
}
3131

3232
fn main() {}

src/test/ui/regions/closure-in-projection-issue-97405.stderr

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
error[E0310]: the parameter type `T` may not live long enough
1+
error[E0310]: the associated type `<impl Iterator as Iterator>::Item` may not live long enough
22
--> $DIR/closure-in-projection-issue-97405.rs:24:5
33
|
44
LL | assert_static(opaque(async move { t; }).next());
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
6-
|
7-
help: consider adding an explicit lifetime bound...
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86
|
9-
LL | fn bad_generic_fn<T: Copy + 'static>(t: T) {
10-
| +++++++++
7+
= help: consider adding an explicit lifetime bound `<impl Iterator as Iterator>::Item: 'static`...
8+
= note: ...so that the type `<impl Iterator as Iterator>::Item` will meet its required lifetime bounds
119

1210
error[E0310]: the associated type `<impl Iterator as Iterator>::Item` may not live long enough
1311
--> $DIR/closure-in-projection-issue-97405.rs:26:5
@@ -18,16 +16,14 @@ LL | assert_static(opaque(move || { t; }).next());
1816
= help: consider adding an explicit lifetime bound `<impl Iterator as Iterator>::Item: 'static`...
1917
= note: ...so that the type `<impl Iterator as Iterator>::Item` will meet its required lifetime bounds
2018

21-
error[E0310]: the parameter type `T` may not live long enough
19+
error[E0310]: the associated type `<impl Iterator as Iterator>::Item` may not live long enough
2220
--> $DIR/closure-in-projection-issue-97405.rs:28:5
2321
|
2422
LL | assert_static(opaque(opaque(async move { t; }).next()).next());
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
26-
|
27-
help: consider adding an explicit lifetime bound...
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2824
|
29-
LL | fn bad_generic_fn<T: Copy + 'static>(t: T) {
30-
| +++++++++
25+
= help: consider adding an explicit lifetime bound `<impl Iterator as Iterator>::Item: 'static`...
26+
= note: ...so that the type `<impl Iterator as Iterator>::Item` will meet its required lifetime bounds
3127

3228
error: aborting due to 3 previous errors
3329

0 commit comments

Comments
 (0)