-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Announcment: MutableRoslyn #3607
Comments
I just have to ask -- why? |
I believe anyone who tried to do any decent amount of tree manipulation already knows the answer. Working with the immutable tree is just pain.
|
@YaakovDavis So, first, almost all functional programming languages use immutable trees as their natural data structure because they're highly amenable to functional manipulation, so immutability is often a natural fit for trees. But second, you can't use this in most of the places people use roslyn today -- like in VS or analyzers. So what's the use case? |
First, it supports conversion from, and to, Roslyn, so it can be used anywhere Roslyn is used. I use it for code-generation and transformation purposes; I have an abstract code that I transform to a concrete implementation by AST mutation. I can see it useful for similar scenarios. Think meta-programming. |
I have not found this to be the case at all. I have run into a few issues like the inability of the syntax factory to handle XML documentation comments (#218), but that isn't a problem with the trees being immutable and it's also something we worked around by creating a new factory. |
The problem with immutable tree manipulation is that any node "update" requires regenerating all its ancestors. This means you have to avoid holding references to ancestor nodes, or keep updating them manually. The Immutable Tree design restricts the user to visitors and rewriters, which can consider only one node at a time, in a depth-first order. While this works for some scenarios, it certainly doesn't for others. If Roslyn's tree is workable for your needs, have fun. |
@YaakovDavis Congrats on your project. |
Hi, @YaakovDavis: I have the urgent necessity to use a mutable tree versions of Roslyn. If is needed I can detail my scenario to support your claims that there are cases where are really important. I tried to follow the reference you put here but is broken. Can you enable that solution for me? Regards |
The repository is now available. I'm not sure about its level of functioning at the moment, hope you find it useful. |
I've released the 1st version of MutableRoslyn; a library for easy mutation of Roslyn syntax trees:
https://github.com/YaakovDavis/MutableRoslyn
The mutable classes are auto-generated from the same XML that's used to generate Roslyn's red nodes, those reducing the risk for implementation errors.
The lib supports Immutable <-> mutable conversion.
A typical workflow would be:
The lib doesn't preserve (unstructured) trivia.
The text was updated successfully, but these errors were encountered: