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

adjust desugaring for async fn to correct drop order #64525

Merged
merged 7 commits into from
Sep 17, 2019

Conversation

nikomatsakis
Copy link
Contributor

Old desugaring, given a user function body { $stmts; $expr }

{
    let $param_pattern0 = $raw_param0;
    ...
    let $param_patternN = $raw_paramN;
    $stmts;
    $expr
}

New desugaring:

{
    let $param_pattern0 = $raw_param0;
    ...
    let $param_patternN = $raw_paramN;
    drop-temps {
        $stmts;
        $expr
    }
}

The drop-temps is an internal bit of HIR that drops temporaries from the resulting expression, but it should be equivalent to return { $stmts; $expr }.

Fixes #64512
Fixes #64391

@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 16, 2019
@petrochenkov
Copy link
Contributor

r? @cramertj (I guess)

Old desugaring, given a user function body { $stmts; $expr }

```
{
    let $param_pattern0 = $raw_param0;
    ...
    let $param_patternN = $raw_paramN;
    $stmts;
    $expr
}
```

New desugaring:

```
{
    let $param_pattern0 = $raw_param0;
    ...
    let $param_patternN = $raw_paramN;
    drop-temps {
        $stmts;
        $expr
    }
}
```

The drop-temps is an internal bit of HIR that drops temporaries from
the resulting expression, but it should be equivalent to `return {
$stmts; $expr }`.
@nikomatsakis
Copy link
Contributor Author

@cramertj is on vacation -- maybe @davidtwco feels up to reviewing this?

r? @davidtwco

If you don't, though, let me know and we'll find somebody else. =)

@rust-highfive rust-highfive assigned davidtwco and unassigned cramertj Sep 16, 2019
@estebank
Copy link
Contributor

This looks correct to me. If no reviewer gets a chance to see it in a timely manner, r=me.

@nikomatsakis
Copy link
Contributor Author

@bors p=1

Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-09-17T08:54:16.4179301Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-09-17T08:54:16.4370554Z ##[command]git config gc.auto 0
2019-09-17T08:54:16.4422163Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-09-17T08:54:16.4481784Z ##[command]git config --get-all http.proxy
2019-09-17T08:54:16.4661926Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/64525/merge:refs/remotes/pull/64525/merge
---
2019-09-17T09:02:07.1232465Z     Checking syntax_ext v0.0.0 (/checkout/src/libsyntax_ext)
2019-09-17T09:02:17.2358966Z error[E0308]: mismatched types
2019-09-17T09:02:17.2360290Z     --> src/librustc/hir/lowering.rs:2714:9
2019-09-17T09:02:17.2360870Z      |
2019-09-17T09:02:17.2361334Z 2713 |     fn lower_block_expr(&mut self, b: &Block) -> P<hir::Expr> {
2019-09-17T09:02:17.2361887Z      |                                                  ------------ expected `hir::ptr::P<hir::Expr>` because of return type
2019-09-17T09:02:17.2362390Z 2714 |         self.expr_block(self.lower_block(b, false), ThinVec::new())
2019-09-17T09:02:17.2362941Z      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `hir::ptr::P`, found struct `hir::Expr`
2019-09-17T09:02:17.2364324Z      = note: expected type `hir::ptr::P<hir::Expr>`
2019-09-17T09:02:17.2364834Z                 found type `hir::Expr`
2019-09-17T09:02:17.2365094Z 
2019-09-17T09:02:17.3800894Z error[E0308]: mismatched types
2019-09-17T09:02:17.3800894Z error[E0308]: mismatched types
2019-09-17T09:02:17.3801168Z   --> src/librustc/hir/lowering/expr.rs:93:21
2019-09-17T09:02:17.3801334Z    |
2019-09-17T09:02:17.3801595Z 93 |                     this.with_new_scopes(|this| this.lower_block_expr(block))
2019-09-17T09:02:17.3802292Z    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `hir::Expr`, found struct `hir::ptr::P`
2019-09-17T09:02:17.3802738Z    = note: expected type `hir::Expr`
2019-09-17T09:02:17.3802957Z               found type `hir::ptr::P<hir::Expr>`
2019-09-17T09:02:17.3802990Z 
2019-09-17T09:02:17.4770011Z error[E0308]: mismatched types
2019-09-17T09:02:17.4770011Z error[E0308]: mismatched types
2019-09-17T09:02:17.4770467Z    --> src/librustc/hir/lowering/expr.rs:309:45
2019-09-17T09:02:17.4770660Z     |
2019-09-17T09:02:17.4770882Z 309 |         let then_arm = self.arm(then_pat, P(then_expr));
2019-09-17T09:02:17.4771161Z     |                                             ^^^^^^^^^ expected struct `hir::Expr`, found struct `hir::ptr::P`
2019-09-17T09:02:17.4771546Z     = note: expected type `hir::Expr`
2019-09-17T09:02:17.4771765Z                found type `hir::ptr::P<hir::Expr>`
2019-09-17T09:02:17.4771797Z 
2019-09-17T09:02:17.5715279Z error[E0308]: mismatched types
2019-09-17T09:02:17.5715279Z error[E0308]: mismatched types
2019-09-17T09:02:17.5715684Z    --> src/librustc/hir/lowering/expr.rs:377:45
2019-09-17T09:02:17.5715912Z     |
2019-09-17T09:02:17.5716208Z 377 |         let then_arm = self.arm(then_pat, P(then_expr));
2019-09-17T09:02:17.5716729Z     |                                             ^^^^^^^^^ expected struct `hir::Expr`, found struct `hir::ptr::P`
2019-09-17T09:02:17.5717353Z     = note: expected type `hir::Expr`
2019-09-17T09:02:17.5717635Z                found type `hir::ptr::P<hir::Expr>`
2019-09-17T09:02:17.5717670Z 
2019-09-17T09:02:17.7278751Z error[E0061]: this function takes 1 parameter but 2 parameters were supplied
2019-09-17T09:02:17.7278751Z error[E0061]: this function takes 1 parameter but 2 parameters were supplied
2019-09-17T09:02:17.7279051Z     --> src/librustc/hir/lowering/item.rs:1074:46
2019-09-17T09:02:17.7279212Z      |
2019-09-17T09:02:17.7279469Z 1074 |         self.lower_fn_body(decl, |this| this.lower_block_expr(body, false))
2019-09-17T09:02:17.7280109Z      | 
2019-09-17T09:02:17.7280313Z     ::: src/librustc/hir/lowering.rs:2713:5
2019-09-17T09:02:17.7280474Z      |
2019-09-17T09:02:17.7280474Z      |
2019-09-17T09:02:17.7280711Z 2713 |     fn lower_block_expr(&mut self, b: &Block) -> P<hir::Expr> {
2019-09-17T09:02:17.7281011Z 
2019-09-17T09:02:17.7281208Z error[E0308]: mismatched types
2019-09-17T09:02:17.7281398Z     --> src/librustc/hir/lowering/item.rs:1074:41
2019-09-17T09:02:17.7281569Z      |
2019-09-17T09:02:17.7281569Z      |
2019-09-17T09:02:17.7281804Z 1074 |         self.lower_fn_body(decl, |this| this.lower_block_expr(body, false))
2019-09-17T09:02:17.7282130Z      |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `hir::Expr`, found struct `hir::ptr::P`
2019-09-17T09:02:17.7282539Z      = note: expected type `hir::Expr`
2019-09-17T09:02:17.7282986Z                 found type `hir::ptr::P<hir::Expr>`
2019-09-17T09:02:17.7283020Z 
2019-09-17T09:02:17.8255493Z error[E0308]: mismatched types
2019-09-17T09:02:17.8255493Z error[E0308]: mismatched types
2019-09-17T09:02:17.8256583Z     --> src/librustc/hir/lowering/item.rs:1237:27
2019-09-17T09:02:17.8257079Z      |
2019-09-17T09:02:17.8258343Z 1237 |                         P(user_body),
2019-09-17T09:02:17.8258937Z      |                           ^^^^^^^^^ expected struct `hir::Expr`, found struct `hir::ptr::P`
2019-09-17T09:02:17.8259854Z      = note: expected type `hir::Expr`
2019-09-17T09:02:17.8260343Z                 found type `hir::ptr::P<hir::Expr>`
2019-09-17T09:02:17.8260543Z 
2019-09-17T09:02:30.6044370Z error: aborting due to 7 previous errors
---
2019-09-17T09:02:30.7929633Z == clock drift check ==
2019-09-17T09:02:30.7946076Z   local time: Tue Sep 17 09:02:30 UTC 2019
2019-09-17T09:02:30.9552375Z   network time: Tue, 17 Sep 2019 09:02:30 GMT
2019-09-17T09:02:30.9559748Z == end clock drift check ==
2019-09-17T09:02:31.7950353Z ##[error]Bash exited with code '1'.
2019-09-17T09:02:31.7993678Z ##[section]Starting: Checkout
2019-09-17T09:02:31.7995803Z ==============================================================================
2019-09-17T09:02:31.7995879Z Task         : Get sources
2019-09-17T09:02:31.7995928Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

LGTM! r=me when CI is passing.

Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

Oh, just remembered, will the reference need updated with this change? rust-lang/reference#674 is still open from the initial change.

@nikomatsakis
Copy link
Contributor Author

@bors r=davidtwco

@bors
Copy link
Contributor

bors commented Sep 17, 2019

📌 Commit 2d8b10f has been approved by davidtwco

@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 Sep 17, 2019
@nikomatsakis
Copy link
Contributor Author

@davidtwco

Oh, just remembered, will the reference need updated with this change? rust-lang/reference#674 is still open from the initial change.

I was planning to take a look at the reference and decide what needed to be updated.

@bors
Copy link
Contributor

bors commented Sep 17, 2019

⌛ Testing commit 2d8b10f with merge 7efe1c6...

bors added a commit that referenced this pull request Sep 17, 2019
… r=davidtwco

adjust desugaring for async fn to correct drop order

Old desugaring, given a user function body `{ $stmts; $expr }`

```
{
    let $param_pattern0 = $raw_param0;
    ...
    let $param_patternN = $raw_paramN;
    $stmts;
    $expr
}
```

New desugaring:

```
{
    let $param_pattern0 = $raw_param0;
    ...
    let $param_patternN = $raw_paramN;
    drop-temps {
        $stmts;
        $expr
    }
}
```

The drop-temps is an internal bit of HIR that drops temporaries from the resulting expression, but it should be equivalent to `return { $stmts; $expr }`.

Fixes #64512
Fixes #64391
@bors
Copy link
Contributor

bors commented Sep 17, 2019

☀️ Test successful - checks-azure
Approved by: davidtwco
Pushing 7efe1c6 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 17, 2019
@bors bors merged commit 2d8b10f into rust-lang:master Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
8 participants