-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Remove special-casing for argument patterns in MIR typeck (attempt to fix perf regression of #133858) #135273
base: master
Are you sure you want to change the base?
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
I suppose I should maybe cc @rust-lang/wg-compiler-performance since this is following up on a perf regression (sorry for the ping if it's unnecessary!) |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 72945be with merge 445852ab3c7ebf27903981a26388ea9877a819e3... |
…ing, r=<try> Remove special-casing for argument patterns in MIR typeck (attempt to fix perf regression of rust-lang#133858) See [my comment](rust-lang#133858 (comment)) on rust-lang#133858 for more information. This is just a guess as to what went wrong, and I haven't been able to get the profiler running locally, so I'll need a perf run to make sure this actually helps. There's one test's stderr that suffers a bit, but this was just papering over the issue anyway. Making region errors point to the correct constraints in the presence of invariance/contravariance is a broader problem; the current way it's handled is mostly based on guesswork, luck, and hoping it works out. Properly handling that (somehow) would improve the test's stderr without the hack that this PR reverts.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (445852a): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary -4.2%, secondary -0.9%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary -5.7%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 764.798s -> 766.902s (0.28%) |
// Assignments generated from lowering argument patterns shouldn't be called | ||
// "assignments" in diagnostics and aren't interesting to blame for errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe differentiating the assignments generated from lowering argument patterns to where they are lowered instead would still allow to do this diagnostics improvement at a lower cost -- or the opposite, using the same method but on the error path, where we know it's not as perf-sensitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, using the same method only on the error path doesn't seem clean to me, at least in the general case. The constraint category is used by best_blame_constraint
, which runs during borrowck on the happy path when outlives constraints from closures need to be propagated to whatever body they're defined in. We could maybe track in best_blame_constraint
whether we're emitting an error or checking a closure, but we'd risk not blaming a propagated outlives constraint from a closure if it happened to be from an argument pattern. There's already a bit of weirdness with not blaming ideal constraints when they're propagated from closures, so I'd rather not make that more confusing.
Differentiating assignments during lowering would work, I think. I'd looked into putting the information in the assignment's span (as a new kind of desugaring) to avoid needing to store anything extra in the MIR itself. I opted not to go for that though since it looked like keeping track of which assignments came from argument patterns would require an unpleasant amount of bookkeeping during either MIR or THIR construction. It wouldn't be hard, but the added complexity didn't seem worth it to me for such a niche diagnostic tweak1. I don't think I checked how much bookkeeping it'd be to do elsewhere, though.
Another option would be to give up (for now) on preventing assignments from argument patterns from being blamed, and instead just pick a different name for assignments (like "binding", maybe2) when they're syntactically not from assignment-like syntax. This should be doable entirely on the error path, and would also mean we could avoid calling match expressions "assignments" too if we'd like.
We could also try an entirely different heuristic to hopefully better address the issue this hack was papering over (see the footnote below) but it'd be a substantial enough change that it should have its own PR, and I'm honestly not confident the fix I have in mind would work. There might be some other less-fragile/hacky way of writing best_blame_constraint
altogether, but I'm not sure how if so. borrowck as written makes it difficult to tell exactly why region errors occur, hence the need for best_blame_constraint
to divine some meaning.
I'm not sure which of these options would be best to pursue, but I think just picking a different word for assignments from argument patterns (and maybe also match expressions) would be easiest and least intrusive.
Footnotes
-
I think the argument pattern is only being blamed here instead of the more relevant assignment in the function body because of how we handle invariance in diagnostics. The main trick
best_blame_constraint
uses to guess what to blame for region errors breaks down when the regions involved are related contravariantly, and we currently don't have a reliable way of knowing when that's the case. Hence all the heuristics like that one to try and blame something hopefully-reasonable even in those cases. ↩ -
I'm not totally sure on what word would be best. The nice thing about "assignment" is it's very clear about the relationship being described. ↩
Seems that was the cause of the perf regression, thanks!. However, the diagnostics change is unfortunate. @lcnr, as the reviewer for #133858, this PR reintroduces the diagnostics issue you pointed it in 50222db#r1888290353 do you prefer:
This PR removes the hack linked that also caused the perf regression, without diagnostics getting too much worse, so it's not the end of the world. It seems possible to avoid choosing the least bad outcome of the two though, so my personal preference is for the revert now, and reland the changes when both issues are fixed. What is your preference? |
seems fine to me, have to admit I don't have an opinion on this 😅 |
I also think the diagnostics regression of this pr is small enough to also be totally fine 🤷 would be happy if someone (@dianne :p) were to really dive into mir borrowck diagnostics for a while to really improve/clean them up, but I don't think small changes to the status quo (i.e. the diagnostics regression in this pr) are too impactful either way ^^' |
Ok thank you, I’ll ask in todays meeting to check with the others. |
After discussing in today's t-compiler meeting, we chose to land this perf fix with the small diagnostics regression rather than the revert. @bors r+ |
…ing, r=lqd Remove special-casing for argument patterns in MIR typeck (attempt to fix perf regression of rust-lang#133858) See [my comment](rust-lang#133858 (comment)) on rust-lang#133858 for more information. This is just a guess as to what went wrong, and I haven't been able to get the profiler running locally, so I'll need a perf run to make sure this actually helps. There's one test's stderr that suffers a bit, but this was just papering over the issue anyway. Making region errors point to the correct constraints in the presence of invariance/contravariance is a broader problem; the current way it's handled is mostly based on guesswork, luck, and hoping it works out. Properly handling that (somehow) would improve the test's stderr without the hack that this PR reverts.
💔 Test failed - checks-actions |
The job Click to see the possible cause of the failure (guessed by this bot)
|
@bors retry network issue |
(Turns out it was a skill issue, rather than a network issue, after all.) |
See my comment on #133858 for more information. This is just a guess as to what went wrong, and I haven't been able to get the profiler running locally, so I'll need a perf run to make sure this actually helps.
There's one test's stderr that suffers a bit, but this was just papering over the issue anyway. Making region errors point to the correct constraints in the presence of invariance/contravariance is a broader problem; the current way it's handled is mostly based on guesswork, luck, and hoping it works out. Properly handling that (somehow) would improve the test's stderr without the hack that this PR reverts.