Make function definitions allocate the body more lazily. (#2557)

Lazy allocation means that we can use a single node block for _all_ empty node blocks. The change in timing for when the definition node is emitted shouldn't affect semantic correctness; the signature is already present for recursive calls.
This commit is contained in:
Jon Ross-Perkins
2023-01-27 11:46:12 -08:00
committed by GitHub
parent 2ffbe72384
commit 94cbb9d917
23 changed files with 78 additions and 117 deletions
@@ -16,18 +16,6 @@ auto SemanticsNodeBlockStack::Push() -> void {
stack_.push_back(SemanticsNodeBlockId::Invalid);
}
auto SemanticsNodeBlockStack::PushWithUnconditionalAlloc()
-> SemanticsNodeBlockId {
SemanticsNodeBlockId block_id(node_blocks_->size());
CARBON_VLOG() << "NodeBlock Push " << stack_.size() << ": " << block_id
<< "\n";
CARBON_CHECK(stack_.size() < (1 << 20))
<< "Excessive stack size: likely infinite loop";
node_blocks_->resize(block_id.index + 1);
stack_.push_back(block_id);
return block_id;
}
auto SemanticsNodeBlockStack::PeekForAdd() -> SemanticsNodeBlockId {
auto& back = stack_.back();
if (!back.is_valid()) {