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

Code before:
  }

  // Handle calls to builtins.
  if (builtin_kind != SemIR::BuiltinFunctionKind::None) {
    return MakeConstantForBuiltinCall(
        eval_context.context(), loc, call, builtin_kind,
        eval_context.inst_blocks().Get(call.args_id), phase);
  }

  return SemIR::ConstantId::NotConstant;
}

// Creates a FacetType constant.
static auto MakeFacetTypeResult(Context& context,
                                const SemIR::FacetTypeInfo& info, Phase phase)
    -> SemIR::ConstantId {
  SemIR::FacetTypeId facet_type_id = context.facet_types().Add(info);
  return MakeConstantResult(
      context,
      SemIR::FacetType{.type_id = SemIR::TypeType::SingletonTypeId,
                       .facet_type_id = facet_type_id},
      phase);
}

// Implementation for `TryEvalInst`, wrapping `Context` with `EvalContext`.

// Tail call should not be diagnosed as recursion.
// https://github.com/llvm/llvm-project/issues/125724
// NOLINTNEXTLINE(misc-no-recursion): Tail call.
static auto TryEvalInstInContext(EvalContext& eval_context,
                                 SemIR::InstId inst_id, SemIR::Inst inst)
    -> SemIR::ConstantId {
  // TODO: Ensure we have test coverage for each of these cases that can result
  // in a constant, once those situations are all reachable.
  CARBON_KIND_SWITCH(inst) {
    // These cases are constants if their operands are.
    case SemIR::AddrOf::Kind:
      return RebuildIfFieldsAreConstant(eval_context, inst,
                                        &SemIR::AddrOf::type_id,
                                        &SemIR::AddrOf::lvalue_id);
    case CARBON_KIND(SemIR::ArrayType array_type): {
      return RebuildAndValidateIfFieldsAreConstant(
          eval_context, inst,
          [&](SemIR::ArrayType result) {
            auto bound_id = array_type.bound_id;
            auto bound_inst = eval_context.insts().Get(result.bound_id);
            auto int_bound = bound_inst.TryAs<SemIR::IntValue>();
            if (!int_bound) {
              CARBON_CHECK(eval_context.constant_values()
                               .Get(result.bound_id)
                               .is_symbolic(),

Review comment (suggestion):
```suggestion
//
```

Drive-by comment on comment. :)

Code after:
  }

  // Handle calls to builtins.
  if (builtin_kind != SemIR::BuiltinFunctionKind::None) {
    return MakeConstantForBuiltinCall(
        eval_context.context(), loc, call, builtin_kind,
        eval_context.inst_blocks().Get(call.args_id), phase);
  }

  return SemIR::ConstantId::NotConstant;
}

// Creates a FacetType constant.
static auto MakeFacetTypeResult(Context& context,
                                const SemIR::FacetTypeInfo& info, Phase phase)
    -> SemIR::ConstantId {
  SemIR::FacetTypeId facet_type_id = context.facet_types().Add(info);
  return MakeConstantResult(
      context,
      SemIR::FacetType{.type_id = SemIR::TypeType::SingletonTypeId,
                       .facet_type_id = facet_type_id},
      phase);
}

// Implementation for `TryEvalInst`, wrapping `Context` with `EvalContext`.
//
// Tail call should not be diagnosed as recursion.
// https://github.com/llvm/llvm-project/issues/125724
// NOLINTNEXTLINE(misc-no-recursion): Tail call.
static auto TryEvalInstInContext(EvalContext& eval_context,
                                 SemIR::InstId inst_id, SemIR::Inst inst)
    -> SemIR::ConstantId {
  // TODO: Ensure we have test coverage for each of these cases that can result
  // in a constant, once those situations are all reachable.
  CARBON_KIND_SWITCH(inst) {
    // These cases are constants if their operands are.
    case SemIR::AddrOf::Kind:
      return RebuildIfFieldsAreConstant(eval_context, inst,
                                        &SemIR::AddrOf::type_id,
                                        &SemIR::AddrOf::lvalue_id);
    case CARBON_KIND(SemIR::ArrayType array_type): {
      return RebuildAndValidateIfFieldsAreConstant(
          eval_context, inst,
          [&](SemIR::ArrayType result) {
            auto bound_id = array_type.bound_id;
            auto bound_inst = eval_context.insts().Get(result.bound_id);
            auto int_bound = bound_inst.TryAs<SemIR::IntValue>();
            if (!int_bound) {
              CARBON_CHECK(eval_context.constant_values()
                               .Get(result.bound_id)
                               .is_symbolic(),