Skip to content

Commit 2d1de16

Browse files
authored
Add unit tagging to ImplId (#6214)
1 parent 9010249 commit 2d1de16

File tree

7 files changed

+31
-16
lines changed

7 files changed

+31
-16
lines changed

scripts/lldbinit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def print_usage() -> None:
8888
"facet_type": ("SemIR::MakeFacetTypeId", DECIMAL),
8989
"function": ("SemIR::MakeFunctionId", HEX),
9090
"generic": ("SemIR::MakeGenericId", DECIMAL),
91-
"impl": ("SemIR::MakeImplId", DECIMAL),
91+
"impl": ("SemIR::MakeImplId", HEX),
9292
"inst_block": ("SemIR::MakeInstBlockId", DECIMAL),
9393
"inst": ("SemIR::MakeInstId", HEX),
9494
"interface": ("SemIR::MakeInterfaceId", DECIMAL),

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ fn Foo[T:! type](p: T*) -> (T*, ()) {
459459
// CHECK:STDOUT: inst6000005B: {kind: PatternType, arg0: inst6000005A, type: type(TypeType)}
460460
// CHECK:STDOUT: inst6000005C: {kind: LookupImplWitness, arg0: inst6000001B, arg1: specific_interface0, type: type(inst(WitnessType))}
461461
// CHECK:STDOUT: inst6000005D: {kind: ImportRefUnloaded, arg0: import_ir_inst15, arg1: entity_name<none>}
462-
// CHECK:STDOUT: inst6000005E: {kind: ImplDecl, arg0: impl0, arg1: inst_block_empty}
462+
// CHECK:STDOUT: inst6000005E: {kind: ImplDecl, arg0: impl60000000, arg1: inst_block_empty}
463463
// CHECK:STDOUT: inst6000005F: {kind: BindSymbolicName, arg0: entity_name1, arg1: inst<none>, type: type(inst60000047)}
464464
// CHECK:STDOUT: inst60000060: {kind: SymbolicBindingType, arg0: entity_name1, arg1: inst6000005F, type: type(TypeType)}
465465
// CHECK:STDOUT: inst60000061: {kind: ConstType, arg0: inst60000060, type: type(TypeType)}
@@ -469,7 +469,7 @@ fn Foo[T:! type](p: T*) -> (T*, ()) {
469469
// CHECK:STDOUT: inst60000065: {kind: ImportRefLoaded, arg0: import_ir_inst19, arg1: entity_name<none>, type: type(TypeType)}
470470
// CHECK:STDOUT: inst60000066: {kind: ImportRefLoaded, arg0: import_ir_inst20, arg1: entity_name<none>, type: type(TypeType)}
471471
// CHECK:STDOUT: inst60000067: {kind: ImportRefUnloaded, arg0: import_ir_inst21, arg1: entity_name<none>}
472-
// CHECK:STDOUT: inst60000068: {kind: ImplWitnessTable, arg0: inst_block30, arg1: impl0}
472+
// CHECK:STDOUT: inst60000068: {kind: ImplWitnessTable, arg0: inst_block30, arg1: impl60000000}
473473
// CHECK:STDOUT: inst60000069: {kind: ImplWitness, arg0: inst60000068, arg1: specific2, type: type(inst(WitnessType))}
474474
// CHECK:STDOUT: inst6000006A: {kind: BindSymbolicName, arg0: entity_name1, arg1: inst<none>, type: type(inst60000047)}
475475
// CHECK:STDOUT: inst6000006B: {kind: SymbolicBindingType, arg0: entity_name1, arg1: inst6000006A, type: type(TypeType)}
@@ -504,29 +504,29 @@ fn Foo[T:! type](p: T*) -> (T*, ()) {
504504
// CHECK:STDOUT: inst60000088: {kind: SpecificImplFunction, arg0: inst60000087, arg1: specific6, type: type(inst(SpecificFunctionType))}
505505
// CHECK:STDOUT: inst60000089: {kind: PatternType, arg0: inst60000060, type: type(TypeType)}
506506
// CHECK:STDOUT: inst6000008A: {kind: ImportRefUnloaded, arg0: import_ir_inst45, arg1: entity_name<none>}
507-
// CHECK:STDOUT: inst6000008B: {kind: ImplDecl, arg0: impl1, arg1: inst_block_empty}
507+
// CHECK:STDOUT: inst6000008B: {kind: ImplDecl, arg0: impl60000001, arg1: inst_block_empty}
508508
// CHECK:STDOUT: inst6000008C: {kind: ImportRefLoaded, arg0: import_ir_inst47, arg1: entity_name<none>, type: type(TypeType)}
509509
// CHECK:STDOUT: inst6000008D: {kind: ImportRefLoaded, arg0: import_ir_inst48, arg1: entity_name<none>, type: type(TypeType)}
510510
// CHECK:STDOUT: inst6000008E: {kind: ImportRefUnloaded, arg0: import_ir_inst49, arg1: entity_name<none>}
511-
// CHECK:STDOUT: inst6000008F: {kind: ImplDecl, arg0: impl2, arg1: inst_block_empty}
511+
// CHECK:STDOUT: inst6000008F: {kind: ImplDecl, arg0: impl60000002, arg1: inst_block_empty}
512512
// CHECK:STDOUT: inst60000090: {kind: ImportRefLoaded, arg0: import_ir_inst51, arg1: entity_name<none>, type: type(TypeType)}
513513
// CHECK:STDOUT: inst60000091: {kind: ImportRefLoaded, arg0: import_ir_inst52, arg1: entity_name<none>, type: type(TypeType)}
514514
// CHECK:STDOUT: inst60000092: {kind: ImportRefUnloaded, arg0: import_ir_inst53, arg1: entity_name<none>}
515-
// CHECK:STDOUT: inst60000093: {kind: ImplDecl, arg0: impl3, arg1: inst_block_empty}
515+
// CHECK:STDOUT: inst60000093: {kind: ImplDecl, arg0: impl60000003, arg1: inst_block_empty}
516516
// CHECK:STDOUT: inst60000094: {kind: ImportRefLoaded, arg0: import_ir_inst55, arg1: entity_name<none>, type: type(TypeType)}
517517
// CHECK:STDOUT: inst60000095: {kind: ImportRefLoaded, arg0: import_ir_inst56, arg1: entity_name<none>, type: type(TypeType)}
518518
// CHECK:STDOUT: inst60000096: {kind: ImportRefUnloaded, arg0: import_ir_inst57, arg1: entity_name<none>}
519-
// CHECK:STDOUT: inst60000097: {kind: ImplDecl, arg0: impl4, arg1: inst_block_empty}
519+
// CHECK:STDOUT: inst60000097: {kind: ImplDecl, arg0: impl60000004, arg1: inst_block_empty}
520520
// CHECK:STDOUT: inst60000098: {kind: ImportRefLoaded, arg0: import_ir_inst59, arg1: entity_name<none>, type: type(TypeType)}
521521
// CHECK:STDOUT: inst60000099: {kind: ImportRefLoaded, arg0: import_ir_inst60, arg1: entity_name<none>, type: type(TypeType)}
522522
// CHECK:STDOUT: inst6000009A: {kind: ImportRefLoaded, arg0: import_ir_inst61, arg1: entity_name<none>, type: type(inst(WitnessType))}
523-
// CHECK:STDOUT: inst6000009B: {kind: ImplDecl, arg0: impl5, arg1: inst_block_empty}
523+
// CHECK:STDOUT: inst6000009B: {kind: ImplDecl, arg0: impl60000005, arg1: inst_block_empty}
524524
// CHECK:STDOUT: inst6000009C: {kind: SymbolicBindingPattern, arg0: entity_name21, type: type(inst60000017)}
525525
// CHECK:STDOUT: inst6000009D: {kind: ImportRefLoaded, arg0: import_ir_inst64, arg1: entity_name<none>, type: type(TypeType)}
526526
// CHECK:STDOUT: inst6000009E: {kind: ImportRefLoaded, arg0: import_ir_inst65, arg1: entity_name<none>, type: type(TypeType)}
527527
// CHECK:STDOUT: inst6000009F: {kind: ImportRefLoaded, arg0: import_ir_inst66, arg1: entity_name<none>, type: type(TypeType)}
528528
// CHECK:STDOUT: inst600000A0: {kind: ImportRefUnloaded, arg0: import_ir_inst67, arg1: entity_name<none>}
529-
// CHECK:STDOUT: inst600000A1: {kind: ImplWitnessTable, arg0: inst_block47, arg1: impl5}
529+
// CHECK:STDOUT: inst600000A1: {kind: ImplWitnessTable, arg0: inst_block47, arg1: impl60000005}
530530
// CHECK:STDOUT: inst600000A2: {kind: ImplWitness, arg0: inst600000A1, arg1: specific7, type: type(inst(WitnessType))}
531531
// CHECK:STDOUT: inst600000A3: {kind: BindSymbolicName, arg0: entity_name1, arg1: inst<none>, type: type(TypeType)}
532532
// CHECK:STDOUT: inst600000A4: {kind: PointerType, arg0: inst600000A3, type: type(TypeType)}
@@ -546,15 +546,15 @@ fn Foo[T:! type](p: T*) -> (T*, ()) {
546546
// CHECK:STDOUT: inst600000B2: {kind: PointerType, arg0: inst600000B1, type: type(TypeType)}
547547
// CHECK:STDOUT: inst600000B3: {kind: PatternType, arg0: inst600000B2, type: type(TypeType)}
548548
// CHECK:STDOUT: inst600000B4: {kind: ImportRefUnloaded, arg0: import_ir_inst84, arg1: entity_name<none>}
549-
// CHECK:STDOUT: inst600000B5: {kind: ImplDecl, arg0: impl6, arg1: inst_block_empty}
549+
// CHECK:STDOUT: inst600000B5: {kind: ImplDecl, arg0: impl60000006, arg1: inst_block_empty}
550550
// CHECK:STDOUT: inst600000B6: {kind: ImportRefLoaded, arg0: import_ir_inst86, arg1: entity_name<none>, type: type(TypeType)}
551551
// CHECK:STDOUT: inst600000B7: {kind: ImportRefLoaded, arg0: import_ir_inst87, arg1: entity_name<none>, type: type(TypeType)}
552552
// CHECK:STDOUT: inst600000B8: {kind: ImportRefUnloaded, arg0: import_ir_inst88, arg1: entity_name<none>}
553-
// CHECK:STDOUT: inst600000B9: {kind: ImplDecl, arg0: impl7, arg1: inst_block_empty}
553+
// CHECK:STDOUT: inst600000B9: {kind: ImplDecl, arg0: impl60000007, arg1: inst_block_empty}
554554
// CHECK:STDOUT: inst600000BA: {kind: ImportRefLoaded, arg0: import_ir_inst90, arg1: entity_name<none>, type: type(TypeType)}
555555
// CHECK:STDOUT: inst600000BB: {kind: ImportRefLoaded, arg0: import_ir_inst91, arg1: entity_name<none>, type: type(TypeType)}
556556
// CHECK:STDOUT: inst600000BC: {kind: ImportRefUnloaded, arg0: import_ir_inst92, arg1: entity_name<none>}
557-
// CHECK:STDOUT: inst600000BD: {kind: ImplDecl, arg0: impl8, arg1: inst_block_empty}
557+
// CHECK:STDOUT: inst600000BD: {kind: ImplDecl, arg0: impl60000008, arg1: inst_block_empty}
558558
// CHECK:STDOUT: inst600000BE: {kind: BindSymbolicName, arg0: entity_name26, arg1: inst<none>, type: type(inst60000047)}
559559
// CHECK:STDOUT: inst600000BF: {kind: SymbolicBindingType, arg0: entity_name26, arg1: inst600000BE, type: type(TypeType)}
560560
// CHECK:STDOUT: inst600000C0: {kind: TupleType, arg0: inst_block57, type: type(TypeType)}
@@ -565,7 +565,7 @@ fn Foo[T:! type](p: T*) -> (T*, ()) {
565565
// CHECK:STDOUT: inst600000C5: {kind: ImportRefLoaded, arg0: import_ir_inst98, arg1: entity_name<none>, type: type(TypeType)}
566566
// CHECK:STDOUT: inst600000C6: {kind: ImportRefLoaded, arg0: import_ir_inst99, arg1: entity_name<none>, type: type(TypeType)}
567567
// CHECK:STDOUT: inst600000C7: {kind: ImportRefUnloaded, arg0: import_ir_inst100, arg1: entity_name<none>}
568-
// CHECK:STDOUT: inst600000C8: {kind: ImplWitnessTable, arg0: inst_block60, arg1: impl8}
568+
// CHECK:STDOUT: inst600000C8: {kind: ImplWitnessTable, arg0: inst_block60, arg1: impl60000008}
569569
// CHECK:STDOUT: inst600000C9: {kind: ImplWitness, arg0: inst600000C8, arg1: specific10, type: type(inst(WitnessType))}
570570
// CHECK:STDOUT: inst600000CA: {kind: BindSymbolicName, arg0: entity_name1, arg1: inst<none>, type: type(inst60000047)}
571571
// CHECK:STDOUT: inst600000CB: {kind: BindSymbolicName, arg0: entity_name26, arg1: inst<none>, type: type(inst60000047)}
@@ -610,7 +610,7 @@ fn Foo[T:! type](p: T*) -> (T*, ()) {
610610
// CHECK:STDOUT: inst600000F2: {kind: SpecificImplFunction, arg0: inst600000F1, arg1: specific15, type: type(inst(SpecificFunctionType))}
611611
// CHECK:STDOUT: inst600000F3: {kind: PatternType, arg0: inst600000BF, type: type(TypeType)}
612612
// CHECK:STDOUT: inst600000F4: {kind: ImportRefUnloaded, arg0: import_ir_inst134, arg1: entity_name<none>}
613-
// CHECK:STDOUT: inst600000F5: {kind: ImplDecl, arg0: impl9, arg1: inst_block_empty}
613+
// CHECK:STDOUT: inst600000F5: {kind: ImplDecl, arg0: impl60000009, arg1: inst_block_empty}
614614
// CHECK:STDOUT: inst600000F6: {kind: BindSymbolicName, arg0: entity_name41, arg1: inst<none>, type: type(inst60000047)}
615615
// CHECK:STDOUT: inst600000F7: {kind: SymbolicBindingType, arg0: entity_name41, arg1: inst600000F6, type: type(TypeType)}
616616
// CHECK:STDOUT: inst600000F8: {kind: TupleType, arg0: inst_block79, type: type(TypeType)}
@@ -623,7 +623,7 @@ fn Foo[T:! type](p: T*) -> (T*, ()) {
623623
// CHECK:STDOUT: inst600000FF: {kind: ImportRefLoaded, arg0: import_ir_inst142, arg1: entity_name<none>, type: type(TypeType)}
624624
// CHECK:STDOUT: inst60000100: {kind: ImportRefLoaded, arg0: import_ir_inst143, arg1: entity_name<none>, type: type(TypeType)}
625625
// CHECK:STDOUT: inst60000101: {kind: ImportRefUnloaded, arg0: import_ir_inst144, arg1: entity_name<none>}
626-
// CHECK:STDOUT: inst60000102: {kind: ImplWitnessTable, arg0: inst_block82, arg1: impl9}
626+
// CHECK:STDOUT: inst60000102: {kind: ImplWitnessTable, arg0: inst_block82, arg1: impl60000009}
627627
// CHECK:STDOUT: inst60000103: {kind: ImplWitness, arg0: inst60000102, arg1: specific16, type: type(inst(WitnessType))}
628628
// CHECK:STDOUT: inst60000104: {kind: BindSymbolicName, arg0: entity_name1, arg1: inst<none>, type: type(inst60000047)}
629629
// CHECK:STDOUT: inst60000105: {kind: BindSymbolicName, arg0: entity_name26, arg1: inst<none>, type: type(inst60000047)}

toolchain/sem_ir/ids.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ auto AssociatedConstantId::Print(llvm::raw_ostream& out) const -> void {
6666
IdBase::PrintHex(out);
6767
}
6868

69+
auto ImplId::Print(llvm::raw_ostream& out) const -> void {
70+
IdBase::PrintHex(out);
71+
}
72+
6973
auto GenericInstIndex::Print(llvm::raw_ostream& out) const -> void {
7074
out << "generic_inst";
7175
if (has_value()) {

toolchain/sem_ir/ids.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ struct ImplId : public IdBase<ImplId> {
356356
static constexpr llvm::StringLiteral Label = "impl";
357357

358358
using IdBase::IdBase;
359+
360+
auto Print(llvm::raw_ostream& out) const -> void;
359361
};
360362

361363
// The ID of a `Generic`.

toolchain/sem_ir/impl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
namespace Carbon::SemIR {
1010

11+
ImplStore::ImplStore(File& sem_ir)
12+
: sem_ir_(sem_ir), values_(IdTag(sem_ir.check_ir_id().index, 0)) {}
13+
1114
auto ImplStore::GetOrAddLookupBucket(const Impl& impl) -> LookupBucketRef {
1215
auto self_id = sem_ir_.constant_values().GetConstantInstId(impl.self_id);
1316
InterfaceId interface_id = InterfaceId::None;

toolchain/sem_ir/impl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class ImplStore {
164164
ImplId single_id_storage_;
165165
};
166166

167-
explicit ImplStore(File& sem_ir) : sem_ir_(sem_ir) {}
167+
explicit ImplStore(File& sem_ir);
168168

169169
// Returns a reference to the lookup bucket containing the list of impls with
170170
// this self type and constraint, or adds a new bucket if this is the first
@@ -185,6 +185,10 @@ class ImplStore {
185185
return values_.OutputYaml();
186186
}
187187

188+
auto GetRawIndex(ImplId id) const -> int32_t {
189+
return values_.GetRawIndex(id);
190+
}
191+
188192
// Collects memory usage of members.
189193
auto CollectMemUsage(MemUsage& mem_usage, llvm::StringRef label) const
190194
-> void {

toolchain/sem_ir/inst_namer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class InstNamer {
5959
index = sem_ir_->associated_constants().GetRawIndex(id);
6060
} else if constexpr (std::is_same_v<IdT, FunctionId>) {
6161
index = sem_ir_->functions().GetRawIndex(id);
62+
} else if constexpr (std::is_same_v<IdT, ImplId>) {
63+
index = sem_ir_->impls().GetRawIndex(id);
6264
}
6365
return static_cast<ScopeId>(GetScopeIdOffset(ScopeIdTypeEnum::For<IdT>) +
6466
index);

0 commit comments

Comments
 (0)