mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Document monotonic mutability of the AST (#1079)
Also document an important precondition on `InterpExp` and `InterpPattern`
This commit is contained in:
@@ -7,6 +7,16 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
The code in this directory defines the AST that represents Carbon code in the
|
||||
rest of `executable-semantics`.
|
||||
|
||||
The AST is not quite immutable, because some node properties are set during some
|
||||
phase of static analysis, rather than during parsing. However, AST mutations are
|
||||
_monotonic_: once set, a node property cannot be changed. Furthermore, if a
|
||||
property is set after parsing, its documentation specifies what phase is
|
||||
responsible for setting it. Certain properties have `has_foo()` members for
|
||||
querying whether they are set, but those are for internal use within the phase
|
||||
that sets them. As a result, you can think of the AST as if it were immutable,
|
||||
but with certain parts that you can't yet observe, depending on what phase of
|
||||
compilation you're in.
|
||||
|
||||
All node types in the AST are derived from [`AstNode`](ast_node.h), and use
|
||||
[LLVM-style RTTI](https://llvm.org/docs/HowToSetUpLLVMStyleRTTI.html) to support
|
||||
safe down-casting and similar operations. Each abstract class `Foo` in the
|
||||
|
||||
Reference in New Issue
Block a user