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

Code before:

static auto DumpNoNewline(const File& file, SpecificId specific_id) -> void {
  llvm::errs() << specific_id;
  if (specific_id.is_valid()) {
    llvm::errs() << ": " << file.specifics().Get(specific_id);
  }
}

LLVM_DUMP_METHOD auto Dump(const File& file, ClassId class_id) -> void {
  llvm::errs() << class_id;
  if (class_id.is_valid()) {
    auto class_obj = file.classes().Get(class_id);
    llvm::errs() << ": " << class_obj;
    DumpIfValid(file, class_obj.name_id);
  }
  llvm::errs() << '\n';
}

LLVM_DUMP_METHOD auto Dump(const File& file, ConstantId const_id) -> void {
  DumpNoNewline(file, const_id);
  llvm::errs() << '\n';
}

LLVM_DUMP_METHOD auto Dump(const File& file, EntityNameId entity_name_id)
    -> void {
  llvm::errs() << entity_name_id;
  if (entity_name_id.is_valid()) {
    auto entity_name = file.entity_names().Get(entity_name_id);
    llvm::errs() << ": " << entity_name;
    DumpIfValid(file, entity_name.name_id);
  }
  llvm::errs() << '\n';
}

LLVM_DUMP_METHOD auto Dump(const File& file, FacetTypeId facet_type_id)
    -> void {
  llvm::errs() << facet_type_id;
  if (facet_type_id.is_valid()) {
    auto facet_type = file.facet_types().Get(facet_type_id);
    llvm::errs() << ": " << facet_type;
    for (auto impls : facet_type.impls_constraints) {
      llvm::errs() << "\n  - ";
      DumpNoNewline(file, impls.interface_id);
      if (impls.specific_id.is_valid()) {
        llvm::errs() << "; ";
        DumpNoNewline(file, impls.specific_id);
      }
    }
    for (auto rewrite : facet_type.rewrite_constraints) {
      llvm::errs() << "\n  - ";
      DumpNoNewline(file, rewrite.lhs_const_id);

Review comment (suggestion):
I would suggest for each of these to write the type being dumped in the output too, see for example https://github.com/carbon-language/carbon-lang/pull/4747/files?diff=unified&w=0#diff-e690edf9337d3bd7e874588bc9d865536d6c69f2b7e8db79a9ef3aa9fd4b6edbL33-L42

So it could be something like `EntityNameId(...the stuff in here...)`

Code after:

static auto DumpNoNewline(const File& file, SpecificId specific_id) -> void {
  llvm::errs() << specific_id;
  if (specific_id.is_valid()) {
    llvm::errs() << ": " << file.specifics().Get(specific_id);
  }
}

LLVM_DUMP_METHOD auto Dump(const File& file, ClassId class_id) -> void {
  llvm::errs() << class_id;
  if (class_id.is_valid()) {
    auto class_obj = file.classes().Get(class_id);
    llvm::errs() << ": " << class_obj;
    DumpNameIfValid(file, class_obj.name_id);
  }
  llvm::errs() << '\n';
}

LLVM_DUMP_METHOD auto Dump(const File& file, ConstantId const_id) -> void {
  DumpNoNewline(file, const_id);
  llvm::errs() << '\n';
}

LLVM_DUMP_METHOD auto Dump(const File& file, EntityNameId entity_name_id)
    -> void {
  llvm::errs() << entity_name_id;
  if (entity_name_id.is_valid()) {
    auto entity_name = file.entity_names().Get(entity_name_id);
    llvm::errs() << ": " << entity_name;
    DumpNameIfValid(file, entity_name.name_id);
  }
  llvm::errs() << '\n';
}

LLVM_DUMP_METHOD auto Dump(const File& file, FacetTypeId facet_type_id)
    -> void {
  llvm::errs() << facet_type_id;
  if (facet_type_id.is_valid()) {
    auto facet_type = file.facet_types().Get(facet_type_id);
    llvm::errs() << ": " << facet_type;
    for (auto impls : facet_type.impls_constraints) {
      llvm::errs() << "\n  - ";
      DumpNoNewline(file, impls.interface_id);
      if (impls.specific_id.is_valid()) {
        llvm::errs() << "; ";
        DumpNoNewline(file, impls.specific_id);
      }
    }
    for (auto rewrite : facet_type.rewrite_constraints) {
      llvm::errs() << "\n  - ";
      DumpNoNewline(file, rewrite.lhs_const_id);