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

Code before:
File::File(const Parse::Tree* parse_tree, CheckIRId check_ir_id,
           const std::optional<Parse::Tree::PackagingDecl>& packaging_decl,
           SharedValueStores& value_stores, std::string filename)
    : parse_tree_(parse_tree),
      check_ir_id_(check_ir_id),
      package_id_(packaging_decl ? packaging_decl->names.package_id
                                 : PackageNameId::None),
      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),
      cpp_global_vars_(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 `+2` prevents adding a tag for the global ids
      // `ImportIRId::{ApiForImpl,Cpp}`.
      import_irs_(IdTag(check_ir_id.index, 2)),
      // 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) {
  // `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));
  }
}

Review comment (suggestion):
```suggestion
      // The `2` prevents adding a tag for the global ids
```

Code after:
File::File(const Parse::Tree* parse_tree, CheckIRId check_ir_id,
           const std::optional<Parse::Tree::PackagingDecl>& packaging_decl,
           SharedValueStores& value_stores, std::string filename)
    : parse_tree_(parse_tree),
      check_ir_id_(check_ir_id),
      package_id_(packaging_decl ? packaging_decl->names.package_id
                                 : PackageNameId::None),
      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),
      cpp_global_vars_(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 `2` prevents adding a tag for the global ids
      // `ImportIRId::{ApiForImpl,Cpp}`.
      import_irs_(IdTag(check_ir_id.index, 2)),
      // 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) {
  // `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));
  }
}