diff --git a/toolchain/check/testdata/basics/raw_sem_ir/builtins.carbon b/toolchain/check/testdata/basics/raw_sem_ir/builtins.carbon index 182889b545c4..67957a5d5834 100644 --- a/toolchain/check/testdata/basics/raw_sem_ir/builtins.carbon +++ b/toolchain/check/testdata/basics/raw_sem_ir/builtins.carbon @@ -28,7 +28,7 @@ // CHECK:STDOUT: generics: {} // CHECK:STDOUT: specifics: {} // CHECK:STDOUT: struct_type_fields: -// CHECK:STDOUT: struct_type_fields0: {} +// CHECK:STDOUT: struct_type_fields_empty: {} // CHECK:STDOUT: types: // CHECK:STDOUT: 'type(TypeType)': // CHECK:STDOUT: value_repr: {kind: copy, type: type(TypeType)} diff --git a/toolchain/check/testdata/basics/raw_sem_ir/cpp_interop.carbon b/toolchain/check/testdata/basics/raw_sem_ir/cpp_interop.carbon index 9270b2ba9cf5..d00a43ebdd63 100644 --- a/toolchain/check/testdata/basics/raw_sem_ir/cpp_interop.carbon +++ b/toolchain/check/testdata/basics/raw_sem_ir/cpp_interop.carbon @@ -73,7 +73,7 @@ fn G(x: Cpp.X) { // CHECK:STDOUT: generics: {} // CHECK:STDOUT: specifics: {} // CHECK:STDOUT: struct_type_fields: -// CHECK:STDOUT: struct_type_fields0: {} +// CHECK:STDOUT: struct_type_fields_empty: {} // CHECK:STDOUT: struct_type_fields60000001: // CHECK:STDOUT: 0: {name_id: name5, type_inst_id: inst6000001F} // CHECK:STDOUT: struct_type_fields60000002: diff --git a/toolchain/check/testdata/basics/raw_sem_ir/multifile.carbon b/toolchain/check/testdata/basics/raw_sem_ir/multifile.carbon index 22d12a08af39..4f19e5dd2338 100644 --- a/toolchain/check/testdata/basics/raw_sem_ir/multifile.carbon +++ b/toolchain/check/testdata/basics/raw_sem_ir/multifile.carbon @@ -45,7 +45,7 @@ fn B() { // CHECK:STDOUT: generics: {} // CHECK:STDOUT: specifics: {} // CHECK:STDOUT: struct_type_fields: -// CHECK:STDOUT: struct_type_fields0: {} +// CHECK:STDOUT: struct_type_fields_empty: {} // CHECK:STDOUT: types: // CHECK:STDOUT: 'type(TypeType)': // CHECK:STDOUT: value_repr: {kind: copy, type: type(TypeType)} @@ -109,7 +109,7 @@ fn B() { // CHECK:STDOUT: generics: {} // CHECK:STDOUT: specifics: {} // CHECK:STDOUT: struct_type_fields: -// CHECK:STDOUT: struct_type_fields0: {} +// CHECK:STDOUT: struct_type_fields_empty: {} // CHECK:STDOUT: types: // CHECK:STDOUT: 'type(TypeType)': // CHECK:STDOUT: value_repr: {kind: copy, type: type(TypeType)} diff --git a/toolchain/check/testdata/basics/raw_sem_ir/multifile_with_textual_ir.carbon b/toolchain/check/testdata/basics/raw_sem_ir/multifile_with_textual_ir.carbon index e22f1bfb7e35..86a623599d5a 100644 --- a/toolchain/check/testdata/basics/raw_sem_ir/multifile_with_textual_ir.carbon +++ b/toolchain/check/testdata/basics/raw_sem_ir/multifile_with_textual_ir.carbon @@ -45,7 +45,7 @@ fn B() { // CHECK:STDOUT: generics: {} // CHECK:STDOUT: specifics: {} // CHECK:STDOUT: struct_type_fields: -// CHECK:STDOUT: struct_type_fields0: {} +// CHECK:STDOUT: struct_type_fields_empty: {} // CHECK:STDOUT: types: // CHECK:STDOUT: 'type(TypeType)': // CHECK:STDOUT: value_repr: {kind: copy, type: type(TypeType)} @@ -128,7 +128,7 @@ fn B() { // CHECK:STDOUT: generics: {} // CHECK:STDOUT: specifics: {} // CHECK:STDOUT: struct_type_fields: -// CHECK:STDOUT: struct_type_fields0: {} +// CHECK:STDOUT: struct_type_fields_empty: {} // CHECK:STDOUT: types: // CHECK:STDOUT: 'type(TypeType)': // CHECK:STDOUT: value_repr: {kind: copy, type: type(TypeType)} diff --git a/toolchain/check/testdata/basics/raw_sem_ir/one_file.carbon b/toolchain/check/testdata/basics/raw_sem_ir/one_file.carbon index 5622e448422e..266dc9ac104b 100644 --- a/toolchain/check/testdata/basics/raw_sem_ir/one_file.carbon +++ b/toolchain/check/testdata/basics/raw_sem_ir/one_file.carbon @@ -343,7 +343,7 @@ fn Foo[T:! type](p: T*) -> (T*, ()) { // CHECK:STDOUT: specific60000017: {generic: generic60000001, args: inst_block6000006F} // CHECK:STDOUT: specific60000018: {generic: generic60000001, args: inst_block60000071} // CHECK:STDOUT: struct_type_fields: -// CHECK:STDOUT: struct_type_fields0: {} +// CHECK:STDOUT: struct_type_fields_empty: {} // CHECK:STDOUT: types: // CHECK:STDOUT: 'type(TypeType)': // CHECK:STDOUT: value_repr: {kind: copy, type: type(TypeType)} diff --git a/toolchain/check/testdata/basics/raw_sem_ir/one_file_with_textual_ir.carbon b/toolchain/check/testdata/basics/raw_sem_ir/one_file_with_textual_ir.carbon index 9d00d444fde4..986e3d43e35a 100644 --- a/toolchain/check/testdata/basics/raw_sem_ir/one_file_with_textual_ir.carbon +++ b/toolchain/check/testdata/basics/raw_sem_ir/one_file_with_textual_ir.carbon @@ -36,7 +36,7 @@ fn Foo(n: ()) -> ((), ()) { // CHECK:STDOUT: generics: {} // CHECK:STDOUT: specifics: {} // CHECK:STDOUT: struct_type_fields: -// CHECK:STDOUT: struct_type_fields0: {} +// CHECK:STDOUT: struct_type_fields_empty: {} // CHECK:STDOUT: types: // CHECK:STDOUT: 'type(TypeType)': // CHECK:STDOUT: value_repr: {kind: copy, type: type(TypeType)} diff --git a/toolchain/driver/testdata/stdin.carbon b/toolchain/driver/testdata/stdin.carbon index 4c7d829d0bc8..29780d700d3c 100644 --- a/toolchain/driver/testdata/stdin.carbon +++ b/toolchain/driver/testdata/stdin.carbon @@ -40,7 +40,7 @@ // CHECK:STDOUT: generics: {} // CHECK:STDOUT: specifics: {} // CHECK:STDOUT: struct_type_fields: -// CHECK:STDOUT: struct_type_fields0: {} +// CHECK:STDOUT: struct_type_fields_empty: {} // CHECK:STDOUT: types: // CHECK:STDOUT: 'type(TypeType)': // CHECK:STDOUT: value_repr: {kind: copy, type: type(TypeType)} diff --git a/toolchain/sem_ir/dump.cpp b/toolchain/sem_ir/dump.cpp index 832aea97e1a5..d8bc4931f73d 100644 --- a/toolchain/sem_ir/dump.cpp +++ b/toolchain/sem_ir/dump.cpp @@ -53,7 +53,8 @@ static auto DumpGenericSummary(const File& file, GenericId generic_id) static auto DumpInstSummary(const File& file, InstId inst_id) -> std::string { RawStringOstream out; out << inst_id; - if (inst_id.has_value()) { + if (inst_id.has_value() && inst_id != InstId::InitTombstone && + inst_id != InstId::ImplWitnessTablePlaceholder) { out << ": " << file.insts().Get(inst_id); } return out.TakeStr(); @@ -228,7 +229,7 @@ LLVM_DUMP_METHOD auto Dump(const File& file, InstBlockId inst_block_id) out << inst_block_id; if (inst_block_id.has_value()) { out << ":"; - auto inst_block = file.inst_blocks().Get(inst_block_id); + auto inst_block = file.inst_blocks().GetOrEmpty(inst_block_id); for (auto inst_id : inst_block) { out << "\n - " << DumpInstSummary(file, inst_id); } diff --git a/toolchain/sem_ir/ids.cpp b/toolchain/sem_ir/ids.cpp index ca0a318858dd..6326247b5d87 100644 --- a/toolchain/sem_ir/ids.cpp +++ b/toolchain/sem_ir/ids.cpp @@ -15,6 +15,10 @@ namespace Carbon::SemIR { auto InstId::Print(llvm::raw_ostream& out) const -> void { if (IsSingletonInstId(*this)) { out << Label << "(" << SingletonInstKinds[index] << ")"; + } else if (*this == InitTombstone) { + out << Label << "(InitTombstone)"; + } else if (*this == ImplWitnessTablePlaceholder) { + out << Label << "(ImplWitnessTablePlaceholder)"; } else { IdBase::Print(out); } @@ -207,6 +211,22 @@ auto InstBlockId::Print(llvm::raw_ostream& out) const -> void { } } +auto StructTypeFieldsId::Print(llvm::raw_ostream& out) const -> void { + if (*this == Empty) { + out << Label << "_empty"; + } else { + IdBase::Print(out); + } +} + +auto CustomLayoutId::Print(llvm::raw_ostream& out) const -> void { + if (*this == Empty) { + out << Label << "_empty"; + } else { + IdBase::Print(out); + } +} + auto TypeId::Print(llvm::raw_ostream& out) const -> void { out << Label << "("; if (*this == TypeType::TypeId) { @@ -240,6 +260,14 @@ auto LibraryNameId::Print(llvm::raw_ostream& out) const -> void { } } +auto RequireImplsBlockId::Print(llvm::raw_ostream& out) const -> void { + if (*this == Empty) { + out << Label << "_empty"; + } else { + IdBase::Print(out); + } +} + auto LocId::Print(llvm::raw_ostream& out) const -> void { switch (kind()) { case Kind::None: diff --git a/toolchain/sem_ir/ids.h b/toolchain/sem_ir/ids.h index 3ee4796f08df..fd0521ca6470 100644 --- a/toolchain/sem_ir/ids.h +++ b/toolchain/sem_ir/ids.h @@ -819,6 +819,7 @@ struct StructTypeFieldsId : public IdBase { static const StructTypeFieldsId Empty; using IdBase::IdBase; + auto Print(llvm::raw_ostream& out) const -> void; }; inline constexpr StructTypeFieldsId StructTypeFieldsId::Empty = @@ -840,6 +841,7 @@ struct CustomLayoutId : public IdBase { static constexpr int FirstFieldIndex = 2; using IdBase::IdBase; + auto Print(llvm::raw_ostream& out) const -> void; }; inline constexpr CustomLayoutId CustomLayoutId::Empty = CustomLayoutId(0); @@ -945,6 +947,7 @@ struct RequireImplsBlockId : public IdBase { static const RequireImplsBlockId Empty; using IdBase::IdBase; + auto Print(llvm::raw_ostream& out) const -> void; }; inline constexpr RequireImplsBlockId RequireImplsBlockId::Empty =