Split global init out from InstBlockStack. (#4101)

Creates a `GlobalInit` class for storing relevant values, pulling
functions off `InstBlockStack` and `Context`. Adds a `Context` pointer
just so that it doesn't need to be passed in on each call (`Finalize` in
particular uses several members).

Note we have several different `InstBlockStack` instances, so several
copies of the relevant members were simply unused.
This commit is contained in:
Jon Ross-Perkins
2024-07-03 17:49:47 +00:00
committed by GitHub
parent 5ebcbae2e8
commit cf389bf5d3
9 changed files with 120 additions and 60 deletions
+4 -9
View File
@@ -21,9 +21,10 @@ auto InstBlockStack::Push(SemIR::InstBlockId id) -> void {
++size_;
}
auto InstBlockStack::PushGlobalInit() -> void {
Push(init_block_id_);
stack_[size_ - 1].content = std::move(init_block_);
auto InstBlockStack::Push(SemIR::InstBlockId id,
llvm::ArrayRef<SemIR::InstId> inst_ids) -> void {
Push(id);
stack_[size_ - 1].content = inst_ids;
}
auto InstBlockStack::PeekOrAdd(int depth) -> SemIR::InstBlockId {
@@ -57,12 +58,6 @@ auto InstBlockStack::Pop() -> SemIR::InstBlockId {
return back.id;
}
auto InstBlockStack::PopGlobalInit() -> void {
init_block_ = std::move(stack_[size_ - 1].content);
init_block_id_ = stack_[size_ - 1].id;
PopAndDiscard();
}
auto InstBlockStack::PopAndDiscard() -> void {
CARBON_CHECK(!empty()) << "no current block";
--size_;