Context
TreeNode (introduced in PR #147 at Sources/SyntaxParser/TreeNode.swift) is declared as final class but behaves as a value type:
- Built up during a single traversal, then read-only
- Encoded to JSON immediately after construction
Equatable conformance compares fields, not identity
The only genuine need for a reference type in this pipeline is the mutable current pointer inside TokenVisitor, which is already a separate internal type.
Proposed Work
Convert TreeNode to a struct. Key considerations:
- The
parent: Int? back-reference is by ID (not object identity), so no reference cycle concerns
Codable and Equatable synthesization works the same for structs
TokenVisitor builds nodes by mutating a current node — this will need to capture the struct by value and reassign, rather than mutating through a reference
Context
TreeNode(introduced in PR #147 atSources/SyntaxParser/TreeNode.swift) is declared asfinal classbut behaves as a value type:Equatableconformance compares fields, not identityThe only genuine need for a reference type in this pipeline is the mutable
currentpointer insideTokenVisitor, which is already a separate internal type.Proposed Work
Convert
TreeNodeto astruct. Key considerations:parent: Int?back-reference is by ID (not object identity), so no reference cycle concernsCodableandEquatablesynthesization works the same for structsTokenVisitorbuilds nodes by mutating acurrentnode — this will need to capture the struct by value and reassign, rather than mutating through a reference