Bladeren bron

Store pointer not reference in `ConstantStore` (#4398)

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
josh11b 1 jaar geleden
bovenliggende
commit
c721a020a7
3 gewijzigde bestanden met toevoegingen van 6 en 6 verwijderingen
  1. 3 3
      toolchain/sem_ir/constant.cpp
  2. 2 2
      toolchain/sem_ir/constant.h
  3. 1 1
      toolchain/sem_ir/file.cpp

+ 3 - 3
toolchain/sem_ir/constant.cpp

@@ -10,7 +10,7 @@ namespace Carbon::SemIR {
 
 auto ConstantStore::GetOrAdd(Inst inst, bool is_symbolic) -> ConstantId {
   auto result = map_.Insert(inst, [&] {
-    auto inst_id = sem_ir_.insts().AddInNoBlock(LocIdAndInst::NoLoc(inst));
+    auto inst_id = sem_ir_->insts().AddInNoBlock(LocIdAndInst::NoLoc(inst));
     ConstantId const_id = ConstantId::Invalid;
     if (is_symbolic) {
       // The instruction in the constants store is an abstract symbolic
@@ -20,11 +20,11 @@ auto ConstantStore::GetOrAdd(Inst inst, bool is_symbolic) -> ConstantId {
                            .generic_id = GenericId::Invalid,
                            .index = GenericInstIndex::Invalid};
       const_id =
-          sem_ir_.constant_values().AddSymbolicConstant(symbolic_constant);
+          sem_ir_->constant_values().AddSymbolicConstant(symbolic_constant);
     } else {
       const_id = SemIR::ConstantId::ForTemplateConstant(inst_id);
     }
-    sem_ir_.constant_values().Set(inst_id, const_id);
+    sem_ir_->constant_values().Set(inst_id, const_id);
     constants_.push_back(inst_id);
     return const_id;
   });

+ 2 - 2
toolchain/sem_ir/constant.h

@@ -143,7 +143,7 @@ class ConstantValueStore {
 // Provides storage for instructions representing deduplicated global constants.
 class ConstantStore {
  public:
-  explicit ConstantStore(File& sem_ir) : sem_ir_(sem_ir) {}
+  explicit ConstantStore(File* sem_ir) : sem_ir_(sem_ir) {}
 
   // Adds a new constant instruction, or gets the existing constant with this
   // value. Returns the ID of the constant.
@@ -166,7 +166,7 @@ class ConstantStore {
   auto size() const -> int { return constants_.size(); }
 
  private:
-  File& sem_ir_;
+  File* const sem_ir_;
   Map<Inst, ConstantId> map_;
   llvm::SmallVector<InstId, 0> constants_;
 };

+ 1 - 1
toolchain/sem_ir/file.cpp

@@ -32,7 +32,7 @@ File::File(CheckIRId check_ir_id, IdentifierId package_id,
       name_scopes_(&insts_),
       constant_values_(ConstantId::NotConstant),
       inst_blocks_(allocator_),
-      constants_(*this) {
+      constants_(this) {
   // `type` and the error type are both complete types.
   types_.SetValueRepr(TypeId::TypeType,
                       {.kind = ValueRepr::Copy, .type_id = TypeId::TypeType});