mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 21:41:27 +01:00
Basic support for generic bindings. (#3555)
This change adds a `BindSymbolicName` instruction for generic bindings, paralleling the existing `BindName`. A mechanism is also added to allow both kinds of binding to be accessed uniformly, for convenience in the case where the two different kinds of binding are treated the same. Generic bindings of type `type` are allowed to be used as types, although no operations are provided for such types. For now lowering treats these types as empty structs, which seems like a reasonable lowering for non-monomorphized unconstrained types.
This commit is contained in:
@@ -53,8 +53,9 @@ auto HandleVariableDecl(Context& context, Parse::VariableDeclId parse_node)
|
||||
}
|
||||
|
||||
// Extract the name binding.
|
||||
auto value_id = context.node_stack().Pop<Parse::NodeKind::BindingPattern>();
|
||||
if (auto bind_name = context.insts().Get(value_id).TryAs<SemIR::BindName>()) {
|
||||
auto value_id = context.node_stack().PopPattern();
|
||||
if (auto bind_name =
|
||||
context.insts().Get(value_id).TryAs<SemIR::AnyBindName>()) {
|
||||
// Form a corresponding name in the current context, and bind the name to
|
||||
// the variable.
|
||||
auto name_context = context.decl_name_stack().MakeUnqualifiedName(
|
||||
@@ -63,6 +64,7 @@ auto HandleVariableDecl(Context& context, Parse::VariableDeclId parse_node)
|
||||
context.decl_name_stack().AddNameToLookup(name_context, value_id);
|
||||
value_id = bind_name->value_id;
|
||||
}
|
||||
// TODO: Handle other kinds of pattern.
|
||||
|
||||
// Pop the `returned` specifier if present.
|
||||
context.node_stack()
|
||||
|
||||
Reference in New Issue
Block a user