Skip to content

Commit c653b1a

Browse files
committed
Enable optimisations in Runnres.run
1 parent e64e2d3 commit c653b1a

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import java.nio.charset.StandardCharsets
1313

1414
class QuoteDriver extends Driver {
1515

16-
def run[T](expr: Expr[T]): T = {
16+
def run[T](expr: Expr[T], optimise: Boolean): T = {
1717
val ctx: Context = initCtx.fresh
18-
// TODO enable optimisation?
19-
// ctx.settings.optimise.update(true)(ctx)
18+
ctx.settings.optimise.update(optimise)(ctx)
2019

2120
val outDir = new VirtualDirectory("(memory)", None)
2221

compiler/src/dotty/tools/dotc/quoted/Runners.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ object Runners {
1313

1414
implicit def runner[T]: Runner[T] = new Runner[T] {
1515

16-
def run(expr: Expr[T]): T = expr match {
17-
case expr: ConstantExpr[T] => expr.value
18-
case _ => new QuoteDriver().run(expr)
19-
}
16+
def run(expr: Expr[T]): T = Runners.run(expr, optimise = false)
2017

2118
def show(expr: Expr[T]): String = expr match {
2219
case expr: ConstantExpr[T] =>
@@ -27,4 +24,9 @@ object Runners {
2724
case _ => new QuoteDriver().show(expr)
2825
}
2926
}
27+
28+
def run[T](expr: Expr[T], optimise: Boolean): T = expr match {
29+
case expr: ConstantExpr[T] => expr.value
30+
case _ => new QuoteDriver().run(expr, optimise)
31+
}
3032
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
val a: Int = 3
3+
println("foo")
4+
2.+(a)
5+
}
6+
foo
7+
5
8+
foo
9+
5
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
import dotty.tools.dotc.quoted.Runners._
3+
4+
import scala.quoted._
5+
6+
object Test {
7+
def main(args: Array[String]): Unit = {
8+
val expr = '{
9+
val a = 3
10+
println("foo")
11+
2 + a
12+
}
13+
println(expr.show)
14+
println(run(expr.run, optimise = true))
15+
println(expr.run)
16+
}
17+
}

0 commit comments

Comments
 (0)