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
+2 -9
View File
@@ -520,18 +520,11 @@ static auto MarkPatternUnused(Context& context, SemIR::InstId inst_id) -> bool {
auto current_inst_id = worklist.pop_back_val();
auto inst = context.insts().Get(current_inst_id);
CARBON_KIND_SWITCH(inst) {
case SemIR::OutParamPattern::Kind:
case SemIR::RefParamPattern::Kind:
case SemIR::ValueParamPattern::Kind:
case SemIR::VarParamPattern::Kind: {
auto param = inst.As<SemIR::AnyParamPattern>();
case CARBON_KIND_ANY(SemIR::AnyParamPattern, param): {
worklist.push_back(param.subpattern_id);
break;
}
case SemIR::RefBindingPattern::Kind:
case SemIR::SymbolicBindingPattern::Kind:
case SemIR::ValueBindingPattern::Kind: {
auto bind = inst.As<SemIR::AnyBindingPattern>();
case CARBON_KIND_ANY(SemIR::AnyBindingPattern, bind): {
auto& name = context.entity_names().Get(bind.entity_name_id);
name.is_unused = true;
// We treat `_` as not marking the pattern as unused for the purpose of