ronantakizawa/codereview-bench huggingface dataset:
Repository: carbon-language/carbon-lang
File: common/error_test.cpp (C++)

Code before:
};

TYPED_TEST(ErrorOrTest, AssignOrReturnNoErrorAcrossErrorTypes) {
  using TestErrorOr = typename TestFixture::template TestErrorOrTemp<int>;
  auto result = []() -> ErrorOr<int> {
    CARBON_ASSIGN_OR_RETURN(int a, TestErrorOr(1));
    CARBON_ASSIGN_OR_RETURN(const int b, []() -> TestErrorOr {
      CARBON_ASSIGN_OR_RETURN(
          int inner, (static_cast<ErrorOr<int, AnotherCustomError>>(2)));
      return inner;
    }());
    int c = 0;
    CARBON_ASSIGN_OR_RETURN(c, TestErrorOr(3));
    return a + b + c;
  }();
  EXPECT_THAT(result, IsSuccess(Eq(6)));
}

TYPED_TEST(ErrorOrTest, AssignOrReturnErrorAcrossErrorTypes) {
  using TestErrorOr = typename TestFixture::template TestErrorOrTemp<int>;
  auto result = []() -> ErrorOr<int> {
    CARBON_ASSIGN_OR_RETURN(int a, TestErrorOr(1));
    CARBON_ASSIGN_OR_RETURN(const int b, []() -> TestErrorOr {
      CARBON_ASSIGN_OR_RETURN(int inner,
                              (static_cast<ErrorOr<int, AnotherCustomError>>(
                                  AnotherCustomError())));
      return inner;
    }());
    int c = 0;
    CARBON_ASSIGN_OR_RETURN(c, TestErrorOr(3));
    return a + b + c;
  }();

  // When directly using the `Error` type, the explicit custom type above has
  // its message preserved. When testing against `CustomError`, that one
  // overrides the message.
  if constexpr (std::same_as<TypeParam, Error>) {
    EXPECT_THAT(result, IsError("Another custom test error!"));
  } else {
    EXPECT_THAT(result, IsError("Custom test error!"));
  }
}

}  // namespace
}  // namespace Carbon


Review comment (suggestion):
```suggestion
                              (ErrorOr<int, AnotherCustomError>(
                                  AnotherCustomError()));
```

Similar to the above

Code after:
    CARBON_ASSIGN_OR_RETURN(int a, TestErrorOr(1));
    CARBON_ASSIGN_OR_RETURN(const int b, []() -> TestErrorOr {
      CARBON_ASSIGN_OR_RETURN(int inner, (ErrorOr<int, AnotherCustomError>(2)));
      return inner;
    }());
    int c = 0;
    CARBON_ASSIGN_OR_RETURN(c, TestErrorOr(3));
    return a + b + c;
  }();
  EXPECT_THAT(result, IsSuccess(Eq(6)));
}

TYPED_TEST(ErrorOrTest, AssignOrReturnErrorAcrossErrorTypes) {
  using TestErrorOr = ErrorOr<int, TypeParam>;
  auto result = []() -> ErrorOr<int> {
    CARBON_ASSIGN_OR_RETURN(int a, TestErrorOr(1));
    CARBON_ASSIGN_OR_RETURN(const int b, []() -> TestErrorOr {
      CARBON_ASSIGN_OR_RETURN(
          int inner, (ErrorOr<int, AnotherCustomError>(AnotherCustomError())));
      return inner;
    }());
    int c = 0;
    CARBON_ASSIGN_OR_RETURN(c, TestErrorOr(3));
    return a + b + c;
  }();

  // When directly using the `Error` type, the explicit custom type above has
  // its message preserved. When testing against `CustomError`, that one
  // overrides the message.
  if constexpr (std::same_as<TypeParam, Error>) {
    EXPECT_THAT(result, IsError("Another custom test error!"));
  } else {
    EXPECT_THAT(result, IsError("Custom test error!"));
  }
}

}  // namespace
}  // namespace Carbon
Repository: carbon-language/carbon-lang
File: toolchain/check/facet_type.cpp (C++)

Code before:
  for (auto& constraint : rewrites) {
    auto lhs_access =
        context.insts().TryGetAs<SemIR::ImplWitnessAccess>(constraint.lhs_id);
    if (!lhs_access) {
      continue;
    }

    rewrite_values.InsertNotRewritten(context, *lhs_access, constraint.rhs_id);
  }
  for (auto& constraint : rewrites) {
    auto lhs_access =
        context.insts().TryGetAs<SemIR::ImplWitnessAccess>(constraint.lhs_id);
    if (!lhs_access) {
      continue;
    }

    rewrite_values.SetBeingRewritten(context, *lhs_access);

    auto replace_witness_callbacks =
        SubstImplWitnessAccessCallbacks(&context, loc_id, &rewrite_values);
    auto subst_rhs_id =
        SubstInst(context, constraint.rhs_id, replace_witness_callbacks);
    constraint.rhs_id = rewrite_values.SetFullyRewritten(
        context, loc_id, *lhs_access, constraint.lhs_id, subst_rhs_id);

    if (constraint.rhs_id == SemIR::ErrorInst::InstId) {
      return false;
    }
  }

  // Drop any duplicate rewrites in the `rewrites` vector by walking through the
  // `rewrite_values` map and dropping the computed RHS value for each LHS the
  // first time we see it, and erasing the constraint from the vector if we see
  // the same LHS again.
  size_t keep_size = rewrites.size();
  for (size_t i = 0; i < keep_size;) {
    auto& constraint = rewrites[i];

    auto lhs_access =
        context.insts().TryGetAs<SemIR::ImplWitnessAccess>(constraint.lhs_id);
    if (!lhs_access) {
      ++i;
      continue;
    }

    auto* rewrite_value = *rewrite_values.FindRef(context, *lhs_access);
    auto rhs_id = std::exchange(rewrite_value->inst_id, SemIR::InstId::None);
    if (rhs_id == SemIR::InstId::None) {
      std::swap(rewrites[i], rewrites[keep_size - 1]);
      --keep_size;
    } else {

Review comment (refactor):
Maybe we could skip updating `rhs_id` here, and instead update it in the loop below when we extract it from the rewrite values list?

Code after:
  // duplicate rewrites in the `rewrites` vector by walking through the
  // `rewrite_values` map and dropping the computed RHS value for each LHS the
  // first time we see it, and erasing the constraint from the vector if we see
  // the same LHS again.
  size_t keep_size = rewrites.size();
  for (size_t i = 0; i < keep_size;) {
    auto& constraint = rewrites[i];

    auto lhs_access =
        context.insts().TryGetAs<SemIR::ImplWitnessAccess>(constraint.lhs_id);
    if (!lhs_access) {
      ++i;
      continue;
    }

    auto& rewrite_value = *rewrite_values.FindRef(context, *lhs_access);
    auto rhs_id = std::exchange(rewrite_value.inst_id, SemIR::InstId::None);
    if (rhs_id == SemIR::InstId::None) {
      std::swap(rewrites[i], rewrites[keep_size - 1]);
      --keep_size;
    } else {
      rewrites[i].rhs_id = rhs_id;
      ++i;
    }
  }
  rewrites.erase(rewrites.begin() + keep_size, rewrites.end());

  return true;
}

}  // namespace Carbon::Check
Repository: carbon-language/carbon-lang
File: toolchain/diagnostics/diagnostic_emitter_test.cpp (C++)

Code before:
  CARBON_DIAGNOSTIC(TestDiagnostic, Warning, "simple warning");
  CARBON_DIAGNOSTIC(TestDiagnosticNote, Note, "note");
  EXPECT_CALL(
      consumer_,
      HandleDiagnostic(IsDiagnostic(
          Diagnostics::Level::Warning,
          ElementsAre(
              IsDiagnosticMessage(Diagnostics::Kind::TestDiagnostic,
                                  Diagnostics::Level::Warning, 1, 1,
                                  "simple warning"),
              IsDiagnosticMessage(Diagnostics::Kind::TestDiagnosticNote,
                                  Diagnostics::Level::Note, 1, 2, "note")))));
  emitter_.Build(1, TestDiagnostic).Note(2, TestDiagnosticNote).Emit();
}

TEST_F(EmitterTest, Flush) {
  bool flushed = false;
  auto flush_fn = [&]() { flushed = true; };

  {
    FakeEmitter emitter(&consumer_);
    emitter.AddFlushFn(flush_fn);

    // Registering the function does not flush.
    EXPECT_FALSE(flushed);
    flushed = false;

    // Explicit calls to `Flush` should flush.
    emitter.Flush();
    EXPECT_TRUE(flushed);
    flushed = false;

    {
      Diagnostics::AnnotationScope annot(&emitter, [](auto&) {});

      // Registering an annotation scope should flush.
      EXPECT_TRUE(flushed);
      flushed = false;
    }

    // Unregistering an annotation scope should flush.
    EXPECT_TRUE(flushed);
    flushed = false;
  }

  // Destroying the emitter should flush.
  EXPECT_TRUE(flushed);
  flushed = false;
}

}  // namespace

Review comment (suggestion):
```suggestion
```

Just feels a little redundant here

Code after:
  CARBON_DIAGNOSTIC(TestDiagnostic, Warning, "simple warning");
  CARBON_DIAGNOSTIC(TestDiagnosticNote, Note, "note");
  EXPECT_CALL(
      consumer_,
      HandleDiagnostic(IsDiagnostic(
          Diagnostics::Level::Warning,
          ElementsAre(
              IsDiagnosticMessage(Diagnostics::Kind::TestDiagnostic,
                                  Diagnostics::Level::Warning, 1, 1,
                                  "simple warning"),
              IsDiagnosticMessage(Diagnostics::Kind::TestDiagnosticNote,
                                  Diagnostics::Level::Note, 1, 2, "note")))));
  emitter_.Build(1, TestDiagnostic).Note(2, TestDiagnosticNote).Emit();
}

TEST_F(EmitterTest, Flush) {
  bool flushed = false;
  auto flush_fn = [&]() { flushed = true; };

  {
    FakeEmitter emitter(&consumer_);
    emitter.AddFlushFn(flush_fn);

    // Registering the function does not flush.
    EXPECT_FALSE(flushed);

    // Explicit calls to `Flush` should flush.
    emitter.Flush();
    EXPECT_TRUE(flushed);
    flushed = false;

    {
      Diagnostics::AnnotationScope annot(&emitter, [](auto&) {});

      // Registering an annotation scope should flush.
      EXPECT_TRUE(flushed);
      flushed = false;
    }

    // Unregistering an annotation scope should flush.
    EXPECT_TRUE(flushed);
    flushed = false;
  }

  // Destroying the emitter should flush.
  EXPECT_TRUE(flushed);
  flushed = false;
}

}  // namespace
}  // namespace Carbon::Testing
Repository: carbon-language/carbon-lang
File: toolchain/check/type_structure.h (C/C++)

Code before:
  static auto ConsumeRhsSymbolic(
      llvm::SmallVector<Structural>::const_iterator& lhs_cursor,
      llvm::SmallVector<ConcreteType>::const_iterator& lhs_concrete_cursor,
      llvm::SmallVector<Structural>::const_iterator& rhs_cursor) -> bool;

  // The structural position of concrete and symbolic values in the type.
  llvm::SmallVector<Structural> structure_;

  // Indices of the symbolic entries in structure_.
  llvm::SmallVector<int> symbolic_type_indices_;

  // The related value for each `Concrete` and `ConcreteOpenParen` entry in
  // the type `structure_`, in the same order. See `ConcreteType`.
  llvm::SmallVector<ConcreteType> concrete_types_;
};

// Constructs the TypeStructure for a self type or facet value and an interface
// constraint (e.g. `Iface(A, B(C))`), which represents the location of unknown
// symbolic values in the combined signature and which is ordered by them.
//
// Given `impl C as Z {}` the `self_const_id` would be a `C` and the interface
// constraint would be `Z`.
auto BuildTypeStructure(Context& context, SemIR::InstId self_inst_id,
                        SemIR::SpecificInterface interface)
    -> std::optional<TypeStructure>;

}  // namespace Carbon::Check

#endif  // CARBON_TOOLCHAIN_CHECK_TYPE_STRUCTURE_H_


Review comment (suggestion):
```suggestion
//
// Returns nullopt if an ErrorInst is encountered in the self type or facet value.
auto BuildTypeStructure(Context& context, SemIR::InstId self_inst_id,
```

Code after:
  static auto ConsumeRhsSymbolic(
      llvm::SmallVector<Structural>::const_iterator& lhs_cursor,
      llvm::SmallVector<ConcreteType>::const_iterator& lhs_concrete_cursor,
      llvm::SmallVector<Structural>::const_iterator& rhs_cursor) -> bool;

  // The structural position of concrete and symbolic values in the type.
  llvm::SmallVector<Structural> structure_;

  // Indices of the symbolic entries in structure_.
  llvm::SmallVector<int> symbolic_type_indices_;

  // The related value for each `Concrete` and `ConcreteOpenParen` entry in
  // the type `structure_`, in the same order. See `ConcreteType`.
  llvm::SmallVector<ConcreteType> concrete_types_;
};

// Constructs the TypeStructure for a self type or facet value and an interface
// constraint (e.g. `Iface(A, B(C))`), which represents the location of unknown
// symbolic values in the combined signature and which is ordered by them.
//
// Given `impl C as Z {}` the `self_const_id` would be a `C` and the interface
// constraint would be `Z`.
//
// Returns nullopt if an ErrorInst is encountered in the self type or facet
// value.
auto BuildTypeStructure(Context& context, SemIR::InstId self_inst_id,
                        SemIR::SpecificInterface interface)
    -> std::optional<TypeStructure>;

}  // namespace Carbon::Check

#endif  // CARBON_TOOLCHAIN_CHECK_TYPE_STRUCTURE_H_
Repository: carbon-language/carbon-lang
File: common/enum_mask_base_test.cpp (C++)

Code before:
  EXPECT_TRUE(true) << TestKind::Beep;
}

TEST(EnumMaskBaseTest, Switch) {
  TestKind kind = TestKind::Boop;

  switch (kind) {
    case TestKind::Beep: {
      FAIL() << "Beep case selected!";
      break;
    }
    case TestKind::Boop: {
      EXPECT_EQ(kind, TestKind::Boop);
      break;
    }
    case TestKind::Burr: {
      FAIL() << "Burr case selected!";
      break;
    }
  }
}

TEST(EnumMaskBaseTest, Comparison) {
  TestKind kind = TestKind::Beep;

  // Make sure all the different comparisons work, and also to work with
  // GoogleTest expectations.
  EXPECT_EQ(TestKind::Beep, kind);
  EXPECT_NE(TestKind::Boop, kind);
  EXPECT_LT(kind, TestKind::Boop);
  EXPECT_GT(TestKind::Burr, kind);
  EXPECT_LE(kind, TestKind::Beep);
  EXPECT_GE(TestKind::Beep, kind);

  // These should also all be constexpr.
  constexpr TestKind Kind2 = TestKind::Beep;
  static_assert(Kind2 == TestKind::Beep);
  static_assert(Kind2 != TestKind::Boop);
  static_assert(Kind2 < TestKind::Boop);
  static_assert(!(Kind2 > TestKind::Burr));
  static_assert(Kind2 <= TestKind::Beep);
  static_assert(!(Kind2 >= TestKind::Burr));
}

TEST(EnumMaskBaseTest, AddRemove) {
  TestKind kind = TestKind::Beep;
  EXPECT_EQ(kind, TestKind::Beep);
  kind.Add(TestKind::Beep);
  EXPECT_EQ(kind, TestKind::Beep);
  kind.Add(TestKind::Burr);
  EXPECT_EQ(kind, TestKind::Beep | TestKind::Burr);

Review comment (suggestion):
```suggestion
  // Make sure all the different comparisons work, and also work with
```

Code after:
  EXPECT_TRUE(true) << TestKind::Beep;
}

TEST(EnumMaskBaseTest, Switch) {
  TestKind kind = TestKind::Boop;

  switch (kind) {
    case TestKind::Beep: {
      FAIL() << "Beep case selected!";
      break;
    }
    case TestKind::Boop: {
      EXPECT_EQ(kind, TestKind::Boop);
      break;
    }
    case TestKind::Burr: {
      FAIL() << "Burr case selected!";
      break;
    }
  }
}

TEST(EnumMaskBaseTest, Equality) {
  TestKind kind = TestKind::Beep;

  // Make sure all the different comparisons work, and also work with
  // GoogleTest expectations.
  EXPECT_EQ(TestKind::Beep, kind);
  EXPECT_NE(TestKind::Boop, kind);

  // These should also all be constexpr.
  constexpr TestKind Kind2 = TestKind::Beep;
  static_assert(Kind2 == TestKind::Beep);
  static_assert(Kind2 != TestKind::Boop);
}

TEST(EnumMaskBaseTest, AddRemove) {
  TestKind kind = TestKind::Beep;
  EXPECT_EQ(kind, TestKind::Beep);
  kind.Add(TestKind::Beep);
  EXPECT_EQ(kind, TestKind::Beep);
  kind.Add(TestKind::Burr);
  EXPECT_EQ(kind, TestKind::Beep | TestKind::Burr);
  kind.Remove(TestKind::Beep);
  EXPECT_EQ(kind, TestKind::Burr);
  kind.Remove(TestKind::Beep);
  EXPECT_EQ(kind, TestKind::Burr);
  kind.Remove(TestKind::Burr);
  EXPECT_EQ(kind, TestKind::None);
}
Repository: carbon-language/carbon-lang
File: toolchain/check/type.cpp (C++)

Code before:
    return SemIR::ErrorInst::TypeId;
  }
  return GetTypeImpl<SemIR::PatternType>(
      context, context.types().GetInstId(scrutinee_type_id));
}

auto GetUnboundElementType(Context& context, SemIR::TypeInstId class_type_id,
                           SemIR::TypeInstId element_type_id) -> SemIR::TypeId {
  return GetTypeImpl<SemIR::UnboundElementType>(context, class_type_id,
                                                element_type_id);
}

auto GetCanonicalFacetOrTypeValue(Context& context, SemIR::InstId inst_id)
    -> SemIR::InstId {
  if (inst_id == SemIR::ErrorInst::InstId) {
    return inst_id;
  }

  CARBON_CHECK(
      context.types().IsFacetType(context.insts().Get(inst_id).type_id()),
      "{0}", context.insts().Get(inst_id).type_id());

  inst_id = context.constant_values().GetConstantInstId(inst_id);

  if (auto access = context.insts().TryGetAs<SemIR::FacetAccessType>(inst_id)) {
    inst_id = access->facet_value_inst_id;
  }

  return inst_id;
}

auto GetCanonicalFacetOrTypeValue(Context& context, SemIR::ConstantId const_id)
    -> SemIR::ConstantId {
  return context.constant_values().Get(GetCanonicalFacetOrTypeValue(
      context, context.constant_values().GetInstId(const_id)));
}

}  // namespace Carbon::Check


Review comment (suggestion):
Had you considered returning directly? There's a trade-off here between single return point vs not needing to look further to determine whether the result can be used differently.
```suggestion
    return access->facet_value_inst_id;
```

Code after:
    return SemIR::ErrorInst::TypeId;
  }
  return GetTypeImpl<SemIR::PatternType>(
      context, context.types().GetInstId(scrutinee_type_id));
}

auto GetUnboundElementType(Context& context, SemIR::TypeInstId class_type_id,
                           SemIR::TypeInstId element_type_id) -> SemIR::TypeId {
  return GetTypeImpl<SemIR::UnboundElementType>(context, class_type_id,
                                                element_type_id);
}

auto GetCanonicalFacetOrTypeValue(Context& context, SemIR::InstId inst_id)
    -> SemIR::InstId {
  if (inst_id == SemIR::ErrorInst::InstId) {
    return inst_id;
  }

  CARBON_CHECK(
      context.types().IsFacetType(context.insts().Get(inst_id).type_id()),
      "{0}", context.insts().Get(inst_id).type_id());

  auto const_inst_id = context.constant_values().GetConstantInstId(inst_id);

  if (auto access =
          context.insts().TryGetAs<SemIR::FacetAccessType>(const_inst_id)) {
    return access->facet_value_inst_id;
  }

  return const_inst_id;
}

auto GetCanonicalFacetOrTypeValue(Context& context, SemIR::ConstantId const_id)
    -> SemIR::ConstantId {
  return context.constant_values().Get(GetCanonicalFacetOrTypeValue(
      context, context.constant_values().GetInstId(const_id)));
}

}  // namespace Carbon::Check
Repository: carbon-language/carbon-lang
File: toolchain/sem_ir/ids.cpp (C++)

Code before:

auto ConstantId::Print(llvm::raw_ostream& out, bool disambiguate) const
    -> void {
  if (!has_value()) {
    IdBase::Print(out);
    return;
  }
  if (is_concrete()) {
    if (disambiguate) {
      out << "concrete_constant(";
    }
    out << concrete_inst_id();
    if (disambiguate) {
      out << ")";
    }
  } else if (is_symbolic()) {
    out << symbolic_id();
  } else {
    CARBON_CHECK(!is_constant());
    out << "runtime";
  }
}

auto CheckIRId::Print(llvm::raw_ostream& out) const -> void {
  if (*this == Cpp) {
    out << Label << "Cpp";
  } else {
    IdBase::Print(out);
  }
}

auto GenericInstIndex::Print(llvm::raw_ostream& out) const -> void {
  out << "generic_inst";
  if (has_value()) {
    out << (region() == Declaration ? "_in_decl" : "_in_def") << index();
  } else {
    out << "<none>";
  }
}

auto ImportIRId::Print(llvm::raw_ostream& out) const -> void {
  if (*this == ApiForImpl) {
    out << Label << "ApiForImpl";
  } else if (*this == Cpp) {
    out << Label << "Cpp";
  } else {
    IdBase::Print(out);
  }
}

auto BoolValue::Print(llvm::raw_ostream& out) const -> void {

Review comment (suggestion):
```suggestion
    out << Label << "(Cpp)";
```

This would be like inst(Singletons) as well

Code after:

auto ConstantId::Print(llvm::raw_ostream& out, bool disambiguate) const
    -> void {
  if (!has_value()) {
    IdBase::Print(out);
    return;
  }
  if (is_concrete()) {
    if (disambiguate) {
      out << "concrete_constant(";
    }
    out << concrete_inst_id();
    if (disambiguate) {
      out << ")";
    }
  } else if (is_symbolic()) {
    out << symbolic_id();
  } else {
    CARBON_CHECK(!is_constant());
    out << "runtime";
  }
}

auto CheckIRId::Print(llvm::raw_ostream& out) const -> void {
  if (*this == Cpp) {
    out << Label << "(Cpp)";
  } else {
    IdBase::Print(out);
  }
}

auto GenericInstIndex::Print(llvm::raw_ostream& out) const -> void {
  out << "generic_inst";
  if (has_value()) {
    out << (region() == Declaration ? "_in_decl" : "_in_def") << index();
  } else {
    out << "<none>";
  }
}

auto ImportIRId::Print(llvm::raw_ostream& out) const -> void {
  if (*this == ApiForImpl) {
    out << Label << "(ApiForImpl)";
  } else if (*this == Cpp) {
    out << Label << "(Cpp)";
  } else {
    IdBase::Print(out);
  }
}

auto BoolValue::Print(llvm::raw_ostream& out) const -> void {
Repository: carbon-language/carbon-lang
File: toolchain/sem_ir/ids.cpp (C++)

Code before:
  } else {
    CARBON_CHECK(!is_constant());
    out << "runtime";
  }
}

auto CheckIRId::Print(llvm::raw_ostream& out) const -> void {
  if (*this == Cpp) {
    out << Label << "Cpp";
  } else {
    IdBase::Print(out);
  }
}

auto GenericInstIndex::Print(llvm::raw_ostream& out) const -> void {
  out << "generic_inst";
  if (has_value()) {
    out << (region() == Declaration ? "_in_decl" : "_in_def") << index();
  } else {
    out << "<none>";
  }
}

auto ImportIRId::Print(llvm::raw_ostream& out) const -> void {
  if (*this == ApiForImpl) {
    out << Label << "ApiForImpl";
  } else if (*this == Cpp) {
    out << Label << "Cpp";
  } else {
    IdBase::Print(out);
  }
}

auto BoolValue::Print(llvm::raw_ostream& out) const -> void {
  if (*this == False) {
    out << "false";
  } else if (*this == True) {
    out << "true";
  } else {
    CARBON_FATAL("Invalid bool value {0}", index);
  }
}

auto CharId::Print(llvm::raw_ostream& out) const -> void {
  // TODO: If we switch to C++23, `std::format("`{:?}`")` might be a better
  // choice.
  out << "U+";
  llvm::write_hex(out, index, llvm::HexPrintStyle::Upper, 4);
}

auto IntKind::Print(llvm::raw_ostream& out) const -> void {

Review comment (suggestion):
```suggestion
    out << Label << "(ApiForImpl)";
```

Code after:
  } else {
    CARBON_CHECK(!is_constant());
    out << "runtime";
  }
}

auto CheckIRId::Print(llvm::raw_ostream& out) const -> void {
  if (*this == Cpp) {
    out << Label << "(Cpp)";
  } else {
    IdBase::Print(out);
  }
}

auto GenericInstIndex::Print(llvm::raw_ostream& out) const -> void {
  out << "generic_inst";
  if (has_value()) {
    out << (region() == Declaration ? "_in_decl" : "_in_def") << index();
  } else {
    out << "<none>";
  }
}

auto ImportIRId::Print(llvm::raw_ostream& out) const -> void {
  if (*this == ApiForImpl) {
    out << Label << "(ApiForImpl)";
  } else if (*this == Cpp) {
    out << Label << "(Cpp)";
  } else {
    IdBase::Print(out);
  }
}

auto BoolValue::Print(llvm::raw_ostream& out) const -> void {
  if (*this == False) {
    out << "false";
  } else if (*this == True) {
    out << "true";
  } else {
    CARBON_FATAL("Invalid bool value {0}", index);
  }
}

auto CharId::Print(llvm::raw_ostream& out) const -> void {
  // TODO: If we switch to C++23, `std::format("`{:?}`")` might be a better
  // choice.
  out << "U+";
  llvm::write_hex(out, index, llvm::HexPrintStyle::Upper, 4);
}

auto IntKind::Print(llvm::raw_ostream& out) const -> void {