Skip to content

Commit 5dc8ec8

Browse files
committed
Remove a stack frame from .await calls
1 parent e6cef04 commit 5dc8ec8

File tree

5 files changed

+40
-25
lines changed

5 files changed

+40
-25
lines changed

src/libcore/future/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ where
7777
#[unstable(feature = "gen_future", issue = "50547")]
7878
#[cfg(not(bootstrap))]
7979
#[inline]
80-
pub unsafe fn poll_with_context<F>(f: Pin<&mut F>, mut cx: ResumeTy) -> Poll<F::Output>
81-
where
82-
F: Future,
83-
{
84-
F::poll(f, cx.0.as_mut())
80+
pub unsafe fn get_context<'a, 'b>(cx: ResumeTy) -> &'a mut Context<'b> {
81+
&mut *cx.0.as_ptr().cast()
8582
}

src/librustc_ast_lowering/expr.rs

+34-11
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
556556
/// ```rust
557557
/// match <expr> {
558558
/// mut pinned => loop {
559-
/// match unsafe { ::std::future::poll_with_context(
559+
/// match unsafe { ::std::future::Future::poll(
560560
/// <::std::pin::Pin>::new_unchecked(&mut pinned),
561-
/// task_context,
561+
/// ::std::future::get_context(task_context),
562562
/// ) } {
563563
/// ::std::task::Poll::Ready(result) => break result,
564564
/// ::std::task::Poll::Pending => {}
@@ -598,9 +598,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
598598
let task_context_ident = Ident::with_dummy_span(sym::_task_context);
599599

600600
// unsafe {
601-
// ::std::future::poll_with_context(
601+
// ::std::future::Future::poll(
602602
// ::std::pin::Pin::new_unchecked(&mut pinned),
603-
// task_context,
603+
// ::std::future::get_context(task_context),
604604
// )
605605
// }
606606
let poll_expr = {
@@ -621,10 +621,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
621621
arena_vec![self; ref_mut_pinned],
622622
);
623623
let new_unchecked = self.expr(span, new_unchecked_expr_kind, ThinVec::new());
624-
let call = self.expr_call_std_path(
624+
let get_context = self.expr_call_std_path_mut(
625625
gen_future_span,
626-
&[sym::future, sym::poll_with_context],
627-
arena_vec![self; new_unchecked, task_context],
626+
&[sym::future, sym::get_context],
627+
arena_vec![self; task_context],
628+
);
629+
let call = self.expr_call_std_path(
630+
span,
631+
&[sym::future, sym::Future, sym::poll],
632+
arena_vec![self; new_unchecked, get_context],
628633
);
629634
self.arena.alloc(self.expr_unsafe(call))
630635
};
@@ -1326,25 +1331,43 @@ impl<'hir> LoweringContext<'_, 'hir> {
13261331
self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[]), ThinVec::new()))
13271332
}
13281333

1334+
fn expr_call_mut(
1335+
&mut self,
1336+
span: Span,
1337+
e: &'hir hir::Expr<'hir>,
1338+
args: &'hir [hir::Expr<'hir>],
1339+
) -> hir::Expr<'hir> {
1340+
self.expr(span, hir::ExprKind::Call(e, args), ThinVec::new())
1341+
}
1342+
13291343
fn expr_call(
13301344
&mut self,
13311345
span: Span,
13321346
e: &'hir hir::Expr<'hir>,
13331347
args: &'hir [hir::Expr<'hir>],
13341348
) -> &'hir hir::Expr<'hir> {
1335-
self.arena.alloc(self.expr(span, hir::ExprKind::Call(e, args), ThinVec::new()))
1349+
self.arena.alloc(self.expr_call_mut(span, e, args))
13361350
}
13371351

13381352
// Note: associated functions must use `expr_call_std_path`.
1339-
fn expr_call_std_path(
1353+
fn expr_call_std_path_mut(
13401354
&mut self,
13411355
span: Span,
13421356
path_components: &[Symbol],
13431357
args: &'hir [hir::Expr<'hir>],
1344-
) -> &'hir hir::Expr<'hir> {
1358+
) -> hir::Expr<'hir> {
13451359
let path =
13461360
self.arena.alloc(self.expr_std_path(span, path_components, None, ThinVec::new()));
1347-
self.expr_call(span, path, args)
1361+
self.expr_call_mut(span, path, args)
1362+
}
1363+
1364+
fn expr_call_std_path(
1365+
&mut self,
1366+
span: Span,
1367+
path_components: &[Symbol],
1368+
args: &'hir [hir::Expr<'hir>],
1369+
) -> &'hir hir::Expr<'hir> {
1370+
self.arena.alloc(self.expr_call_std_path_mut(span, path_components, args))
13481371
}
13491372

13501373
// Create an expression calling an associated function of an std type.

src/librustc_span/symbol.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,9 @@ symbols! {
546546
plugin,
547547
plugin_registrar,
548548
plugins,
549+
poll,
549550
Poll,
550-
poll_with_context,
551+
get_context,
551552
powerpc_target_feature,
552553
precise_pointer_size_matching,
553554
pref_align_of,

src/test/ui/async-await/issue-70594.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ error[E0277]: the trait bound `(): std::future::Future` is not satisfied
3232
|
3333
LL | [1; ().await];
3434
| ^^^^^^^^ the trait `std::future::Future` is not implemented for `()`
35-
|
36-
::: $SRC_DIR/libcore/future/mod.rs:LL:COL
3735
|
38-
LL | F: Future,
39-
| ------ required by this bound in `std::future::poll_with_context`
36+
= note: required by `std::future::Future::poll`
4037

4138
error: aborting due to 5 previous errors
4239

src/test/ui/async-await/issues/issue-62009-1.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ error[E0277]: the trait bound `[closure@$DIR/issue-62009-1.rs:12:5: 12:15]: std:
3232
|
3333
LL | (|_| 2333).await;
3434
| ^^^^^^^^^^^^^^^^ the trait `std::future::Future` is not implemented for `[closure@$DIR/issue-62009-1.rs:12:5: 12:15]`
35-
|
36-
::: $SRC_DIR/libcore/future/mod.rs:LL:COL
3735
|
38-
LL | F: Future,
39-
| ------ required by this bound in `std::future::poll_with_context`
36+
= note: required by `std::future::Future::poll`
4037

4138
error: aborting due to 4 previous errors
4239

0 commit comments

Comments
 (0)