Generate a RequireDecl instruction for require declarations (#6318)

The `RequireDecl` instruction points, via a `RequireImplsId` to a
`RequireImpls` structure in a `ValueStore`. That structure holds the
self-type and facet type, as well as the generic id and parent scope.
`RequireImpls` is always a generic since it only appears in an
`interface` or `constraint`, which both have a generic parameter `Self`
applied to all their members.

The `RequireDecl` instruction evaluates to itself, but drops the
decl_block_id since the instructions within the `require` declaration
are not required in the canonical value which is only used for import.
And import will want to import the `RequireImpls` structure along with
the `Interface` or `NamedConstraint` structure it is in, rather than
recreate it from the decl's instructions. This also avoids repeating all
the instructions within the `require` decl in the textual semir's
constants block.

Adding the `RequireImpls` to the `Interface` or `NamedConstraint`
structure is not yet done, so they are not available for impl lookup or
import yet.
This commit is contained in:
Dana Jansens
2025-11-11 14:16:09 +00:00
committed by GitHub
parent e087209f6f
commit 81e55bed8a
21 changed files with 811 additions and 76 deletions
+2
View File
@@ -190,6 +190,7 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id,
/*is_extern=*/false, SemIR::LibraryNameId::None),
{.self_id = self_type_inst_id,
.constraint_id = constraint_type_inst_id,
// This requires that the facet type is identified.
.interface = CheckConstraintIsInterface(
context, impl_decl_id, constraint_type_inst_id),
.is_final = is_final}};
@@ -230,6 +231,7 @@ auto HandleParseNode(Context& context, Parse::ImplDefinitionStartId node_id)
impl_decl_id, impl_info.scope_id,
context.generics().GetSelfSpecific(impl_info.generic_id));
StartGenericDefinition(context, impl_info.generic_id);
// This requires that the facet type is complete.
ImplWitnessStartDefinition(context, impl_info);
context.inst_block_stack().Push();
context.node_stack().Push(node_id, impl_id);