Skip to content

Commit ce10970

Browse files
authored
Add dumping for NamedConstraintId and shorten untagged id printing (#6319)
Adds support to the `dump` debugger command for named constraint ids, which are printed as `constraint<number>`. While doing so, we print whether the `constraint` is complete or not, and add the same to `interface` to match. And we noticed that the printing of name and name scope ids, which are not tagged, are very verbose by adding 7 `0`s to them for no reason. So make the dump output easier to read by dropping 0 prefixes. Before: ``` name_scope00000000: {inst: inst0000000E, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {name00000000: inst6000000F, name00000001: inst60000011}} {kind: Namespace, arg0: name_scope00000000, arg1: inst<none>, type: type(inst(NamespaceType))} `package` ``` After: ``` name_scope0: {inst: instE, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {name0: inst6000000F, name1: inst60000011}} {kind: Namespace, arg0: name_scope0, arg1: inst<none>, type: type(inst(NamespaceType))} `package` ```
1 parent 99cebcf commit ce10970

File tree

14 files changed

+537
-511
lines changed

14 files changed

+537
-511
lines changed

scripts/lldbinit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def print_usage() -> None:
7878
id_types = {
7979
"class": "SemIR::MakeClassId",
8080
"constant": "SemIR::MakeConstantId",
81+
"constraint": "SemIR::MakeNamedConstraintId",
8182
"symbolic_constant": "SemIR::MakeSymbolicConstantId",
8283
"entity_name": "SemIR::MakeEntityNameId",
8384
"facet_type": "SemIR::MakeFacetTypeId",

toolchain/base/index_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct IdBase : public AnyIdBase, public Printable<IdT> {
5959
auto Print(llvm::raw_ostream& out) const -> void {
6060
out << IdT::Label;
6161
if (has_value()) {
62-
out << llvm::format_hex_no_prefix(index, 8, /*Upper=*/true);
62+
out << llvm::format_hex_no_prefix(index, 0, /*Upper=*/true);
6363
} else {
6464
out << "<none>";
6565
}

toolchain/base/shared_value_stores_test.cpp

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

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")))));
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")))));
6261
}
6362

6463
} // namespace

toolchain/check/dump.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ LLVM_DUMP_METHOD static auto Dump(const Context& context,
7171
return SemIR::Dump(context.sem_ir(), generic_id);
7272
}
7373

74+
LLVM_DUMP_METHOD static auto Dump(
75+
const Context& context,
76+
SemIR::IdentifiedFacetTypeId identified_facet_type_id) -> std::string {
77+
return SemIR::Dump(context.sem_ir(), identified_facet_type_id);
78+
}
79+
7480
LLVM_DUMP_METHOD static auto Dump(const Context& context, SemIR::ImplId impl_id)
7581
-> std::string {
7682
return SemIR::Dump(context.sem_ir(), impl_id);
@@ -109,10 +115,10 @@ LLVM_DUMP_METHOD static auto Dump(const Context& context,
109115
return SemIR::Dump(context.sem_ir(), name_scope_id);
110116
}
111117

112-
LLVM_DUMP_METHOD static auto Dump(
113-
const Context& context,
114-
SemIR::IdentifiedFacetTypeId identified_facet_type_id) -> std::string {
115-
return SemIR::Dump(context.sem_ir(), identified_facet_type_id);
118+
LLVM_DUMP_METHOD static auto Dump(const Context& context,
119+
SemIR::NamedConstraintId named_constraint_id)
120+
-> std::string {
121+
return SemIR::Dump(context.sem_ir(), named_constraint_id);
116122
}
117123

118124
LLVM_DUMP_METHOD static auto Dump(const Context& context,

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

Lines changed: 5 additions & 5 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_scope00000000: {inst: inst0000000E, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {}}
23+
// CHECK:STDOUT: name_scope0: {inst: instE, 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_fields00000000: {}
31+
// CHECK:STDOUT: struct_type_fields0: {}
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_scope00000000, arg1: inst<none>, type: type(inst(NamespaceType))}
54+
// CHECK:STDOUT: instE: {kind: Namespace, arg0: name_scope0, 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))
@@ -68,13 +68,13 @@
6868
// CHECK:STDOUT: 'inst(SpecificFunctionType)': concrete_constant(inst(SpecificFunctionType))
6969
// CHECK:STDOUT: 'inst(VtableType)': concrete_constant(inst(VtableType))
7070
// CHECK:STDOUT: 'inst(WitnessType)': concrete_constant(inst(WitnessType))
71-
// CHECK:STDOUT: inst0000000E: concrete_constant(inst0000000E)
71+
// CHECK:STDOUT: instE: concrete_constant(instE)
7272
// CHECK:STDOUT: symbolic_constants: {}
7373
// CHECK:STDOUT: inst_blocks:
7474
// CHECK:STDOUT: inst_block_empty: {}
7575
// CHECK:STDOUT: exports: {}
7676
// CHECK:STDOUT: imports: {}
7777
// CHECK:STDOUT: global_init: {}
7878
// CHECK:STDOUT: inst_block60000004:
79-
// CHECK:STDOUT: 0: inst0000000E
79+
// CHECK:STDOUT: 0: instE
8080
// CHECK:STDOUT: ...

0 commit comments

Comments
 (0)