Skip to content

Commit

Permalink
[IR] Make RuntimeCompilerAware use our API instead of Scala quasiquotes
Browse files Browse the repository at this point in the history
  • Loading branch information
ggevay committed Jul 13, 2018
1 parent 68dd6f0 commit f997446
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,22 @@ trait RuntimeCompilerAware {
}

protected lazy val addContext = TreeTransform("RuntimeCompilerAware.addContext", tree => {
import u.Quasiquote
q"(env: $Env) => { implicit val e: $Env = env; $tree }"
// This is roughly equivalent to the following:
//import u.Quasiquote
//q"(env: $Env) => { implicit val e: $Env = env; $tree }"

// Note that instead of making an implicit ValDef inside the lambda,
// it would be good to make the parameter of the lambda implicit.
// However, showCode prints such code incorrectly. See
// https://github.com/scala/bug/issues/10936

val envSym = compiler.api.ParSym(compiler.api.Owner.encl, compiler.api.TermName.fresh("env"), Env)
val eValDef = compiler.api.ValDef(
compiler.api.ValSym(compiler.api.Owner.encl, compiler.api.TermName.fresh("e"), Env, u.Flag.IMPLICIT),
compiler.api.ParRef(envSym)
)
val body = compiler.api.Block(Seq(eValDef), tree)
compiler.api.Lambda(Seq(envSym), body)
})

/** Adds a [[File]] to the classpath. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ trait Terms { this: AST =>
val pts = params.map(_.info)
val tpe = Type.fun(pts, body.tpe)
val sym = TermSym.free(TermName.lambda, tpe)
val als = for ((p, t) <- params zip pts) yield ParSym(sym, p.name, t)
val als = for ((p, t) <- params zip pts)
yield ParSym(sym, p.name, t, if (p.isImplicit) u.Flag.IMPLICIT else u.NoFlags)
val rhs = Sym.subst(sym, params zip als)(body)
val fun = u.Function(als.map(ParDef(_)).toList, rhs)
setSymbol(fun, sym)
Expand Down

0 comments on commit f997446

Please sign in to comment.