-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Region inference: Use outlives-static constraints in constraint search #140737
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
base: master
Are you sure you want to change the base?
Region inference: Use outlives-static constraints in constraint search #140737
Conversation
f4af776
to
72e81ea
Compare
72e81ea
to
9a1face
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
7902ae9
to
6539053
Compare
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #140466) made this pull request unmergeable. Please resolve the merge conflicts. |
6539053
to
a209255
Compare
(We may also want a perf run to see if I messed something up badly) |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Region inference: Use outlives-static constraints in constraint search Revise the extra `r: 'static` constraints added upon universe issues to add an explanation, and use that explanation during constraint blame search. This greatly simplifies the region inference logic, which now does not need to reverse-engineer the event that caused a region to outlive `'static`. This cosmetically changes the output of two UI tests. I blessed them i separate commits with separate motivations, but that can of course be squashed as desired. We probably want that. The PR was extracted out of #130227 and consists of one-third of its functional payload. It is based on #140466, so that has to land first. We probably want a perf run of this. It shouldn't have much of an impact and a positive one if any, but I have been wrong before. In particular, SCC annotations are heavier now. r? lcnr
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (0d3d480): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 0.4%, secondary -1.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 753.257s -> 756.017s (0.37%) |
a209255
to
335fa61
Compare
Revise the extra `r: 'static` constraints added upon universe issues to add an explanation, and use that explanation during constraint blame search. This greatly simplifies the region inference logic, which now does not need to reverse-engineer the event that caused a region to outlive 'static.
335fa61
to
6a325fd
Compare
let blame_to = if annotation.representative.rvid() == max_u_rvid { | ||
// The SCC's representative is not nameable from some region | ||
// that ends up in the SCC. | ||
let small_universed_rvid = find_region( |
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.
why can we not use the region from max_nameable_universe
here?
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.
That sometimes slightly worsens the error messages (or at least causes diagnostics regressions) because previous logic picked the first smallest region. It's very annoying.
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.
can you dump the changes caused by this somewhere? I personally believe that some amount of diagnostics regression is acceptable if it cleans up the code/removes subtly different variations of the same concept.
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.
Here's the an output from the UI tests attached when doing that!
$ ./x test ui --keep-stage 1 > simpler-choice-blame-ui-tests.log
simpler-choice-blame-ui-tests.log
There's a bunch of squiggly lines getting longer, which I think is mostly harmless:
- tests/ui/higher-ranked/higher-ranked-lifetime-error.rs: I'd say fully harmless, a slightly longer squiggly line
- tests/ui/higher-ranked/trait-bounds/due-to-where-clause.rs same as above
- tests/ui/mismatched_types/hr-projection-mismatch.rs#current same as above
Then there is a duplicate of a diagnostic due to a longer span which we may or may not care about, in tests/ui/associated-inherent-types/issue-111404-1.rs
. This should be very fixable in the error reporting phase, but that part of the code is absolutely incomprehensible (though I've tried), and I've simply given up on it.
I remember this being much, much worse! Maybe this is acceptable?
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.
If you think this is ok, say the word and I'll dump like half the file to get rid of this extra logic!
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.
from placeholder to an existential should error, shouldn't it?
we only add outlives-static
whenever we've got "scc_which_cannot_name reaches(transitively outlives) placeholder" constraints 🤔
My question above was, why does
rust/compiler/rustc_borrowck/src/region_infer/mod.rs
Lines 1796 to 1810 in b03635d
// If we are passing through a constraint added because `'lt: 'unnameable`, | |
// where cannot name `'unnameable`, redirect search towards `'unnameable`. | |
let due_to_placeholder_outlives = path.iter().find_map(|c| { | |
if let ConstraintCategory::OutlivesUnnameablePlaceholder(lt, unnameable) = c.category { | |
Some((lt, unnameable)) | |
} else { | |
None | |
} | |
}); | |
let path = if let Some((lt, unnameable)) = due_to_placeholder_outlives { | |
// This the `false` argument is what prevents circular reasoning here! | |
self.constraint_path_to(lt, |r| r == unnameable, false).unwrap().0 | |
} else { | |
path | |
}; |
constraint_path_to(lt, ..)
instead of constraint_path_to(from_region, ..)
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.
My question above was [...]
I think this was a misthought/optimisation I did at some point (since it should shorten the path by starting from somewhere in the middle as opposed to restarting all of the search). The general “complete context-less redirect” model also appealed to me. Changing the behaviour does restore some of the original output for tests/ui/nll/ice-106874.stderr
, as far as I can tell, creates no other regressions, and generally simplifies everything so I’ll uh just go with that.
You’re very good at spotting my bullshit!
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.
I would love for u to look into why that other constraint exists.
This is my next order of business, because if I can show that then we can bless the note-less output and have an Even Simpler Implementation™
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.
from placeholder to an existential should error, shouldn't it?
It should, and it's handled separately in the next PR after this one! While writing this I discovered universes on random regions so I've resorted to partially mindlessly reimplementing the previous logic (which, among other things, deals with a member of an SCC being unable to name the representative, which is tricky to express without adding tons of extra outlives-static constraints -- a thing we may want to do!).
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.
Interesting update: I dug into this, and it turns out the Complicated Logic I had before is actually essential to discovering placeholders outliving existentials. I'm not sure how exactly, which is an indication it was way, way too clever.
This is somewhat good news, because it means I must fold in the next PR, which does this logic much clearer and more straightforward.
ecc1d79
to
a34f352
Compare
Co-authored-by: lcnr <[email protected]>
a34f352
to
0328df9
Compare
|
Co-authored-by: lcnr <[email protected]>
8695bb5
to
b03635d
Compare
☔ The latest upstream changes (presumably #144469) made this pull request unmergeable. Please resolve the merge conflicts. |
Revise the extra
r: 'static
constraints added upon universe issues to add an explanation, and use that explanation during constraint blame search. This greatly simplifies the region inference logic, which now does not need to reverse-engineer the event that caused a region to outlive'static
.This cosmetically changes the output of two UI tests. I blessed them i separate commits with separate motivations, but that can of course be squashed as desired. We probably want that.
The PR was extracted out of #130227 and consists of one-third of its functional payload.
r? lcnr