Repository: carbon-language/carbon-lang
File: toolchain/sem_ir/file.cpp (C++)

Code before:
      library_id_(packaging_decl ? LibraryNameId::ForStringLiteralValueId(
                                       packaging_decl->names.library_id)
                                 : LibraryNameId::Default),
      value_stores_(&value_stores),
      filename_(std::move(filename)),
      functions_(check_ir_id),
      cpp_overload_sets_(check_ir_id),
      classes_(check_ir_id),
      interfaces_(check_ir_id),
      associated_constants_(check_ir_id),
      impls_(*this),
      specific_interfaces_(check_ir_id),
      generics_(check_ir_id),
      specifics_(check_ir_id),
      // The `+1` prevents adding a tag to the global `NameSpace::PackageInstId`
      // instruction. It's not a "singleton" instruction, but it's a unique
      // instruction id that comes right after the singletons.
      insts_(this, SingletonInstKinds.size() + 1),
      vtables_(check_ir_id),
      constant_values_(ConstantId::NotConstant, &insts_),
      inst_blocks_(allocator_),
      constants_(this),
      // 1 reserved id for `StructTypeFields::Empty`.
      struct_type_fields_(allocator_, IdTag(check_ir_id.index, 1)) {
  // `type` and the error type are both complete & concrete types.
  types_.SetComplete(
      TypeType::TypeId,
      {.value_repr = {.kind = ValueRepr::Copy, .type_id = TypeType::TypeId}});
  types_.SetComplete(
      ErrorInst::TypeId,
      {.value_repr = {.kind = ValueRepr::Copy, .type_id = ErrorInst::TypeId}});

  insts_.Reserve(SingletonInstKinds.size());
  for (auto kind : SingletonInstKinds) {
    auto inst_id =
        insts_.AddInNoBlock(LocIdAndInst::NoLoc(Inst::MakeSingleton(kind)));
    constant_values_.Set(inst_id, ConstantId::ForConcreteConstant(inst_id));
  }
}

File::~File() = default;

auto File::Verify() const -> ErrorOr<Success> {
  // Invariants don't necessarily hold for invalid IR.
  if (has_errors_) {
    return Success();
  }

  // Check that every code block has a terminator sequence that appears at the
  // end of the block.
  for (const Function& function : functions_.values()) {

Review comment (suggestion):
```suggestion
      // 1 reserved id for `StructTypeFieldsId::Empty`.
```

Code after:
      library_id_(packaging_decl ? LibraryNameId::ForStringLiteralValueId(
                                       packaging_decl->names.library_id)
                                 : LibraryNameId::Default),
      value_stores_(&value_stores),
      filename_(std::move(filename)),
      entity_names_(check_ir_id),
      functions_(check_ir_id),
      cpp_overload_sets_(check_ir_id),
      classes_(check_ir_id),
      interfaces_(check_ir_id),
      associated_constants_(check_ir_id),
      facet_types_(check_ir_id),
      identified_facet_types_(&facet_types_),
      impls_(*this),
      specific_interfaces_(check_ir_id),
      generics_(check_ir_id),
      specifics_(check_ir_id),
      // The `+1` prevents adding a tag to the global `NameSpace::PackageInstId`
      // instruction. It's not a "singleton" instruction, but it's a unique
      // instruction id that comes right after the singletons.
      insts_(this, SingletonInstKinds.size() + 1),
      vtables_(check_ir_id),
      constant_values_(ConstantId::NotConstant, &insts_),
      inst_blocks_(allocator_, check_ir_id),
      constants_(this),
      // 1 reserved id for `StructTypeFields::Empty`.
      struct_type_fields_(allocator_, IdTag(check_ir_id.index, 1)) {
  // `type` and the error type are both complete & concrete types.
  types_.SetComplete(
      TypeType::TypeId,
      {.value_repr = {.kind = ValueRepr::Copy, .type_id = TypeType::TypeId}});
  types_.SetComplete(
      ErrorInst::TypeId,
      {.value_repr = {.kind = ValueRepr::Copy, .type_id = ErrorInst::TypeId}});

  insts_.Reserve(SingletonInstKinds.size());
  for (auto kind : SingletonInstKinds) {
    auto inst_id =
        insts_.AddInNoBlock(LocIdAndInst::NoLoc(Inst::MakeSingleton(kind)));
    constant_values_.Set(inst_id, ConstantId::ForConcreteConstant(inst_id));
  }
}

File::~File() = default;

auto File::Verify() const -> ErrorOr<Success> {
  // Invariants don't necessarily hold for invalid IR.
  if (has_errors_) {
    return Success();
  }