Document monotonic mutability of the AST (#1079)

Also document an important precondition on `InterpExp` and `InterpPattern`
This commit is contained in:
Geoff Romer
2022-02-16 09:42:47 -08:00
committed by GitHub
parent 7e9b24390f
commit 74c054c86e
2 changed files with 14 additions and 2 deletions
+10
View File
@@ -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