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
}

tests/run-with-compiler/i3947.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Test {
1010
val name = '{ ($lclazz).getCanonicalName }
1111
println()
1212
println(name.show)
13-
println(name.run)
13+
println(run(name))
1414
}
1515

1616
// classOf[Object]

tests/run-with-compiler/i3947b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Test {
1010
val name = '{ ($lclazz).getCanonicalName }
1111
println()
1212
println(name.show)
13-
println(name.run)
13+
println(run(name))
1414
}
1515

1616
// primitives

tests/run-with-compiler/i3947b2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Test {
1010
val name = '{ ($lclazz).getCanonicalName }
1111
println()
1212
println(name.show)
13-
println(name.run)
13+
println(run(name))
1414
}
1515

1616
// primitives

tests/run-with-compiler/i3947b3.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Test {
1010
val name = '{ ($lclazz).getCanonicalName }
1111
println()
1212
println(name.show)
13-
println(name.run)
13+
println(run(name))
1414
}
1515

1616
// primitives

tests/run-with-compiler/i3947c.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Test {
1010
val name = '{ ($lclazz).getCanonicalName }
1111
println()
1212
println(name.show)
13-
println(name.run)
13+
println(run(name))
1414
}
1515

1616
test(classOf[Null])

tests/run-with-compiler/i3947d.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Test {
1010
val name = '{ ($lclazz).getCanonicalName }
1111
println()
1212
println(name.show)
13-
println(name.run)
13+
println(run(name))
1414
}
1515

1616
test(classOf[Foo])

tests/run-with-compiler/i3947d2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Test {
1010
val name = '{ ($lclazz).getCanonicalName }
1111
println()
1212
println(name.show)
13-
println(name.run)
13+
println(run(name))
1414
}
1515

1616
test(classOf[foo.Foo])

tests/run-with-compiler/i3947e.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object Test {
1111
val name = '{ ($lclazz).getCanonicalName }
1212
println()
1313
println(name.show)
14-
println(name.run)
14+
println(run(name))
1515
}
1616

1717
// class Object

tests/run-with-compiler/i3947f.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Test {
1010
val name = '{ ($lclazz).getCanonicalName }
1111
println()
1212
println(name.show)
13-
println(name.run)
13+
println(run(name))
1414
}
1515

1616
// class Array[Object]

tests/run-with-compiler/i3947g.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Test {
1010
val name = '{ ($lclazz).getCanonicalName }
1111
println()
1212
println(name.show)
13-
println(name.run)
13+
println(run(name))
1414
}
1515

1616
// primitive arrays

tests/run-with-compiler/i3947i.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Test {
1010
val name = '{ ($lclazz).getCanonicalName }
1111
println()
1212
println(name.show)
13-
println(name.run)
13+
println(run(name))
1414
}
1515

1616
// primitive arrays

tests/run-with-compiler/i3947j.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Test {
1010
val name = '{ ($lclazz).getCanonicalName }
1111
println()
1212
println(name.show)
13-
println(name.run)
13+
println(run(name))
1414
}
1515

1616
test(classOf[Array[Array[Int]]])

tests/run-with-compiler/i4591.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Test {
99

1010
def main(args: Array[String]): Unit = {
1111
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
12-
foo('{Option(9)}).run
12+
run(foo('{Option(9)}))
1313
}
1414

1515
}

tests/run-with-compiler/i5965.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ object Test {
99
'[List]
1010
val list = bound('{List(1, 2, 3)})
1111
println(list.show)
12-
println(list.run)
12+
println(run(list))
1313

1414
val opt = bound('{Option(4)})
1515
println(opt.show)
16-
println(opt.run)
16+
println(run(opt))
1717

1818
val map = bound('{Map(4 -> 1)})
1919
println(map.show)
20-
println(map.run)
20+
println(run(map))
2121
}
2222

2323
def bound[T: Type, S[_]: Type](x: Expr[S[T]]): Expr[S[T]] = '{

tests/run-with-compiler/i5965b.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ object Test {
1010
'[List]
1111
val list = bound('{List(1, 2, 3)})
1212
println(list.show)
13-
println(list.run)
13+
println(run(list))
1414

1515
val opt = bound('{Option(4)})
1616
println(opt.show)
17-
println(opt.run)
17+
println(run(opt))
1818

1919
val map = bound('{Map(4 -> 1)})
2020
println(map.show)
21-
println(map.run)
21+
println(run(map))
2222
}
2323

2424
def bound[T: Type, S[_]: Type](x: Expr[S[T]]): Expr[S[T]] = '{

tests/run-with-compiler/quote-ackermann-1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ object Test {
44

55
def main(args: Array[String]): Unit = {
66
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
7-
val ack3 = ackermann(3).run
7+
val ack3 = run { ackermann(3) }
88
println(ack3(1))
99
println(ack3(2))
1010
println(ack3(3))

tests/run-with-compiler/quote-fun-app-1.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ object Test {
44

55
def main(args: Array[String]): Unit = {
66
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
7-
val f = f1.run
7+
val f = run {
8+
f1
9+
}
810
println(f(42))
911
println(f(43))
1012
}

tests/run-with-compiler/quote-owners-2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Test {
55
def main(args: Array[String]): Unit = {
66
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
77
val q = f(g(Type.IntTag))
8-
println(q.run)
8+
println(run(q))
99
println(q.show)
1010
}
1111

tests/run-with-compiler/quote-owners.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ object Test {
44
def main(args: Array[String]): Unit = {
55
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
66
val q = f
7-
println(q.run)
7+
println(run(q))
88
println(q.show)
99
}
1010

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Test {
99
}
1010
println()
1111

12-
val lambda = lambdaExpr.run
12+
val lambda = run(lambdaExpr)
1313
lambda(4)
1414
lambda(5)
1515
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ object Test {
1616
}
1717
new A
1818
}
19-
println(classExpr.run)
20-
println(classExpr.run.getClass == classExpr.run.getClass)
21-
println(classExpr2.run)
22-
println(classExpr2.run.getClass)
19+
println(run(classExpr))
20+
println(run(classExpr).getClass == run(classExpr).getClass)
21+
println(run(classExpr2))
22+
println(run(classExpr2).getClass)
2323
}
2424
}

tests/run-with-compiler/quote-run-constants.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ import scala.quoted._
66
object Test {
77
def main(args: Array[String]): Unit = {
88
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
9-
def run[T](expr: Expr[T]): Unit = println(expr.run)
9+
def runAndPrint[T](expr: Expr[T]): Unit = println(run(expr))
1010
def show[T](expr: Expr[T]): Unit = println(expr.show)
1111

12-
run(true)
13-
run('a')
14-
run('\n')
15-
run('"')
16-
run('\'')
17-
run('\\')
18-
run(1)
19-
run(2)
20-
run(3L)
21-
run(4.0f)
22-
run(5.0d)
23-
run("xyz")
12+
runAndPrint(true)
13+
runAndPrint('a')
14+
runAndPrint('\n')
15+
runAndPrint('"')
16+
runAndPrint('\'')
17+
runAndPrint('\\')
18+
runAndPrint(1)
19+
runAndPrint(2)
20+
runAndPrint(3L)
21+
runAndPrint(4.0f)
22+
runAndPrint(5.0d)
23+
runAndPrint("xyz")
2424

2525
println("======")
2626

tests/run-with-compiler/quote-run-many.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ object Test {
99
2 + a
1010
}
1111
for (i <- 0 to 200)
12-
expr(i).run
12+
run {
13+
expr(i)
14+
}
1315
}
1416
}

0 commit comments

Comments
 (0)