Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The goal is to separate the generic node storage and traversal operations from the specific concept of an abstract syntax tree (=AST).
An AST requires some extra bits of information (e.g., metadata), but adding this to
PackedTree
would make the type it no longer applicable for use cases that want just a sequence of nodes and the associated operations without anything else.While there currently are no such use cases, I can foresee that changing in the future, so splitting the two things makes sense.
As is, the current code is a dead end. Conceptually, the node tree operations (e.g.:
child
,next
, etc.) do not care about the concrete storage type -- they only require an input type that's a random-access supporting container type whose element is a type with a mutablekind
andval
property, nothing more. This makes them an ideal candidate for static interfaces (i.e.,concept
), but said NimSkull feature is not yet stable enough.I've tried to approximate the ideal solution (static interfaces) by making
PackedTree
type only represent the node storage and have it be parameterized with the node type, withAst
then embedding aPackedTree
instance and providing a wrapper template for everyPackedTree
routine such thatAst
can be used in the same way aPackedTree
can be, but this is annoying to maintain and it also significantly hurts code clarity, since various routines forBuilder
,ChangeSet
, etc. have to use unnecessarily broad interfaces.Using inheritance would work a little better in practice, but is not really correct (an
Ast
cannot be used everywhere aPackedTree
can be, for example, serialization), and it would likely also surface some NimSkull bugs/issues with argument subtyping anditerator
s.Progress on this PR needs to wait until NimSkull supports working static interfaces. In the meantime,
PackedTree
will have to become theAst
type.