Skip to content

Simplify universal impl-trait collection during lowering #96644

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

Closed
6 tasks
cjgillot opened this issue May 2, 2022 · 5 comments · Fixed by #97598
Closed
6 tasks

Simplify universal impl-trait collection during lowering #96644

cjgillot opened this issue May 2, 2022 · 5 comments · Fixed by #97598
Assignees
Labels
A-HIR Area: The high-level intermediate representation (HIR) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Comments

@cjgillot
Copy link
Contributor

cjgillot commented May 2, 2022

During lowering (rustc_ast_lowering), universal impl-trait are desugared to extra generic parameters to the current item, and their bounds added to the where clause.

fn foo<T>(u: impl Bar) where T: Foo

becomes

fn foo<T, _U>(u: _U) where T: Foo, _U: Bar

This is done by carrying two vectors inside ImplTraitContext::Universal.
These vectors are only created by add_implicit_generics method, and references to them are passed around.
We should prefer having them as fields in LoweringContext.

Instructions:

  • Move the two vectors from ImplTraitContext::Universal to field in LoweringContext;
  • Take and replace the values of these fields in with_hir_id_owner, and assert that the value after the call to f is empty;
  • Add a itctx: ImplTraitContext parameter to add_implicit_generics and assert that these fields are empty on return if itctxt is not Universal;
  • Replace all calls to lower_generics by calls to add_implicit_generics;
  • Rename add_implicit_generics to lower_generics;
  • Maybe inline lower_generics_mut into lower_generics (if this simplifies the logic, not sure).

Please contact me on zulip for any question.

@cjgillot cjgillot added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. A-HIR Area: The high-level intermediate representation (HIR) E-help-wanted Call for participation: Help is requested to fix this issue. labels May 2, 2022
@spastorino spastorino self-assigned this May 2, 2022
@cameron1024
Copy link
Contributor

@rustbot claim

@rustbot rustbot assigned cameron1024 and unassigned spastorino May 28, 2022
@spastorino
Copy link
Member

@cameron1024 just in case, I have parts of this already done, and I'm doing some other bigger changes related to this stuff. Didn't send a PR yet because I want to land everything at once.

@spastorino
Copy link
Member

@cameron1024 I ended sending a PR for this because as I've said, I had some things already done. Please feel free to ping us on Zulip and we can find more tasks for you to work on if you want ❤️.

@cameron1024
Copy link
Contributor

Ah no problem, been a busy few days so I just got round to this. I'm pretty new to zulip, is there a particular place to ask?

@spastorino
Copy link
Member

@bors bors closed this as completed in 42bcd41 Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-HIR Area: The high-level intermediate representation (HIR) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants