Skip to content

Homogenize $ and run notation #6689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/test-resources/repl-macros/i6007
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ scala> val v = '{ (if true then Some(1) else None).map(v => v+1) }
val v: quoted.Expr[Option[Int]] = Expr(<pickled tasty>)
scala> v.show
val res0: String = (if (true) scala.Some.apply[scala.Int](1) else scala.None).map[scala.Int](((v: scala.Int) => v.+(1)))
scala> v.run
scala> scala.quoted.run(v)
val res1: Option[Int] = Some(2)
1 change: 1 addition & 0 deletions library/src-2.x/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package quoted {
*
* May throw a FreeVariableError on expressions that came from a macro.
*/
@deprecated("Use scala.quoted.run", "")
final def run(implicit toolbox: Toolbox): T = toolbox.run(this)

}
Expand Down
1 change: 1 addition & 0 deletions library/src-3.x/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package quoted {
*
* May throw a FreeVariableError on expressions that came from a macro.
*/
@deprecated("Use scala.quoted.run", "")
final def run(implicit toolbox: Toolbox): T = toolbox.run(this)

}
Expand Down
14 changes: 14 additions & 0 deletions library/src-3.x/scala/quoted/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ package scala

package object quoted {

/** Evaluate the contents of this expression and return the result.
*
* Usage:
* ```
* val e: T = run {
* expr
* }
* ```
* where `expr: Expr[T]`
*
* May throw a FreeVariableError on expressions that came from a macro.
*/
def run[T](expr: Expr[T]) given (toolbox: Toolbox): T = toolbox.run(expr)

object autolift {
implicit def autoToExpr[T: Liftable](x: T): Expr[T] = x.toExpr
}
Expand Down
20 changes: 10 additions & 10 deletions tests/run-with-compiler-custom-args/staged-streams_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -678,25 +678,25 @@ object Test {

def main(args: Array[String]): Unit = {
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
println(test1().run)
println(run(test1()))
println
println(test2().run)
println(run(test2()))
println
println(test3().run)
println(run(test3()))
println
println(test4().run)
println(run(test4()))
println
println(test5().run)
println(run(test5()))
println
println(test6().run)
println(run(test6()))
println
println(test7().run)
println(run(test7()))
println
println(test8().run)
println(run(test8()))
println
println(test9().run)
println(run(test9()))
println
println(test10().run)
println(run(test10()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3876-b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Test {
def f(x: Int): Int = x + x
f
}
println(f2(x).run)
println(run(f2(x)))
println(f2(x).show)
}
}
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3876-c.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Test {
val f: (x: Int) => Int = x => x + x
f
}
println(f3(x).run)
println(run(f3(x)))
println(f3(x).show) // TODO improve printer
}
}
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3876-d.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object Test {
val f4: Expr[Int => Int] = '{
inlineLambda
}
println(f4(x).run)
println(run(f4(x)))
println(f4(x).show)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3876-e.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object Test {
val f4: Expr[Int => Int] = '{
inlineLambda
}
println(f4(x).run)
println(run(f4(x)))
println(f4(x).show)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3876.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object Test {
val x: Expr[Int] = '{3}

val f: Expr[Int => Int] = '{ (x: Int) => x + x }
println(f(x).run)
println(run(f(x)))
println(f(x).show)
}
}
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3946.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ object Test {
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
val u: Expr[Unit] = '{}
println(u.show)
println(u.run)
println(run(u))
}
}
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3947.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Test {
val name = '{ ($lclazz).getCanonicalName }
println()
println(name.show)
println(name.run)
println(run(name))
}

// classOf[Object]
Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3947b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Test {
val name = '{ ($lclazz).getCanonicalName }
println()
println(name.show)
println(name.run)
println(run(name))
}

// primitives
Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3947b2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Test {
val name = '{ ($lclazz).getCanonicalName }
println()
println(name.show)
println(name.run)
println(run(name))
}

// primitives
Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3947b3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Test {
val name = '{ ($lclazz).getCanonicalName }
println()
println(name.show)
println(name.run)
println(run(name))
}

// primitives
Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3947c.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Test {
val name = '{ ($lclazz).getCanonicalName }
println()
println(name.show)
println(name.run)
println(run(name))
}

test(classOf[Null])
Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3947d.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Test {
val name = '{ ($lclazz).getCanonicalName }
println()
println(name.show)
println(name.run)
println(run(name))
}

test(classOf[Foo])
Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3947d2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Test {
val name = '{ ($lclazz).getCanonicalName }
println()
println(name.show)
println(name.run)
println(run(name))
}

test(classOf[foo.Foo])
Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3947e.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object Test {
val name = '{ ($lclazz).getCanonicalName }
println()
println(name.show)
println(name.run)
println(run(name))
}

// class Object
Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3947f.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Test {
val name = '{ ($lclazz).getCanonicalName }
println()
println(name.show)
println(name.run)
println(run(name))
}

// class Array[Object]
Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3947g.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Test {
val name = '{ ($lclazz).getCanonicalName }
println()
println(name.show)
println(name.run)
println(run(name))
}

// primitive arrays
Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3947i.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Test {
val name = '{ ($lclazz).getCanonicalName }
println()
println(name.show)
println(name.run)
println(run(name))
}

// primitive arrays
Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i3947j.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Test {
val name = '{ ($lclazz).getCanonicalName }
println()
println(name.show)
println(name.run)
println(run(name))
}

test(classOf[Array[Array[Int]]])
Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/i4591.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Test {

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

}
6 changes: 3 additions & 3 deletions tests/run-with-compiler/i5965.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ object Test {
'[List]
val list = bound('{List(1, 2, 3)})
println(list.show)
println(list.run)
println(run(list))

val opt = bound('{Option(4)})
println(opt.show)
println(opt.run)
println(run(opt))

val map = bound('{Map(4 -> 1)})
println(map.show)
println(map.run)
println(run(map))
}

def bound[T: Type, S[_]: Type](x: Expr[S[T]]): Expr[S[T]] = '{
Expand Down
6 changes: 3 additions & 3 deletions tests/run-with-compiler/i5965b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ object Test {
'[List]
val list = bound('{List(1, 2, 3)})
println(list.show)
println(list.run)
println(run(list))

val opt = bound('{Option(4)})
println(opt.show)
println(opt.run)
println(run(opt))

val map = bound('{Map(4 -> 1)})
println(map.show)
println(map.run)
println(run(map))
}

def bound[T: Type, S[_]: Type](x: Expr[S[T]]): Expr[S[T]] = '{
Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/quote-ackermann-1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object Test {

def main(args: Array[String]): Unit = {
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
val ack3 = ackermann(3).run
val ack3 = run { ackermann(3) }
println(ack3(1))
println(ack3(2))
println(ack3(3))
Expand Down
4 changes: 3 additions & 1 deletion tests/run-with-compiler/quote-fun-app-1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ object Test {

def main(args: Array[String]): Unit = {
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
val f = f1.run
val f = run {
f1
}
println(f(42))
println(f(43))
}
Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/quote-owners-2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object Test {
def main(args: Array[String]): Unit = {
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
val q = f(g(Type.IntTag))
println(q.run)
println(run(q))
println(q.show)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/quote-owners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object Test {
def main(args: Array[String]): Unit = {
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
val q = f
println(q.run)
println(run(q))
println(q.show)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/quote-run-b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Test {
}
println()

val lambda = lambdaExpr.run
val lambda = run(lambdaExpr)
lambda(4)
lambda(5)
}
Expand Down
8 changes: 4 additions & 4 deletions tests/run-with-compiler/quote-run-c.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ object Test {
}
new A
}
println(classExpr.run)
println(classExpr.run.getClass == classExpr.run.getClass)
println(classExpr2.run)
println(classExpr2.run.getClass)
println(run(classExpr))
println(run(classExpr).getClass == run(classExpr).getClass)
println(run(classExpr2))
println(run(classExpr2).getClass)
}
}
26 changes: 13 additions & 13 deletions tests/run-with-compiler/quote-run-constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import scala.quoted._
object Test {
def main(args: Array[String]): Unit = {
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
def run[T](expr: Expr[T]): Unit = println(expr.run)
def runAndPrint[T](expr: Expr[T]): Unit = println(run(expr))
def show[T](expr: Expr[T]): Unit = println(expr.show)

run(true)
run('a')
run('\n')
run('"')
run('\'')
run('\\')
run(1)
run(2)
run(3L)
run(4.0f)
run(5.0d)
run("xyz")
runAndPrint(true)
runAndPrint('a')
runAndPrint('\n')
runAndPrint('"')
runAndPrint('\'')
runAndPrint('\\')
runAndPrint(1)
runAndPrint(2)
runAndPrint(3L)
runAndPrint(4.0f)
runAndPrint(5.0d)
runAndPrint("xyz")

println("======")

Expand Down
4 changes: 3 additions & 1 deletion tests/run-with-compiler/quote-run-many.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ object Test {
2 + a
}
for (i <- 0 to 200)
expr(i).run
run {
expr(i)
}
}
}
Loading