Skip to content

Commit f64b088

Browse files
authored
Dump all non-indexed ids as hex (#6228)
The indexed ids are kept in decimal since they won't get tagging because their ordered-ness is significant to their usage, as I understand it. Addressing #6215 (comment) feedback
1 parent 0716756 commit f64b088

File tree

14 files changed

+1345
-1386
lines changed

14 files changed

+1345
-1386
lines changed

scripts/lldbinit.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,27 @@ def print_usage() -> None:
7575

7676
context = args[0]
7777

78-
DECIMAL = 10
79-
HEX = 16
80-
8178
# The set of "Make" functions in dump.cpp, and whether the ids are printed
8279
# in decimal or hex.
8380
id_types = {
84-
"class": ("SemIR::MakeClassId", HEX),
85-
"constant": ("SemIR::MakeConstantId", DECIMAL),
86-
"symbolic_constant": ("SemIR::MakeSymbolicConstantId", DECIMAL),
87-
"entity_name": ("SemIR::MakeEntityNameId", DECIMAL),
88-
"facet_type": ("SemIR::MakeFacetTypeId", DECIMAL),
89-
"function": ("SemIR::MakeFunctionId", HEX),
90-
"generic": ("SemIR::MakeGenericId", DECIMAL),
91-
"impl": ("SemIR::MakeImplId", HEX),
92-
"inst_block": ("SemIR::MakeInstBlockId", DECIMAL),
93-
"inst": ("SemIR::MakeInstId", HEX),
94-
"interface": ("SemIR::MakeInterfaceId", DECIMAL),
95-
"name": ("SemIR::MakeNameId", DECIMAL),
96-
"name_scope": ("SemIR::MakeNameScopeId", DECIMAL),
97-
"identified_facet_type": ("SemIR::MakeIdentifiedFacetTypeId", DECIMAL),
98-
"specific": ("SemIR::MakeSpecificId", DECIMAL),
99-
"specific_interface": ("SemIR::MakeSpecificInterfaceId", HEX),
100-
"struct_type_fields": ("SemIR::MakeStructTypeFieldsId", DECIMAL),
101-
"type": ("SemIR::MakeTypeId", DECIMAL),
81+
"class": "SemIR::MakeClassId",
82+
"constant": "SemIR::MakeConstantId",
83+
"symbolic_constant": "SemIR::MakeSymbolicConstantId",
84+
"entity_name": "SemIR::MakeEntityNameId",
85+
"facet_type": "SemIR::MakeFacetTypeId",
86+
"function": "SemIR::MakeFunctionId",
87+
"generic": "SemIR::MakeGenericId",
88+
"impl": "SemIR::MakeImplId",
89+
"inst_block": "SemIR::MakeInstBlockId",
90+
"inst": "SemIR::MakeInstId",
91+
"interface": "SemIR::MakeInterfaceId",
92+
"name": "SemIR::MakeNameId",
93+
"name_scope": "SemIR::MakeNameScopeId",
94+
"identified_facet_type": "SemIR::MakeIdentifiedFacetTypeId",
95+
"specific": "SemIR::MakeSpecificId",
96+
"specific_interface": "SemIR::MakeSpecificInterfaceId",
97+
"struct_type_fields": "SemIR::MakeStructTypeFieldsId",
98+
"type": "SemIR::MakeTypeId",
10299
}
103100

104101
def print_dump(context: str, expr: str) -> None:
@@ -123,8 +120,8 @@ def print_dump(context: str, expr: str) -> None:
123120
if len(args) != 2:
124121
print_usage()
125122
return
126-
(make_id_fn, base) = id_types[m[1]]
127-
id = int(m[2], base)
123+
make_id_fn = id_types[m[1]]
124+
id = int(m[2], 16)
128125
print_dump(context, f"{make_id_fn}({id})")
129126
found_id_type = True
130127

toolchain/base/index_base.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,6 @@ struct IdBase : public AnyIdBase, public Printable<IdT> {
5757
static const IdT& None;
5858

5959
auto Print(llvm::raw_ostream& out) const -> void {
60-
out << IdT::Label;
61-
if (has_value()) {
62-
out << index;
63-
} else {
64-
out << "<none>";
65-
}
66-
}
67-
68-
// TODO: Make Print() do the hex thing for all IDs and remove this function.
69-
auto PrintHex(llvm::raw_ostream& out) const -> void {
7060
out << IdT::Label;
7161
if (has_value()) {
7262
out << llvm::format_hex_no_prefix(index, 8, /*Upper=*/true);
@@ -98,6 +88,17 @@ struct IndexBase : public IdBase<IdT> {
9888
-> std::strong_ordering {
9989
return lhs.index <=> rhs.index;
10090
}
91+
92+
// Print indexed ids in decimal, since they won't have tagging (because, as
93+
// the class comment explains, these ids are not entirely opaque).
94+
auto Print(llvm::raw_ostream& out) const -> void {
95+
out << IdT::Label;
96+
if (this->has_value()) {
97+
out << this->index;
98+
} else {
99+
out << "<none>";
100+
}
101+
}
101102
};
102103

103104
// A random-access iterator for arrays using IndexBase-derived types.

toolchain/base/shared_value_stores_test.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ TEST(SharedValueStores, PrintVals) {
5252
RawStringOstream out;
5353
value_stores.Print(out);
5454

55-
EXPECT_THAT(Yaml::Value::FromText(out.TakeStr()),
56-
MatchSharedValues(
57-
ElementsAre(Pair("ap_int0", Yaml::Scalar("999999999999"))),
58-
ElementsAre(Pair("real0", Yaml::Scalar("8*10^8"))), IsEmpty(),
59-
ElementsAre(Pair("identifier0", Yaml::Scalar("a"))),
60-
ElementsAre(Pair("string0", Yaml::Scalar("foo'\"baz")))));
55+
EXPECT_THAT(
56+
Yaml::Value::FromText(out.TakeStr()),
57+
MatchSharedValues(
58+
ElementsAre(Pair("ap_int00000000", Yaml::Scalar("999999999999"))),
59+
ElementsAre(Pair("real00000000", Yaml::Scalar("8*10^8"))), IsEmpty(),
60+
ElementsAre(Pair("identifier00000000", Yaml::Scalar("a"))),
61+
ElementsAre(Pair("string00000000", Yaml::Scalar("foo'\"baz")))));
6162
}
6263

6364
} // namespace

toolchain/check/testdata/basics/raw_sem_ir/builtins.carbon

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
// CHECK:STDOUT: import_ir_insts: {}
2121
// CHECK:STDOUT: clang_decls: {}
2222
// CHECK:STDOUT: name_scopes:
23-
// CHECK:STDOUT: name_scope0: {inst: inst0000000E, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {}}
23+
// CHECK:STDOUT: name_scope00000000: {inst: inst0000000E, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {}}
2424
// CHECK:STDOUT: entity_names: {}
2525
// CHECK:STDOUT: cpp_global_vars: {}
2626
// CHECK:STDOUT: functions: {}
2727
// CHECK:STDOUT: classes: {}
2828
// CHECK:STDOUT: generics: {}
2929
// CHECK:STDOUT: specifics: {}
3030
// CHECK:STDOUT: struct_type_fields:
31-
// CHECK:STDOUT: struct_type_fields0: {}
31+
// CHECK:STDOUT: struct_type_fields00000000: {}
3232
// CHECK:STDOUT: types:
3333
// CHECK:STDOUT: 'type(TypeType)':
3434
// CHECK:STDOUT: value_repr: {kind: copy, type: type(TypeType)}
@@ -51,7 +51,7 @@
5151
// CHECK:STDOUT: 'inst(SpecificFunctionType)': {kind: SpecificFunctionType, type: type(TypeType)}
5252
// CHECK:STDOUT: 'inst(VtableType)': {kind: VtableType, type: type(TypeType)}
5353
// CHECK:STDOUT: 'inst(WitnessType)': {kind: WitnessType, type: type(TypeType)}
54-
// CHECK:STDOUT: inst0000000E: {kind: Namespace, arg0: name_scope0, arg1: inst<none>, type: type(inst(NamespaceType))}
54+
// CHECK:STDOUT: inst0000000E: {kind: Namespace, arg0: name_scope00000000, arg1: inst<none>, type: type(inst(NamespaceType))}
5555
// CHECK:STDOUT: constant_values:
5656
// CHECK:STDOUT: values:
5757
// CHECK:STDOUT: 'inst(TypeType)': concrete_constant(inst(TypeType))
@@ -75,6 +75,6 @@
7575
// CHECK:STDOUT: exports: {}
7676
// CHECK:STDOUT: imports: {}
7777
// CHECK:STDOUT: global_init: {}
78-
// CHECK:STDOUT: inst_block4:
78+
// CHECK:STDOUT: inst_block00000004:
7979
// CHECK:STDOUT: 0: inst0000000E
8080
// CHECK:STDOUT: ...

0 commit comments

Comments
 (0)