-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
optimize NLL constraint propagation a little #49472
optimize NLL constraint propagation a little #49472
Conversation
a8a09b4
to
8144c8f
Compare
@bors try |
@@ -34,25 +51,29 @@ impl<'tcx> RegionInferenceContext<'tcx> { | |||
/// - `Ok(false)` if the walk was completed with no changes; | |||
/// - `Err(early)` if the walk was existed early by `op`. `earlyelem` is the | |||
/// value that `op` returned. | |||
pub(super) fn dfs<C>(&self, mir: &Mir<'tcx>, mut op: C) -> Result<bool, C::Early> | |||
#[inline(never)] // ensure dfs is identifiable in profiles |
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.
Should we keep this in? Seems potentially bad for performance, though it does seem somewhat unlikely.
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.
(removed comment from review that was intended as response to @Mark-Simulacrum above)
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 don't believe this would ever be criticial for performance, this is why I kept it in, but for sure it is not relevant now, given the data we're looking at. =) And it's convenient for profiling etc.
…=<try> optimize NLL constraint propagation a little Removes a bone-headed hot spot in NLL constant propagation; we were re-allocating the stack vector and hashmap as we repeated the DFS. This change shares those resources across each call. It also modifies the constraint list to be a linked list; arguably I should revert that, though, as this didn't turn out to be a perf hit and perhaps the old code was clearer? (Still, the new style appeals to me.) r? @pnkfelix
@@ -539,7 +587,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { | |||
for type_test in &self.type_tests { | |||
debug!("check_type_test: {:?}", type_test); | |||
|
|||
if self.eval_region_test(mir, type_test.point, type_test.lower_bound, &type_test.test) { | |||
if self.eval_region_test(mir, dfs_storage, type_test.point, type_test.lower_bound, &type_test.test) { |
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.
[00:05:33] tidy error: /checkout/src/librustc_mir/borrow_check/nll/region_infer/mod.rs:590: line longer than 100 chars
[00:05:34] some tidy checks failed
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.
r=me after you've addressed the nits.
@@ -34,25 +51,29 @@ impl<'tcx> RegionInferenceContext<'tcx> { | |||
/// - `Ok(false)` if the walk was completed with no changes; | |||
/// - `Err(early)` if the walk was existed early by `op`. `earlyelem` is the | |||
/// value that `op` returned. | |||
pub(super) fn dfs<C>(&self, mir: &Mir<'tcx>, mut op: C) -> Result<bool, C::Early> | |||
#[inline(never)] // ensure dfs is identifiable in profiles |
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.
(removed comment from review that was intended as response to @Mark-Simulacrum above)
@@ -143,10 +148,22 @@ pub struct Constraint { | |||
/// At this location. | |||
point: Location, | |||
|
|||
/// Later on, we thread the constraints onto a linked list | |||
/// sorted by their `sub` field. So if you had: |
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.
The use of the word "sort" in this comment confused me: "There's a single list and its sorted by the sub
field? Or there's a bunch of lists and each is individually sorted by the sub
field -- but how is there any kind of sort order here?"
I usually treat the term "sort" as meaning "make an ordered sequence"; but here you mean it more as "group together (via a linked list) all of the constraints that have the same sub
field."
@@ -403,10 +422,23 @@ impl<'tcx> RegionInferenceContext<'tcx> { | |||
infcx: &InferCtxt<'_, 'gcx, 'tcx>, | |||
mir: &Mir<'tcx>, | |||
mir_def_id: DefId, | |||
) -> Option<ClosureRegionRequirements<'gcx>> { | |||
common::time(infcx.tcx.sess, &format!("solve({:?})", mir_def_id), || { |
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.
Consider using something a little more specific than just "solve" here, like "solve region constraints", just to ease lives of other users of -Z time-passes
☀️ Test successful - status-travis |
@Mark-Simulacrum try run succeeded, were you gonna do a perf run? |
Totally forgot, but I've started it now. We can land without too, I don't particularly care. |
551d512
to
ca8176d
Compare
@bors r=pnkfelix |
📌 Commit ca8176d has been approved by |
@Mark-Simulacrum as usual, I am unable to construct a working URL :( This is what I tried: But I know it's gonna' be faster. UPDATE: Oh, hey, it works now! But I got the order of the revisions backward. Try this: |
…=pnkfelix optimize NLL constraint propagation a little Removes a bone-headed hot spot in NLL constant propagation; we were re-allocating the stack vector and hashmap as we repeated the DFS. This change shares those resources across each call. It also modifies the constraint list to be a linked list; arguably I should revert that, though, as this didn't turn out to be a perf hit and perhaps the old code was clearer? (Still, the new style appeals to me.) r? @pnkfelix
☀️ Test successful - status-appveyor, status-travis |
Removes a bone-headed hot spot in NLL constant propagation; we were re-allocating the stack vector and hashmap as we repeated the DFS. This change shares those resources across each call.
It also modifies the constraint list to be a linked list; arguably I should revert that, though, as this didn't turn out to be a perf hit and perhaps the old code was clearer? (Still, the new style appeals to me.)
r? @pnkfelix