-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Remove placeholders completely #130227
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?
Remove placeholders completely #130227
Conversation
r? nikomatsakis |
@rustbot author |
This comment has been minimized.
This comment has been minimized.
07b10ca
to
6ab45ce
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.
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.
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #130724) made this pull request unmergeable. Please resolve the merge conflicts. |
da9ccef
to
4633c56
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…mpletely, r=<try> [WIP] Remove placeholders completely This PR does shotgun surgery on borrowck to remove all special handling of placeholders, completely replacing them with a preprocessing step that rewrites placeholder leaks into constraints, removing constraint propagation of placeholders and all logic used to detect placeholder violations during error reporting. This finishes what rust-lang#123720 started. The new method works like this: 1. during SCC construction, some information about SCC membership and reachability is retained 2. just after SCC construction, a constraint `r - (from: to_invalid) - > 'static` is added when `r` is the representative of an SCC and 1. that SCC either has had its universe shrunk because it reaches a region with a smaller one (in which case `to_invalid` is the smallest-universed region it reaches), or if it reaches a region with a too large universe that isn't part of the SCC (in which case `to_invalid` is the region with a too large universe). In either case, `from` is also `r`. 2. some region `reaches` in `r`'s SCC reaches another placeholder, `reached`, in which case the added constraint is `r -> (reaches: reached) 'static`. Through clever choice of defaults (chosing minimum elements), `reached` will be `r` if at all possible. When tracing errors for diagnostics one of these special constraints along a path are treated much like a HTTP redirect: if we are explaining `from: to` and reach an edge with `reaches: invalid` we stop the search and start following `reaches: invalid` instead. When doing this the implicit edges `x: 'static` for every region `x` are ignored, since the search would otherwise be able to cheat by going through 'static and re-find the same edge again. A bunch of optimisations are possible: - Conservatively add constraints, e.g. one per SCC. May worsen error tracing! - as a final pass, allow fusing the annotations for the SCC after adding the extra constraints to remove unnecessary information and save memory. This could be done cheaply since we already iterate over the entire SCC. - currently, if constraints are added the entire set of SCCs are recomputed. This is of course rather wasteful, and we could maybe do better. There are a bunch of rather nice bonuses: - We now don't need to expose region indices in `MirTypeckRegionConstraints` to the entire crate. The only entry point is `placeholder_region()` so correctness of the indices is now guaranteed - A lot of things that were previously iterations over lists is now a single lookup - The constraint graph search functions are simple and at least one of them can now take a proper region as target rather than a predicate function. The only case that needs the predicate argument to `find_constraint_path_to()` is `find_sub_region_live_at()`, which may or may not be possible to work around. r? nikomatsakis
Failing test cases left: "for any two lifetimes" becomes "for any one", with the other replaced by the user-supplied region variable
missing "note: due to current limitations in the borrow checker, this implies a
|
This comment has been minimized.
This comment has been minimized.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
The change consists of a few changed spans and a reordering of emitted errors. This seems benign to me, and moreover very difficult to fix since the old behaviour relies on information that is no longer retained.
733bb16
to
55e292d
Compare
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.
have to take a bit more time to properly review this, some thoughts as i skimmed over it
☔ The latest upstream changes (presumably #138719) made this pull request unmergeable. Please resolve the merge conflicts. |
During work on rust-lang#130227, I discovered several situations not covered by any previously existing UI test. This commit introudces tests to cover that.
This rewires SCC annotations to have them be a separate, visitor-type data structure. It was broken out of rust-lang#130227, which needed them to be able to remove unused annotations after computation without recomputing the SCCs themselves. As a drive-by it also removes some redundant code from the hot loop in SCC construction for a performance improvement.
…c-annotations, r=<try> Decouple SCC annotations from SCCs This rewires SCC annotations to have them be a separate, visitor-type data structure. It was broken out of rust-lang#130227, which needed them to be able to remove unused annotations after computation without recomputing the SCCs themselves. As a drive-by it also removes some redundant code from the hot loop in SCC construction for a performance improvement. r? lcnr
During work on rust-lang#130227, I discovered several situations not covered by any previously existing UI test. This commit introudces tests to cover that.
…, r=lcnr Add tests for two untested cases of placeholder relations During work on rust-lang#130227, I discovered several situations not covered by any previously existing UI test. This commit introudces tests to cover that. r? lcnr
…, r=lcnr Add tests for two untested cases of placeholder relations During work on rust-lang#130227, I discovered several situations not covered by any previously existing UI test. This commit introudces tests to cover that. r? lcnr
During work on rust-lang#130227, I discovered several situations not covered by any previously existing UI test. This commit introudces tests to cover that.
This rewires SCC annotations to have them be a separate, visitor-type data structure. It was broken out of rust-lang#130227, which needed them to be able to remove unused annotations after computation without recomputing the SCCs themselves. As a drive-by it also removes some redundant code from the hot loop in SCC construction for a performance improvement.
…r=lcnr Add tests for two untested cases of placeholder relations During work on rust-lang#130227, I discovered several situations not covered by any previously existing UI test. This commit introudces tests to cover that. r? lcnr
During work on rust-lang#130227, I discovered several situations not covered by any previously existing UI test. This commit introudces tests to cover that.
This PR does shotgun surgery on borrowck to remove all special handling of placeholders, completely replacing them with a preprocessing step that rewrites placeholder leaks into constraints, removing constraint propagation of placeholders and most of the logic used to detect placeholder violations during error reporting. This finishes what #123720 started. Due to the already sprawling scope of this PR, not all the breaks are clean. In particular, some of the error reporting code can almost certainly be further simplified.
The new method works like this:
r - (from: to_invalid) - > 'static
is added whenr
is the representative of an SCC andto_invalid
is the smallest-universed region it reaches), or if it reaches a region with a too large universe that isn't part of the SCC (in which caseto_invalid
is the region with a too large universe). In either case,from
is alsor
.reaches
inr
's SCC reaches another placeholder,reached
, in which case the added constraint isr -> (reaches: reached) 'static
. Through clever choice of defaults (chosing minimum elements),reached
will ber
if at all possible.When tracing errors for diagnostics one of these special constraints along a path are treated much like a HTTP redirect: if we are explaining
from: to
and reach an edge withreaches: invalid
we stop the search and start followingreaches: invalid
instead. When doing this the implicit edgesx: 'static
for every regionx
are ignored, since the search would otherwise be able to cheat by going through 'static and re-find the same edge again.Type-tests are also rewritten to account for placeholder issues. In particular, if a bound implies
: 'static
, this is flagged using a new variant, and if a test is guaranteed to always fail (e.g. if an equals bound reaches different placeholders), it is replaced with a bound that is always unsatisfied.A bunch of optimisations are possible:
Conservatively add constraints, e.g. one per SCC. May worsen error tracing!as a final pass, allow fusing the annotations for the SCC after adding the extra constraints to remove unnecessary information and save memory. This could be done cheaply since we already iterate over the entire set of SCCs.There are a bunch of rather nice bonuses:
MirTypeckRegionConstraints
to the entire crate. The only entry point isplaceholder_region()
so correctness of the indices is now guaranteedfind_constraint_path_to()
isfind_sub_region_live_at()
, which may or may not be possible to work around.r? nikomatsakis