Possible to deserialise an AST? #1592
-
|
I was just wondering if it's possible to deserialise an AST. I know there's an My use case is that I'm writing a language server, and I'd like to be able to cache compilations, in a similar way to what clangd does. I know something like this is pretty non-trivial in C++, but is there any interest or plans? I imagine we could do something very similar to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
It would be nice to have for sure but it's not implemented yet. Deserialization is much harder than serialization because you have to correctly create the C++ objects and link them back up to each other, deduplicate types, make sure you're handling all of the private state of the nodes and not just the public stuff we're currently serializing, find places where we assume we'll have access to syntax nodes, etc. |
Beta Was this translation helpful? Give feedback.
Doesn't necessarily have to be a friend if each AST type can also serialize the private stuff and then knows how to recreate itself from the deserialized data, but I doubt that is the case currently.
Different classes of AST nodes are de-duped, basic types being one of them. When types are serialized they're generally done in a way that would make it hard to recover that (like we just serialize some string instead of all of the type details, though there are various options controlling the output now).
It's all doable with some work though, just many things to solve. Ax another example, basically all string memory (for symbol names and whatnot) is backed by the original file loaded into t…