Support CARBON_KIND with Any types (#6828)

This uses the `CARBON_KIND_ANY(AnyImportRef, auto import_ref):` syntax
that seemed to be favored [on
Discord](https://discord.com/channels/655572317891461132/655578254970716160/1478486848207720478).

This converted uses in the `sem_ir` directory to show it works
initially, then added `check` for full coverage plus validating the
`SemIR::` namespace discard.

Note in inst_namer.cpp, AnyBindingPattern includes FormBindingPattern
which wasn't previously handled.

I'm disabling clang-format because I think it formats with readability
issues, e.g.:

```
#define CARBON_KIND_ANY_EXPAND_AnyBinding(X, SEP)                        \
  X(::Carbon::SemIR::AliasBinding)                                       \
  SEP X(::Carbon::SemIR::FormBinding) SEP X(::Carbon::SemIR::RefBinding) \
      SEP X(::Carbon::SemIR::SymbolicBinding)                            \
          SEP X(::Carbon::SemIR::ValueBinding)
```

Since `SEP` is typically a comma, it's also a nuisance to treat as an
argument to `X` (which could get better results).

Assisted-by: Google Antigravity with Gemini 3 Flash
This commit is contained in:
Jon Ross-Perkins
2026-03-05 01:20:37 +00:00
committed by GitHub
parent 4d0003765d
commit 002b7c74ea
9 changed files with 333 additions and 153 deletions
+6 -12
View File
@@ -634,20 +634,14 @@ auto MatchContext::EmitPatternMatch(Context& context,
});
auto pattern = context.insts().Get(entry.pattern_id);
CARBON_KIND_SWITCH(pattern) {
case SemIR::RefBindingPattern::Kind:
case SemIR::SymbolicBindingPattern::Kind:
case SemIR::ValueBindingPattern::Kind:
case SemIR::FormBindingPattern::Kind:
DoEmitPatternMatch(context, pattern.As<SemIR::AnyBindingPattern>(),
entry);
case CARBON_KIND_ANY(SemIR::AnyBindingPattern, any_binding_pattern): {
DoEmitPatternMatch(context, any_binding_pattern, entry);
break;
case SemIR::FormParamPattern::Kind:
case SemIR::RefParamPattern::Kind:
case SemIR::ValueParamPattern::Kind:
case SemIR::VarParamPattern::Kind:
case SemIR::OutParamPattern::Kind:
DoEmitPatternMatch(context, pattern.As<SemIR::AnyParamPattern>(), entry);
}
case CARBON_KIND_ANY(SemIR::AnyParamPattern, any_param_pattern): {
DoEmitPatternMatch(context, any_param_pattern, entry);
break;
}
case CARBON_KIND(SemIR::ReturnSlotPattern return_slot_pattern): {
DoEmitPatternMatch(context, return_slot_pattern, entry);
break;