Make named constraint eval to a FacetType with itself in it (#6308)

This requires declared FacetTypes to hold NamedConstraintIds (along with
a specific) that are named in an extend or impls requirement. We add
support to stringify and formatter to display the named constraints in
the facet type, and special case when a facet type contains a single
extend named constraint, like we did for a single extend interface.

This means that `RequireIndentifiedFacetType` can now fail, if the facet
type contains a forward-declared named constraint. Add the appropriate
diagnostics for each call to this function, and note the ones that
should change to `RequireCompleteFacetType` in the future with TODOs.

We also add tests for using facet types that can or can't be identified,
or completed, with named constraints in them.
This commit is contained in:
Dana Jansens
2025-10-31 22:10:35 +00:00
committed by GitHub
parent ed31a6dbe8
commit ca3f95faa6
27 changed files with 1011 additions and 432 deletions
+10 -1
View File
@@ -296,7 +296,16 @@ auto CheckConstraintIsInterface(Context& context, SemIR::InstId impl_decl_id,
return SemIR::SpecificInterface::None;
}
auto identified_id = RequireIdentifiedFacetType(context, *facet_type);
auto identified_id = RequireIdentifiedFacetType(context, *facet_type, [&] {
CARBON_DIAGNOSTIC(ImplOfUnidentifiedFacetType, Error,
"facet type {0} cannot be identified in `impl as`",
InstIdAsType);
return context.emitter().Build(impl_decl_id, ImplOfUnidentifiedFacetType,
constraint_id);
});
if (!identified_id.has_value()) {
return SemIR::SpecificInterface::None;
}
const auto& identified = context.identified_facet_types().Get(identified_id);
if (!identified.is_valid_impl_as_target()) {
CARBON_DIAGNOSTIC(ImplOfNotOneInterface, Error,