Просмотр исходного кода

Rename mutable accessor in `InstBlock` store. (#4659)

Mutating a block is a strange and rare operation and shouldn't have an
innocuous name like `Get`.
Richard Smith 1 год назад
Родитель
Сommit
d81ed4b58f
2 измененных файлов с 5 добавлено и 3 удалено
  1. 4 2
      toolchain/sem_ir/block_value_store.h
  2. 1 1
      toolchain/sem_ir/copy_on_write_block.h

+ 4 - 2
toolchain/sem_ir/block_value_store.h

@@ -50,8 +50,10 @@ class BlockValueStore : public Yaml::Printable<BlockValueStore<IdT>> {
     return values_.Get(id);
   }
 
-  // Returns the requested block.
-  auto Get(IdT id) -> llvm::MutableArrayRef<ElementType> {
+  // Returns a mutable view of the requested block. This operation should be
+  // avoided where possible; we generally want blocks to be immutable once
+  // created.
+  auto GetMutable(IdT id) -> llvm::MutableArrayRef<ElementType> {
     return values_.Get(id);
   }
 

+ 1 - 1
toolchain/sem_ir/copy_on_write_block.h

@@ -58,7 +58,7 @@ class CopyOnWriteBlock {
     if (id_ == source_id_) {
       id_ = (file_.*ValueStore)().Add((file_.*ValueStore)().Get(source_id_));
     }
-    (file_.*ValueStore)().Get(id_)[i] = value;
+    (file_.*ValueStore)().GetMutable(id_)[i] = value;
   }
 
  private: