Skip to content

Conversation

@danakj
Copy link
Contributor

@danakj danakj commented Nov 25, 2025

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::GetOrAddLookupBucket can 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.

@danakj danakj requested a review from a team as a code owner November 25, 2025 23:24
@danakj danakj requested review from dwblaikie and removed request for a team November 25, 2025 23:24
@danakj danakj force-pushed the specific-named-constraints branch from 13d2bed to d44f699 Compare November 25, 2025 23:26
@danakj danakj requested review from a team and jonmeow and removed request for a team and dwblaikie November 26, 2025 21:37
Comment on lines 924 to 928
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);
Copy link
Contributor

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);

Copy link
Contributor Author

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.

Copy link
Contributor Author

@danakj danakj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, PTAL

Comment on lines 924 to 928
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);
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants