3 ms·
Storing AST instead of source code is one of the goals of the very interesting Unison programming language: https://www.unisonweb.org/ https://www.unisonweb.org
by nerdponx 5y ago
Storing AST instead of source code is one of the goals of the very interesting Unison programming language: https://www.unisonweb.org/ https://www.unisonweb.org/
Part of what's nice about Git (and plain text in general) is that it's the lowest common denominator for a lot of things. This is why traditional Unix tools are built oriented around streams of bytes. Text is a low level carrier protocol; you can encode almost anything in it, but you need to agree on some kind of format.
The good part is that you can use very very generic tools on almost arbitrary pieces of data. The bad part is that you might have to do a lot of parsing and re-parsing of the same data, and you have to contend with the dangers of underspecified formats.
Git follows the Unix tradition in this regard. As a result, it is nearly universal in what it can store. You can use it to store pretty much anything, but you are now at the lowest common denominator of support for any particular data format.
Git-for-ASTs will no longer have this universality property, but will gain a lot more power in the covered domain. This is a design tradeoff.
One thing that's nice about Git is that you can specify arbitrary diff drivers with the "attributes" system. So even if the Git database is storing plain text, your diff driver can parse your source code into ASTs and present AST diffs to you when you run `git diff`. Perhaps more impressive, you can configure custom merge drivers, so you can (theoretically) implement semantic merging of ASTs right inside Git.
There are probably some fundamental limitations of this system, because the underlying data is still stored as blobs of bytes. But you can get pretty far as long as you don't mind parsing and re-parsing the same text over and over.
- ssivark 5y agoHas this approach been tried? (Unison or otherwise…)
- nerdponx 5y agoI believe Unison is the only attempt to do this at a programming language/environment level. For Git diffs, there is Diffsitter, which uses Tree Sitter to generate semantic diffs of code files: https://github.com/afnanenayet/diffsitter https://github.com/afnanenayet/diffsitter I have not used it, but it is high on my todo list.