SwiftSyntax.SyntaxRewriter API suggestion

I have 2 pet peeves with SyntaxRewriter, both of them related to its efficiency:

  • It rewrites the whole tree, even for the nodes you are not interested in, creating new raw nodes for everything.
  • The with... methods create new parent nodes all the way to the root of the tree that the node belongs to, but SyntaxRewriter doesn't need the parents, it treats the node you give it as a leaf node to add in its own tree. That means all the created new parent nodes are wasted. In the existing model, SyntaxRewriter should probably give you parent-less leaf nodes to rewrite at least. But then as a client you may need to check the parents.

I don't have specific suggestions right now but I'm taking the opportunity of this thread to suggest rethinking how SyntaxRewriter should work so it is more efficient to use. That may involve significantly changing how the API looks right now (e.g should it become a protocol like SyntaxVisitor, etc. ).