mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-27 07:50:11 +01:00
For parameters (and in the future, arguments too; generally comma-separated lists) track two node blocks: 1. param_ir: The complete IR. 2. param_refs: Nodes within the IR that are the "root" parameter. param_refs should allow quick counting of the # of parameters, and more efficient comparison of call args with function parameters. param_ir should be necessary to generate the actual signature. In order to construct this, this refactors the node_block_stack into its own class, which is reused in params_stack. These carry references to the underlying SmallVector for lazy modification in order to avoid a dependency cycle with SemanticsIR (also see notes on empty node blocks below). When finalized, the block pair is pushed onto finished_params_stack. That's because node_stack only has space for one thing, and this is two things -- so I'm essentially choosing a trade-off of adding another stack in order to avoid consuming more space in the expectation that most parse nodes have 0 or 1 things to return, and 2 will be very rare. As factored, this currently consolidates most empty node blocks into a single canonical empty node block. This is because I think empty blocks, i.e. `()`, will be very common. In order to achieve this, SemanticsNodeBlockStack does lazy creation. An alternative approach would have been to use 1 node block per parameter. We decided against this in order to reduce the number of vectors being created.
38 lines
1.3 KiB
Plaintext
38 lines
1.3 KiB
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
// AUTOUPDATE
|
|
// RUN: %{carbon-run-semantics}
|
|
// CHECK:STDOUT: cross_reference_irs_size: 1
|
|
// CHECK:STDOUT: callables: [
|
|
// CHECK:STDOUT: {param_ir: block0, param_refs: block0}
|
|
// CHECK:STDOUT: ]
|
|
// CHECK:STDOUT: integer_literals: [
|
|
// CHECK:STDOUT: ]
|
|
// CHECK:STDOUT: strings: [
|
|
// CHECK:STDOUT: Foo,
|
|
// CHECK:STDOUT: ]
|
|
// CHECK:STDOUT: nodes: [
|
|
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: block0, type: node0},
|
|
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: block1, type: node1},
|
|
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: block2, type: node0},
|
|
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: block3, type: node0},
|
|
// CHECK:STDOUT: {kind: FunctionDeclaration, arg0: callable0},
|
|
// CHECK:STDOUT: {kind: BindName, arg0: str0, arg1: node4},
|
|
// CHECK:STDOUT: {kind: FunctionDefinition, arg0: node4, arg1: block2},
|
|
// CHECK:STDOUT: ]
|
|
// CHECK:STDOUT: node_blocks: [
|
|
// CHECK:STDOUT: [
|
|
// CHECK:STDOUT: ],
|
|
// CHECK:STDOUT: [
|
|
// CHECK:STDOUT: node4,
|
|
// CHECK:STDOUT: node5,
|
|
// CHECK:STDOUT: node6,
|
|
// CHECK:STDOUT: ],
|
|
// CHECK:STDOUT: [
|
|
// CHECK:STDOUT: ],
|
|
// CHECK:STDOUT: ]
|
|
|
|
fn Foo() {}
|