mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
This switches to single list storage of SemanticsNode. The driving motivation behind this is to simplify cross-references within a given IR. Types of nodes will frequently refer to other blocks. This causes a significant increase in the number of cross-references, which can become difficult to manage (and reason about). By reducing to a single list of nodes, cross-references are only needed when crossing IR boundaries. Because cross-references now only have 2 things to track (IR and index), they can be a regular SemanticsNode and don't need further indirection. This wasn't motivating, but feels like it reinforces the simplification. Note this isn't being used to deduplicate nodes, at least right now. That could lead to difficult-to-update situations, but also most nodes are associated with the underlying ParseTree::Node in order to track sources for diagnostics; as a consequence, nodes representing equal text in different source locations wouldn't be the same node. There may be future opportunities here, discussed with @zygoloid, but no action is taken at present. We may eventually want to switch the storage of NodeBlocks to have `[start, end)` ranges instead of individual numbers, but I'm leaving that alone for now. As an aside, I noticed I was accidentally overloading the copy constructor on SemanticsIR. I've added some disambiguation on that, but am not deleting the copy constructor per style advice (even though the type should never be copied due to storage size). codespell tries to change `CrossReference -> cross-reference` so disabling it there.
35 lines
1.3 KiB
Modula-2
35 lines
1.3 KiB
Modula-2
// 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
|
|
//
|
|
// Note that this is an X-macro header.
|
|
//
|
|
// It does not use `#include` guards, and instead is designed to be `#include`ed
|
|
// after the x-macro is defined in order for its inclusion to expand to the
|
|
// desired output. The x-macro for this header is `CARBON_PARSE_NODE_KIND`. The
|
|
// definition provided will be removed at the end of this file to clean up.
|
|
|
|
#ifndef CARBON_SEMANTICS_NODE_KIND
|
|
#error "Must define the x-macro to use this file."
|
|
#endif
|
|
|
|
CARBON_SEMANTICS_NODE_KIND(Invalid)
|
|
|
|
// A cross-reference between IRs.
|
|
CARBON_SEMANTICS_NODE_KIND(CrossReference)
|
|
|
|
CARBON_SEMANTICS_NODE_KIND(Assign)
|
|
CARBON_SEMANTICS_NODE_KIND(BinaryOperatorAdd)
|
|
CARBON_SEMANTICS_NODE_KIND(BindName)
|
|
CARBON_SEMANTICS_NODE_KIND(Builtin)
|
|
CARBON_SEMANTICS_NODE_KIND(CodeBlock)
|
|
CARBON_SEMANTICS_NODE_KIND(FunctionDeclaration)
|
|
CARBON_SEMANTICS_NODE_KIND(FunctionDefinition)
|
|
CARBON_SEMANTICS_NODE_KIND(IntegerLiteral)
|
|
CARBON_SEMANTICS_NODE_KIND(RealLiteral)
|
|
CARBON_SEMANTICS_NODE_KIND(Return)
|
|
CARBON_SEMANTICS_NODE_KIND(ReturnExpression)
|
|
CARBON_SEMANTICS_NODE_KIND(VarStorage)
|
|
|
|
#undef CARBON_SEMANTICS_NODE_KIND
|