-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Get specific interfaces with correct specific from named constraints #6435
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
base: trunk
Are you sure you want to change the base?
Conversation
13d2bed to
d44f699
Compare
toolchain/check/type_completion.cpp
Outdated
| auto require_specific_id = MakeCopyOfSpecificAndAppendSelf( | ||
| context, loc_id, impls.specific_id, require.generic_id, | ||
| GetRequireImplsSpecificSelf(context, require)); | ||
| auto facet_type_id = GetFacetTypeInSpecific( | ||
| context, require.facet_type_inst_id, require_specific_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.
The way these are composed, it seems like the APIs are intended to be generic, but it seems like (for example) MakeCopyOfSpecificAndAppendSelf and GetRequireImplsSpecificSelf are tightly associated since they're both assuming operation on the same structure. Had you considered a single function that took in require and returned facet_type_id?
e.g. auto facet_type_id = GetFacetTypeInRequireImpls(context, loc_id, impls.specific_id, require);
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.
Yeah I was just trying to break things into smaller pieces. I have been thinking about how I will need to do this same operation in more places. In particular, in an impl declaration, we will need to find all the required interfaces (in the impl's specific facet type) and ensure they have been implemented already. So I think this will need to become a single operation that is exposed elsewhere, probably from sem_ir/require_impls.h. But for now, leaving it here.
I can combine some of these steps.
danakj
left a comment
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.
Thanks, PTAL
toolchain/check/type_completion.cpp
Outdated
| auto require_specific_id = MakeCopyOfSpecificAndAppendSelf( | ||
| context, loc_id, impls.specific_id, require.generic_id, | ||
| GetRequireImplsSpecificSelf(context, require)); | ||
| auto facet_type_id = GetFacetTypeInSpecific( | ||
| context, require.facet_type_inst_id, require_specific_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.
Yeah I was just trying to break things into smaller pieces. I have been thinking about how I will need to do this same operation in more places. In particular, in an impl declaration, we will need to find all the required interfaces (in the impl's specific facet type) and ensure they have been implemented already. So I think this will need to become a single operation that is exposed elsewhere, probably from sem_ir/require_impls.h. But for now, leaving it here.
I can combine some of these steps.
When forming an IdentifiedFacetType, we collect interfaces named by require decls in named constraints that the facet type refers to. These interfaces come with a specific, but the require decl is inside an named constraint which may be generic. So we need the specific being applied to the containing named constraint to also be applied to the require decl and its target interfaces.
This uncovered that the facet type in require decls was not being imported correctly, as it was not being attached to the require decl's generic. This is fixed by making import of RequireImplsDecl multiphase, so that the decl instruction exists before we resolve the facet type within it. And by pointing the generic importing machinery to the RequireImplsDecl, and from there to the RequireImpls structure to get the generic id.
Then
ImplStore::GetOrAddLookupBucketcan use an IdentifiedFacetType to correctly get the interface being impl'd, both in the local and the imported named constraint case. Which allows us to correctly diagnose redeclarations in the impl file of an impl of an interface through a named constraint. And to correctly not diagnose them when the specific in the generic named constraint differs from other decls.