Skip to content

Commit a486c12

Browse files
authored
Add unit tagging to SpecificInterfaceId (#6215)
1 parent c2d2142 commit a486c12

File tree

7 files changed

+27
-13
lines changed

7 files changed

+27
-13
lines changed

scripts/lldbinit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def print_usage() -> None:
9696
"name_scope": ("SemIR::MakeNameScopeId", DECIMAL),
9797
"identified_facet_type": ("SemIR::MakeIdentifiedFacetTypeId", DECIMAL),
9898
"specific": ("SemIR::MakeSpecificId", DECIMAL),
99-
"specific_interface": ("SemIR::MakeSpecificInterfaceId", DECIMAL),
99+
"specific_interface": ("SemIR::MakeSpecificInterfaceId", HEX),
100100
"struct_type_fields": ("SemIR::MakeStructTypeFieldsId", DECIMAL),
101101
"type": ("SemIR::MakeTypeId", DECIMAL),
102102
}

toolchain/base/canonical_value_store.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class CanonicalValueStore {
3030
using RefType = ValueStoreTypes<ValueT>::RefType;
3131
using ConstRefType = ValueStoreTypes<ValueT>::ConstRefType;
3232

33+
CanonicalValueStore() = default;
34+
explicit CanonicalValueStore(IdTag tag) : values_(tag) {}
35+
3336
// Stores a canonical copy of the value and returns an ID to reference it. If
3437
// the value is already in the store, returns the ID of the existing value.
3538
auto Add(ValueType value) -> IdT;
@@ -63,6 +66,8 @@ class CanonicalValueStore {
6366
mem_usage.Add(MemUsage::ConcatLabel(label, "set_"), bytes, bytes);
6467
}
6568

69+
auto GetRawIndex(IdT id) const -> int32_t { return values_.GetRawIndex(id); }
70+
6671
private:
6772
class KeyContext;
6873

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ fn Foo[T:! type](p: T*) -> (T*, ()) {
458458
// CHECK:STDOUT: inst60000059: {kind: BindSymbolicName, arg0: entity_name4, arg1: inst<none>, type: type(inst60000047)}
459459
// CHECK:STDOUT: inst6000005A: {kind: SymbolicBindingType, arg0: entity_name4, arg1: inst60000059, type: type(TypeType)}
460460
// CHECK:STDOUT: inst6000005B: {kind: PatternType, arg0: inst6000005A, type: type(TypeType)}
461-
// CHECK:STDOUT: inst6000005C: {kind: LookupImplWitness, arg0: inst6000001B, arg1: specific_interface0, type: type(inst(WitnessType))}
461+
// CHECK:STDOUT: inst6000005C: {kind: LookupImplWitness, arg0: inst6000001B, arg1: specific_interface60000000, type: type(inst(WitnessType))}
462462
// CHECK:STDOUT: inst6000005D: {kind: ImportRefUnloaded, arg0: import_ir_inst15, arg1: entity_name<none>}
463463
// CHECK:STDOUT: inst6000005E: {kind: ImplDecl, arg0: impl60000000, arg1: inst_block_empty}
464464
// CHECK:STDOUT: inst6000005F: {kind: BindSymbolicName, arg0: entity_name1, arg1: inst<none>, type: type(inst60000047)}
@@ -493,13 +493,13 @@ fn Foo[T:! type](p: T*) -> (T*, ()) {
493493
// CHECK:STDOUT: inst6000007C: {kind: PatternType, arg0: inst6000007B, type: type(TypeType)}
494494
// CHECK:STDOUT: inst6000007D: {kind: RequireCompleteType, arg0: inst60000061, type: type(inst(WitnessType))}
495495
// CHECK:STDOUT: inst6000007E: {kind: RequireCompleteType, arg0: inst60000060, type: type(inst(WitnessType))}
496-
// CHECK:STDOUT: inst6000007F: {kind: LookupImplWitness, arg0: inst6000005F, arg1: specific_interface0, type: type(inst(WitnessType))}
496+
// CHECK:STDOUT: inst6000007F: {kind: LookupImplWitness, arg0: inst6000005F, arg1: specific_interface60000000, type: type(inst(WitnessType))}
497497
// CHECK:STDOUT: inst60000080: {kind: FunctionTypeWithSelfType, arg0: inst60000050, arg1: inst6000005F, type: type(TypeType)}
498498
// CHECK:STDOUT: inst60000081: {kind: ImplWitnessAccess, arg0: inst6000007F, arg1: element0, type: type(symbolic_constant60)}
499499
// CHECK:STDOUT: inst60000082: {kind: SpecificImplFunction, arg0: inst60000081, arg1: specific5, type: type(inst(SpecificFunctionType))}
500500
// CHECK:STDOUT: inst60000083: {kind: RequireCompleteType, arg0: inst6000007B, type: type(inst(WitnessType))}
501501
// CHECK:STDOUT: inst60000084: {kind: RequireCompleteType, arg0: inst6000007A, type: type(inst(WitnessType))}
502-
// CHECK:STDOUT: inst60000085: {kind: LookupImplWitness, arg0: inst60000079, arg1: specific_interface0, type: type(inst(WitnessType))}
502+
// CHECK:STDOUT: inst60000085: {kind: LookupImplWitness, arg0: inst60000079, arg1: specific_interface60000000, type: type(inst(WitnessType))}
503503
// CHECK:STDOUT: inst60000086: {kind: FunctionTypeWithSelfType, arg0: inst60000050, arg1: inst60000079, type: type(TypeType)}
504504
// CHECK:STDOUT: inst60000087: {kind: ImplWitnessAccess, arg0: inst60000085, arg1: element0, type: type(symbolic_constant69)}
505505
// CHECK:STDOUT: inst60000088: {kind: SpecificImplFunction, arg0: inst60000087, arg1: specific6, type: type(inst(SpecificFunctionType))}
@@ -594,18 +594,18 @@ fn Foo[T:! type](p: T*) -> (T*, ()) {
594594
// CHECK:STDOUT: inst600000E1: {kind: PatternType, arg0: inst600000E0, type: type(TypeType)}
595595
// CHECK:STDOUT: inst600000E2: {kind: RequireCompleteType, arg0: inst600000C0, type: type(inst(WitnessType))}
596596
// CHECK:STDOUT: inst600000E3: {kind: RequireCompleteType, arg0: inst600000BF, type: type(inst(WitnessType))}
597-
// CHECK:STDOUT: inst600000E4: {kind: LookupImplWitness, arg0: inst600000BE, arg1: specific_interface0, type: type(inst(WitnessType))}
597+
// CHECK:STDOUT: inst600000E4: {kind: LookupImplWitness, arg0: inst600000BE, arg1: specific_interface60000000, type: type(inst(WitnessType))}
598598
// CHECK:STDOUT: inst600000E5: {kind: FunctionTypeWithSelfType, arg0: inst60000050, arg1: inst600000BE, type: type(TypeType)}
599599
// CHECK:STDOUT: inst600000E6: {kind: ImplWitnessAccess, arg0: inst600000E4, arg1: element0, type: type(symbolic_constant145)}
600600
// CHECK:STDOUT: inst600000E7: {kind: SpecificImplFunction, arg0: inst600000E6, arg1: specific13, type: type(inst(SpecificFunctionType))}
601601
// CHECK:STDOUT: inst600000E8: {kind: RequireCompleteType, arg0: inst600000E0, type: type(inst(WitnessType))}
602602
// CHECK:STDOUT: inst600000E9: {kind: RequireCompleteType, arg0: inst600000DD, type: type(inst(WitnessType))}
603-
// CHECK:STDOUT: inst600000EA: {kind: LookupImplWitness, arg0: inst600000DC, arg1: specific_interface0, type: type(inst(WitnessType))}
603+
// CHECK:STDOUT: inst600000EA: {kind: LookupImplWitness, arg0: inst600000DC, arg1: specific_interface60000000, type: type(inst(WitnessType))}
604604
// CHECK:STDOUT: inst600000EB: {kind: FunctionTypeWithSelfType, arg0: inst60000050, arg1: inst600000DC, type: type(TypeType)}
605605
// CHECK:STDOUT: inst600000EC: {kind: ImplWitnessAccess, arg0: inst600000EA, arg1: element0, type: type(symbolic_constant154)}
606606
// CHECK:STDOUT: inst600000ED: {kind: SpecificImplFunction, arg0: inst600000EC, arg1: specific14, type: type(inst(SpecificFunctionType))}
607607
// CHECK:STDOUT: inst600000EE: {kind: RequireCompleteType, arg0: inst600000DF, type: type(inst(WitnessType))}
608-
// CHECK:STDOUT: inst600000EF: {kind: LookupImplWitness, arg0: inst600000DE, arg1: specific_interface0, type: type(inst(WitnessType))}
608+
// CHECK:STDOUT: inst600000EF: {kind: LookupImplWitness, arg0: inst600000DE, arg1: specific_interface60000000, type: type(inst(WitnessType))}
609609
// CHECK:STDOUT: inst600000F0: {kind: FunctionTypeWithSelfType, arg0: inst60000050, arg1: inst600000DE, type: type(TypeType)}
610610
// CHECK:STDOUT: inst600000F1: {kind: ImplWitnessAccess, arg0: inst600000EF, arg1: element0, type: type(symbolic_constant159)}
611611
// CHECK:STDOUT: inst600000F2: {kind: SpecificImplFunction, arg0: inst600000F1, arg1: specific15, type: type(inst(SpecificFunctionType))}
@@ -657,29 +657,29 @@ fn Foo[T:! type](p: T*) -> (T*, ()) {
657657
// CHECK:STDOUT: inst60000120: {kind: PatternType, arg0: inst6000011F, type: type(TypeType)}
658658
// CHECK:STDOUT: inst60000121: {kind: RequireCompleteType, arg0: inst600000F8, type: type(inst(WitnessType))}
659659
// CHECK:STDOUT: inst60000122: {kind: RequireCompleteType, arg0: inst600000F7, type: type(inst(WitnessType))}
660-
// CHECK:STDOUT: inst60000123: {kind: LookupImplWitness, arg0: inst600000F6, arg1: specific_interface0, type: type(inst(WitnessType))}
660+
// CHECK:STDOUT: inst60000123: {kind: LookupImplWitness, arg0: inst600000F6, arg1: specific_interface60000000, type: type(inst(WitnessType))}
661661
// CHECK:STDOUT: inst60000124: {kind: FunctionTypeWithSelfType, arg0: inst60000050, arg1: inst600000F6, type: type(TypeType)}
662662
// CHECK:STDOUT: inst60000125: {kind: ImplWitnessAccess, arg0: inst60000123, arg1: element0, type: type(symbolic_constant226)}
663663
// CHECK:STDOUT: inst60000126: {kind: SpecificImplFunction, arg0: inst60000125, arg1: specific19, type: type(inst(SpecificFunctionType))}
664664
// CHECK:STDOUT: inst60000127: {kind: RequireCompleteType, arg0: inst6000011F, type: type(inst(WitnessType))}
665665
// CHECK:STDOUT: inst60000128: {kind: RequireCompleteType, arg0: inst6000011A, type: type(inst(WitnessType))}
666-
// CHECK:STDOUT: inst60000129: {kind: LookupImplWitness, arg0: inst60000119, arg1: specific_interface0, type: type(inst(WitnessType))}
666+
// CHECK:STDOUT: inst60000129: {kind: LookupImplWitness, arg0: inst60000119, arg1: specific_interface60000000, type: type(inst(WitnessType))}
667667
// CHECK:STDOUT: inst6000012A: {kind: FunctionTypeWithSelfType, arg0: inst60000050, arg1: inst60000119, type: type(TypeType)}
668668
// CHECK:STDOUT: inst6000012B: {kind: ImplWitnessAccess, arg0: inst60000129, arg1: element0, type: type(symbolic_constant235)}
669669
// CHECK:STDOUT: inst6000012C: {kind: SpecificImplFunction, arg0: inst6000012B, arg1: specific20, type: type(inst(SpecificFunctionType))}
670670
// CHECK:STDOUT: inst6000012D: {kind: RequireCompleteType, arg0: inst6000011C, type: type(inst(WitnessType))}
671-
// CHECK:STDOUT: inst6000012E: {kind: LookupImplWitness, arg0: inst6000011B, arg1: specific_interface0, type: type(inst(WitnessType))}
671+
// CHECK:STDOUT: inst6000012E: {kind: LookupImplWitness, arg0: inst6000011B, arg1: specific_interface60000000, type: type(inst(WitnessType))}
672672
// CHECK:STDOUT: inst6000012F: {kind: FunctionTypeWithSelfType, arg0: inst60000050, arg1: inst6000011B, type: type(TypeType)}
673673
// CHECK:STDOUT: inst60000130: {kind: ImplWitnessAccess, arg0: inst6000012E, arg1: element0, type: type(symbolic_constant240)}
674674
// CHECK:STDOUT: inst60000131: {kind: SpecificImplFunction, arg0: inst60000130, arg1: specific21, type: type(inst(SpecificFunctionType))}
675675
// CHECK:STDOUT: inst60000132: {kind: RequireCompleteType, arg0: inst6000011E, type: type(inst(WitnessType))}
676-
// CHECK:STDOUT: inst60000133: {kind: LookupImplWitness, arg0: inst6000011D, arg1: specific_interface0, type: type(inst(WitnessType))}
676+
// CHECK:STDOUT: inst60000133: {kind: LookupImplWitness, arg0: inst6000011D, arg1: specific_interface60000000, type: type(inst(WitnessType))}
677677
// CHECK:STDOUT: inst60000134: {kind: FunctionTypeWithSelfType, arg0: inst60000050, arg1: inst6000011D, type: type(TypeType)}
678678
// CHECK:STDOUT: inst60000135: {kind: ImplWitnessAccess, arg0: inst60000133, arg1: element0, type: type(symbolic_constant245)}
679679
// CHECK:STDOUT: inst60000136: {kind: SpecificImplFunction, arg0: inst60000135, arg1: specific22, type: type(inst(SpecificFunctionType))}
680680
// CHECK:STDOUT: inst60000137: {kind: PatternType, arg0: inst600000F7, type: type(TypeType)}
681-
// CHECK:STDOUT: inst60000138: {kind: LookupImplWitness, arg0: inst6000001B, arg1: specific_interface0, type: type(inst(WitnessType))}
682-
// CHECK:STDOUT: inst60000139: {kind: LookupImplWitness, arg0: inst6000001C, arg1: specific_interface0, type: type(inst(WitnessType))}
681+
// CHECK:STDOUT: inst60000138: {kind: LookupImplWitness, arg0: inst6000001B, arg1: specific_interface60000000, type: type(inst(WitnessType))}
682+
// CHECK:STDOUT: inst60000139: {kind: LookupImplWitness, arg0: inst6000001C, arg1: specific_interface60000000, type: type(inst(WitnessType))}
683683
// CHECK:STDOUT: inst6000013A: {kind: FacetValue, arg0: inst6000001B, arg1: inst_block103, type: type(inst60000047)}
684684
// CHECK:STDOUT: inst6000013B: {kind: FunctionTypeWithSelfType, arg0: inst60000050, arg1: inst6000013A, type: type(TypeType)}
685685
// CHECK:STDOUT: inst6000013C: {kind: ImplWitnessAccess, arg0: inst60000138, arg1: element0, type: type(symbolic_constant256)}

toolchain/sem_ir/file.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ File::File(const Parse::Tree* parse_tree, CheckIRId check_ir_id,
4040
classes_(IdTag(check_ir_id.index, 0)),
4141
associated_constants_(IdTag(check_ir_id.index, 0)),
4242
impls_(*this),
43+
specific_interfaces_(IdTag(check_ir_id.index, 0)),
4344
// The `+1` prevents adding a tag to the global `NameSpace::PackageInstId`
4445
// instruction. It's not a "singleton" instruction, but it's a unique
4546
// instruction id that comes right after the singletons.

toolchain/sem_ir/ids.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ auto ImplId::Print(llvm::raw_ostream& out) const -> void {
7070
IdBase::PrintHex(out);
7171
}
7272

73+
auto SpecificInterfaceId::Print(llvm::raw_ostream& out) const -> void {
74+
IdBase::PrintHex(out);
75+
}
76+
7377
auto GenericInstIndex::Print(llvm::raw_ostream& out) const -> void {
7478
out << "generic_inst";
7579
if (has_value()) {

toolchain/sem_ir/ids.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ struct SpecificInterfaceId : public IdBase<SpecificInterfaceId> {
391391
static constexpr llvm::StringLiteral Label = "specific_interface";
392392

393393
using IdBase::IdBase;
394+
395+
auto Print(llvm::raw_ostream& out) const -> void;
394396
};
395397

396398
// The index of an instruction that depends on generic parameters within a

toolchain/sem_ir/inst_namer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class InstNamer {
6161
index = sem_ir_->functions().GetRawIndex(id);
6262
} else if constexpr (std::is_same_v<IdT, ImplId>) {
6363
index = sem_ir_->impls().GetRawIndex(id);
64+
} else if constexpr (std::is_same_v<IdT, SpecificInterfaceId>) {
65+
index = sem_ir_->specific_interfaces().GetRawIndex(id);
6466
}
6567
return static_cast<ScopeId>(GetScopeIdOffset(ScopeIdTypeEnum::For<IdT>) +
6668
index);

0 commit comments

Comments
 (0)