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

typeck: simplify the handling of diverges #68422

Merged
merged 3 commits into from
Jan 22, 2020

Conversation

Centril
Copy link
Contributor

@Centril Centril commented Jan 21, 2020

Some drive-by cleanup while working on hir::ExprKind::Let.
Ostensibly, this has some perf benefits due to reduced allocation and whatnot as well.

r? @eddyb

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 21, 2020
let scrut_diverges = self.diverges.get();
self.diverges.set(Diverges::Maybe);
// Otherwise, we have to union together the types that the arms produce and so forth.
let scrut_diverges = self.diverges.replace(Diverges::Maybe);
Copy link
Member

Choose a reason for hiding this comment

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

Ohh, we might have more similar places where we use get and set, predating Cell::replace.
I found some in these two files, if someone wants to take them:

  • src/librustc/ty/print/pretty.rs
  • src/librustc/infer/mod.rs

(there's others, but they use the result of get() to compute the value to set, and I don't think we have a nice abstraction for that)

// #55810: Type check patterns first so we get types for all bindings.
for arm in arms {
self.check_pat_top(&arm.pat, scrut_ty, Some(scrut.span), true);
}
Copy link
Member

Choose a reason for hiding this comment

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

I assume "they're now subsumed by unreachable_patterns warnings" in the deleted comment is why you can do this change now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed #68429.

(To recap what I said in private: check/pat.rs does not mention diverges, except indirectly by type checking expressions, which only occur in literals and range patterns, but those cannot be typed at a diverging type, so removing this code has no effect.)

@@ -200,16 +183,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
arms: &'tcx [hir::Arm<'tcx>],
source: hir::MatchSource,
) {
if self.diverges.get().is_always() {
Copy link
Member

Choose a reason for hiding this comment

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

I think this was a performance microopt?

@eddyb
Copy link
Member

eddyb commented Jan 21, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Jan 21, 2020

📌 Commit 7dceff9 has been approved by eddyb

@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 Jan 21, 2020
Centril added a commit to Centril/rust that referenced this pull request Jan 21, 2020
typeck: simplify the handling of `diverges`

Some drive-by cleanup while working on `hir::ExprKind::Let`.
Ostensibly, this has some perf benefits due to reduced allocation and whatnot as well.

r? @eddyb
Centril added a commit to Centril/rust that referenced this pull request Jan 22, 2020
typeck: simplify the handling of `diverges`

Some drive-by cleanup while working on `hir::ExprKind::Let`.
Ostensibly, this has some perf benefits due to reduced allocation and whatnot as well.

r? @eddyb
bors added a commit that referenced this pull request Jan 22, 2020
Rollup of 3 pull requests

Successful merges:

 - #68421 (Update cargo, books)
 - #68422 (typeck: simplify the handling of `diverges`)
 - #68439 (Update Clippy)

Failed merges:

r? @ghost
@bors bors merged commit 7dceff9 into rust-lang:master Jan 22, 2020
@Centril Centril deleted the diverges-simplify branch January 22, 2020 11:26
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.

4 participants