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

Fix SourceScope for if let bindings. #97931

Merged
merged 6 commits into from
Jun 20, 2022

Conversation

xldenis
Copy link
Contributor

@xldenis xldenis commented Jun 9, 2022

Fixes #97799.

I'm not sure how to test this properly, is there any way to observe the difference in behavior apart from ui tests? I'm worried that they would be overlooked in the case of a regression.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 9, 2022
@rust-highfive
Copy link
Collaborator

r? @nagisa

(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 Jun 9, 2022
@xldenis xldenis force-pushed the fix-if-let-source-scopes branch 2 times, most recently from 2231462 to dbcc102 Compare June 9, 2022 22:33
@rust-log-analyzer

This comment has been minimized.

Comment on lines 1806 to 1808
if let Some(scope) = scope {
self.source_scope = scope;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is done in lower_match for match statements, so I do the same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, this seems insufficient to solve the underlying issue, though its close.

Comment on lines 10 to 11
scope 1 {
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not super happy about this, but only creating a scope when we actually created bindings would require much more invasive changes since we need to bubble up the scope from declare_bindings in lower_let_expr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The other option would be to create a scope only for if let statements regardless of if they have bindings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nagisa do you consider this to be an issue? I've reduced it to only introduce scopes for if let but it can still happen

Copy link
Member

Choose a reason for hiding this comment

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

I haven't had an opportunity to give this PR a thorough look yet. I'll need to think about the implications of this approach too, so I can't promise I'll be able to get back to you this week.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fine, this bug is a blocker for some of my work but I'll be at a conference next week anyways

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 it is perfectly fine to create scopes liberally if it serves some purpose (such as simplifying the code) – it seems like it would likely be much more straightfoward to clean this up as a MIR transformation pass after the fact if this ever came up as a sticking point.

@rust-log-analyzer

This comment has been minimized.

@xldenis
Copy link
Contributor Author

xldenis commented Jun 10, 2022

There is one failing test (is ignored on my local machine?) but I would like some validation of the approach anyways if possible.

@nagisa
Copy link
Member

nagisa commented Jun 11, 2022

is there any way to observe the difference in behavior apart from ui tests

A test for this sort of issue would go into src/test/debuginfo/. var-captured-in-sendable-closure.rs might serve as a reasonable template the test necessary here.

@wesleywiser
Copy link
Member

Thanks for working on this @xldenis! I took the liberty of pushing a debuginfo test into your PR branch.

@nagisa
Copy link
Member

nagisa commented Jun 19, 2022

I feel there might be some nice way to make lower_let_expr simpler somehow, but I don’t think thinking about it needs to block the fix here.

@bors r+

@bors
Copy link
Contributor

bors commented Jun 19, 2022

📌 Commit a434e4c has been approved by nagisa

@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 Jun 19, 2022
@xldenis
Copy link
Contributor Author

xldenis commented Jun 19, 2022

I feel there might be some nice way to make lower_let_expr simpler somehow, but I don’t think thinking about it needs to block the fix here.

I also think this, but more broadly I think the whole logic including then_else_break could probably be simplified.

@bors
Copy link
Contributor

bors commented Jun 20, 2022

⌛ Testing commit a434e4c with merge 9a0b774...

@bors
Copy link
Contributor

bors commented Jun 20, 2022

☀️ Test successful - checks-actions
Approved by: nagisa
Pushing 9a0b774 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 20, 2022
@bors bors merged commit 9a0b774 into rust-lang:master Jun 20, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 20, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (9a0b774): comparison url.

Instruction count

  • Primary benchmarks: 😿 relevant regressions found
  • Secondary benchmarks: 😿 relevant regression found
mean1 max count2
Regressions 😿
(primary)
0.4% 0.5% 4
Regressions 😿
(secondary)
0.3% 0.3% 1
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
N/A N/A 0
All 😿🎉 (primary) 0.4% 0.5% 4

Max RSS (memory usage)

Results
  • Primary benchmarks: 😿 relevant regressions found
  • Secondary benchmarks: 😿 relevant regression found
mean1 max count2
Regressions 😿
(primary)
3.1% 6.0% 2
Regressions 😿
(secondary)
1.4% 1.4% 1
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
N/A N/A 0
All 😿🎉 (primary) 3.1% 6.0% 2

Cycles

Results
  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 🎉 relevant improvement found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-3.7% -3.7% 1
All 😿🎉 (primary) N/A N/A 0

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot added the perf-regression Performance regression. label Jun 20, 2022
@xldenis xldenis deleted the fix-if-let-source-scopes branch June 21, 2022 02:24
@Mark-Simulacrum Mark-Simulacrum added the perf-regression-triaged The performance regression has been triaged. label Jun 21, 2022
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. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Identifiers introduced via if let binding can't be debugged
9 participants