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

Add a note README.md stating that the Ast is immutable #342

Open
ChrML opened this issue Sep 28, 2022 · 2 comments
Open

Add a note README.md stating that the Ast is immutable #342

ChrML opened this issue Sep 28, 2022 · 2 comments

Comments

@ChrML
Copy link

ChrML commented Sep 28, 2022

I was checking to see if I can redistribute the AST accross multiple threads, such as for caching the AST for multiple Jint that are running the same script. So it's natural to check if the AST is immutable, and hence safe for this, like e.g. the Roslyn syntax tree is.

According to the source code I have looked at so far, the AST is indeed immutable, but it would be nice if the documentation mentioned it somewhere :). So other people later don't have to spend time investigating the source code to figure that out.

@lahma
Copy link
Collaborator

lahma commented Sep 28, 2022

From Jint's perspective using Engine.PrepareScript should guarantee safe instance for multi-threading. But it's always possible to mutate the custom state field if any code decides to do so afterwards. But the AST structure should be static.

@adams85
Copy link
Collaborator

adams85 commented Sep 28, 2022

I'd say the AST is immutable-ish. The tree structure and node-specific data are immutable indeed but there are a few general or optional properties (like SyntaxElement.Range, SyntaxElement.Location, SyntaxElement.AssociatedData, Program.Tokens, Program.Comments, etc.) which are not for performance and/or backward compatibility reasons.

There are some warnings about this in the XML comments of these properties but the documentation could be improved for sure.

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

No branches or pull requests

3 participants