Print special ids as their names and don't crash when dumping them (#6398)

This commit is contained in:
Dana Jansens
2025-11-19 16:58:51 +00:00
committed by GitHub
parent 315b0ac241
commit f220359a9f
10 changed files with 43 additions and 11 deletions
+1 -1
View File
@@ -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)}
@@ -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:
@@ -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)}
@@ -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)}
+1 -1
View File
@@ -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)}
@@ -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)}
+1 -1
View File
@@ -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)}
+3 -2
View File
@@ -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);
}
+28
View File
@@ -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:
+3
View File
@@ -819,6 +819,7 @@ struct StructTypeFieldsId : public IdBase<StructTypeFieldsId> {
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<CustomLayoutId> {
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<RequireImplsBlockId> {
static const RequireImplsBlockId Empty;
using IdBase::IdBase;
auto Print(llvm::raw_ostream& out) const -> void;
};
inline constexpr RequireImplsBlockId RequireImplsBlockId::Empty =