Skip to content

Prevent use of SyntaxNodePtr and AstPtr on mutable trees #151

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

Merged

Conversation

Technohacker
Copy link
Contributor

Both of these use source code locations to identify the node, which can get invalidated by syntax tree mutations. This commit adds assertions to prevent their use, and adds documentation to inform users of the issue

Fixes #150

@Technohacker
Copy link
Contributor Author

There's an added is_mutable() method for cursor::SyntaxNode and api::SyntaxNode which was needed for use in the API module. It may also be useful as a public API in case users wish to check if a tree is mutable

There's also 2 tests added to ensure this panic behaviour, but I've had to make a custom impl of Language to do so

@jelmer
Copy link
Contributor

jelmer commented May 10, 2024

@Technohacker this appears conflicted now

@Technohacker
Copy link
Contributor Author

Ah I can get that resolved in a few mins

Both of these use source code locations to identify the node, which can
get invalidated by syntax tree mutations. This commit adds assertions to
prevent their use, and adds documentation to inform users of the issue

Fixes rust-analyzer#150
@Technohacker Technohacker force-pushed the prevent-astptr-on-mut-tree branch from 0df34b7 to 242ed0c Compare May 10, 2024 16:30
@Technohacker
Copy link
Contributor Author

All done 👍
I've still assumed mutable trees should cause panics since I figured it's a programming mistake to use SyntaxNodePtrs on mutable trees. Should it be an Option return like the missing node case instead?

Also not sure what's going on with the CI, could you have a check?

@jelmer
Copy link
Contributor

jelmer commented May 11, 2024

Hmm, it appears to fail in master for the same reasons. https://github.com/rust-analyzer/rowan/actions/runs/9030330328/job/24814372618

@Veykril
Copy link
Member

Veykril commented May 13, 2024

Well that's a fun new lint we trigger

@Veykril
Copy link
Member

Veykril commented May 13, 2024

Thanks

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

Successfully merging this pull request may close these issues.

AstPtr can de-sync from mutable Syntax Tree after mutation
3 participants