Open AtticusKuhn opened 3 months ago
cc: @alexkeizer because he knows a lot about the parser.
It's an interesting idea! One thing to keep in mind, though, is that we intend to prove things about the programs defined by the macro, so we currently do our best to have the DSL generate ICom
s in a normal(-ish) form.
Now, this can work with your syntactic translation approach, it would involve doing a lot of reduction. This reduction can be quite fragile, and in fact, we've been trying to reduce the amount of full-blown reduction needed to more controlled approaches through simp
-sets. This can be made to work with this approach as well, I'm sure, but you run the risk of in the process really only moved the complexity around.
Furthermore, having to do our own type checking means we have to, well, implement our own typechecking, yes, but it also means we get to generate our own, meaningful errors. Having Lean do the type-checking means letting Lean generate the type errors, and those are likely going to be in terms of the translation, making it a particularly leaky abstraction and not very user friendly.
Here is an idea that could shorten the code for the lean-mlir parser substantially.
The gist of this idea is to not do any typechecking ourselves, but to syntactically transform the llvm expression into a lean expresion so that the lean compiler does the typechecking.
For example, we could have an elaborator which would elaborate
into
This way, our macros would only do a syntactic transformation, and leave the type-checking to the lean compiler. The benefit of this idea is that we could drastically reduce the number of lines of code in the parser.