Repository: carbon-language/carbon-lang
File: toolchain/check/eval.cpp (C++)

Code before:
      }
      case CARBON_KIND(SemIR::FacetTypeId facet_type_id): {
        const auto& info =
            eval_context.context().facet_types().Get(facet_type_id);
        for (const auto& interface : info.extend_constraints) {
          resolve_specific_decl(interface.specific_id);
        }
        for (const auto& interface : info.self_impls_constraints) {
          resolve_specific_decl(interface.specific_id);
        }
        break;
      }

      case CARBON_KIND(SemIR::DestInstId _):
        break;
      case CARBON_KIND(SemIR::EntityNameId _):
        break;
      case CARBON_KIND(SemIR::InstBlockId _):
        break;
      case CARBON_KIND(SemIR::InstId _):
        break;
      case CARBON_KIND(SemIR::MetaInstId _):
        break;
      case CARBON_KIND(SemIR::StructTypeFieldsId _):
        break;
      case CARBON_KIND(SemIR::TypeInstId _):
        break;

      default:
        CARBON_CHECK(
            !KindHasGetConstantValueOverload<SemIR::IdKind>::Value(
                arg_and_kind.kind()),
            "Missing case for {0} which has a GetConstantValue() overload",
            arg_and_kind.kind());
        break;
    }
  }
}

auto AddImportedConstant(Context& context, SemIR::Inst inst)
    -> SemIR::ConstantId {
  EvalContext eval_context(&context, SemIR::LocId::None);
  CARBON_CHECK(inst.kind().has_type(), "Can't import untyped instructions: {0}",
               inst.kind());
  Phase phase = GetPhase(context.constant_values(),
                         context.types().GetConstantId(inst.type_id()));
  if (!ReplaceAllFieldsWithConstantValues(eval_context, &inst, &phase)) {
    return SemIR::ConstantId::NotConstant;
  }
  return MakeConstantResult(context, inst, phase);
}

Review comment (suggestion):
Maybe:

```suggestion
      case SemIR::IdKind::For<SemIR::DestInstId>:
      case SemIR::IdKind::For<SemIR::EntityNameId>:
      case SemIR::IdKind::For<SemIR::InstBlockId>:
      case SemIR::IdKind::For<SemIR::InstId>:
      case SemIR::IdKind::For<SemIR::MetaInstId>:
      case SemIR::IdKind::For<SemIR::StructTypeFieldsId>:
      case SemIR::IdKind::For<SemIR::TypeInstId>:
        // Has a `GetConstantValue()` overload, but nothing to canonicalize for
        // the specific_id.
```

Code after:
        ResolveSpecificDeclForSpecificId(eval_context, specific_id);
        break;
      }
      case CARBON_KIND(SemIR::SpecificInterfaceId specific_interface_id): {
        ResolveSpecificDeclForSpecificId(eval_context,
                                         eval_context.specific_interfaces()
                                             .Get(specific_interface_id)
                                             .specific_id);
        break;
      }

        // These id types have a GetConstantValue() overload but that overload
        // does not canonicalize any SpecificId in the value type.
      case SemIR::IdKind::For<SemIR::DestInstId>:
      case SemIR::IdKind::For<SemIR::EntityNameId>:
      case SemIR::IdKind::For<SemIR::InstBlockId>:
      case SemIR::IdKind::For<SemIR::InstId>:
      case SemIR::IdKind::For<SemIR::MetaInstId>:
      case SemIR::IdKind::For<SemIR::StructTypeFieldsId>:
      case SemIR::IdKind::For<SemIR::TypeInstId>:
        break;

      default:
        CARBON_CHECK(
            !KindHasGetConstantValueOverload<SemIR::IdKind>::Value(
                arg_and_kind.kind()),
            "Missing case for {0} which has a GetConstantValue() overload",
            arg_and_kind.kind());
        break;
    }
  }
}

auto AddImportedConstant(Context& context, SemIR::Inst inst)
    -> SemIR::ConstantId {
  EvalContext eval_context(&context, SemIR::LocId::None);
  CARBON_CHECK(inst.kind().has_type(), "Can't import untyped instructions: {0}",
               inst.kind());
  Phase phase = GetPhase(context.constant_values(),
                         context.types().GetConstantId(inst.type_id()));
  if (!ReplaceAllFieldsWithConstantValues(eval_context, &inst, &phase)) {
    return SemIR::ConstantId::NotConstant;
  }
  return MakeConstantResult(context, inst, phase);
}

// Performs an index into a homogeneous aggregate, retrieving the specified
// element.
static auto PerformArrayIndex(EvalContext& eval_context, SemIR::ArrayIndex inst)
    -> SemIR::ConstantId {
  Phase phase = Phase::Concrete;