3 ms·
I haven't actually checked the source, but I've heard that clang-format works by assigning "badness" weights to each choice of whitespace between tokens, and th
by MathMonkeyMan 2y ago
I haven't actually checked the source, but I've heard that clang-format works by assigning "badness" weights to each choice of whitespace between tokens, and then runs Dijkstra's (or some other DP) to find the least bad set of choices. A recent Tom7 video said that Knuth did the same thing for text justification.
How about we do a similar thing for ASTs? Like a peephole optimizer looking for runs of instructions that could be substituted for simpler alternatives, a tree diff could identify diff patterns that "might be trivial." You have a whole catalog of these patterns, and assign to each a weight. Then the displayed diff is the optimal set of choices "consider different or not?"
You would need some additional ingredient, though; some boundary condition. Otherwise "everything is the same" would always minimize badness.
- amelius 2y agohttps://en.wikipedia.org/wiki/Edit_distance https://en.wikipedia.org/wiki/Edit_distance