Open shilangyu opened 1 year ago
But this seems wasteful if I already have a syntax node (I would have to turn it into a green node just to rebuild the syntax node in a new thread). Is there a better solution?
I don't work on Rowan, but my understanding is that SyntaxNode
is a wrapper over GreenNode
, meaning that conversion from SyntaxNode
to GreenNode
is essentially free. Also, SyntaxNode
lazily builds other SyntaxNode
s when traversing, so creating one should be fine.
It's dangerous because SyntaxNode
contains a non-atomic reference counter, so your threads could potentially have concurrency issues and free the SyntaxNode
when it still has references for instance. That's why it cannot be Send
. I guess you'll have to do a deep clone.
Send a pair of a GreenNode and SyntaxNodePtr:
https://docs.rs/rowan/0.15.11/rowan/ast/struct.SyntaxNodePtr.html
I have a need to send
SyntaxNode
s to other threads, howeverSyntaxNode
is notSend
. What is the recommended approach to such usecases? I know green nodes are both send and sync, but they dont provide the needed information (text offsets).SyntaxNode
is preferred, as it can be used in typed AST wrappers.One solution that comes to mind is sending the green node and turning it into a syntax node in the new thread. But this seems wasteful if I already have a syntax node (I would have to turn it into a green node just to rebuild the syntax node in a new thread). Is there a better solution?