Refactor InstBlockStore's API, AddDefaultValue -> AddPlaceholder (#5166)

`AddDefaultValue` doesn't quite capture the intended semantics; it
should typically be replaced with an actual value when dealing with
control flows. Trying to indicate the "assign later" with
`AddPlaceholder`, mirroring `AddPlaceholderInst`.

Shifting the `protected` functionality on `BlockValueStore` so that it's
not providing functions just for `InstBlockStore` to use. Also hoping
that seeing the comments next to the function name makes them easier to
understand, whereas `using` buries that a little.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
Jon Ross-Perkins
2025-03-21 23:09:37 +00:00
committed by GitHub
co-authored by Richard Smith
parent 6dbcc78e6c
commit c0ee446cec
8 changed files with 43 additions and 51 deletions
+2 -2
View File
@@ -29,7 +29,7 @@ auto InstBlockStack::PeekOrAdd(int depth) -> SemIR::InstBlockId {
int index = id_stack_.size() - depth - 1;
auto& slot = id_stack_[index];
if (!slot.has_value()) {
slot = sem_ir_->inst_blocks().AddDefaultValue();
slot = sem_ir_->inst_blocks().AddPlaceholder();
}
return slot;
}
@@ -42,7 +42,7 @@ auto InstBlockStack::Pop() -> SemIR::InstBlockId {
// Finalize the block.
if (!insts.empty() && id != SemIR::InstBlockId::Unreachable) {
if (id.has_value()) {
sem_ir_->inst_blocks().Set(id, insts);
sem_ir_->inst_blocks().ReplacePlaceholder(id, insts);
} else {
id = sem_ir_->inst_blocks().Add(insts);
}