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

Conversation

nikomatsakis
Copy link
Contributor

This flag is used to make the execution order around += operators
pessimistic. Failure to save/restore the flag was causing independent
async blocks to effect one another, leading to strange ICEs and failed
assumptions.

Fixes #69307

r? @Zoxc

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 24, 2020
This flag is used to make the execution order around `+=` operators
pessimistic. Failure to save/restore the flag was causing independent
async blocks to effect one another, leading to strange ICEs and failed
assumptions.
@Aaron1011
Copy link
Member

See #61572 for the original discussion that motivated the pessimistic_yield flag.

@nikomatsakis
Copy link
Contributor Author

nikomatsakis commented Mar 26, 2020

@Aaron1011 do you think this change makes sense?

EDIT: I guess I can infer "yes" from the 👍 reaction =)

@Aaron1011
Copy link
Member

@nikomatsakis: Yeah, this looks good to me. I never considered the possibility of having an async block on the RHS of the expression 😄

@Zoxc
Copy link
Contributor

Zoxc commented Mar 30, 2020

I don't really follow the logic here to well, but won't we also need to save/restore fixup_scopes?

@nikomatsakis
Copy link
Contributor Author

I don't believe we do, because when we enter into a += operator expression, we save the length:

let start_point = visitor.fixup_scopes.len();

then we drain everything added since that length:

let target_scopes = visitor.fixup_scopes.drain(start_point..);

In other words, it's a stack, and we never look at what lies on it except the things that were pushed during a particular node.

We could add an assertion that the depth of fixup_scopes is the same when entering/exiting a fn body, I believe that should be true.

@nikomatsakis
Copy link
Contributor Author

Since @Zoxc said they weren't too familiar with this, I'm going to make this

r? @Aaron1011

@rust-highfive rust-highfive assigned Aaron1011 and unassigned Zoxc Apr 3, 2020
@Aaron1011
Copy link
Member

@nikomatsakis: Could you add an additional test that has a nested use of += and .await? Something like:

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

@nikomatsakis
Copy link
Contributor Author

@Aaron1011 done. (Running tests locally now.)

@nikomatsakis
Copy link
Contributor Author

seems like tests pass

@@ -720,6 +720,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
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);
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

@Aaron1011
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Apr 8, 2020

📌 Commit 563152d has been approved by Aaron1011

@bors
Copy link
Contributor

bors commented Apr 8, 2020

🌲 The tree is currently closed for pull requests below priority 1000, this pull request will be tested once the tree is reopened

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 8, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 9, 2020
Rollup of 7 pull requests

Successful merges:

 - rust-lang#67705 (Use unrolled loop for searching NULL in [u16] on Windows)
 - rust-lang#70367 (save/restore `pessimistic_yield` when entering bodies)
 - rust-lang#70822 (Don't lint for self-recursion when the function can diverge)
 - rust-lang#70868 (rustc_codegen_ssa: Refactor construction of linker arguments)
 - rust-lang#70896 (Implement Chain with Option fuses)
 - rust-lang#70916 (Support `#[track_caller]` on functions in `extern "Rust" { ... }`)
 - rust-lang#70918 (rustc_session: forbid lints override regardless of position)

Failed merges:

r? @ghost
@bors bors merged commit ba50bc5 into rust-lang:master Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: src/librustc/middle/region.rs:1037: Encountered greater count 28
5 participants