From 8b62c6dda387fd062e86a0b6df303af6e2d8e0e8 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 24 Jul 2019 16:56:34 +0200 Subject: [PATCH 01/10] Add `quoted.Liftable[List[T]]` to the stdlib --- library/src/scala/quoted/Liftable.scala | 7 +++++++ .../gestalt-type-toolbox-reflect/Macro_1.scala | 7 ------- tests/run-macros/quote-force/quoted_1.scala | 6 ------ tests/run-macros/tasty-interpolation-1/Macro.scala | 11 +---------- tests/run-macros/tasty-location/quoted_1.scala | 6 ------ tests/run-with-compiler/quote-lib.scala | 6 ------ 6 files changed, 8 insertions(+), 35 deletions(-) diff --git a/library/src/scala/quoted/Liftable.scala b/library/src/scala/quoted/Liftable.scala index d26988d55008..7d0578ca1736 100644 --- a/library/src/scala/quoted/Liftable.scala +++ b/library/src/scala/quoted/Liftable.scala @@ -43,4 +43,11 @@ object Liftable { } } + given [T: Type: Liftable] as Liftable[List[T]] = new Liftable[List[T]] { + def toExpr(x: List[T]): given QuoteContext => Expr[List[T]] = x match { + case x :: xs => '{ (${this.toExpr(xs)}).::[T](${the[Liftable[T]].toExpr(x)}) } + case Nil => '{ Nil: List[T] } + } + } + } diff --git a/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala b/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala index 9e3718a26938..c6b51cc1e1ec 100644 --- a/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala +++ b/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala @@ -110,11 +110,4 @@ object TypeToolbox { companionClassOpt.map(_.fullName).getOrElse("").toExpr } - // TODO add to the std lib - private implicit def listIsLiftable[T: Type: Liftable]: Liftable[List[T]] = new Liftable { - def toExpr(list: List[T]) = list match { - case x :: xs => '{${x.toExpr} :: ${toExpr(xs)}} - case Nil => '{Nil} - } - } } diff --git a/tests/run-macros/quote-force/quoted_1.scala b/tests/run-macros/quote-force/quoted_1.scala index b537f3f847ca..7af3975e7183 100644 --- a/tests/run-macros/quote-force/quoted_1.scala +++ b/tests/run-macros/quote-force/quoted_1.scala @@ -12,10 +12,4 @@ object Location { '{new Location(${list})} } - private implicit def ListIsLiftable[T : Liftable : Type]: Liftable[List[T]] = new Liftable[List[T]] { - def toExpr(x: List[T]) = x match { - case x :: xs => '{ ${x} :: ${xs} } - case Nil => '{ List.empty[T] } - } - } } diff --git a/tests/run-macros/tasty-interpolation-1/Macro.scala b/tests/run-macros/tasty-interpolation-1/Macro.scala index 3f64a3e8a7e4..2e803cb7817d 100644 --- a/tests/run-macros/tasty-interpolation-1/Macro.scala +++ b/tests/run-macros/tasty-interpolation-1/Macro.scala @@ -77,16 +77,7 @@ abstract class MacroStringInterpolator[T] { } protected implicit def StringContextIsLiftable: Liftable[StringContext] = new Liftable[StringContext] { - def toExpr(strCtx: StringContext) = { - // TODO define in stdlib? - implicit def ListIsLiftable: Liftable[List[String]] = new Liftable[List[String]] { - override def toExpr(list: List[String]) = list match { - case x :: xs => '{${x.toExpr} :: ${toExpr(xs)}} - case Nil => '{Nil} - } - } - '{StringContext(${strCtx.parts.toList}: _*)} - } + def toExpr(strCtx: StringContext) = '{StringContext(${strCtx.parts.toList}: _*)} } protected class NotStaticlyKnownError(msg: String, expr: Expr[Any]) extends Exception(msg) diff --git a/tests/run-macros/tasty-location/quoted_1.scala b/tests/run-macros/tasty-location/quoted_1.scala index b350cf9c6fa4..15f0ffa15281 100644 --- a/tests/run-macros/tasty-location/quoted_1.scala +++ b/tests/run-macros/tasty-location/quoted_1.scala @@ -18,10 +18,4 @@ object Location { '{new Location(${list})} } - private implicit def ListIsLiftable[T : Liftable : Type]: Liftable[List[T]] = new Liftable[List[T]] { - def toExpr(x: List[T]) = x match { - case x :: xs => '{ $x :: $xs } - case Nil => '{ List.empty[T] } - } - } } diff --git a/tests/run-with-compiler/quote-lib.scala b/tests/run-with-compiler/quote-lib.scala index 04726cd8de57..67e71d2a4173 100644 --- a/tests/run-with-compiler/quote-lib.scala +++ b/tests/run-with-compiler/quote-lib.scala @@ -101,12 +101,6 @@ package liftable { object Lists { - implicit def ListIsLiftable[T: Liftable](implicit t: Type[T]): Liftable[List[T]] = new Liftable[List[T]] { - def toExpr(x: List[T]): given QuoteContext => Expr[List[T]] = x match { - case x :: xs => '{ (${xs}).::[$t](${x}) } - case Nil => '{ Nil: List[$t] } - } - } implicit class LiftedOps[T: Liftable](list: Expr[List[T]])(implicit t: Type[T]) { def foldLeft[U](acc: Expr[U])(f: Expr[(U, T) => U])(implicit u: Type[U], qctx: QuoteContext): Expr[U] = From db0f047cd61dc3601962cca0a67fb07a6deb006d Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 24 Jul 2019 17:28:36 +0200 Subject: [PATCH 02/10] Add `quoted.Liftable[IArray[T]]` to the stdlib --- library/src/scala/quoted/Liftable.scala | 9 +++++++++ tests/run-with-compiler/quote-lib.scala | 9 +++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/library/src/scala/quoted/Liftable.scala b/library/src/scala/quoted/Liftable.scala index 7d0578ca1736..9e2d34ddd019 100644 --- a/library/src/scala/quoted/Liftable.scala +++ b/library/src/scala/quoted/Liftable.scala @@ -1,5 +1,7 @@ package scala.quoted +import scala.reflect.ClassTag + /** A typeclass for types that can be turned to `quoted.Expr[T]` * without going through an explicit `'{...}` operation. */ @@ -43,6 +45,13 @@ object Liftable { } } + given [T: Type: Liftable: ClassTag] as Liftable[IArray[T]] = new Liftable[IArray[T]] { + def toExpr(iarray: IArray[T]): given QuoteContext => Expr[IArray[T]] = '{ + val array = new Array[T](${Liftable_Int_delegate.toExpr(iarray.length)})(ClassTag(${ClassIsLiftable.toExpr(the[ClassTag[T]].runtimeClass)})) + ${ Expr.block(List.tabulate(iarray.length)(i => '{ array(${Liftable_Int_delegate.toExpr(i)}) = ${the[Liftable[T]].toExpr(iarray(i))} }), '{ array.asInstanceOf[IArray[T]] }) } + } + } + given [T: Type: Liftable] as Liftable[List[T]] = new Liftable[List[T]] { def toExpr(x: List[T]): given QuoteContext => Expr[List[T]] = x match { case x :: xs => '{ (${this.toExpr(xs)}).::[T](${the[Liftable[T]].toExpr(x)}) } diff --git a/tests/run-with-compiler/quote-lib.scala b/tests/run-with-compiler/quote-lib.scala index 67e71d2a4173..b8622e247044 100644 --- a/tests/run-with-compiler/quote-lib.scala +++ b/tests/run-with-compiler/quote-lib.scala @@ -35,6 +35,9 @@ object Test { list.unrolledFoldLeft[Int](0)('{ (acc: Int, x: Int) => acc + x }).show list.unrolledForeach('{ (x: Int) => println(x) }).show + val iarray: IArray[Int] = IArray(1, 2, 3) + val liftedIArray: Expr[IArray[Int]] = iarray + println("quote lib ok") } } @@ -120,11 +123,5 @@ package liftable { } } - object Arrays { - implicit def ArrayIsLiftable[T: Liftable](implicit t: Type[T], ct: Expr[ClassTag[T]]): Liftable[Array[T]] = new Liftable[Array[T]] { - def toExpr(arr: Array[T]) = '{ new Array[$t](${arr.length})($ct) } - } - } - } } From b334a944f1bf16ca1c122fcbf6f4c4773fb5a6d8 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 24 Jul 2019 18:04:32 +0200 Subject: [PATCH 03/10] Add missing non-bootstraped toExpr --- library/src-non-bootstrapped/scala/quoted/package.scala | 3 +++ library/src/scala/quoted/Liftable.scala | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/library/src-non-bootstrapped/scala/quoted/package.scala b/library/src-non-bootstrapped/scala/quoted/package.scala index aa724ad6f937..0151f2dcde10 100644 --- a/library/src-non-bootstrapped/scala/quoted/package.scala +++ b/library/src-non-bootstrapped/scala/quoted/package.scala @@ -8,4 +8,7 @@ package object quoted { def withQuoteContext[T](thunk: given QuoteContext => T) given (toolbox: Toolbox): T = throw new Exception("Non bootsrapped library") + implicit object ExprOps { + def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = the[Liftable[T]].toExpr(x) + } } diff --git a/library/src/scala/quoted/Liftable.scala b/library/src/scala/quoted/Liftable.scala index 9e2d34ddd019..2c16c802e01f 100644 --- a/library/src/scala/quoted/Liftable.scala +++ b/library/src/scala/quoted/Liftable.scala @@ -47,14 +47,14 @@ object Liftable { given [T: Type: Liftable: ClassTag] as Liftable[IArray[T]] = new Liftable[IArray[T]] { def toExpr(iarray: IArray[T]): given QuoteContext => Expr[IArray[T]] = '{ - val array = new Array[T](${Liftable_Int_delegate.toExpr(iarray.length)})(ClassTag(${ClassIsLiftable.toExpr(the[ClassTag[T]].runtimeClass)})) - ${ Expr.block(List.tabulate(iarray.length)(i => '{ array(${Liftable_Int_delegate.toExpr(i)}) = ${the[Liftable[T]].toExpr(iarray(i))} }), '{ array.asInstanceOf[IArray[T]] }) } + val array = new Array[T](${iarray.length.toExpr})(ClassTag(${the[ClassTag[T]].runtimeClass.toExpr})) + ${ Expr.block(List.tabulate(iarray.length)(i => '{ array(${i.toExpr}) = ${iarray(i).toExpr} }), '{ array.asInstanceOf[IArray[T]] }) } } } given [T: Type: Liftable] as Liftable[List[T]] = new Liftable[List[T]] { def toExpr(x: List[T]): given QuoteContext => Expr[List[T]] = x match { - case x :: xs => '{ (${this.toExpr(xs)}).::[T](${the[Liftable[T]].toExpr(x)}) } + case x :: xs => '{ (${xs.toExpr}).::[T](${x.toExpr}) } case Nil => '{ Nil: List[T] } } } From a6048a785487cd5eadd895cac4023c07117de472 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 24 Jul 2019 18:08:26 +0200 Subject: [PATCH 04/10] Add `quoted.Liftable[Option[T]]` to the stdlib --- library/src/scala/quoted/Liftable.scala | 7 +++++++ tests/run-with-compiler/quote-lib.scala | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/library/src/scala/quoted/Liftable.scala b/library/src/scala/quoted/Liftable.scala index 2c16c802e01f..4dfdd92db70e 100644 --- a/library/src/scala/quoted/Liftable.scala +++ b/library/src/scala/quoted/Liftable.scala @@ -59,4 +59,11 @@ object Liftable { } } + given [T: Type: Liftable] as Liftable[Option[T]] = new Liftable[Option[T]] { + def toExpr(x: Option[T]): given QuoteContext => Expr[Option[T]] = x match { + case Some(x) => '{ Some[T](${x.toExpr}) } + case None => '{ None: Option[T] } + } + } + } diff --git a/tests/run-with-compiler/quote-lib.scala b/tests/run-with-compiler/quote-lib.scala index b8622e247044..4ec4ba22bcbe 100644 --- a/tests/run-with-compiler/quote-lib.scala +++ b/tests/run-with-compiler/quote-lib.scala @@ -38,6 +38,11 @@ object Test { val iarray: IArray[Int] = IArray(1, 2, 3) val liftedIArray: Expr[IArray[Int]] = iarray + val some: Option[Int] = Some(2) + val none: Option[Int] = Some(2) + val liftedSome: Expr[Option[Int]] = some + val liftedNone: Expr[Option[Int]] = none + println("quote lib ok") } } From eb125d53c0bfae41d824d5a6df6219416a654de0 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 24 Jul 2019 18:16:51 +0200 Subject: [PATCH 05/10] Add `quoted.Liftable[Either[L, R]]` to the stdlib --- library/src/scala/quoted/Liftable.scala | 7 +++++++ tests/run-with-compiler/quote-lib.scala | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/library/src/scala/quoted/Liftable.scala b/library/src/scala/quoted/Liftable.scala index 4dfdd92db70e..0356b4d337ba 100644 --- a/library/src/scala/quoted/Liftable.scala +++ b/library/src/scala/quoted/Liftable.scala @@ -66,4 +66,11 @@ object Liftable { } } + given [L: Type: Liftable, R: Type: Liftable] as Liftable[Either[L, R]] = new Liftable[Either[L, R]] { + def toExpr(x: Either[L, R]): given QuoteContext => Expr[Either[L, R]] = x match { + case Left(x) => '{ Left[L, R](${x.toExpr}) } + case Right(x) => '{ Right[L, R](${x.toExpr}) } + } + } + } diff --git a/tests/run-with-compiler/quote-lib.scala b/tests/run-with-compiler/quote-lib.scala index 4ec4ba22bcbe..e93fbc7eeae1 100644 --- a/tests/run-with-compiler/quote-lib.scala +++ b/tests/run-with-compiler/quote-lib.scala @@ -43,6 +43,11 @@ object Test { val liftedSome: Expr[Option[Int]] = some val liftedNone: Expr[Option[Int]] = none + val left: Either[Int, Long] = Left(1) + val right: Either[Int, Long] = Right(2L) + left.toExpr + right.toExpr + println("quote lib ok") } } From ddaf5b65d3e2cc4d9189f4d8884b03d88d01b720 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 25 Jul 2019 18:40:02 +0200 Subject: [PATCH 06/10] Add `quoted.Liftable[Seq[T]]` to the stdlib --- library/src/scala/quoted/Liftable.scala | 7 +++++++ tests/run-with-compiler/quote-lib.scala | 3 +++ 2 files changed, 10 insertions(+) diff --git a/library/src/scala/quoted/Liftable.scala b/library/src/scala/quoted/Liftable.scala index 0356b4d337ba..df54cd4cfb9d 100644 --- a/library/src/scala/quoted/Liftable.scala +++ b/library/src/scala/quoted/Liftable.scala @@ -52,6 +52,13 @@ object Liftable { } } + given [T: Type: Liftable] as Liftable[Seq[T]] = new Liftable[Seq[T]] { + def toExpr(seq: Seq[T]): given QuoteContext => Expr[Seq[T]] = given qctx => { + import qctx.tasty._ + Repeated(seq.map(x => the[Liftable[T]].toExpr(x).unseal).toList, the[quoted.Type[T]].unseal).seal.asInstanceOf[Expr[Seq[T]]] + } + } + given [T: Type: Liftable] as Liftable[List[T]] = new Liftable[List[T]] { def toExpr(x: List[T]): given QuoteContext => Expr[List[T]] = x match { case x :: xs => '{ (${xs.toExpr}).::[T](${x.toExpr}) } diff --git a/tests/run-with-compiler/quote-lib.scala b/tests/run-with-compiler/quote-lib.scala index e93fbc7eeae1..c8725f64f14a 100644 --- a/tests/run-with-compiler/quote-lib.scala +++ b/tests/run-with-compiler/quote-lib.scala @@ -29,6 +29,9 @@ object Test { val list: List[Int] = List(1, 2, 3) val liftedList: Expr[List[Int]] = list + val seq: Seq[Int] = Seq(1, 2, 3) + val liftedSeq: Expr[Seq[Int]] = seq + liftedList.foldLeft[Int](0)('{ (acc: Int, x: Int) => acc + x }).show liftedList.foreach('{ (x: Int) => println(x) }).show From 05c77dccbae7d6819e0ccb6819e3bde6d7d8d038 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 25 Jul 2019 18:43:33 +0200 Subject: [PATCH 07/10] Add `quoted.Liftable[Set[T]]` to the stdlib --- library/src/scala/quoted/Liftable.scala | 5 +++++ tests/run-with-compiler/quote-lib.scala | 3 +++ 2 files changed, 8 insertions(+) diff --git a/library/src/scala/quoted/Liftable.scala b/library/src/scala/quoted/Liftable.scala index df54cd4cfb9d..e035d5654b29 100644 --- a/library/src/scala/quoted/Liftable.scala +++ b/library/src/scala/quoted/Liftable.scala @@ -66,6 +66,11 @@ object Liftable { } } + given [T: Type: Liftable] as Liftable[Set[T]] = new Liftable[Set[T]] { + def toExpr(set: Set[T]): given QuoteContext => Expr[Set[T]] = + '{ Set(${set.toSeq.toExpr}: _*) } + } + given [T: Type: Liftable] as Liftable[Option[T]] = new Liftable[Option[T]] { def toExpr(x: Option[T]): given QuoteContext => Expr[Option[T]] = x match { case Some(x) => '{ Some[T](${x.toExpr}) } diff --git a/tests/run-with-compiler/quote-lib.scala b/tests/run-with-compiler/quote-lib.scala index c8725f64f14a..826e0dce28b1 100644 --- a/tests/run-with-compiler/quote-lib.scala +++ b/tests/run-with-compiler/quote-lib.scala @@ -32,6 +32,9 @@ object Test { val seq: Seq[Int] = Seq(1, 2, 3) val liftedSeq: Expr[Seq[Int]] = seq + val set: Set[Int] = Set(1, 2, 3) + val liftedSet: Expr[Set[Int]] = set + liftedList.foldLeft[Int](0)('{ (acc: Int, x: Int) => acc + x }).show liftedList.foreach('{ (x: Int) => println(x) }).show From 6f02d96962cf015baa463dbe4c96d31d236c57b8 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 25 Jul 2019 19:15:17 +0200 Subject: [PATCH 08/10] Add `quoted.Liftable[TupleN[T1, ...]]` for `N <= 22` to the stdlib --- library/src/scala/quoted/Liftable.scala | 146 ++++++++++++++++++++++++ tests/run-with-compiler/quote-lib.scala | 51 ++++----- 2 files changed, 168 insertions(+), 29 deletions(-) diff --git a/library/src/scala/quoted/Liftable.scala b/library/src/scala/quoted/Liftable.scala index e035d5654b29..012b91971e31 100644 --- a/library/src/scala/quoted/Liftable.scala +++ b/library/src/scala/quoted/Liftable.scala @@ -85,4 +85,150 @@ object Liftable { } } + given [T1: Type: Liftable] as Liftable[Tuple1[T1]] = new { + def toExpr(tup: Tuple1[T1]) = + '{ Tuple1(${tup._1.toExpr}) } + } + + given [T1: Type: Liftable, T2: Type: Liftable] as Liftable[Tuple2[T1, T2]] = new { + def toExpr(tup: Tuple2[T1, T2]) = + '{ (${tup._1.toExpr}, ${tup._2.toExpr}) } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable] as Liftable[Tuple3[T1, T2, T3]] = new { + def toExpr(tup: Tuple3[T1, T2, T3]) = + '{ (${tup._1.toExpr}, ${tup._2.toExpr}, ${tup._3.toExpr}) } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable] as Liftable[Tuple4[T1, T2, T3, T4]] = new { + def toExpr(tup: Tuple4[T1, T2, T3, T4]) = + '{ (${tup._1.toExpr}, ${tup._2.toExpr}, ${tup._3.toExpr}, ${tup._4.toExpr}) } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable] as Liftable[Tuple5[T1, T2, T3, T4, T5]] = new { + def toExpr(tup: Tuple5[T1, T2, T3, T4, T5]) = { + val (x1, x2, x3, x4, x5) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable] as Liftable[Tuple6[T1, T2, T3, T4, T5, T6]] = new { + def toExpr(tup: Tuple6[T1, T2, T3, T4, T5, T6]) = { + val (x1, x2, x3, x4, x5, x6) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable] as Liftable[Tuple7[T1, T2, T3, T4, T5, T6, T7]] = new { + def toExpr(tup: Tuple7[T1, T2, T3, T4, T5, T6, T7]) = { + val (x1, x2, x3, x4, x5, x6, x7) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable] as Liftable[Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] = new { + def toExpr(tup: Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) = { + val (x1, x2, x3, x4, x5, x6, x7, x8) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable] as Liftable[Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] = new { + def toExpr(tup: Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable] as Liftable[Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] = new { + def toExpr(tup: Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable] as Liftable[Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]] = new { + def toExpr(tup: Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable] as Liftable[Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]] = new { + def toExpr(tup: Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable] as Liftable[Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]] = new { + def toExpr(tup: Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable] as Liftable[Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]] = new { + def toExpr(tup: Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable, T15: Type: Liftable] as Liftable[Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]] = new { + def toExpr(tup: Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}, ${x15.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable, T15: Type: Liftable, T16: Type: Liftable] as Liftable[Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]] = new { + def toExpr(tup: Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}, ${x15.toExpr}, ${x16.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable, T15: Type: Liftable, T16: Type: Liftable, T17: Type: Liftable] as Liftable[Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]] = new { + def toExpr(tup: Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}, ${x15.toExpr}, ${x16.toExpr}, ${x17.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable, T15: Type: Liftable, T16: Type: Liftable, T17: Type: Liftable, T18: Type: Liftable] as Liftable[Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]] = new { + def toExpr(tup: Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}, ${x15.toExpr}, ${x16.toExpr}, ${x17.toExpr}, ${x18.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable, T15: Type: Liftable, T16: Type: Liftable, T17: Type: Liftable, T18: Type: Liftable, T19: Type: Liftable] as Liftable[Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]] = new { + def toExpr(tup: Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}, ${x15.toExpr}, ${x16.toExpr}, ${x17.toExpr}, ${x18.toExpr}, ${x19.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable, T15: Type: Liftable, T16: Type: Liftable, T17: Type: Liftable, T18: Type: Liftable, T19: Type: Liftable, T20: Type: Liftable] as Liftable[Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]] = new { + def toExpr(tup: Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}, ${x15.toExpr}, ${x16.toExpr}, ${x17.toExpr}, ${x18.toExpr}, ${x19.toExpr}, ${x20.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable, T15: Type: Liftable, T16: Type: Liftable, T17: Type: Liftable, T18: Type: Liftable, T19: Type: Liftable, T20: Type: Liftable, T21: Type: Liftable] as Liftable[Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]] = new { + def toExpr(tup: Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}, ${x15.toExpr}, ${x16.toExpr}, ${x17.toExpr}, ${x18.toExpr}, ${x19.toExpr}, ${x20.toExpr}, ${x21.toExpr}) } + } + } + + given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable, T15: Type: Liftable, T16: Type: Liftable, T17: Type: Liftable, T18: Type: Liftable, T19: Type: Liftable, T20: Type: Liftable, T21: Type: Liftable, T22: Type: Liftable] as Liftable[Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]] = new { + def toExpr(tup: Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22) = tup + '{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}, ${x15.toExpr}, ${x16.toExpr}, ${x17.toExpr}, ${x18.toExpr}, ${x19.toExpr}, ${x20.toExpr}, ${x21.toExpr}, ${x22.toExpr}) } + } + } + } diff --git a/tests/run-with-compiler/quote-lib.scala b/tests/run-with-compiler/quote-lib.scala index 826e0dce28b1..a8754abf2b7d 100644 --- a/tests/run-with-compiler/quote-lib.scala +++ b/tests/run-with-compiler/quote-lib.scala @@ -5,7 +5,6 @@ import scala.quoted.autolift._ import liftable.Units._ import liftable.Lets._ import liftable.Loops._ -import liftable.Tuples._ import liftable.Lists._ import liftable.Exprs._ @@ -25,6 +24,28 @@ object Test { val t2: Expr[(Int, Int)] = (2, 3) val t3: Expr[(Int, Int, Int)] = (2, 3, 4) val t4: Expr[(Int, Int, Int, Int)] = (2, 3, 4, 5) + (1, 2, 3, 4).toExpr + (1, 2, 3, 4, 5).toExpr + (1, 2, 3, 4, 5, 6).toExpr + (1, 2, 3, 4, 5, 6, 7).toExpr + (1, 2, 3, 4, 5, 6, 7, 8).toExpr + (1, 2, 3, 4, 5, 6, 7, 8, 9).toExpr + (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).toExpr + (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11).toExpr + (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12).toExpr + (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13).toExpr + (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14).toExpr + (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).toExpr + (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16).toExpr + (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17).toExpr + (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18).toExpr + (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19).toExpr + (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20).toExpr + (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21).toExpr + (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22).toExpr +// (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23).toExpr +// (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24).toExpr +// (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25).toExpr val list: List[Int] = List(1, 2, 3) val liftedList: Expr[List[Int]] = list @@ -90,34 +111,6 @@ package liftable { def liftedDoWhile(body: Expr[Unit])(cond: Expr[Boolean]) given QuoteContext: Expr[Unit] = '{ do $body while ($cond) } } - object Tuples { - - implicit def Tuple1IsLiftable[T1: Liftable](implicit t1: Type[T1]): Liftable[Tuple1[T1]] = new Liftable[Tuple1[T1]] { - def toExpr(x: Tuple1[T1]) = - '{ Tuple1[$t1](${ x._1}) } - } - - implicit def Tuple2IsLiftable[T1: Liftable, T2: Liftable](implicit t1: Type[T1], t2: Type[T2]): Liftable[(T1, T2)] = new Liftable[(T1, T2)] { - def toExpr(x: (T1, T2)) = - '{ Tuple2[$t1, $t2](${x._1}, ${x._2}) } - - } - - implicit def Tuple3IsLiftable[T1: Liftable, T2: Liftable, T3: Liftable](implicit t1: Type[T1], t2: Type[T2], t3: Type[T3]): Liftable[(T1, T2, T3)] = new Liftable[(T1, T2, T3)] { - def toExpr(x: (T1, T2, T3)) = - '{ Tuple3[$t1, $t2, $t3](${x._1}, ${x._2}, ${x._3}) } - - } - - implicit def Tuple4IsLiftable[T1: Liftable, T2: Liftable, T3: Liftable, T4: Liftable](implicit t1: Type[T1], t2: Type[T2], t3: Type[T3], t4: Type[T4]): Liftable[(T1, T2, T3, T4)] = new Liftable[(T1, T2, T3, T4)] { - def toExpr(x: (T1, T2, T3, T4)) = - '{ Tuple4[$t1, $t2, $t3, $t4](${x._1}, ${x._2}, ${x._3}, ${x._4}) } - } - - // TODO more tuples - - } - object Lists { From 57962263052db5afc1bb543e12b3e9451e9b4e57 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 25 Jul 2019 19:20:56 +0200 Subject: [PATCH 09/10] Add `quoted.Liftable[Map[T, U]]` to the stdlib --- library/src/scala/quoted/Liftable.scala | 5 +++++ tests/run-with-compiler/quote-lib.scala | 3 +++ 2 files changed, 8 insertions(+) diff --git a/library/src/scala/quoted/Liftable.scala b/library/src/scala/quoted/Liftable.scala index 012b91971e31..35dc483c70d5 100644 --- a/library/src/scala/quoted/Liftable.scala +++ b/library/src/scala/quoted/Liftable.scala @@ -71,6 +71,11 @@ object Liftable { '{ Set(${set.toSeq.toExpr}: _*) } } + given [T: Type: Liftable, U: Type: Liftable] as Liftable[Map[T, U]] = new Liftable[Map[T, U]] { + def toExpr(map: Map[T, U]): given QuoteContext => Expr[Map[T, U]] = + '{ Map(${map.toSeq.toExpr}: _*) } + } + given [T: Type: Liftable] as Liftable[Option[T]] = new Liftable[Option[T]] { def toExpr(x: Option[T]): given QuoteContext => Expr[Option[T]] = x match { case Some(x) => '{ Some[T](${x.toExpr}) } diff --git a/tests/run-with-compiler/quote-lib.scala b/tests/run-with-compiler/quote-lib.scala index a8754abf2b7d..94598f49d35f 100644 --- a/tests/run-with-compiler/quote-lib.scala +++ b/tests/run-with-compiler/quote-lib.scala @@ -56,6 +56,9 @@ object Test { val set: Set[Int] = Set(1, 2, 3) val liftedSet: Expr[Set[Int]] = set + val map: Map[Int, Char] = Map(1 -> 'a', 2 -> 'b', 3 -> 'c') + val liftedMap: Expr[Map[Int, Char]] = map + liftedList.foldLeft[Int](0)('{ (acc: Int, x: Int) => acc + x }).show liftedList.foreach('{ (x: Int) => println(x) }).show From 81dd055aedff3dae85b1b17e88212450bd1cf98d Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 26 Jul 2019 09:22:57 +0200 Subject: [PATCH 10/10] Use reuse toExprOfSeq and toExprOfList --- .../src-non-bootstrapped/scala/quoted/package.scala | 6 ++++++ library/src/scala/quoted/Liftable.scala | 12 ++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/library/src-non-bootstrapped/scala/quoted/package.scala b/library/src-non-bootstrapped/scala/quoted/package.scala index 0151f2dcde10..51e19c14f400 100644 --- a/library/src-non-bootstrapped/scala/quoted/package.scala +++ b/library/src-non-bootstrapped/scala/quoted/package.scala @@ -10,5 +10,11 @@ package object quoted { implicit object ExprOps { def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = the[Liftable[T]].toExpr(x) + + def (seq: Seq[Expr[T]]) toExprOfSeq[T] given (tp: Type[T], qctx: QuoteContext): Expr[Seq[T]] = + throw new Exception("Non bootsrapped library") + + def (list: List[Expr[T]]) toExprOfList[T] given Type[T], QuoteContext: Expr[List[T]] = + throw new Exception("Non bootsrapped library") } } diff --git a/library/src/scala/quoted/Liftable.scala b/library/src/scala/quoted/Liftable.scala index 35dc483c70d5..1437407aad6f 100644 --- a/library/src/scala/quoted/Liftable.scala +++ b/library/src/scala/quoted/Liftable.scala @@ -53,17 +53,13 @@ object Liftable { } given [T: Type: Liftable] as Liftable[Seq[T]] = new Liftable[Seq[T]] { - def toExpr(seq: Seq[T]): given QuoteContext => Expr[Seq[T]] = given qctx => { - import qctx.tasty._ - Repeated(seq.map(x => the[Liftable[T]].toExpr(x).unseal).toList, the[quoted.Type[T]].unseal).seal.asInstanceOf[Expr[Seq[T]]] - } + def toExpr(xs: Seq[T]): given QuoteContext => Expr[Seq[T]] = + xs.map(the[Liftable[T]].toExpr).toExprOfSeq } given [T: Type: Liftable] as Liftable[List[T]] = new Liftable[List[T]] { - def toExpr(x: List[T]): given QuoteContext => Expr[List[T]] = x match { - case x :: xs => '{ (${xs.toExpr}).::[T](${x.toExpr}) } - case Nil => '{ Nil: List[T] } - } + def toExpr(xs: List[T]): given QuoteContext => Expr[List[T]] = + xs.map(the[Liftable[T]].toExpr).toExprOfList } given [T: Type: Liftable] as Liftable[Set[T]] = new Liftable[Set[T]] {