Skip to content
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

save/restore pessimistic_yield when entering bodies #70367

Merged
merged 3 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/librustc_passes/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,9 +717,17 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
self.cx.parent
);

// Save all state that is specific to the outer function
// body. These will be restored once down below, once we've
// visited the body.
let outer_ec = mem::replace(&mut self.expr_and_pat_count, 0);
let outer_cx = self.cx;
let outer_ts = mem::take(&mut self.terminating_scopes);
// The 'pessimistic yield' flag is set to true when we are
// processing a `+=` statement and have to make pessimistic
// control flow assumptions. This doesn't apply to nested
// bodies within the `+=` statements. See #69307.
let outer_pessimistic_yield = mem::replace(&mut self.pessimistic_yield, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment linking to #69307?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

self.terminating_scopes.insert(body.value.hir_id.local_id);

if let Some(root_id) = self.cx.root_id {
Expand Down Expand Up @@ -771,6 +779,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
self.expr_and_pat_count = outer_ec;
self.cx = outer_cx;
self.terminating_scopes = outer_ts;
self.pessimistic_yield = outer_pessimistic_yield;
}

fn visit_arm(&mut self, a: &'tcx Arm<'tcx>) {
Expand Down
30 changes: 30 additions & 0 deletions src/test/ui/async-await/issues/issue-69307-nested.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Regression test for #69307
//
// Having a `async { .. foo.await .. }` block appear inside of a `+=`
// expression was causing an ICE due to a failure to save/restore
// state in the AST numbering pass when entering a nested body.
//
// check-pass
// edition:2018

fn block_on<F>(_: F) -> usize {
0
}

fn main() {}

async fn bar() {
let mut sum = 0;
sum += {
block_on(async {
baz().await;
let mut inner = 1;
inner += block_on(async {
baz().await;
0
})
})
};
}

async fn baz() {}
23 changes: 23 additions & 0 deletions src/test/ui/async-await/issues/issue-69307.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Regression test for #69307
//
// Having a `async { .. foo.await .. }` block appear inside of a `+=`
// expression was causing an ICE due to a failure to save/restore
// state in the AST numbering pass when entering a nested body.
//
// check-pass
// edition:2018

fn block_on<F>(_: F) -> usize {
0
}

fn main() {}

async fn bar() {
let mut sum = 0;
sum += block_on(async {
baz().await;
});
}

async fn baz() {}