-
Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-traits[RETIRED] Working group: Traits[RETIRED] Working group: Traits
Description
After some discussion with @cramertj, I wanted to write up a rough idea for how to represent impl Trait in the HIR etc. The key idea is to move towards a place where we represent the abstract type that an impl Trait conceptually desugars to as a distinct "item" in the HIR.
Today, for each usage of impl Trait, we create a def-id, which basically represents the abstract type behind the impl Trait. However, in the HIR itself, we continue to mirror the syntax, so for example the variant for ImplTrait includes the bounds listed inline. This is not I think what we really want.
The refactoring then is to do the following:
- Add to the
hir::Cratea "abstract type" vector sort of like the list of bodies. - Add a
hir::AbstractTypestruct that contains the following:- A scope (which is the def-id of some item)
- A list of generics (types, lifetimes)
- A list of bounds
- Modify the
ImplTraitvariant ofhir::Tywith to include a "list of substs" in some form (and not have bounds) - During HIR lowering:
- track the generics that are in scope at any given item
- when we encounter an
impl trait, we create and push ahir::AbstractType:- scope is the enclosing item
- clone the generics that are in scope to serve as the list of generics
- move the list of bounds from the
ast::Tyinto thehir::AbstractType
- generate the
hir::ImplTrait(DefId, [T, 'a])where the "substs" are references to all the lifetimse/types in scope (I'm not entirely sure how best to represent and synthesize those?)
- If we do this right:
- Region name resolution will basically just work, and in particular there is no need to worry about early- vs late-bound resolution.
- When we add first class abstract types, they can build on this same data structure
- we'll have to solve the unification problems of course =)
Metadata
Metadata
Assignees
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-traits[RETIRED] Working group: Traits[RETIRED] Working group: Traits