-
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
refactor LoweringContext::lower_generics_mut #86298
Conversation
@@ -1379,58 +1379,66 @@ impl<'hir> LoweringContext<'_, 'hir> { | |||
} | |||
} | |||
|
|||
// Get the `LocalId` of `bound_pred.bounded_ty`, but only if it's a plain type parameter. | |||
fn get_def_id(&mut self, bound_pred: &WhereBoundPredicate) -> Option<LocalDefId> { |
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 you give a longer name to this function? There are already plenty of ways to get def_ids here.
Perhaps predicate_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.
I think ty_param_id
is probably more accurate.
} | ||
if def_id == self.resolver.local_def_id(param.id) { | ||
add_bounds.entry(param.id).or_default().push(bound.clone()); | ||
continue 'next_bound; | ||
} | ||
} |
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 loop can be refactored into a call to generics.params.iter().find
. The matches!
test should perhaps be an assertion on the found parameter.
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.
Are you saying that param.id
won't match unless it's a type parameter? I guess duplicate LocalDefId
s aren't supposed to happen, and we already know that def_id
is for a TyParam
. I'm also wary of adding an assertion where there wasn't one in the original code.
On the other hand, the matches!
will allow skipping of calls to self.resolver.local_def_id
for non-type generic parameters, which could have a performance impact, given that this function is kind of quadratic in the number of generic parameters.
☔ The latest upstream changes (presumably #87338) made this pull request unmergeable. Please resolve the merge conflicts. |
Further reduce nesting by using early exits and replacing the innermost loop with `.find()`. Also eliminates the labeled branch. Add comments explaining why the copying of `?Sized` bounds is necessary.
30eebcd
to
0771f9c
Compare
.map(|d| (d.base_res(), d.unresolved_segments())) | ||
{ | ||
Some((Res::Def(DefKind::TyParam, def_id), 0)) | ||
if bound_pred.bound_generic_params.is_empty() => |
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 match expression and this test do not depend on bound
. Can those be lifted out of the loop?
☔ The latest upstream changes (presumably #88061) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping from triage: |
Reduce nesting by using early exits and factoring out a helper
function. Also add comments explaining why the copying of
?Sized
bounds is necessary.r? @estebank
@rustbot label +A-hir +A-traits +C-cleanup +T-compiler