From d81ed4b58fddf3d180955c9f0f64d9cea015c2eb Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 10 Dec 2024 12:23:24 -0800 Subject: [PATCH] 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`. --- toolchain/sem_ir/block_value_store.h | 6 ++++-- toolchain/sem_ir/copy_on_write_block.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/toolchain/sem_ir/block_value_store.h b/toolchain/sem_ir/block_value_store.h index f5f812d611bf..d27e2fd54c5c 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 7fc279c3745d..1ec9a11b7eda 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: