Skip to content

refactor LoweringContext::lower_generics_mut - #86298

Closed
tlyu wants to merge 1 commit into
rust-lang:masterfrom
tlyu:refactor-lower-generics-mut
Closed

refactor LoweringContext::lower_generics_mut#86298
tlyu wants to merge 1 commit into
rust-lang:masterfrom
tlyu:refactor-lower-generics-mut

Conversation

@tlyu

@tlyutlyu commented Jun 14, 2021

Copy link
Copy Markdown
Contributor

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

@rustbotrustbot added A-HIR Area: The high-level intermediate representation (HIR) A-trait-system Area: Trait system C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 14, 2021
@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 14, 2021
@JohnCSimonJohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 5, 2021
@joelpalmerjoelpalmer added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 20, 2021

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
ContributorAuthor

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.

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
ContributorAuthor

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

@bors

bors commented Jul 24, 2021

Copy link
Copy Markdown
Collaborator

☔ 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.
@tlyu
tlyuforce-pushed the refactor-lower-generics-mut branch from 30eebcd to 0771f9cCompareJuly 25, 2021 03:38
@tlyu

tlyu commented Jul 25, 2021

Copy link
Copy Markdown
ContributorAuthor

@cjgillot Thanks for the review and for the suggestions! After the merge of #87338, I rebased and did some more deindenting. Using .find() for the innermost loop also allowed the elimination of the labeled break.

@JohnCSimonJohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 15, 2021
@inquisitivecrystalinquisitivecrystal added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 24, 2021
.map(|d| (d.base_res(), d.unresolved_segments()))
{
Some((Res::Def(DefKind::TyParam, def_id), 0))
if bound_pred.bound_generic_params.is_empty() =>

Copy link
Copy Markdown
Contributor

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?

@jackh726

Copy link
Copy Markdown
Member

r? @jackh726

This might need a bit of a rebase once #88061 lands, but I think the cleanup here is still useful

@bors

bors commented Sep 8, 2021

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #88061) made this pull request unmergeable. Please resolve the merge conflicts.

@jackh726jackh726 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 9, 2021
@JohnCSimon

Copy link
Copy Markdown

Ping from triage:
@tlyu Can you please address the merge conflicts

@borsbors closed this in 746e465Oct 1, 2021
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-HIRArea: The high-level intermediate representation (HIR)A-trait-systemArea: Trait systemC-cleanupCategory: PRs that clean code up or issues documenting cleanup.S-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@tlyu@bors@jackh726@JohnCSimon@cjgillot@estebank@rust-highfive@joelpalmer@inquisitivecrystal@rustbot