mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add an associated entity instruction and corresponding type for interface elements. (#3730)
When declaring an associated entity in an interface -- just associated functions for now -- create an associated entity value and corresponding type to represent a "slot in a witness table". Also track the list of associated entities on the interface so that we will eventually be able to check impls against them. Associated entities are represented as the integer index of their slot in a witness table. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
parent
90369815ad
commit
33c1e9ca95
@@ -130,7 +130,9 @@ auto HandleInterfaceDefinitionStart(
|
||||
|
||||
context.inst_block_stack().Push();
|
||||
context.node_stack().Push(parse_node, interface_id);
|
||||
// TODO: Perhaps use the args_type_info_stack for a witness table.
|
||||
|
||||
// We use the arg stack to build the witness table type.
|
||||
context.args_type_info_stack().Push();
|
||||
|
||||
// TODO: Handle the case where there's control flow in the interface body. For
|
||||
// example:
|
||||
@@ -153,10 +155,13 @@ auto HandleInterfaceDefinition(Context& context,
|
||||
context.inst_block_stack().Pop();
|
||||
context.scope_stack().Pop();
|
||||
context.decl_name_stack().PopScope();
|
||||
auto associated_entities_id = context.args_type_info_stack().Pop();
|
||||
|
||||
// The interface type is now fully defined.
|
||||
auto& interface_info = context.interfaces().Get(interface_id);
|
||||
interface_info.defined = true;
|
||||
if (!interface_info.associated_entities_id.is_valid()) {
|
||||
interface_info.associated_entities_id = associated_entities_id;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user