-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
Some changes occurred in src/tools/clippy. cc @rust-lang/clippy |
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
Blocked on #96296. |
Neat |
facb761
to
9b29e9a
Compare
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
2caba45
to
7c0727e
Compare
This comment was marked as resolved.
This comment was marked as resolved.
7c0727e
to
5f6be7f
Compare
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 5f6be7f with merge c572965bed3faeadf9101c64e711316e43d6f1d9... |
☀️ Try build successful - checks-actions |
Queued c572965bed3faeadf9101c64e711316e43d6f1d9 with parent 4a52e0f, future comparison URL. |
Finished benchmarking commit (c572965bed3faeadf9101c64e711316e43d6f1d9): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
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 @bors rollup=never Footnotes |
I guess this is the part of |
@@ -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" } |
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.
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)?; |
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 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)?; |
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 is also wrong, the other way around.
@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. |
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.
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.
/// 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]`. |
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 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() |
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 the unwrap here be changed to an expect or uwrap_or_else(|| bug!())
?
Blocked on #97839 |
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 resolutionto correctly handle late-bound Debruijn indices. I don't know yet how to clean this up.
Based on #96296