Skip to content

[let_chains, 1/6] Remove hir::ExprKind::If#59288

Merged
bors merged 5 commits intorust-lang:masterfrom
Centril:hir-if-to-match
May 11, 2019
Merged

[let_chains, 1/6] Remove hir::ExprKind::If#59288
bors merged 5 commits intorust-lang:masterfrom
Centril:hir-if-to-match

Conversation

@Centril
Copy link
Contributor

@Centril Centril commented Mar 19, 2019

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 19, 2019
@petrochenkov petrochenkov self-assigned this Mar 19, 2019
@rust-highfive

This comment has been minimized.

@petrochenkov
Copy link
Contributor

IIRC, I got some lifetime issues after trying to desugar all ifs into matches (rather than those containing is), with RefCells being held for too long (or too little?) and panicking etc.
Don't remember the details right now, perhaps it's fixable.

@petrochenkov
Copy link
Contributor

This seems like a nice simplification even regardless of if-let chains, we only need to make sure that it doesn't regress 1) codegen 2) compile times, and 3) diagnostics.

Similarly, desugaring while into loop is also required for implementing pattern matching expressions, but is also a nice simplification otherwise.

(I'll try to review the code later today.)

@petrochenkov
Copy link
Contributor

petrochenkov commented Mar 19, 2019

On the other hand, the desugaring for pattern matching expressions at the AST/HIR border turned out incredibly hacky, when I tried it.
It also made impossible to support those expressions in pattern guards.

match thing {
    PAT(y) if let Some(x) = y {
        print(x); // Nope
    }
}

So it's a pretty real possibility that it's better done somewhere at HIR->MIR time.

@Centril
Copy link
Contributor Author

Centril commented Mar 19, 2019

This seems like a nice simplification even regardless of if-let chains, we only need to make sure that it doesn't regress 1) codegen 2) compile times, and 3) diagnostics.

I think I fixed all diagnostics issues that I had... some even got improved. :) As for codegen there are issues in #59288 (comment) wrt. mir-opt tests (thus the WIP) that I don't really understand yet.

Similarly, desugaring while into loop is also required for implementing pattern matching expressions, but is also a nice simplification otherwise.

Yup, I'd like to do that as step 4 in the process after having done the if part of the RFC fully. Maybe even remove continue from HIR after step 6...

(I'll try to review the code later today.)

:)

On the other hand, the desugaring for pattern matching expressions at the AST/HIR border turned out incredibly hacky, when I tried it.

When I tried it out with LBV + a fold in lowering it didn't feel so bad. Haven't thought about the implications of if-let-guards + if-let-chains tho wrt. lowering. :)

@rust-highfive

This comment has been minimized.

@Centril
Copy link
Contributor Author

Centril commented Mar 19, 2019

(I believe @oli-obk is looking into the mir-opt stuff)

Centril added a commit to Centril/rust that referenced this pull request Mar 19, 2019
Run branch cleanup after copy prop

This is preliminary work for rust-lang#59288 (comment) which gets rid of `if` in the HIR.

cc @rust-lang/wg-mir-opt 	@Centril
@oli-obk
Copy link
Contributor

oli-obk commented Mar 19, 2019

@bors try

@bors
Copy link
Collaborator

bors commented Mar 19, 2019

⌛ Trying commit db4452fab28c9374dd6676b702dc36b43e2a45b5 with merge bf82f43c83ada4fffaf93a633dfce5c7f55d57fe...

@rust-highfive

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Mar 19, 2019

☀️ Try build successful - checks-travis
Build commit: bf82f43c83ada4fffaf93a633dfce5c7f55d57fe

@oli-obk
Copy link
Contributor

oli-obk commented Mar 19, 2019

@rust-timer build

@oli-obk
Copy link
Contributor

oli-obk commented Mar 19, 2019

@rust-timer build bf82f43c83ada4fffaf93a633dfce5c7f55d57fe

@rust-timer
Copy link
Collaborator

Success: Queued bf82f43c83ada4fffaf93a633dfce5c7f55d57fe with parent ef4d1c4, comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit bf82f43c83ada4fffaf93a633dfce5c7f55d57fe

@Centril Centril force-pushed the hir-if-to-match branch 2 times, most recently from 772ab34 to 9a0d37d Compare March 21, 2019 10:11
@rust-highfive

This comment has been minimized.

@bors

This comment has been minimized.

@Centril Centril added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 22, 2019
@petrochenkov petrochenkov added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 23, 2019
@Centril Centril force-pushed the hir-if-to-match branch from c6eac6a to f9cc5a6 Compare May 10, 2019 17:56
@Centril
Copy link
Contributor Author

Centril commented May 10, 2019

Filed FIXME issue, rebased, and did a minor cleanup after the .await PR.

@oli-obk Please take a look :)

@oli-obk
Copy link
Contributor

oli-obk commented May 10, 2019

@bors r+

@bors
Copy link
Collaborator

bors commented May 10, 2019

📌 Commit f9cc5a6 has been approved by oli-obk

@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 May 10, 2019
@bors
Copy link
Collaborator

bors commented May 10, 2019

⌛ Testing commit f9cc5a6 with merge acc7e65...

bors added a commit that referenced this pull request May 10, 2019
[let_chains, 1/6] Remove hir::ExprKind::If

Per #53667 (comment).

r? @oli-obk
@bors
Copy link
Collaborator

bors commented May 11, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: oli-obk
Pushing acc7e65 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 11, 2019
@bors bors merged commit f9cc5a6 into rust-lang:master May 11, 2019
@rust-highfive
Copy link
Contributor

📣 Toolstate changed by #59288!

Tested on commit acc7e65.
Direct link to PR: #59288

💔 clippy-driver on windows: test-pass → build-fail (cc @Manishearth @llogiq @mcarton @oli-obk @phansch, @rust-lang/infra).
💔 clippy-driver on linux: test-pass → build-fail (cc @Manishearth @llogiq @mcarton @oli-obk @phansch, @rust-lang/infra).
💔 rls on windows: test-pass → build-fail (cc @Xanewok, @rust-lang/infra).
💔 rls on linux: test-pass → build-fail (cc @Xanewok, @rust-lang/infra).

@Manishearth
Copy link
Member

Have you looked into how hard it will be to make clippy migrate to these? We have a lot of lints around ifs, and the lowering may lose some context necessary to make these work. Removing lints because they're no longer possible isn't an option.

IMO for such changes where there's a good chance clippy lints will be unfixably broken we should be notified of this before it merges :/

@Manishearth
Copy link
Member

I appreciate it being split up, though, it's easier to make this evaluation if one thing breaks at a time :)

@Centril
Copy link
Contributor Author

Centril commented May 11, 2019

We have a lot of lints around ifs, and the lowering may lose some context necessary to make these work.

The lowering preserves information about the source; you can check MatchSource::IfDesugar to see whether it originated from an if.

@oli-obk thought it would work for clippy and as you know, he also works on clippy...

@Manishearth
Copy link
Member

Manishearth commented May 11, 2019 via email

@Centril
Copy link
Contributor Author

Centril commented May 11, 2019

For the later steps can you work with us to ensure stuff isn't broken before landing? Mostly just pinging me when the PR is ready to merge so I can work on a patch

Sure. Fwiw, I expected Oliver to be the "work with us" party... ;)

The next steps will be to introduce ast::ExprKind::Let and then to use 'label: { ... break 'label value }. That will probably be less straightforward but I think we can introduce similar desugaring info as needed. I could introduce ast::ExprKind::Let in a separate intermediate step however without connecting the parser (already done in a PR but I could probably split things).

@Manishearth
Copy link
Member

Manishearth commented May 11, 2019 via email

@nnethercote
Copy link
Contributor

This ended up being a non-trivial perf regression.

@Centril
Copy link
Contributor Author

Centril commented Jun 3, 2019

Yep; this was expected. #60730 will hopefully reduce some of those regressions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-let_chains `#![feature(let_chains)]` 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

Development

Successfully merging this pull request may close these issues.

10 participants