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

Is cstree up-to-date with rowan? #69

Open
elenakrittik opened this issue Jan 20, 2025 · 5 comments
Open

Is cstree up-to-date with rowan? #69

elenakrittik opened this issue Jan 20, 2025 · 5 comments

Comments

@elenakrittik
Copy link

According to crates.io, cstree has branched off from rowan "almost 4 years ago" and ever since then, both projects have regularly published new versions. I have already implemented an AST generator targeting rowan and on the surface, cstree seems to retain the overall API, and since having more optimizations won't hurt i am considering switching to cstree. Are there any notable differences besides those listed in the README that arose because of the projects' long history, and, while i suspect the answer is cstree (why would you create and maintain this otherwise), would you recommend rowan or cstree for new projects?

@domenicquirl
Copy link
Owner

Hey @elenakrittik!
As far as I know, the bullet points in the README are still different between the two crates. Most relevant of that is probably the lack of mutability methods in cstree. I've kept up with rowan to some extend, but not 100% so there might be some additional changes that have happened on their side which I missed. In addition, cstree has had a few additions as well over its most recent releases:

  • In version 0.12.0, we added a derive macro for Syntax (which is the equivalent to Language in rowan). There is also a small optimization with the static_text method on that trait.
  • Just recently we expanded the abilities of Checkpoints for backtracking, not sure how relevant this is for generating AST nodes.

I've also been working on more future stuff in the background, but that has been progressing very slowly for having limited time reasons (the most recent commit on that branch had its 2nd birthday recently 💀 ).

Do you have a link to your tool so I could get an idea what it looks like? Are you doing something similar to ungrammar or is this going in a different direction?

@domenicquirl
Copy link
Owner

would you recommend rowan or cstree for new projects?

Regarding your other question, I'm not sure I can answer that because it's going to depend heavily on both the project and which kinds of libraries you've already worked with. I'd guess that cstree is a bit more of an upfront effort to get going, because some of its optimizations (around interning in particular) make the API a fair bit more complicated. On the other hand some of that is mitigated by the new derive macro and I've always found the mutable tree API in rowan a little bit confusing (and I think rust-analyzer is transitioning away from using it) and with cstree your syntax trees will be Send, which might make things easier if you are working with multiple threads.

It might be a good starting point to think about whether your project wants to use an interner (that is compatible with cstree) already, in which case the ability to use the same one throughout your code is certainly a plus. But ofc. rowan will probably always be more battle-tested and also in fairness more actively maintained than cstree.

@elenakrittik
Copy link
Author

I'm doing it using ungrammar, yep! (Though i suspect i'll eventually fork it because there are just too many things that make working with it a huge pain (but less pain than a custom format and/or implementation).) The AST crate is defined here, and the generator (invoked via a build.rs) lies here (notably, the grammar is defined here). I'd say the AST interface is pretty much the same as rust-analyzer's besides some cosmetic changes like more docs, but the generator is significantly simpler (one might even say "dumbed down"!) and does not rely on any hacks or have special casing unless necessary by design (e.g. with the T! macro, which needs to escape braces/brackets/parens because of Rust's syntax limitations).

@elenakrittik
Copy link
Author

would you recommend rowan or cstree for new projects?

Regarding your other question, I'm not sure I can answer that because it's going to depend heavily on both the project and which kinds of libraries you've already worked with. I'd guess that cstree is a bit more of an upfront effort to get going, because some of its optimizations (around interning in particular) make the API a fair bit more complicated. On the other hand some of that is mitigated by the new derive macro and I've always found the mutable tree API in rowan a little bit confusing (and I think rust-analyzer is transitioning away from using it) and with cstree your syntax trees will be Send, which might make things easier if you are working with multiple threads.

It might be a good starting point to think about whether your project wants to use an interner (that is compatible with cstree) already, in which case the ability to use the same one throughout your code is certainly a plus. But ofc. rowan will probably always be more battle-tested and also in fairness more actively maintained than cstree.

My (our, we're a team, but i led the work on transitioning from the traditional tree ASTs to untyped CSTs) project is a language toolchain, so interning and parallelization is certainly some of the things that we will use. I think i'll try to diff cstree and rowan and then give an up-to-date report on the differences between the two, which optimizations or features are present in one but not another, etc.

@domenicquirl
Copy link
Owner

Looks like your doing most of the calls that actually go into rowan inside SyntaxNodeExt anyways and use those helper methods in the generated code, so should be even easier to replace.

I think i'll try to diff cstree and rowan and then give an up-to-date report on the differences between the two, which optimizations or features are present in one but not another, etc.

If you do, that would be very much appreciated! Could probably use to update the README with your findings ☺

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

No branches or pull requests

2 participants