Open romac opened 5 years ago
For reference, the meta approach attributed to me above is a very simple way of reflecting/quoting expressions, and splicing them back into the program, which looks like:
@meta
def mul(n: Int, expr: Expr[Int]): Expr[Int] = {
require(n >= 0)
if (n == 0) Expr.IntLiteral(0)
else if (n == 1) expr
else Expr.Plus(expr, mul(n - 1, expr))
}
def testMul = {
val five = splice(mul(5, quote(1)))
assert(5 == five)
}
and yields the following program after the reflection phase:
def testMul = {
val five = 1 + 1 + 1 + 1 + 1
assert(5 == five)
}
Isn't the difference between the two proposals just a question of somehow exposing the solver within the meta-language API (and maybe compiling meta functions)? I expect that exposing the solver should be straightforward. As for compiling meta functions, if we rely on codegen, this should be relatively easy. We can probably also use the Scala compiler somehow but that might be more involved, especially if we want to allow meta functions to call back out into the solver.
Isn't the difference between the two proposals just a question of somehow exposing the solver within the meta-language API (and maybe compiling meta functions)?
It is, I just figured I would open this issue as a kind of meta-issue for discussion/tracking progress, but we could indeed merge them.
I expect that exposing the solver should be straightforward. As for compiling meta functions, if we rely on codegen, this should be relatively easy. We can probably also use the Scala compiler somehow but that might be more involved, especially if we want to allow meta functions to call back out into the solver.
Agreed, on both points.
— @vkuncak
Related to #683.