Skip to content
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

Separate object lifetime default from lifetime resolution #97393

Closed
wants to merge 13 commits into from

Conversation

cjgillot
Copy link
Contributor

@cjgillot cjgillot commented May 25, 2022

Resolution of object lifetime default is currently done during lifetime resolution.
However, this computation happens at a higher level, fetching generics_of query to be well defined.

This separation allows to remove the computation of "early index" from lifetime resolution,
relying on the computation performed by generics_of instead.
Having a completely separate computation allows to avoid cycles between lifetime resolution and generics_of.

Caveat: this implementation still replicates the nested Binder model from lifetime resolution
to correctly handle late-bound Debruijn indices. I don't know yet how to clean this up.

Based on #96296

@rust-highfive
Copy link
Collaborator

Some changes occurred in src/tools/clippy.

cc @rust-lang/clippy

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels May 25, 2022
@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 25, 2022
@rust-log-analyzer

This comment has been minimized.

@petrochenkov
Copy link
Contributor

Blocked on #96296.

@petrochenkov petrochenkov added S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 25, 2022
@jackh726
Copy link
Member

Neat

@rust-log-analyzer

This comment has been minimized.

@bors

This comment was marked as resolved.

@cjgillot cjgillot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Jun 3, 2022
@bors

This comment was marked as resolved.

@cjgillot
Copy link
Contributor Author

cjgillot commented Jun 4, 2022

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 4, 2022
@bors
Copy link
Contributor

bors commented Jun 4, 2022

⌛ Trying commit 5f6be7f with merge c572965bed3faeadf9101c64e711316e43d6f1d9...

@bors
Copy link
Contributor

bors commented Jun 4, 2022

☀️ Try build successful - checks-actions
Build commit: c572965bed3faeadf9101c64e711316e43d6f1d9 (c572965bed3faeadf9101c64e711316e43d6f1d9)

@rust-timer
Copy link
Collaborator

Queued c572965bed3faeadf9101c64e711316e43d6f1d9 with parent 4a52e0f, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c572965bed3faeadf9101c64e711316e43d6f1d9): comparison url.

Instruction count

  • Primary benchmarks: mixed results
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
0.4% 0.9% 54
Regressions 😿
(secondary)
0.6% 1.0% 31
Improvements 🎉
(primary)
-0.3% -0.3% 11
Improvements 🎉
(secondary)
-0.7% -1.9% 27
All 😿🎉 (primary) 0.3% 0.9% 65

Max RSS (memory usage)

Results
  • Primary benchmarks: 🎉 relevant improvements found
  • Secondary benchmarks: 😿 relevant regressions found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
1.6% 2.0% 2
Improvements 🎉
(primary)
-2.4% -6.6% 9
Improvements 🎉
(secondary)
N/A N/A 0
All 😿🎉 (primary) -2.4% -6.6% 9

Cycles

Results
  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 🎉 relevant improvement found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-2.4% -2.4% 1
All 😿🎉 (primary) N/A N/A 0

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking 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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 4, 2022
@petrochenkov
Copy link
Contributor

I guess this is the part of compiler/rustc_resolve/src/late/lifetimes.rs that has nothing to do with name resolution.
r? @jackh726

@@ -1591,7 +1591,13 @@ rustc_queries! {
/// for each parameter if a trait object were to be passed for that parameter.
/// For example, for `struct Foo<'a, T, U>`, this would be `['static, 'static]`.
/// For `struct Foo<'a, T: 'a, U>`, this would instead be `['a, 'static]`.
query object_lifetime_defaults(_: LocalDefId) -> Option<&'tcx [ObjectLifetimeDefault]> {
query object_lifetime_default(_: DefId) -> Option<ObjectLifetimeDefault> {
desc { "looking up lifetime defaults for a region on an item" }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
desc { "looking up lifetime defaults for a region on an item" }
desc { "compute object lifetime defaults for a generic parameter" }

}
};
let object_lifetime_default = |i: usize| {
let param = generics.params.get(i)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. The index of argument in HIR may not correspond to the index in ty::Generics.

}
ObjectLifetimeDefault::Static => Some(Region::Static),
ObjectLifetimeDefault::Param(def_id) => {
let index = *generics.param_def_id_to_index.get(&def_id)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also wrong, the other way around.

@cjgillot
Copy link
Contributor Author

cjgillot commented Jun 5, 2022

@jackh726 I think the handling of generic arguments could be re-implemented without touching HIR at all, and would be more robust. However, I need a bit of guidance here.

Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going through this. Is it possible that we can split out commits 1,2,3,8 , and 9 into a separate PR? That seems like an "easy" first step here.

Comment on lines 1591 to 1593
/// for each parameter if a trait object were to be passed for that parameter.
/// For example, for `struct Foo<'a, T, U>`, this would be `['static, 'static]`.
/// For `struct Foo<'a, T: 'a, U>`, this would instead be `['a, 'static]`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this comment is still true?

.map(set_to_region)
.collect()
}
self.tcx.object_lifetime_defaults(def_id).unwrap().iter().map(set_to_region).collect()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the unwrap here be changed to an expect or uwrap_or_else(|| bug!())?

@jackh726
Copy link
Member

Blocked on #97839

@jackh726 jackh726 added S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 26, 2022
@cjgillot cjgillot closed this Jul 27, 2022
@cjgillot cjgillot deleted the object-lifetime-default branch July 27, 2022 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants