Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Pparse: check ast invariants after preprocessing #1938
This small PR proposes to check AST invariants after the preprocessing phase of the toplevel.
For instance, running a faulty ppx that generates an empty tuple with
let t = [%tuple];;
raises with this PR an error in the toplevel itself:
rather than an internal fatal error:
It's a rather abstract discussion, but I view invariants as things that one would like to express in the Parsetree definition, but one cannot do it due to technical limitations (or it would make the code too heavy/irregular). Not particularly as expectations specific to the compiler. This is also reflected in the fact that attribute payloads are checked for invariants, even if the compiler doesn't do anything with them.
One expect in particular some kind of roundtripping property between the parser and printers (in concrete syntax), limited to Parsetree that respects the invariants. And this should hold also for "ppx" called by external tools, for debugging purposes.