diff --git a/toolchain/sem_ir/block_value_store.h b/toolchain/sem_ir/block_value_store.h index f5f812d611bfb..d27e2fd54c5c3 100644 --- a/toolchain/sem_ir/block_value_store.h +++ b/toolchain/sem_ir/block_value_store.h @@ -50,8 +50,10 @@ class BlockValueStore : public Yaml::Printable> { return values_.Get(id); } - // Returns the requested block. - auto Get(IdT id) -> llvm::MutableArrayRef { + // 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 { return values_.Get(id); } diff --git a/toolchain/sem_ir/copy_on_write_block.h b/toolchain/sem_ir/copy_on_write_block.h index 7fc279c3745d3..1ec9a11b7eda0 100644 --- a/toolchain/sem_ir/copy_on_write_block.h +++ b/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: