From 0755598fa85b12da89d414e15337d425678bca53 Mon Sep 17 00:00:00 2001 From: Jon Ross-Perkins Date: Tue, 25 Oct 2022 17:23:04 -0700 Subject: [PATCH] Refactor semantics to provide a more block-y IR (#2349) As a step towards builtins, provide more blocks. The intent is that any significant scope change will become its own NodeBlock. Builtins should produce the first set of node blocks. Note, SemanticsIR as set up here isn't handling ordering of import processing -- I haven't thought that through much beyond that we probably want some lighter-weight processing of the parse tree to achieve it. But I think the essence of loading builtins first as their own IR block is... probably right? --- toolchain/driver/driver.cpp | 3 +- toolchain/semantics/semantics_ir.cpp | 41 ++++++-------- toolchain/semantics/semantics_ir.h | 20 +++++-- toolchain/semantics/semantics_node.cpp | 9 +++ toolchain/semantics/semantics_node.h | 45 ++++++++++++++- toolchain/semantics/semantics_node_kind.def | 16 ++---- .../semantics_parse_tree_handler.cpp | 55 +++++++++++++++++-- .../semantics/semantics_parse_tree_handler.h | 52 ++++++++---------- toolchain/semantics/testdata/empty.carbon | 4 +- .../semantics/testdata/function/basic.carbon | 15 +++-- .../semantics/testdata/function/order.carbon | 37 +++++++------ .../testdata/return/binary_op.carbon | 27 +++++---- .../semantics/testdata/return/literal.carbon | 21 ++++--- .../semantics/testdata/return/trivial.carbon | 17 +++--- 14 files changed, 232 insertions(+), 130 deletions(-) diff --git a/toolchain/driver/driver.cpp b/toolchain/driver/driver.cpp index faaec5a3283a..dcdfbe07c9c1 100644 --- a/toolchain/driver/driver.cpp +++ b/toolchain/driver/driver.cpp @@ -162,7 +162,8 @@ auto Driver::RunDumpSubcommand(DiagnosticConsumer& consumer, return !tokenized_source.has_errors() && !parse_tree.has_errors(); } - SemanticsIR semantics_ir(tokenized_source, parse_tree); + SemanticsIR semantics_ir; + semantics_ir.Build(tokenized_source, parse_tree); if (dump_mode == DumpMode::SemanticsIR) { consumer.Flush(); semantics_ir.Print(output_stream_); diff --git a/toolchain/semantics/semantics_ir.cpp b/toolchain/semantics/semantics_ir.cpp index f9c186bcd152..972749f1f000 100644 --- a/toolchain/semantics/semantics_ir.cpp +++ b/toolchain/semantics/semantics_ir.cpp @@ -12,51 +12,42 @@ namespace Carbon { -SemanticsIR::SemanticsIR(const TokenizedBuffer& tokens, - const ParseTree& parse_tree) { +auto SemanticsIR::Build(const TokenizedBuffer& tokens, + const ParseTree& parse_tree) -> void { SemanticsParseTreeHandler(tokens, parse_tree, *this).Build(); } auto SemanticsIR::Print(llvm::raw_ostream& out) const -> void { + constexpr int Indent = 2; + out << "identifiers = {\n"; for (int32_t i = 0; i < static_cast(identifiers_.size()); ++i) { - out.indent(2); + out.indent(Indent); out << SemanticsIdentifierId(i) << " = \"" << identifiers_[i] << "\";\n"; } out << "},\n"; out << "integer_literals = {\n"; for (int32_t i = 0; i < static_cast(integer_literals_.size()); ++i) { - out.indent(2); + out.indent(Indent); out << SemanticsIntegerLiteralId(i) << " = " << integer_literals_[i] << ";\n"; } out << "},\n"; - out << "nodes = {\n"; - int indent = 2; - for (int32_t i = 0; i < static_cast(nodes_.size()); ++i) { - SemanticsNode node = nodes_[i]; + out << "node_blocks = {\n"; + for (int32_t i = 0; i < static_cast(node_blocks_.size()); ++i) { + out.indent(Indent); + out << SemanticsNodeBlockId(i) << " = {\n"; - // Adjust indent for block contents. - switch (node.kind()) { - case SemanticsNodeKind::CodeBlockStart(): - case SemanticsNodeKind::FunctionDefinitionStart(): - out.indent(indent); - indent += 2; - break; - case SemanticsNodeKind::CodeBlockEnd(): - case SemanticsNodeKind::FunctionDefinitionEnd(): - indent -= 2; - out.indent(indent); - break; - default: - // No indentation change. - out.indent(indent); - break; + const auto& node_block = node_blocks_[i]; + for (int32_t i = 0; i < static_cast(node_block.size()); ++i) { + out.indent(2 * Indent); + out << SemanticsNodeId(i) << " = " << node_block[i] << ";\n"; } - out << SemanticsNodeId(i) << " = " << node << ";\n"; + out.indent(Indent); + out << "},\n"; } out << "}\n"; } diff --git a/toolchain/semantics/semantics_ir.h b/toolchain/semantics/semantics_ir.h index a8c76c889e56..92d60dcecc87 100644 --- a/toolchain/semantics/semantics_ir.h +++ b/toolchain/semantics/semantics_ir.h @@ -19,7 +19,9 @@ namespace Carbon { // Provides semantic analysis on a ParseTree. class SemanticsIR { public: - SemanticsIR(const TokenizedBuffer& tokens, const ParseTree& parse_tree); + // Adds the IR for the provided ParseTree. + auto Build(const TokenizedBuffer& tokens, const ParseTree& parse_tree) + -> void; // Prints the full IR. auto Print(llvm::raw_ostream& out) const -> void; @@ -40,15 +42,23 @@ class SemanticsIR { return id; } - auto AddNode(SemanticsNode node) -> SemanticsNodeId { - SemanticsNodeId id(nodes_.size()); - nodes_.push_back(node); + // Starts a new node block. + auto AddNodeBlock() -> SemanticsNodeBlockId { + SemanticsNodeBlockId id(node_blocks_.size()); + node_blocks_.resize(node_blocks_.size() + 1); return id; } + auto AddNode(SemanticsNodeBlockId block_id, SemanticsNode node) { + auto& block = node_blocks_[block_id.id]; + SemanticsNodeId node_id(block.size()); + block.push_back(node); + return node_id; + } + llvm::SmallVector identifiers_; llvm::SmallVector integer_literals_; - llvm::SmallVector nodes_; + llvm::SmallVector> node_blocks_; }; } // namespace Carbon diff --git a/toolchain/semantics/semantics_node.cpp b/toolchain/semantics/semantics_node.cpp index e2df4a4999d7..98ebd0f82e74 100644 --- a/toolchain/semantics/semantics_node.cpp +++ b/toolchain/semantics/semantics_node.cpp @@ -27,6 +27,15 @@ static auto PrintArgs(llvm::raw_ostream& out, out << integer_literal; } +static auto PrintArgs(llvm::raw_ostream& out, SemanticsNodeBlockId node_block) { + out << node_block; +} + +static auto PrintArgs(llvm::raw_ostream& out, + SemanticsNodeIdAndNodeBlockId node_and_node_block) { + out << node_and_node_block.node << ", " << node_and_node_block.node_block; +} + void SemanticsNode::Print(llvm::raw_ostream& out) const { out << kind_ << "("; switch (kind_) { diff --git a/toolchain/semantics/semantics_node.h b/toolchain/semantics/semantics_node.h index df8477149b08..ecdaaf82523f 100644 --- a/toolchain/semantics/semantics_node.h +++ b/toolchain/semantics/semantics_node.h @@ -19,7 +19,7 @@ struct SemanticsNodeId { SemanticsNodeId(SemanticsNodeId const&) = default; auto operator=(const SemanticsNodeId& other) -> SemanticsNodeId& = default; - void Print(llvm::raw_ostream& out) const { out << "%" << id; } + void Print(llvm::raw_ostream& out) const { out << "node" << id; } int32_t id; }; @@ -29,7 +29,7 @@ struct SemanticsIdentifierId { SemanticsIdentifierId() : id(-1) {} explicit SemanticsIdentifierId(int32_t id) : id(id) {} - void Print(llvm::raw_ostream& out) const { out << "%s" << id; } + void Print(llvm::raw_ostream& out) const { out << "ident" << id; } int32_t id; }; @@ -39,7 +39,17 @@ struct SemanticsIntegerLiteralId { SemanticsIntegerLiteralId() : id(-1) {} explicit SemanticsIntegerLiteralId(int32_t id) : id(id) {} - void Print(llvm::raw_ostream& out) const { out << "%s" << id; } + void Print(llvm::raw_ostream& out) const { out << "int" << id; } + + int32_t id; +}; + +// Type-safe storage of node blocks. +struct SemanticsNodeBlockId { + SemanticsNodeBlockId() : id(-1) {} + explicit SemanticsNodeBlockId(int32_t id) : id(id) {} + + void Print(llvm::raw_ostream& out) const { out << "block" << id; } int32_t id; }; @@ -47,6 +57,10 @@ struct SemanticsIntegerLiteralId { struct SemanticsTwoNodeIds { SemanticsNodeId nodes[2]; }; +struct SemanticsNodeIdAndNodeBlockId { + SemanticsNodeId node; + SemanticsNodeBlockId node_block; +}; union SemanticsNodeArgs { struct None {}; @@ -55,16 +69,24 @@ union SemanticsNodeArgs { explicit SemanticsNodeArgs(SemanticsNodeId one_node) : one_node(one_node) {} explicit SemanticsNodeArgs(SemanticsTwoNodeIds two_nodes) : two_nodes(two_nodes) {} + explicit SemanticsNodeArgs(SemanticsIdentifierId identifier) : identifier(identifier) {} explicit SemanticsNodeArgs(SemanticsIntegerLiteralId integer_literal) : integer_literal(integer_literal) {} + explicit SemanticsNodeArgs(SemanticsNodeBlockId node_block) + : node_block(node_block) {} + explicit SemanticsNodeArgs(SemanticsNodeIdAndNodeBlockId node_and_node_block) + : node_and_node_block(node_and_node_block) {} None no_args; SemanticsNodeId one_node; SemanticsTwoNodeIds two_nodes; + SemanticsIdentifierId identifier; SemanticsIntegerLiteralId integer_literal; + SemanticsNodeBlockId node_block; + SemanticsNodeIdAndNodeBlockId node_and_node_block; }; // TODO: This is currently 8 bytes only because of two_nodes; others are only 4 // bytes. The NodeKind is 1 byte; if we reduced this structure to 7 bytes (3.5 @@ -95,6 +117,7 @@ class SemanticsNode { SemanticsNodeKind::Name(), \ SemanticsNodeArgs(SemanticsTwoNodeIds{node1, node2})); \ } + #define CARBON_SEMANTICS_MAKE_identifier(Name) \ static auto Make##Name(SemanticsIdentifierId identifier)->SemanticsNode { \ return SemanticsNode(SemanticsNodeKind::Name(), \ @@ -106,6 +129,19 @@ class SemanticsNode { return SemanticsNode(SemanticsNodeKind::Name(), \ SemanticsNodeArgs(integer_literal)); \ } +#define CARBON_SEMANTICS_MAKE_node_block(Name) \ + static auto Make##Name(SemanticsNodeBlockId node_block)->SemanticsNode { \ + return SemanticsNode(SemanticsNodeKind::Name(), \ + SemanticsNodeArgs(node_block)); \ + } +#define CARBON_SEMANTICS_MAKE_node_and_node_block(Name) \ + static auto Make##Name(SemanticsNodeId node, \ + SemanticsNodeBlockId node_block) \ + ->SemanticsNode { \ + return SemanticsNode( \ + SemanticsNodeKind::Name(), \ + SemanticsNodeArgs(SemanticsNodeIdAndNodeBlockId{node, node_block})); \ + } #define CARBON_SEMANTICS_NODE_KIND(Name, ArgsType) \ CARBON_SEMANTICS_MAKE_##ArgsType(Name) @@ -114,8 +150,11 @@ class SemanticsNode { #undef CARBON_SEMANTICS_MAKE_no_args #undef CARBON_SEMANTICS_MAKE_one_node #undef CARBON_SEMANTICS_MAKE_two_nodes + #undef CARBON_SEMANTICS_MAKE_identifier #undef CARBON_SEMANTICS_MAKE_integer_literal +#undef CARBON_SEMANTICS_MAKE_node_block +#undef CARBON_SEMANTICS_MAKE_node_and_node_block SemanticsNode() : kind_(SemanticsNodeKind::Invalid()) {} diff --git a/toolchain/semantics/semantics_node_kind.def b/toolchain/semantics/semantics_node_kind.def index 9fd91fcd8ffe..14c69a72592d 100644 --- a/toolchain/semantics/semantics_node_kind.def +++ b/toolchain/semantics/semantics_node_kind.def @@ -19,23 +19,17 @@ CARBON_SEMANTICS_NODE_KIND(Invalid, no_args) // Two nodes: lhs and rhs. CARBON_SEMANTICS_NODE_KIND(BinaryOperatorAdd, two_nodes) -// No args. -CARBON_SEMANTICS_NODE_KIND(CodeBlockStart, no_args) - -// No args. -CARBON_SEMANTICS_NODE_KIND(CodeBlockEnd, no_args) +// The code block. +CARBON_SEMANTICS_NODE_KIND(CodeBlock, node_block) // One node: the name. // TODO: Add a declaration scope as a second arg. CARBON_SEMANTICS_NODE_KIND(FunctionDeclaration, one_node) -// One node: the FunctionDeclaration. -CARBON_SEMANTICS_NODE_KIND(FunctionDefinitionStart, one_node) +// Two nodes: a FunctionDeclaration and its body. +CARBON_SEMANTICS_NODE_KIND(FunctionDefinition, node_and_node_block) -// No args. -CARBON_SEMANTICS_NODE_KIND(FunctionDefinitionEnd, no_args) - -// The decalred IdentifierId. +// The declared IdentifierId. CARBON_SEMANTICS_NODE_KIND(Identifier, identifier) // The declared IntegerLiteralId. diff --git a/toolchain/semantics/semantics_parse_tree_handler.cpp b/toolchain/semantics/semantics_parse_tree_handler.cpp index 0d885d0914db..c34673f61972 100644 --- a/toolchain/semantics/semantics_parse_tree_handler.cpp +++ b/toolchain/semantics/semantics_parse_tree_handler.cpp @@ -12,6 +12,9 @@ namespace Carbon { auto SemanticsParseTreeHandler::Build() -> void { + // Add a block for the ParseTree. + node_block_stack_.push_back(semantics_->AddNodeBlock()); + auto range = parse_tree_->postorder(); for (auto it = range.begin();; ++it) { auto parse_node = *it; @@ -30,6 +33,7 @@ auto SemanticsParseTreeHandler::Build() -> void { } case ParseNodeKind::FileEnd(): { ++it; + CARBON_CHECK(node_block_stack_.size() == 1) << node_block_stack_.size(); CARBON_CHECK(it == range.end()) << "FileEnd should always be last, found " << parse_tree_->node_kind(*it); @@ -67,6 +71,47 @@ auto SemanticsParseTreeHandler::Build() -> void { llvm_unreachable("Should always end at FileEnd"); } +auto SemanticsParseTreeHandler::AddNode(SemanticsNode node) -> SemanticsNodeId { + return semantics_->AddNode(node_block_stack_.back(), node); +} + +auto SemanticsParseTreeHandler::Push(ParseTree::Node parse_node) -> void { + node_stack_.push_back({parse_node, llvm::None}); +} + +auto SemanticsParseTreeHandler::Push(ParseTree::Node parse_node, + SemanticsNode node) -> void { + auto node_id = AddNode(node); + node_stack_.push_back({parse_node, node_id}); +} + +auto SemanticsParseTreeHandler::Pop(ParseNodeKind pop_parse_kind) -> void { + auto back = node_stack_.back(); + auto parse_kind = parse_tree_->node_kind(back.parse_node); + CARBON_CHECK(parse_kind == pop_parse_kind) + << "Expected " << pop_parse_kind << ", found " << parse_kind; + CARBON_CHECK(!back.result_id) << "Expected no result ID on " << parse_kind; + node_stack_.pop_back(); +} + +auto SemanticsParseTreeHandler::PopWithResult() -> SemanticsNodeId { + auto back = node_stack_.back(); + auto node_id = *back.result_id; + node_stack_.pop_back(); + return node_id; +} + +auto SemanticsParseTreeHandler::PopWithResult(ParseNodeKind pop_parse_kind) + -> SemanticsNodeId { + auto back = node_stack_.back(); + auto parse_kind = parse_tree_->node_kind(back.parse_node); + auto node_id = *back.result_id; + CARBON_CHECK(parse_kind == pop_parse_kind) + << "Expected " << pop_parse_kind << ", found " << parse_kind; + node_stack_.pop_back(); + return node_id; +} + auto SemanticsParseTreeHandler::HandleDeclaredName(ParseTree::Node parse_node) -> void { auto text = parse_tree_->GetNodeText(parse_node); @@ -82,7 +127,7 @@ auto SemanticsParseTreeHandler::HandleFunctionDefinition( node_stack_.pop_back(); } Pop(ParseNodeKind::FunctionDefinitionStart()); - semantics_->AddNode(SemanticsNode::MakeFunctionDefinitionEnd()); + node_block_stack_.pop_back(); Push(parse_node); } @@ -91,9 +136,11 @@ auto SemanticsParseTreeHandler::HandleFunctionDefinitionStart( Pop(ParseNodeKind::ParameterList()); auto name_node_id = PopWithResult(ParseNodeKind::DeclaredName()); Pop(ParseNodeKind::FunctionIntroducer()); - auto decl_id = - semantics_->AddNode(SemanticsNode::MakeFunctionDeclaration(name_node_id)); - semantics_->AddNode(SemanticsNode::MakeFunctionDefinitionStart(decl_id)); + + auto decl_id = AddNode(SemanticsNode::MakeFunctionDeclaration(name_node_id)); + auto block_id = semantics_->AddNodeBlock(); + AddNode(SemanticsNode::MakeFunctionDefinition(decl_id, block_id)); + node_block_stack_.push_back(block_id); Push(parse_node); } diff --git a/toolchain/semantics/semantics_parse_tree_handler.h b/toolchain/semantics/semantics_parse_tree_handler.h index d565e779f54a..3b9e7b2effa7 100644 --- a/toolchain/semantics/semantics_parse_tree_handler.h +++ b/toolchain/semantics/semantics_parse_tree_handler.h @@ -8,6 +8,7 @@ #include "common/check.h" #include "toolchain/parser/parse_tree.h" #include "toolchain/semantics/semantics_ir.h" +#include "toolchain/semantics/semantics_node.h" namespace Carbon { @@ -29,40 +30,27 @@ class SemanticsParseTreeHandler { llvm::Optional result_id; }; - auto Push(ParseTree::Node parse_node) -> void { - node_stack_.push_back({parse_node, llvm::None}); - } + // Adds a node to the current block, returning the produced ID. + auto AddNode(SemanticsNode node) -> SemanticsNodeId; - auto Push(ParseTree::Node parse_node, SemanticsNode node) -> void { - auto node_id = semantics_->AddNode(node); - node_stack_.push_back({parse_node, node_id}); - } + // Pushes a parse tree onto the stack. Used when there is no IR generated by + // the node. + auto Push(ParseTree::Node parse_node) -> void; - auto Pop(ParseNodeKind pop_parse_kind) -> void { - auto back = node_stack_.back(); - auto parse_kind = parse_tree_->node_kind(back.parse_node); - CARBON_CHECK(parse_kind == pop_parse_kind) - << "Expected " << pop_parse_kind << ", found " << parse_kind; - CARBON_CHECK(!back.result_id) << "Expected no result ID on " << parse_kind; - node_stack_.pop_back(); - } + // Pushes a parse tree onto the stack, storing the SemanticsNode as the + // result. + auto Push(ParseTree::Node parse_node, SemanticsNode node) -> void; - auto PopWithResult() -> SemanticsNodeId { - auto back = node_stack_.back(); - auto node_id = *back.result_id; - node_stack_.pop_back(); - return node_id; - } + // Pops the top of the stack, verifying that it's the expected kind. + auto Pop(ParseNodeKind pop_parse_kind) -> void; - auto PopWithResult(ParseNodeKind pop_parse_kind) -> SemanticsNodeId { - auto back = node_stack_.back(); - auto parse_kind = parse_tree_->node_kind(back.parse_node); - auto node_id = *back.result_id; - CARBON_CHECK(parse_kind == pop_parse_kind) - << "Expected " << pop_parse_kind << ", found " << parse_kind; - node_stack_.pop_back(); - return node_id; - } + // Pops the top of the stack, returning the result_id. Must only be called for + // nodes that have results. + auto PopWithResult() -> SemanticsNodeId; + + // Pops the top of the stack, verifying that it's the expected kind and + // returning the result_id. Must only be called for nodes that have results. + auto PopWithResult(ParseNodeKind pop_parse_kind) -> SemanticsNodeId; // Parse node handlers. auto HandleDeclaredName(ParseTree::Node parse_node) -> void; @@ -84,6 +72,10 @@ class SemanticsParseTreeHandler { // The stack during Build. Will contain file-level parse nodes on return. llvm::SmallVector node_stack_; + + // The stack of node blocks during build. Only updated on ParseTree nodes that + // affect the stack. + llvm::SmallVector node_block_stack_; }; } // namespace Carbon diff --git a/toolchain/semantics/testdata/empty.carbon b/toolchain/semantics/testdata/empty.carbon index 46bedd30357a..91759c81afce 100644 --- a/toolchain/semantics/testdata/empty.carbon +++ b/toolchain/semantics/testdata/empty.carbon @@ -8,5 +8,7 @@ // CHECK:STDOUT: }, // CHECK:STDOUT: integer_literals = { // CHECK:STDOUT: }, -// CHECK:STDOUT: nodes = { +// CHECK:STDOUT: node_blocks = { +// CHECK:STDOUT: block0 = { +// CHECK:STDOUT: }, // CHECK:STDOUT: } diff --git a/toolchain/semantics/testdata/function/basic.carbon b/toolchain/semantics/testdata/function/basic.carbon index 9aa689f680a7..eb6f41cc4203 100644 --- a/toolchain/semantics/testdata/function/basic.carbon +++ b/toolchain/semantics/testdata/function/basic.carbon @@ -5,15 +5,18 @@ // AUTOUPDATE // RUN: %{carbon-run-semantics} // CHECK:STDOUT: identifiers = { -// CHECK:STDOUT: %s0 = "Foo"; +// CHECK:STDOUT: ident0 = "Foo"; // CHECK:STDOUT: }, // CHECK:STDOUT: integer_literals = { // CHECK:STDOUT: }, -// CHECK:STDOUT: nodes = { -// CHECK:STDOUT: %0 = Identifier(%s0); -// CHECK:STDOUT: %1 = FunctionDeclaration(%0); -// CHECK:STDOUT: %2 = FunctionDefinitionStart(%1); -// CHECK:STDOUT: %3 = FunctionDefinitionEnd(); +// CHECK:STDOUT: node_blocks = { +// CHECK:STDOUT: block0 = { +// CHECK:STDOUT: node0 = Identifier(ident0); +// CHECK:STDOUT: node1 = FunctionDeclaration(node0); +// CHECK:STDOUT: node2 = FunctionDefinition(node1, block1); +// CHECK:STDOUT: }, +// CHECK:STDOUT: block1 = { +// CHECK:STDOUT: }, // CHECK:STDOUT: } fn Foo() {} diff --git a/toolchain/semantics/testdata/function/order.carbon b/toolchain/semantics/testdata/function/order.carbon index 714a9185c9a1..52b2b357c83a 100644 --- a/toolchain/semantics/testdata/function/order.carbon +++ b/toolchain/semantics/testdata/function/order.carbon @@ -5,25 +5,30 @@ // AUTOUPDATE // RUN: %{carbon-run-semantics} // CHECK:STDOUT: identifiers = { -// CHECK:STDOUT: %s0 = "Foo"; -// CHECK:STDOUT: %s1 = "Bar"; -// CHECK:STDOUT: %s2 = "Baz"; +// CHECK:STDOUT: ident0 = "Foo"; +// CHECK:STDOUT: ident1 = "Bar"; +// CHECK:STDOUT: ident2 = "Baz"; // CHECK:STDOUT: }, // CHECK:STDOUT: integer_literals = { // CHECK:STDOUT: }, -// CHECK:STDOUT: nodes = { -// CHECK:STDOUT: %0 = Identifier(%s0); -// CHECK:STDOUT: %1 = FunctionDeclaration(%0); -// CHECK:STDOUT: %2 = FunctionDefinitionStart(%1); -// CHECK:STDOUT: %3 = FunctionDefinitionEnd(); -// CHECK:STDOUT: %4 = Identifier(%s1); -// CHECK:STDOUT: %5 = FunctionDeclaration(%4); -// CHECK:STDOUT: %6 = FunctionDefinitionStart(%5); -// CHECK:STDOUT: %7 = FunctionDefinitionEnd(); -// CHECK:STDOUT: %8 = Identifier(%s2); -// CHECK:STDOUT: %9 = FunctionDeclaration(%8); -// CHECK:STDOUT: %10 = FunctionDefinitionStart(%9); -// CHECK:STDOUT: %11 = FunctionDefinitionEnd(); +// CHECK:STDOUT: node_blocks = { +// CHECK:STDOUT: block0 = { +// CHECK:STDOUT: node0 = Identifier(ident0); +// CHECK:STDOUT: node1 = FunctionDeclaration(node0); +// CHECK:STDOUT: node2 = FunctionDefinition(node1, block1); +// CHECK:STDOUT: node3 = Identifier(ident1); +// CHECK:STDOUT: node4 = FunctionDeclaration(node3); +// CHECK:STDOUT: node5 = FunctionDefinition(node4, block2); +// CHECK:STDOUT: node6 = Identifier(ident2); +// CHECK:STDOUT: node7 = FunctionDeclaration(node6); +// CHECK:STDOUT: node8 = FunctionDefinition(node7, block3); +// CHECK:STDOUT: }, +// CHECK:STDOUT: block1 = { +// CHECK:STDOUT: }, +// CHECK:STDOUT: block2 = { +// CHECK:STDOUT: }, +// CHECK:STDOUT: block3 = { +// CHECK:STDOUT: }, // CHECK:STDOUT: } fn Foo() {} diff --git a/toolchain/semantics/testdata/return/binary_op.carbon b/toolchain/semantics/testdata/return/binary_op.carbon index 6e4b659e3597..b11a405b3545 100644 --- a/toolchain/semantics/testdata/return/binary_op.carbon +++ b/toolchain/semantics/testdata/return/binary_op.carbon @@ -5,21 +5,24 @@ // AUTOUPDATE // RUN: %{carbon-run-semantics} // CHECK:STDOUT: identifiers = { -// CHECK:STDOUT: %s0 = "Main"; +// CHECK:STDOUT: ident0 = "Main"; // CHECK:STDOUT: }, // CHECK:STDOUT: integer_literals = { -// CHECK:STDOUT: %s0 = 12; -// CHECK:STDOUT: %s1 = 34; +// CHECK:STDOUT: int0 = 12; +// CHECK:STDOUT: int1 = 34; // CHECK:STDOUT: }, -// CHECK:STDOUT: nodes = { -// CHECK:STDOUT: %0 = Identifier(%s0); -// CHECK:STDOUT: %1 = FunctionDeclaration(%0); -// CHECK:STDOUT: %2 = FunctionDefinitionStart(%1); -// CHECK:STDOUT: %3 = IntegerLiteral(%s0); -// CHECK:STDOUT: %4 = IntegerLiteral(%s1); -// CHECK:STDOUT: %5 = BinaryOperatorAdd(%3, %4); -// CHECK:STDOUT: %6 = ReturnExpression(%5); -// CHECK:STDOUT: %7 = FunctionDefinitionEnd(); +// CHECK:STDOUT: node_blocks = { +// CHECK:STDOUT: block0 = { +// CHECK:STDOUT: node0 = Identifier(ident0); +// CHECK:STDOUT: node1 = FunctionDeclaration(node0); +// CHECK:STDOUT: node2 = FunctionDefinition(node1, block1); +// CHECK:STDOUT: }, +// CHECK:STDOUT: block1 = { +// CHECK:STDOUT: node0 = IntegerLiteral(int0); +// CHECK:STDOUT: node1 = IntegerLiteral(int1); +// CHECK:STDOUT: node2 = BinaryOperatorAdd(node0, node1); +// CHECK:STDOUT: node3 = ReturnExpression(node2); +// CHECK:STDOUT: }, // CHECK:STDOUT: } fn Main() { diff --git a/toolchain/semantics/testdata/return/literal.carbon b/toolchain/semantics/testdata/return/literal.carbon index 50d9ecf3949a..0930f83e6897 100644 --- a/toolchain/semantics/testdata/return/literal.carbon +++ b/toolchain/semantics/testdata/return/literal.carbon @@ -5,18 +5,21 @@ // AUTOUPDATE // RUN: %{carbon-run-semantics} // CHECK:STDOUT: identifiers = { -// CHECK:STDOUT: %s0 = "Main"; +// CHECK:STDOUT: ident0 = "Main"; // CHECK:STDOUT: }, // CHECK:STDOUT: integer_literals = { -// CHECK:STDOUT: %s0 = 0; +// CHECK:STDOUT: int0 = 0; // CHECK:STDOUT: }, -// CHECK:STDOUT: nodes = { -// CHECK:STDOUT: %0 = Identifier(%s0); -// CHECK:STDOUT: %1 = FunctionDeclaration(%0); -// CHECK:STDOUT: %2 = FunctionDefinitionStart(%1); -// CHECK:STDOUT: %3 = IntegerLiteral(%s0); -// CHECK:STDOUT: %4 = ReturnExpression(%3); -// CHECK:STDOUT: %5 = FunctionDefinitionEnd(); +// CHECK:STDOUT: node_blocks = { +// CHECK:STDOUT: block0 = { +// CHECK:STDOUT: node0 = Identifier(ident0); +// CHECK:STDOUT: node1 = FunctionDeclaration(node0); +// CHECK:STDOUT: node2 = FunctionDefinition(node1, block1); +// CHECK:STDOUT: }, +// CHECK:STDOUT: block1 = { +// CHECK:STDOUT: node0 = IntegerLiteral(int0); +// CHECK:STDOUT: node1 = ReturnExpression(node0); +// CHECK:STDOUT: }, // CHECK:STDOUT: } fn Main() { diff --git a/toolchain/semantics/testdata/return/trivial.carbon b/toolchain/semantics/testdata/return/trivial.carbon index a0cedfdb4f47..340dda775cb4 100644 --- a/toolchain/semantics/testdata/return/trivial.carbon +++ b/toolchain/semantics/testdata/return/trivial.carbon @@ -5,16 +5,19 @@ // AUTOUPDATE // RUN: %{carbon-run-semantics} // CHECK:STDOUT: identifiers = { -// CHECK:STDOUT: %s0 = "Main"; +// CHECK:STDOUT: ident0 = "Main"; // CHECK:STDOUT: }, // CHECK:STDOUT: integer_literals = { // CHECK:STDOUT: }, -// CHECK:STDOUT: nodes = { -// CHECK:STDOUT: %0 = Identifier(%s0); -// CHECK:STDOUT: %1 = FunctionDeclaration(%0); -// CHECK:STDOUT: %2 = FunctionDefinitionStart(%1); -// CHECK:STDOUT: %3 = Return(); -// CHECK:STDOUT: %4 = FunctionDefinitionEnd(); +// CHECK:STDOUT: node_blocks = { +// CHECK:STDOUT: block0 = { +// CHECK:STDOUT: node0 = Identifier(ident0); +// CHECK:STDOUT: node1 = FunctionDeclaration(node0); +// CHECK:STDOUT: node2 = FunctionDefinition(node1, block1); +// CHECK:STDOUT: }, +// CHECK:STDOUT: block1 = { +// CHECK:STDOUT: node0 = Return(); +// CHECK:STDOUT: }, // CHECK:STDOUT: } fn Main() {