-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Compute liveness constraints in location-sensitive polonius #134670
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
Conversation
Again this should be gated and deactivated, but let's check if the changes have any impact: @bors try @rust-timer queue |
This comment was marked as resolved.
This comment was marked as resolved.
Compute liveness constraints in location-sensitive polonius This continues the location-sensitive prototype. In this episode, we build the liveness constraints. Reminder of the approach we're taking: we need variance data to create liveness edges in the forward/backward/both directions (respectively in the cases of covariance, contravariance, invariance) in the localized constraint graph. This PR: - introduces the holder for that, and for the liveness data in the correct shape: the transpose of what we're using today, "live regions per points". - records use/drop live region variance during tracing - records regular live region variance at the end of liveness - records the correctly shaped live region per point matrix - uses all of the above to compute the liveness constraints (There's still technically one tiny part of the liveness owl left to do, but I'll leave it for a future PR: we also need to disable the NLL optimization that avoids computing liveness for locals whose types contain a region outliving a free region -- the existing constraints make it effectively live at all points; this doesn't work under polonius) r? `@jackh726` cc `@matthewjasper`
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.
Finished benchmarking commit (df62f54): comparison URL. Overall result: ❌ regressions - 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)This benchmark run did not return any relevant results for this metric. CyclesResults (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.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 763.813s -> 762.245s (-0.21%) |
47d46ae
to
94fa197
Compare
94fa197
to
0fd4615
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.
First commit
0fd4615
to
f4e292a
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.
Two small thoughts, but r=me with or without addressing them.
if let Some(polonius_context) = typeck.polonius_context.as_mut() { | ||
let num_regions = infcx.num_region_vars(); | ||
let points_per_live_region = typeck.constraints.liveness_constraints.points(); | ||
polonius_context.record_live_regions_per_point(num_regions, points_per_live_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.
I wonder instead of using an Option
in PoloniusContext, if it's better to just use a different struct for MirTypeckResults...
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.
Yes, however I'd like to do something similar in a follow-up if you don't mind: what we eventually want to do I think is compute the localized constraints earlier (as they should only depend on mir typeck + liveness), and only store loan liveness in the context instead, with the optional debugging data that the polonius mir dump needs.
|
||
if region.is_bound() || region.is_erased() { | ||
// ignore these | ||
let Some(region) = self.universal_regions.try_to_region_vid(region) else { |
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.
Hmm, so this seems interesting. Where would we be seeing a Bound
or Erased
region? Seems curious to me that there's some subset of regions that we're essentially just ignoring.
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.
Could be worth adding a comment explaining the cases this might happen.
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.
This came about like so:
- I wanted the variance for vars and free regions and could only get it by duplicating the Generalizer's trick with
TypeRelation
, which unfortunately also yields regions that can't be converted to vids. - so I just ignored these ICE causing kinds and saw no particular changes in the tests (though there are still 6 failures left to diagnose and they could hiding in there): as far as I know there were no live regions that lacked variance due to this. There's also similarly unexpected kinds reaching borrowck, due to issues upstream and/or the ongoing effort of continuing compilation of code as deep as possible, that could be involved. To see whether we should be trying to e.g. recurse after skipping or discharging the binder in a different way that the binders callback is doing maybe, I casually brought it up with Niko who said "seems fine to ignore for now" and we didn't think more of it since then.
Since then I also discovered our test coverage is actually very weak in that area, so I'll ask you what is the correct thing to do 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.
Personally, I would prefer to just fail to compile if we ever hit this (as we do for the examples you linked).
Really, I think there's an underlying problem here that we should investigate.
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.
Sure, I'll put the ICEs back in then, and we can recheck and investigate later.
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.
Yeah, for sure we can always come back to it.
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.
Sure, I'll put the ICEs back in then, and we can recheck and investigate later.
Actually maybe not, I forgot there's too many of them and I don't believe they really matter here: we're not ignoring regions in the graph because of the (transparent to reachability) fallback if no variance is found for a region. As for 'erased
though, it was in this test that involves GCE amongst others, so imho it's fine to ignore for now.
A fixme like you initially suggested looks best under these circumstances. I'll ping you on zulip to discuss.
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.
A FIXME is fine.
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.
Ok cool, I've pushed a fixme in the last commit, explaining why it's fine to not have variance data for these for now but we still need to look into it. Let me know what you think.
This context struct will hold data to help creating localized constraints: - the live regions, with the shape matching a CFG walk, indexed per point - the variance of these live regions, represented as the direction we'll add the appropriate We also add this structure to the mir typeck to record liveness data, and make it responsible for localized constraint creation.
Following the Generalizer's structure, relating e.g. a type with itself will allow tracking the variance wrt the contained regions.
records the variance of: - use live types - drop live generic args
it missed the index and bounds info
transpose liveness matrix and record live regions at the end of MIR typeck
- add a FIXME when looking for the region variance of unexpected regions - drive-by: fix a doc comment link - drive-by: simplify the variance match using exported variants instead
f4e292a
to
089c525
Compare
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (8cdc67e): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression 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 (secondary -2.8%)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 -0.8%, secondary -2.0%)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: 761.218s -> 760.358s (-0.11%) |
This continues the location-sensitive prototype. In this episode, we build the liveness constraints.
Reminder of the approach we're taking: we need variance data to create liveness edges in the forward/backward/both directions (respectively in the cases of covariance, contravariance, invariance) in the localized constraint graph.
This PR:
(There's still technically one tiny part of the liveness owl left to do, but I'll leave it for a future PR: we also need to disable the NLL optimization that avoids computing liveness for locals whose types contain a region outliving a free region -- the existing constraints make it effectively live at all points; this doesn't work under polonius)
r? @jackh726 cc @matthewjasper