Skip to content

Commit 1a9826b

Browse files
authored
Add unit tagging to FunctionId (#6213)
1 parent d0d2f18 commit 1a9826b

File tree

14 files changed

+80
-67
lines changed

14 files changed

+80
-67
lines changed

scripts/lldbinit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def print_usage() -> None:
8686
"symbolic_constant": ("SemIR::MakeSymbolicConstantId", DECIMAL),
8787
"entity_name": ("SemIR::MakeEntityNameId", DECIMAL),
8888
"facet_type": ("SemIR::MakeFacetTypeId", DECIMAL),
89-
"function": ("SemIR::MakeFunctionId", DECIMAL),
89+
"function": ("SemIR::MakeFunctionId", HEX),
9090
"generic": ("SemIR::MakeGenericId", DECIMAL),
9191
"impl": ("SemIR::MakeImplId", DECIMAL),
9292
"inst_block": ("SemIR::MakeInstBlockId", DECIMAL),

toolchain/base/fixed_size_value_store.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class FixedSizeValueStore {
4242
requires std::same_as<IdT, typename ValueStoreT::IdType>
4343
static auto MakeForOverwrite(const ValueStoreT& size_source)
4444
-> FixedSizeValueStore {
45-
FixedSizeValueStore store;
45+
FixedSizeValueStore store(size_source.GetIdTag());
4646
store.values_.resize_for_overwrite(size_source.size());
4747
return store;
4848
}
@@ -81,6 +81,8 @@ class FixedSizeValueStore {
8181
values_.resize(size_source.size(), default_value);
8282
}
8383

84+
explicit FixedSizeValueStore(IdTag tag) : tag_(tag) {}
85+
8486
// Makes a ValueStore using a mapped range of `source`. The `factory_fn`
8587
// receives each enumerated entry for construction of `ValueType`.
8688
template <typename ValueStoreT>

toolchain/base/value_store.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ class ValueStore
164164
static auto MakeFlattenedRange(const ValueStore& store) -> auto {
165165
// Because indices into `ValueStore` are all sequential values from 0, we
166166
// can use llvm::seq to walk all indices in the store.
167-
return llvm::map_range(
168-
llvm::seq(store.size_),
169-
[&](int32_t i) -> ConstRefType { return store.Get(IdType(i)); });
167+
return llvm::map_range(llvm::seq(store.size_),
168+
[&](int32_t i) -> ConstRefType {
169+
return store.Get(IdType(store.tag_.Apply(i)));
170+
});
170171
}
171172

172173
using FlattenedRangeType =
@@ -273,8 +274,9 @@ class ValueStore
273274

274275
// Makes an iterable range over references to all values in the ValueStore.
275276
auto values() [[clang::lifetimebound]] -> auto {
276-
return llvm::map_range(
277-
llvm::seq(size_), [&](int32_t i) -> RefType { return Get(IdType(i)); });
277+
return llvm::map_range(llvm::seq(size_), [&](int32_t i) -> RefType {
278+
return Get(IdType(tag_.Apply(i)));
279+
});
278280
}
279281
auto values() const [[clang::lifetimebound]] -> Range { return Range(*this); }
280282

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ fn G(x: Cpp.X) {
5555
// CHECK:STDOUT: entity_name1: {name: name2, parent_scope: name_scope<none>, index: -1, is_template: 0, clang_decl_id: clang_decl_id<none>}
5656
// CHECK:STDOUT: entity_name2: {name: name2, parent_scope: name_scope<none>, index: -1, is_template: 0, clang_decl_id: clang_decl_id<none>}
5757
// CHECK:STDOUT: functions:
58-
// CHECK:STDOUT: function0: {name: name1, parent_scope: name_scope0, call_params_id: inst_block6, body: [inst_block9]}
59-
// CHECK:STDOUT: function1: {name: name4, parent_scope: name_scope1, call_params_id: inst_block_empty}
60-
// CHECK:STDOUT: function2: {name: name6, parent_scope: name_scope1, call_params_id: inst_block_empty}
61-
// CHECK:STDOUT: function3: {name: name4, parent_scope: name_scope1, call_params_id: inst_block13}
62-
// CHECK:STDOUT: function4: {name: name6, parent_scope: name_scope1, call_params_id: inst_block18}
58+
// CHECK:STDOUT: function60000000: {name: name1, parent_scope: name_scope0, call_params_id: inst_block6, body: [inst_block9]}
59+
// CHECK:STDOUT: function60000001: {name: name4, parent_scope: name_scope1, call_params_id: inst_block_empty}
60+
// CHECK:STDOUT: function60000002: {name: name6, parent_scope: name_scope1, call_params_id: inst_block_empty}
61+
// CHECK:STDOUT: function60000003: {name: name4, parent_scope: name_scope1, call_params_id: inst_block13}
62+
// CHECK:STDOUT: function60000004: {name: name6, parent_scope: name_scope1, call_params_id: inst_block18}
6363
// CHECK:STDOUT: classes:
6464
// CHECK:STDOUT: class60000000: {name: name3, parent_scope: name_scope1, self_type_id: type(inst60000013), inheritance_kind: Base, is_dynamic: 0, scope_id: name_scope2, body_block_id: inst_block10, adapt_id: inst<none>, base_id: inst<none>, complete_type_witness_id: inst60000021, vtable_decl_id: inst<none>}}
6565
// CHECK:STDOUT: generics: {}
@@ -125,8 +125,8 @@ fn G(x: Cpp.X) {
125125
// CHECK:STDOUT: inst60000018: {kind: ValueParamPattern, arg0: inst60000017, arg1: call_param0, type: type(inst60000016)}
126126
// CHECK:STDOUT: inst60000019: {kind: ValueParam, arg0: call_param0, arg1: name2, type: type(inst60000013)}
127127
// CHECK:STDOUT: inst6000001A: {kind: SpliceBlock, arg0: inst_block4, arg1: inst60000014, type: type(TypeType)}
128-
// CHECK:STDOUT: inst6000001B: {kind: FunctionDecl, arg0: function0, arg1: inst_block8, type: type(inst6000001C)}
129-
// CHECK:STDOUT: inst6000001C: {kind: FunctionType, arg0: function0, arg1: specific<none>, type: type(TypeType)}
128+
// CHECK:STDOUT: inst6000001B: {kind: FunctionDecl, arg0: function60000000, arg1: inst_block8, type: type(inst6000001C)}
129+
// CHECK:STDOUT: inst6000001C: {kind: FunctionType, arg0: function60000000, arg1: specific<none>, type: type(TypeType)}
130130
// CHECK:STDOUT: inst6000001D: {kind: TupleType, arg0: inst_block_empty, type: type(TypeType)}
131131
// CHECK:STDOUT: inst6000001E: {kind: StructValue, arg0: inst_block_empty, type: type(inst6000001C)}
132132
// CHECK:STDOUT: inst6000001F: {kind: CustomLayoutType, arg0: struct_type_fields0, arg1: custom_layout1, type: type(TypeType)}
@@ -139,11 +139,11 @@ fn G(x: Cpp.X) {
139139
// CHECK:STDOUT: inst60000026: {kind: CppOverloadSetValue, arg0: cpp_overload_set60000000, type: type(inst60000025)}
140140
// CHECK:STDOUT: inst60000027: {kind: CppOverloadSetValue, arg0: cpp_overload_set60000000, type: type(inst60000025)}
141141
// CHECK:STDOUT: inst60000028: {kind: NameRef, arg0: name4, arg1: inst60000026, type: type(inst60000025)}
142-
// CHECK:STDOUT: inst60000029: {kind: FunctionDecl, arg0: function1, arg1: inst_block_empty, type: type(inst6000002A)}
143-
// CHECK:STDOUT: inst6000002A: {kind: FunctionType, arg0: function1, arg1: specific<none>, type: type(TypeType)}
142+
// CHECK:STDOUT: inst60000029: {kind: FunctionDecl, arg0: function60000001, arg1: inst_block_empty, type: type(inst6000002A)}
143+
// CHECK:STDOUT: inst6000002A: {kind: FunctionType, arg0: function60000001, arg1: specific<none>, type: type(TypeType)}
144144
// CHECK:STDOUT: inst6000002B: {kind: StructValue, arg0: inst_block_empty, type: type(inst6000002A)}
145-
// CHECK:STDOUT: inst6000002C: {kind: FunctionDecl, arg0: function2, arg1: inst_block_empty, type: type(inst6000002D)}
146-
// CHECK:STDOUT: inst6000002D: {kind: FunctionType, arg0: function2, arg1: specific<none>, type: type(TypeType)}
145+
// CHECK:STDOUT: inst6000002C: {kind: FunctionDecl, arg0: function60000002, arg1: inst_block_empty, type: type(inst6000002D)}
146+
// CHECK:STDOUT: inst6000002D: {kind: FunctionType, arg0: function60000002, arg1: specific<none>, type: type(TypeType)}
147147
// CHECK:STDOUT: inst6000002E: {kind: StructValue, arg0: inst_block_empty, type: type(inst6000002D)}
148148
// CHECK:STDOUT: inst6000002F: {kind: Call, arg0: inst6000002C, arg1: inst_block_empty, type: type(inst6000001D)}
149149
// CHECK:STDOUT: inst60000030: {kind: NameRef, arg0: name0, arg1: inst60000010, type: type(inst(NamespaceType))}
@@ -153,17 +153,17 @@ fn G(x: Cpp.X) {
153153
// CHECK:STDOUT: inst60000034: {kind: BindingPattern, arg0: entity_name1, type: type(inst60000016)}
154154
// CHECK:STDOUT: inst60000035: {kind: ValueParamPattern, arg0: inst60000034, arg1: call_param0, type: type(inst60000016)}
155155
// CHECK:STDOUT: inst60000036: {kind: ValueParam, arg0: call_param0, arg1: name2, type: type(inst60000013)}
156-
// CHECK:STDOUT: inst60000037: {kind: FunctionDecl, arg0: function3, arg1: inst_block15, type: type(inst60000038)}
157-
// CHECK:STDOUT: inst60000038: {kind: FunctionType, arg0: function3, arg1: specific<none>, type: type(TypeType)}
156+
// CHECK:STDOUT: inst60000037: {kind: FunctionDecl, arg0: function60000003, arg1: inst_block15, type: type(inst60000038)}
157+
// CHECK:STDOUT: inst60000038: {kind: FunctionType, arg0: function60000003, arg1: specific<none>, type: type(TypeType)}
158158
// CHECK:STDOUT: inst60000039: {kind: StructValue, arg0: inst_block_empty, type: type(inst60000038)}
159159
// CHECK:STDOUT: inst6000003A: {kind: PointerType, arg0: inst60000013, type: type(TypeType)}
160160
// CHECK:STDOUT: inst6000003B: {kind: BindName, arg0: entity_name2, arg1: inst6000003F, type: type(inst6000003A)}
161161
// CHECK:STDOUT: inst6000003C: {kind: PatternType, arg0: inst6000003A, type: type(TypeType)}
162162
// CHECK:STDOUT: inst6000003D: {kind: BindingPattern, arg0: entity_name2, type: type(inst6000003C)}
163163
// CHECK:STDOUT: inst6000003E: {kind: ValueParamPattern, arg0: inst6000003D, arg1: call_param0, type: type(inst6000003C)}
164164
// CHECK:STDOUT: inst6000003F: {kind: ValueParam, arg0: call_param0, arg1: name2, type: type(inst6000003A)}
165-
// CHECK:STDOUT: inst60000040: {kind: FunctionDecl, arg0: function4, arg1: inst_block20, type: type(inst60000041)}
166-
// CHECK:STDOUT: inst60000041: {kind: FunctionType, arg0: function4, arg1: specific<none>, type: type(TypeType)}
165+
// CHECK:STDOUT: inst60000040: {kind: FunctionDecl, arg0: function60000004, arg1: inst_block20, type: type(inst60000041)}
166+
// CHECK:STDOUT: inst60000041: {kind: FunctionType, arg0: function60000004, arg1: specific<none>, type: type(TypeType)}
167167
// CHECK:STDOUT: inst60000042: {kind: StructValue, arg0: inst_block_empty, type: type(inst60000041)}
168168
// CHECK:STDOUT: inst60000043: {kind: ValueAsRef, arg0: inst60000032, type: type(inst60000013)}
169169
// CHECK:STDOUT: inst60000044: {kind: AddrOf, arg0: inst60000043, type: type(inst6000003A)}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn B() {
3939
// CHECK:STDOUT: name_scope0: {inst: inst0000000E, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {name0: inst6000000F}}
4040
// CHECK:STDOUT: entity_names: {}
4141
// CHECK:STDOUT: functions:
42-
// CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, call_params_id: inst_block_empty, body: [inst_block5]}
42+
// CHECK:STDOUT: function60000000: {name: name0, parent_scope: name_scope0, call_params_id: inst_block_empty, body: [inst_block5]}
4343
// CHECK:STDOUT: classes: {}
4444
// CHECK:STDOUT: generics: {}
4545
// CHECK:STDOUT: specifics: {}
@@ -58,8 +58,8 @@ fn B() {
5858
// CHECK:STDOUT: value_repr: {kind: none, type: type(inst60000011)}
5959
// CHECK:STDOUT: insts:
6060
// CHECK:STDOUT: inst0000000E: {kind: Namespace, arg0: name_scope0, arg1: inst<none>, type: type(inst(NamespaceType))}
61-
// CHECK:STDOUT: inst6000000F: {kind: FunctionDecl, arg0: function0, arg1: inst_block_empty, type: type(inst60000010)}
62-
// CHECK:STDOUT: inst60000010: {kind: FunctionType, arg0: function0, arg1: specific<none>, type: type(TypeType)}
61+
// CHECK:STDOUT: inst6000000F: {kind: FunctionDecl, arg0: function60000000, arg1: inst_block_empty, type: type(inst60000010)}
62+
// CHECK:STDOUT: inst60000010: {kind: FunctionType, arg0: function60000000, arg1: specific<none>, type: type(TypeType)}
6363
// CHECK:STDOUT: inst60000011: {kind: TupleType, arg0: inst_block_empty, type: type(TypeType)}
6464
// CHECK:STDOUT: inst60000012: {kind: StructValue, arg0: inst_block_empty, type: type(inst60000010)}
6565
// CHECK:STDOUT: inst60000013: {kind: Return}
@@ -101,8 +101,8 @@ fn B() {
101101
// CHECK:STDOUT: entity_names:
102102
// CHECK:STDOUT: entity_name0: {name: name1, parent_scope: name_scope1, index: -1, is_template: 0, clang_decl_id: clang_decl_id<none>}
103103
// CHECK:STDOUT: functions:
104-
// CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, call_params_id: inst_block_empty, body: [inst_block5]}
105-
// CHECK:STDOUT: function1: {name: name1, parent_scope: name_scope1}
104+
// CHECK:STDOUT: function50000000: {name: name0, parent_scope: name_scope0, call_params_id: inst_block_empty, body: [inst_block5]}
105+
// CHECK:STDOUT: function50000001: {name: name1, parent_scope: name_scope1}
106106
// CHECK:STDOUT: classes: {}
107107
// CHECK:STDOUT: generics: {}
108108
// CHECK:STDOUT: specifics: {}
@@ -123,14 +123,14 @@ fn B() {
123123
// CHECK:STDOUT: inst0000000E: {kind: Namespace, arg0: name_scope0, arg1: inst<none>, type: type(inst(NamespaceType))}
124124
// CHECK:STDOUT: inst5000000F: {kind: ImportDecl, arg0: name1}
125125
// CHECK:STDOUT: inst50000010: {kind: Namespace, arg0: name_scope1, arg1: inst5000000F, type: type(inst(NamespaceType))}
126-
// CHECK:STDOUT: inst50000011: {kind: FunctionDecl, arg0: function0, arg1: inst_block_empty, type: type(inst50000012)}
127-
// CHECK:STDOUT: inst50000012: {kind: FunctionType, arg0: function0, arg1: specific<none>, type: type(TypeType)}
126+
// CHECK:STDOUT: inst50000011: {kind: FunctionDecl, arg0: function50000000, arg1: inst_block_empty, type: type(inst50000012)}
127+
// CHECK:STDOUT: inst50000012: {kind: FunctionType, arg0: function50000000, arg1: specific<none>, type: type(TypeType)}
128128
// CHECK:STDOUT: inst50000013: {kind: TupleType, arg0: inst_block_empty, type: type(TypeType)}
129129
// CHECK:STDOUT: inst50000014: {kind: StructValue, arg0: inst_block_empty, type: type(inst50000012)}
130130
// CHECK:STDOUT: inst50000015: {kind: NameRef, arg0: name1, arg1: inst50000010, type: type(inst(NamespaceType))}
131131
// CHECK:STDOUT: inst50000016: {kind: ImportRefLoaded, arg0: import_ir_inst0, arg1: entity_name0, type: type(inst50000018)}
132-
// CHECK:STDOUT: inst50000017: {kind: FunctionDecl, arg0: function1, arg1: inst_block_empty, type: type(inst50000018)}
133-
// CHECK:STDOUT: inst50000018: {kind: FunctionType, arg0: function1, arg1: specific<none>, type: type(TypeType)}
132+
// CHECK:STDOUT: inst50000017: {kind: FunctionDecl, arg0: function50000001, arg1: inst_block_empty, type: type(inst50000018)}
133+
// CHECK:STDOUT: inst50000018: {kind: FunctionType, arg0: function50000001, arg1: specific<none>, type: type(TypeType)}
134134
// CHECK:STDOUT: inst50000019: {kind: StructValue, arg0: inst_block_empty, type: type(inst50000018)}
135135
// CHECK:STDOUT: inst5000001A: {kind: NameRef, arg0: name1, arg1: inst50000016, type: type(inst50000018)}
136136
// CHECK:STDOUT: inst5000001B: {kind: Call, arg0: inst5000001A, arg1: inst_block_empty, type: type(inst50000013)}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn B() {
3939
// CHECK:STDOUT: name_scope0: {inst: inst0000000E, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {name0: inst6000000F}}
4040
// CHECK:STDOUT: entity_names: {}
4141
// CHECK:STDOUT: functions:
42-
// CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, call_params_id: inst_block_empty, body: [inst_block5]}
42+
// CHECK:STDOUT: function60000000: {name: name0, parent_scope: name_scope0, call_params_id: inst_block_empty, body: [inst_block5]}
4343
// CHECK:STDOUT: classes: {}
4444
// CHECK:STDOUT: generics: {}
4545
// CHECK:STDOUT: specifics: {}
@@ -58,8 +58,8 @@ fn B() {
5858
// CHECK:STDOUT: value_repr: {kind: none, type: type(inst60000011)}
5959
// CHECK:STDOUT: insts:
6060
// CHECK:STDOUT: inst0000000E: {kind: Namespace, arg0: name_scope0, arg1: inst<none>, type: type(inst(NamespaceType))}
61-
// CHECK:STDOUT: inst6000000F: {kind: FunctionDecl, arg0: function0, arg1: inst_block_empty, type: type(inst60000010)}
62-
// CHECK:STDOUT: inst60000010: {kind: FunctionType, arg0: function0, arg1: specific<none>, type: type(TypeType)}
61+
// CHECK:STDOUT: inst6000000F: {kind: FunctionDecl, arg0: function60000000, arg1: inst_block_empty, type: type(inst60000010)}
62+
// CHECK:STDOUT: inst60000010: {kind: FunctionType, arg0: function60000000, arg1: specific<none>, type: type(TypeType)}
6363
// CHECK:STDOUT: inst60000011: {kind: TupleType, arg0: inst_block_empty, type: type(TypeType)}
6464
// CHECK:STDOUT: inst60000012: {kind: StructValue, arg0: inst_block_empty, type: type(inst60000010)}
6565
// CHECK:STDOUT: inst60000013: {kind: Return}
@@ -120,8 +120,8 @@ fn B() {
120120
// CHECK:STDOUT: entity_names:
121121
// CHECK:STDOUT: entity_name0: {name: name1, parent_scope: name_scope1, index: -1, is_template: 0, clang_decl_id: clang_decl_id<none>}
122122
// CHECK:STDOUT: functions:
123-
// CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, call_params_id: inst_block_empty, body: [inst_block5]}
124-
// CHECK:STDOUT: function1: {name: name1, parent_scope: name_scope1}
123+
// CHECK:STDOUT: function50000000: {name: name0, parent_scope: name_scope0, call_params_id: inst_block_empty, body: [inst_block5]}
124+
// CHECK:STDOUT: function50000001: {name: name1, parent_scope: name_scope1}
125125
// CHECK:STDOUT: classes: {}
126126
// CHECK:STDOUT: generics: {}
127127
// CHECK:STDOUT: specifics: {}
@@ -142,14 +142,14 @@ fn B() {
142142
// CHECK:STDOUT: inst0000000E: {kind: Namespace, arg0: name_scope0, arg1: inst<none>, type: type(inst(NamespaceType))}
143143
// CHECK:STDOUT: inst5000000F: {kind: ImportDecl, arg0: name1}
144144
// CHECK:STDOUT: inst50000010: {kind: Namespace, arg0: name_scope1, arg1: inst5000000F, type: type(inst(NamespaceType))}
145-
// CHECK:STDOUT: inst50000011: {kind: FunctionDecl, arg0: function0, arg1: inst_block_empty, type: type(inst50000012)}
146-
// CHECK:STDOUT: inst50000012: {kind: FunctionType, arg0: function0, arg1: specific<none>, type: type(TypeType)}
145+
// CHECK:STDOUT: inst50000011: {kind: FunctionDecl, arg0: function50000000, arg1: inst_block_empty, type: type(inst50000012)}
146+
// CHECK:STDOUT: inst50000012: {kind: FunctionType, arg0: function50000000, arg1: specific<none>, type: type(TypeType)}
147147
// CHECK:STDOUT: inst50000013: {kind: TupleType, arg0: inst_block_empty, type: type(TypeType)}
148148
// CHECK:STDOUT: inst50000014: {kind: StructValue, arg0: inst_block_empty, type: type(inst50000012)}
149149
// CHECK:STDOUT: inst50000015: {kind: NameRef, arg0: name1, arg1: inst50000010, type: type(inst(NamespaceType))}
150150
// CHECK:STDOUT: inst50000016: {kind: ImportRefLoaded, arg0: import_ir_inst0, arg1: entity_name0, type: type(inst50000018)}
151-
// CHECK:STDOUT: inst50000017: {kind: FunctionDecl, arg0: function1, arg1: inst_block_empty, type: type(inst50000018)}
152-
// CHECK:STDOUT: inst50000018: {kind: FunctionType, arg0: function1, arg1: specific<none>, type: type(TypeType)}
151+
// CHECK:STDOUT: inst50000017: {kind: FunctionDecl, arg0: function50000001, arg1: inst_block_empty, type: type(inst50000018)}
152+
// CHECK:STDOUT: inst50000018: {kind: FunctionType, arg0: function50000001, arg1: specific<none>, type: type(TypeType)}
153153
// CHECK:STDOUT: inst50000019: {kind: StructValue, arg0: inst_block_empty, type: type(inst50000018)}
154154
// CHECK:STDOUT: inst5000001A: {kind: NameRef, arg0: name1, arg1: inst50000016, type: type(inst50000018)}
155155
// CHECK:STDOUT: inst5000001B: {kind: Call, arg0: inst5000001A, arg1: inst_block_empty, type: type(inst50000013)}

0 commit comments

Comments
 (0)