Skip to content

Commit 74f30df

Browse files
committed
Homogenize $ and run notation
Now both `$` and `run` correspond to ```scala def $[T](expr: Expr[T]): T = ... def run[T](expr: Expr[T]): T = ... ``` This is the first step towards correct context handling in quote and splices.
1 parent eb27b4a commit 74f30df

40 files changed

+123
-87
lines changed

library/src-2.x/scala/quoted/Expr.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package quoted {
88
*
99
* May throw a FreeVariableError on expressions that came from a macro.
1010
*/
11+
@deprecated("Use scala.quoted.run")
1112
final def run(implicit toolbox: Toolbox): T = toolbox.run(this)
1213

1314
}

library/src-3.x/scala/quoted/Expr.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package quoted {
88
*
99
* May throw a FreeVariableError on expressions that came from a macro.
1010
*/
11+
@deprecated("Use scala.quoted.run")
1112
final def run(implicit toolbox: Toolbox): T = toolbox.run(this)
1213

1314
}

library/src-3.x/scala/quoted/package.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ package scala
22

33
package object quoted {
44

5+
/** Evaluate the contents of this expression and return the result.
6+
*
7+
* Usage:
8+
* ```
9+
* val e: T = run {
10+
* expr
11+
* }
12+
* ```
13+
* where `expr: Expr[T]`
14+
*
15+
* May throw a FreeVariableError on expressions that came from a macro.
16+
*/
17+
def run[T](expr: Expr[T]) given (toolbox: Toolbox): T = toolbox.run(expr)
18+
519
object autolift {
620
implicit def autoToExpr[T: Liftable](x: T): Expr[T] = x.toExpr
721
}

tests/run-with-compiler-custom-args/staged-streams_1.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -678,25 +678,25 @@ object Test {
678678

679679
def main(args: Array[String]): Unit = {
680680
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
681-
println(test1().run)
681+
println(run(test1()))
682682
println
683-
println(test2().run)
683+
println(run(test2()))
684684
println
685-
println(test3().run)
685+
println(run(test3()))
686686
println
687-
println(test4().run)
687+
println(run(test4()))
688688
println
689-
println(test5().run)
689+
println(run(test5()))
690690
println
691-
println(test6().run)
691+
println(run(test6()))
692692
println
693-
println(test7().run)
693+
println(run(test7()))
694694
println
695-
println(test8().run)
695+
println(run(test8()))
696696
println
697-
println(test9().run)
697+
println(run(test9()))
698698
println
699-
println(test10().run)
699+
println(run(test10()))
700700
}
701701
}
702702

tests/run-with-compiler/i3876-b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Test {
99
def f(x: Int): Int = x + x
1010
f
1111
}
12-
println(f2(x).run)
12+
println(run(f2(x)))
1313
println(f2(x).show)
1414
}
1515
}

tests/run-with-compiler/i3876-c.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Test {
99
val f: (x: Int) => Int = x => x + x
1010
f
1111
}
12-
println(f3(x).run)
12+
println(run(f3(x)))
1313
println(f3(x).show) // TODO improve printer
1414
}
1515
}

tests/run-with-compiler/i3876-d.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object Test {
88
val f4: Expr[Int => Int] = '{
99
inlineLambda
1010
}
11-
println(f4(x).run)
11+
println(run(f4(x)))
1212
println(f4(x).show)
1313
}
1414

tests/run-with-compiler/i3876-e.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object Test {
88
val f4: Expr[Int => Int] = '{
99
inlineLambda
1010
}
11-
println(f4(x).run)
11+
println(run(f4(x)))
1212
println(f4(x).show)
1313
}
1414

tests/run-with-compiler/i3876.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object Test {
66
val x: Expr[Int] = '{3}
77

88
val f: Expr[Int => Int] = '{ (x: Int) => x + x }
9-
println(f(x).run)
9+
println(run(f(x)))
1010
println(f(x).show)
1111
}
1212
}

tests/run-with-compiler/i3946.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ object Test {
44
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
55
val u: Expr[Unit] = '{}
66
println(u.show)
7-
println(u.run)
7+
println(run(u))
88
}
99
}

0 commit comments

Comments
 (0)