Replace form insts with actions (#7100)

See
[here](https://docs.google.com/document/d/1rWcueFwIfZox6GKVGxiUG4cBzjrZ6djXiIDGyJDtrE4/edit?tab=t.0)
for the design doc.

This also removes the default value of the `result_type_inst_id`
parameter of `HandleAction`, moves it before the action in the parameter
list, and documents it. This solves two problems:
- The default made it easy to forget, leading to unnecessary
`TypeOfInst` instructions.
- When it was present, putting it after the fairly "bulky" action
argument tended to make the callsite harder to read.
This commit is contained in:
Geoff Romer
2026-04-29 18:13:42 +00:00
committed by GitHub
parent 0124aae041
commit 4c9049346d
97 changed files with 1181 additions and 834 deletions
+19 -7
View File
@@ -5,6 +5,7 @@
#include <utility>
#include "toolchain/base/kind_switch.h"
#include "toolchain/check/action.h"
#include "toolchain/check/context.h"
#include "toolchain/check/convert.h"
#include "toolchain/check/facet_type.h"
@@ -43,8 +44,6 @@ static auto GetLeafBindingPatternInstKind(Parse::NodeKind node_kind,
: SemIR::InstKind::ValueBindingPattern;
case Parse::NodeKind::VarBindingPattern:
return SemIR::InstKind::RefBindingPattern;
case Parse::NodeKind::FormBindingPattern:
return SemIR::InstKind::FormBindingPattern;
default:
CARBON_FATAL("Unexpected node kind: {0}", node_kind);
}
@@ -301,16 +300,26 @@ static auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
context, node_id,
{.type_id = pattern_type_id, .pretty_name_id = name_id});
} else if (node_kind == Parse::NodeKind::FormBindingPattern) {
param_pattern_id =
AddInst<SemIR::FormParamPattern>(context, node_id,
{.type_id = pattern_type_id,
.pretty_name_id = name_id,
.form_id = form_id});
auto pattern_type_inst_id =
context.types().GetTypeInstId(pattern_type_id);
param_pattern_id = HandleAction<SemIR::FormParamPatternAction>(
context,
context.parse_tree()
.As<Parse::NodeIdForKind<
Parse::NodeKind::FormBindingPattern>>(node_id),
pattern_type_inst_id,
{.type_id = SemIR::InstType::TypeId,
.form_id = form_id,
.pretty_name_id = name_id});
} else {
param_pattern_id = AddInst<SemIR::ValueParamPattern>(
context, node_id,
{.type_id = pattern_type_id, .pretty_name_id = name_id});
}
if (param_pattern_id == SemIR::ErrorInst::InstId) {
result_inst_id = SemIR::ErrorInst::InstId;
break;
}
result_inst_id = make_binding_pattern(
SemIR::WrapperBindingPattern::Kind, param_pattern_id);
break;
@@ -330,6 +339,9 @@ static auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
}
case FullPatternStack::Kind::NameBindingDecl: {
if (node_kind == Parse::NodeKind::FormBindingPattern) {
return context.TODO(node_id, "support local form bindings");
}
auto incomplete_diagnostic_context = [&](auto& builder) {
CARBON_DIAGNOSTIC(IncompleteTypeInBindingDecl, Context,
"binding pattern has incomplete type {0} in name "