Selaa lähdekoodia

Add unit tagging to VtableId (#6216)

David Blaikie 6 kuukautta sitten
vanhempi
sitoutus
63118265f0

+ 1 - 0
toolchain/sem_ir/file.cpp

@@ -45,6 +45,7 @@ File::File(const Parse::Tree* parse_tree, CheckIRId check_ir_id,
       // instruction. It's not a "singleton" instruction, but it's a unique
       // instruction. It's not a "singleton" instruction, but it's a unique
       // instruction id that comes right after the singletons.
       // instruction id that comes right after the singletons.
       insts_(this, SingletonInstKinds.size() + 1),
       insts_(this, SingletonInstKinds.size() + 1),
+      vtables_(IdTag(check_ir_id.index, 0)),
       constant_values_(ConstantId::NotConstant, &insts_),
       constant_values_(ConstantId::NotConstant, &insts_),
       inst_blocks_(allocator_),
       inst_blocks_(allocator_),
       constants_(this) {
       constants_(this) {

+ 4 - 0
toolchain/sem_ir/ids.cpp

@@ -62,6 +62,10 @@ auto ClassId::Print(llvm::raw_ostream& out) const -> void {
   IdBase::PrintHex(out);
   IdBase::PrintHex(out);
 }
 }
 
 
+auto VtableId::Print(llvm::raw_ostream& out) const -> void {
+  IdBase::PrintHex(out);
+}
+
 auto AssociatedConstantId::Print(llvm::raw_ostream& out) const -> void {
 auto AssociatedConstantId::Print(llvm::raw_ostream& out) const -> void {
   IdBase::PrintHex(out);
   IdBase::PrintHex(out);
 }
 }

+ 2 - 0
toolchain/sem_ir/ids.h

@@ -324,6 +324,8 @@ struct VtableId : public IdBase<VtableId> {
   static constexpr llvm::StringLiteral Label = "vtable";
   static constexpr llvm::StringLiteral Label = "vtable";
 
 
   using IdBase::IdBase;
   using IdBase::IdBase;
+
+  auto Print(llvm::raw_ostream& out) const -> void;
 };
 };
 
 
 // The ID of an `Interface`.
 // The ID of an `Interface`.

+ 2 - 0
toolchain/sem_ir/inst_namer.h

@@ -63,6 +63,8 @@ class InstNamer {
       index = sem_ir_->impls().GetRawIndex(id);
       index = sem_ir_->impls().GetRawIndex(id);
     } else if constexpr (std::is_same_v<IdT, SpecificInterfaceId>) {
     } else if constexpr (std::is_same_v<IdT, SpecificInterfaceId>) {
       index = sem_ir_->specific_interfaces().GetRawIndex(id);
       index = sem_ir_->specific_interfaces().GetRawIndex(id);
+    } else if constexpr (std::is_same_v<IdT, VtableId>) {
+      index = sem_ir_->vtables().GetRawIndex(id);
     }
     }
     return static_cast<ScopeId>(GetScopeIdOffset(ScopeIdTypeEnum::For<IdT>) +
     return static_cast<ScopeId>(GetScopeIdOffset(ScopeIdTypeEnum::For<IdT>) +
                                 index);
                                 index);