Semantic analysis for if expressions (#2893)

Add semantic analysis and semantics IR building for `if` expressions, and add the first parts of control flow handling to semantics IR. After discussion with @chandlerc, use [block arguments](https://en.wikipedia.org/wiki/Static_single-assignment_form#Block_arguments) to convey values from the two arms of the `if` to the result. For now, only a single block argument is supported, but we should revisit this as we explore more of the requirements of the Semantics IR form.

Functions can now contain multiple code blocks, so grab the entry block up-front instead of assuming the entry block will be at the top of the block stack when we reach the end of function emission.

Add trivial support for `bool` type literal, because without it we can't write testcases.
This commit is contained in:
Richard Smith
2023-06-13 14:38:27 -07:00
committed by GitHub
parent 9606ce2127
commit 202d3f5993
43 changed files with 646 additions and 161 deletions
@@ -27,6 +27,12 @@ class SemanticsNodeBlockStack {
// order to support lazy allocation.
auto Push() -> void;
// Allocates and pushes a new node block.
auto PushForAdd() -> SemanticsNodeBlockId {
Push();
return PeekForAdd();
}
// Peeks at the top node block. This does not trigger lazy allocation, so the
// returned node block may be invalid.
auto Peek() -> SemanticsNodeBlockId { return stack_.back(); }