Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending SyntaxNodes to other threads? #155

Open
shilangyu opened this issue Jun 10, 2023 · 3 comments
Open

Sending SyntaxNodes to other threads? #155

shilangyu opened this issue Jun 10, 2023 · 3 comments

Comments

@shilangyu
Copy link

I have a need to send SyntaxNodes to other threads, however SyntaxNode is not Send. 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?

@tadeokondrak
Copy link

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 SyntaxNodes when traversing, so creating one should be fine.

@edgarogh
Copy link

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.

@matklad
Copy link
Member

matklad commented Jun 22, 2023

Send a pair of a GreenNode and SyntaxNodePtr:

https://docs.rs/rowan/0.15.11/rowan/ast/struct.SyntaxNodePtr.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants