It is not possible in the general case to go 100% ...
# thinking-together
e
It is not possible in the general case to go 100% backwards from a change in the AST. You can't fully reconstruct source from the compiled code, but you can get close. But we are talking exactitudes, so unless your language is visual to begin with, in which case the AST is identical to the source, this won't be happening.
i
You're talking about things like.. reconstructing the exact pattern of indentation, comments (if they aren't represented in the AST).. right?
That's no longer an issue if you use something like https://prettier.io/docs/en/index.html
Prettier enforces a consistent code style (i.e. code formatting that won't affect the AST) across your entire codebase because it disregards the original styling by parsing it away and re-printing the parsed AST with its own rules [...]
I think, in general, it's worth taking it as a given that if AST-aware version control becomes a thing, it'll be in the context of a language that has something like Prettier or gofmt to enforce consistent mapping between AST and source — or it'll be a language where you're expected to edit it in a structural or visual editor. In other words, I don't think anyone is suggesting we use an AST-aware SCM for Java. That's like oiling the doors on the already-sunk Titanic.
g
I am one of those opposed to prettiers. The topic comes up about once a year on the Chrome team. Someone suggests "We should add a auto formatter to the commit system" and then it's always pointed out that an auto formatter never handles the exceptions and ends up making the code less readable. Maybe you believe there should be no exceptions. I disagree. As a simple example let's take javascript objects. should they be
Copy code
const arrayOfRects = [
  { x: 0, y: 0, width: 100, },
  { x: 123, y: 45, width: 10, },
  { x: -45, y: -410, width: -123, },
];
vs
Copy code
const arrayOfRects = [
  {
     x: 0,
     y: 0,
     width: 100,
  },
  {
     x: 123,
     y: 45,
     width: 10,
  },
  {
     x: -45,
     y: -410,
     width: -123,
  },
];
vs
Copy code
const arrayOfRects = [
  { x:   0, y:    0, width:  100, },
  { x: 123, y:   45, width:   10, },
  { x: -45, y: -410, width: -123, },
];
I prefer the last one depending on the situation. There are plenty of places where turning the data into something more like a table makes it much much easier to find errors and see exceptions but auto formaters normal destroy such formatting. In the same way I'd expect issues with VPLs in that people want to arrange their nodes the way that works best for them, not on some auto-layed out way. Consider 6 nodes that could be stacked vertically, horizontally, 3x2, 2x3 or just manually placed wherever. Now two or more people move the nodes and you've got a conflict that needs resolving. Maybe not a good example. I'm just trying to point out that just like an code AST generally removes all formatting info which is often an issue, VPLs probably also have similar types of metadata that will end up causing similar issues.
d
code AST generally removes all formatting info
I'm not sure how true this is in the real world. The AST libraries I have written for myself and those I have used (e.g. Roslyn) retain text-span information so you can navigate to/from the source code, display warnings on the right characters, perform refactorings etc.
e
you are forgetting about lots of things that are eliminated during compilation, like comments for the reader, and what about conditional compilation? Many advanced languages have a preprocessor step with conditional compilation and if you say in C, #if flag .... #else.... #end then the skipped code will not be reconstructed. I have often theorized that the reason C won over every other competitor language of its day, is that it was one of the only ones with a pre-processor. Remember that C was a reaction to PL/1 which was a superior language, but much "heavier". PL/1 was a much better language IMHO. Anyway preprocessors are very important in commercial work, where you often create demo versions, expiring versions, crippled versions, and not having a pre-processor is very painful for commercial developers.