github / semantic

Parsing, analyzing, and comparing source code across many languages
8.94k stars 454 forks source link

AOT codegen #624

Closed patrickt closed 3 years ago

patrickt commented 4 years ago

As detailed in #622, compile-time codegen is not a viable path forward for Cabal or Bazel projects. However, we can take advantage of the fact that we can run Template Haskell splices in the IO monad, with some elbow grease, then pretty-print the resulting TH declarations, piping the result through ormolu. We’ll run this executable every time we bump the grammars, which will lead to much better compile-time caching.

To test:

bazel build //semantic-ast/...
bazel run //semantic-ast:generate-ast -- --language JSON --path $PWD/../tree-sitter-json/src/node-types.json

As always, massive props to @aymannadeem for the TH codegen work: there’s absolutely no way this would have been feasible without being able to piggyback on that work.

Stuff left to do: