Cimple Compiler Components
Comptime Processor Design
Abstractly, comptime data may be mutable. However, c3’s tree is immutable, and all comptime values are stored in the tree. Additionally, the IR is SSA, so we already use phi nodes in the IR. To enable comptime mutability, identifier renaming is used. Identifier renaming is almost exactly the same concept as register renaming, except at the level of the AST instead of hardware. Every assignment like foo = bar generates a brand new internal variable, and renames foo so that the node it identifies changes. For branches, phi nodes are used to resolve which immutable node is referred to. Essentially, mutable data is replaced with mutable references to immutable data.