diff --git a/community-build/community-projects/scalatest b/community-build/community-projects/scalatest index 1ba232a02a22..18111a2b67f5 160000 --- a/community-build/community-projects/scalatest +++ b/community-build/community-projects/scalatest @@ -1 +1 @@ -Subproject commit 1ba232a02a220e0989970b36342f6ad95f5cff01 +Subproject commit 18111a2b67f5626b7a9af5d4608655148d515c2f diff --git a/community-build/community-projects/scodec-bits b/community-build/community-projects/scodec-bits index e0f4a8299c6f..85de35c014b9 160000 --- a/community-build/community-projects/scodec-bits +++ b/community-build/community-projects/scodec-bits @@ -1 +1 @@ -Subproject commit e0f4a8299c6fafe422d6f6bae470484ba4b50e00 +Subproject commit 85de35c014b948f0dd3f94e975c42d17deab4055 diff --git a/community-build/community-projects/utest b/community-build/community-projects/utest index 8dc8e70dabfa..c39c0575e543 160000 --- a/community-build/community-projects/utest +++ b/community-build/community-projects/utest @@ -1 +1 @@ -Subproject commit 8dc8e70dabfa67417a0dfaf91a010c76dda842d4 +Subproject commit c39c0575e543379e030a197dedf8cd7c73e52bc6 diff --git a/community-build/community-projects/xml-interpolator b/community-build/community-projects/xml-interpolator index 0d8fffbf4b8e..9636a93cf540 160000 --- a/community-build/community-projects/xml-interpolator +++ b/community-build/community-projects/xml-interpolator @@ -1 +1 @@ -Subproject commit 0d8fffbf4b8e8e4b72779b6b1fdccaf5e1db4b33 +Subproject commit 9636a93cf540415ad29dd8cd0c67acbc78a960ac diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index da3ceed8590a..eb6ec69376c0 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -809,16 +809,16 @@ class Definitions { @tu lazy val QuoteMatching_ExprMatch: Symbol = QuoteMatchingClass.requiredMethod("ExprMatch") @tu lazy val QuoteMatching_TypeMatch: Symbol = QuoteMatchingClass.requiredMethod("TypeMatch") - @tu lazy val LiftableModule: Symbol = requiredModule("scala.quoted.Liftable") - @tu lazy val LiftableModule_BooleanLiftable: Symbol = LiftableModule.requiredMethod("BooleanLiftable") - @tu lazy val LiftableModule_ByteLiftable: Symbol = LiftableModule.requiredMethod("ByteLiftable") - @tu lazy val LiftableModule_ShortLiftable: Symbol = LiftableModule.requiredMethod("ShortLiftable") - @tu lazy val LiftableModule_IntLiftable: Symbol = LiftableModule.requiredMethod("IntLiftable") - @tu lazy val LiftableModule_LongLiftable: Symbol = LiftableModule.requiredMethod("LongLiftable") - @tu lazy val LiftableModule_FloatLiftable: Symbol = LiftableModule.requiredMethod("FloatLiftable") - @tu lazy val LiftableModule_DoubleLiftable: Symbol = LiftableModule.requiredMethod("DoubleLiftable") - @tu lazy val LiftableModule_CharLiftable: Symbol = LiftableModule.requiredMethod("CharLiftable") - @tu lazy val LiftableModule_StringLiftable: Symbol = LiftableModule.requiredMethod("StringLiftable") + @tu lazy val ToExprModule: Symbol = requiredModule("scala.quoted.ToExpr") + @tu lazy val ToExprModule_BooleanToExpr: Symbol = ToExprModule.requiredMethod("BooleanToExpr") + @tu lazy val ToExprModule_ByteToExpr: Symbol = ToExprModule.requiredMethod("ByteToExpr") + @tu lazy val ToExprModule_ShortToExpr: Symbol = ToExprModule.requiredMethod("ShortToExpr") + @tu lazy val ToExprModule_IntToExpr: Symbol = ToExprModule.requiredMethod("IntToExpr") + @tu lazy val ToExprModule_LongToExpr: Symbol = ToExprModule.requiredMethod("LongToExpr") + @tu lazy val ToExprModule_FloatToExpr: Symbol = ToExprModule.requiredMethod("FloatToExpr") + @tu lazy val ToExprModule_DoubleToExpr: Symbol = ToExprModule.requiredMethod("DoubleToExpr") + @tu lazy val ToExprModule_CharToExpr: Symbol = ToExprModule.requiredMethod("CharToExpr") + @tu lazy val ToExprModule_StringToExpr: Symbol = ToExprModule.requiredMethod("StringToExpr") @tu lazy val QuotedRuntimeModule: Symbol = requiredModule("scala.quoted.runtime.Expr") @tu lazy val QuotedRuntime_exprQuote : Symbol = QuotedRuntimeModule.requiredMethod("quote") diff --git a/compiler/src/dotty/tools/dotc/core/StdNames.scala b/compiler/src/dotty/tools/dotc/core/StdNames.scala index 3eeae9a2ffe9..cc98237c6403 100644 --- a/compiler/src/dotty/tools/dotc/core/StdNames.scala +++ b/compiler/src/dotty/tools/dotc/core/StdNames.scala @@ -597,7 +597,6 @@ object StdNames { val thisPrefix : N = "thisPrefix" val throw_ : N = "throw" val toArray: N = "toArray" - val toExpr: N = "toExpr" val toList: N = "toList" val toObjectArray : N = "toObjectArray" val toSeq: N = "toSeq" diff --git a/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala b/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala index 52b9e53b73c0..224e7e2990c4 100644 --- a/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala @@ -173,23 +173,36 @@ class PickleQuotes extends MacroTransform { Lambda(lambdaTpe, mkConst).withSpan(body.span) } + /** Encode quote using Reflection.Literal + * + * Generate the code + * ```scala + * qctx => scala.quoted.ToExpr.{BooleanToExpr,ShortToExpr, ...}.apply()(qctx) + * ``` + * this closure is always applied directly to the actual context and the BetaReduce phase removes it. + */ + def liftedValue(lit: Literal, lifter: Symbol) = + val exprType = defn.QuotedExprClass.typeRef.appliedTo(body.tpe) + val lambdaTpe = MethodType(defn.QuotesClass.typeRef :: Nil, exprType) + def mkToExprCall(ts: List[Tree]) = + ref(lifter).appliedToType(originalTp).select(nme.apply).appliedTo(lit).appliedTo(ts.head) + Lambda(lambdaTpe, mkToExprCall).withSpan(body.span) + def pickleAsValue(lit: Literal) = { // TODO should all constants be pickled as Literals? // Should examime the generated bytecode size to decide and performance - def liftedValue(lifter: Symbol) = - ref(lifter).appliedToType(originalTp).select(nme.toExpr).appliedTo(lit) lit.const.tag match { case Constants.NullTag => pickleAsLiteral(lit) case Constants.UnitTag => pickleAsLiteral(lit) - case Constants.BooleanTag => liftedValue(defn.LiftableModule_BooleanLiftable) - case Constants.ByteTag => liftedValue(defn.LiftableModule_ByteLiftable) - case Constants.ShortTag => liftedValue(defn.LiftableModule_ShortLiftable) - case Constants.IntTag => liftedValue(defn.LiftableModule_IntLiftable) - case Constants.LongTag => liftedValue(defn.LiftableModule_LongLiftable) - case Constants.FloatTag => liftedValue(defn.LiftableModule_FloatLiftable) - case Constants.DoubleTag => liftedValue(defn.LiftableModule_DoubleLiftable) - case Constants.CharTag => liftedValue(defn.LiftableModule_CharLiftable) - case Constants.StringTag => liftedValue(defn.LiftableModule_StringLiftable) + case Constants.BooleanTag => liftedValue(lit, defn.ToExprModule_BooleanToExpr) + case Constants.ByteTag => liftedValue(lit, defn.ToExprModule_ByteToExpr) + case Constants.ShortTag => liftedValue(lit, defn.ToExprModule_ShortToExpr) + case Constants.IntTag => liftedValue(lit, defn.ToExprModule_IntToExpr) + case Constants.LongTag => liftedValue(lit, defn.ToExprModule_LongToExpr) + case Constants.FloatTag => liftedValue(lit, defn.ToExprModule_FloatToExpr) + case Constants.DoubleTag => liftedValue(lit, defn.ToExprModule_DoubleToExpr) + case Constants.CharTag => liftedValue(lit, defn.ToExprModule_CharToExpr) + case Constants.StringTag => liftedValue(lit, defn.ToExprModule_StringToExpr) } } diff --git a/docs/docs/reference/changed-features/numeric-literals.md b/docs/docs/reference/changed-features/numeric-literals.md index 1ab8c679ab93..05477a15533d 100644 --- a/docs/docs/reference/changed-features/numeric-literals.md +++ b/docs/docs/reference/changed-features/numeric-literals.md @@ -201,7 +201,7 @@ method in the `FromDigits` given instance. That method is defined in terms of a implementation method `fromDigitsImpl`. Here is its definition: ```scala private def fromDigitsImpl(digits: Expr[String])(using ctx: Quotes): Expr[BigFloat] = - digits.unlift match { + digits.value match { case Some(ds) => try { val BigFloat(m, e) = apply(ds) diff --git a/docs/docs/reference/metaprogramming/macros.md b/docs/docs/reference/metaprogramming/macros.md index 3227aa1878c2..8e3e8a715ef6 100644 --- a/docs/docs/reference/metaprogramming/macros.md +++ b/docs/docs/reference/metaprogramming/macros.md @@ -271,33 +271,33 @@ package quoted object Expr { ... - def apply[T: Liftable](x: T)(using Quotes): Expr[T] = summon[Liftable[T]].toExpr(x) + def apply[T: ToExpr](x: T)(using Quotes): Expr[T] = summon[ToExpr[T]].toExpr(x) ... } ``` -This method says that values of types implementing the `Liftable` type class can be -converted ("lifted") to `Expr` values using `Expr.apply`. +This method says that values of types implementing the `ToExpr` type class can be +converted to `Expr` values using `Expr.apply`. -Dotty comes with given instances of `Liftable` for +Dotty comes with given instances of `ToExpr` for several types including `Boolean`, `String`, and all primitive number types. For example, `Int` values can be converted to `Expr[Int]` values by wrapping the value in a `Literal` tree node. This makes use of the underlying tree representation in the compiler for -efficiency. But the `Liftable` instances are nevertheless not _magic_ +efficiency. But the `ToExpr` instances are nevertheless not _magic_ in the sense that they could all be defined in a user program without knowing anything about the representation of `Expr` trees. For -instance, here is a possible instance of `Liftable[Boolean]`: +instance, here is a possible instance of `ToExpr[Boolean]`: ```scala -given Liftable[Boolean] { +given ToExpr[Boolean] { def toExpr(b: Boolean) = if (b) '{ true } else '{ false } } ``` Once we can lift bits, we can work our way up. For instance, here is a -possible implementation of `Liftable[Int]` that does not use the underlying +possible implementation of `ToExpr[Int]` that does not use the underlying tree machinery: ```scala -given Liftable[Int] { +given ToExpr[Int] { def toExpr(n: Int) = n match { case Int.MinValue => '{ Int.MinValue } case _ if n < 0 => '{ - ${ toExpr(-n) } } @@ -307,16 +307,16 @@ given Liftable[Int] { } } ``` -Since `Liftable` is a type class, its instances can be conditional. For example, +Since `ToExpr` is a type class, its instances can be conditional. For example, a `List` is liftable if its element type is: ```scala -given [T: Liftable : Type]: Liftable[List[T]] with +given [T: ToExpr : Type]: ToExpr[List[T]] with def toExpr(xs: List[T]) = xs match { case head :: tail => '{ ${ Expr(head) } :: ${ toExpr(tail) } } case Nil => '{ Nil: List[T] } } ``` -In the end, `Liftable` resembles very much a serialization +In the end, `ToExpr` resembles very much a serialization framework. Like the latter it can be derived systematically for all collections, case classes and enums. Note also that the synthesis of _type-tag_ values of type `Type[T]` is essentially the type-level @@ -433,7 +433,7 @@ either a constant or is a parameter that will be a constant when instantiated. T aspect is also important for macro expansion. To get values out of expressions containing constants `Expr` provides the method -`unlift` (or `unliftOrError`). This will convert the `Expr[T]` into a `Some[T]` (or `T`) when the +`value` (or `valueOrError`). This will convert the `Expr[T]` into a `Some[T]` (or `T`) when the expression contains value. Otherwise it will retrun `None` (or emit an error). To avoid having incidental val bindings generated by the inlining of the `def` it is recommended to use an inline parameter. To illustrate this, consider an @@ -442,7 +442,7 @@ implementation of the `power` function that makes use of a statically known expo inline def power(x: Double, inline n: Int) = ${ powerCode('x, 'n) } private def powerCode(x: Expr[Double], n: Expr[Int])(using Quotes): Expr[Double] = - n.unlift match + n.value match case Some(m) => powerCode(x, m) case None => '{ Math.pow($x, $y) } @@ -604,7 +604,7 @@ inline method that can calculate either a value of type `Int` or a value of type transparent inline def defaultOf(inline str: String) = ${ defaultOfImpl('str) } def defaultOfImpl(strExpr: Expr[String])(using Quotes): Expr[Any] = - strExpr.unliftOrError match + strExpr.valueOrError match case "int" => '{1} case "string" => '{"a"} @@ -632,8 +632,8 @@ It is possible to deconstruct or extract values out of `Expr` using pattern matc `scala.quoted` contains objects that can help extracting values from `Expr`. -* `scala.quoted.Unlifted`: matches an expression of a value (or list of values) and returns the value (or list of values). -* `scala.quoted.Const`/`scala.quoted.Consts`: Same as `Unlifted` but only works on primitive values. +* `scala.quoted.Expr`/`scala.quoted.Exprs`: matches an expression of a value (or list of values) and returns the value (or list of values). +* `scala.quoted.Const`/`scala.quoted.Consts`: Same as `Expr`/`Exprs` but only works on primitive values. * `scala.quoted.Varargs`: matches an explicit sequence of expressions and returns them. These sequences are useful to get individual `Expr[T]` out of a varargs expression of type `Expr[Seq[T]]`. @@ -641,11 +641,13 @@ These could be used in the following way to optimize any call to `sum` that has ```scala inline def sum(inline args: Int*): Int = ${ sumExpr('args) } private def sumExpr(argsExpr: Expr[Seq[Int]])(using Quotes): Expr[Int] = argsExpr match { - case Varargs(Unlifted(args)) => // args is of type Seq[Int] - Expr(args.sum) // precompute result of sum + case Varargs(args @ Exprs(argValues)) => + // args is of type Seq[Expr[Int]] + // argValues is of type Seq[Int] + Expr(argValues.sum) // precompute result of sum case Varargs(argExprs) => // argExprs is of type Seq[Expr[Int]] - val staticSum: Int = argExprs.map(_.unlift.getOrElse(0)) - val dynamicSum: Seq[Expr[Int]] = argExprs.filter(_.unlift.isEmpty) + val staticSum: Int = argExprs.map(_.value.getOrElse(0)) + val dynamicSum: Seq[Expr[Int]] = argExprs.filter(_.value.isEmpty) dynamicSum.foldLeft(Expr(staticSum))((acc, arg) => '{ $acc + $arg }) case _ => '{ $argsExpr.sum } @@ -682,8 +684,8 @@ private def sumExpr(args1: Seq[Expr[Int]])(using Quotes): Expr[Int] = { case arg => Seq(arg) } val args2 = args1.flatMap(flatSumArgs) - val staticSum: Int = args2.map(_.unlift.getOrElse(0)).sum - val dynamicSum: Seq[Expr[Int]] = args2.filter(_.unlift.isEmpty) + val staticSum: Int = args2.map(_.value.getOrElse(0)).sum + val dynamicSum: Seq[Expr[Int]] = args2.filter(_.value.isEmpty) dynamicSum.foldLeft(Expr(staticSum))((acc, arg) => '{ $acc + $arg }) } ``` @@ -759,7 +761,7 @@ private def evalExpr(e: Expr[Int])(using Quotes): Expr[Int] = { // body: Expr[Int => Int] where the argument represents references to y evalExpr(Expr.betaReduce(body)(evalExpr(x))) case '{ ($x: Int) * ($y: Int) } => - (x.unlift, y.unlift) match + (x.value, y.value) match case (Some(a), Some(b)) => Expr(a * b) case _ => e case _ => e diff --git a/library/src-bootstrapped/scala/quoted/Expr.scala b/library/src-bootstrapped/scala/quoted/Expr.scala index 9f4c6801abfc..d1f399fe958e 100644 --- a/library/src-bootstrapped/scala/quoted/Expr.scala +++ b/library/src-bootstrapped/scala/quoted/Expr.scala @@ -28,11 +28,26 @@ object Expr { Block(statements.map(Term.of), Term.of(expr)).asExpr.asInstanceOf[Expr[T]] } - /** Lift a value into an expression containing the construction of that value */ - def apply[T](x: T)(using lift: Liftable[T])(using Quotes): Expr[T] = - lift.toExpr(x) + /** Creates an expression that will construct the value `x` */ + def apply[T](x: T)(using ToExpr[T])(using Quotes): Expr[T] = + scala.Predef.summon[ToExpr[T]].apply(x) - /** Lifts this sequence of expressions into an expression of a sequence + /** Get `Some` of a copy of the value if the expression contains a literal constant or constructor of `T`. + * Otherwise returns `None`. + * + * Usage: + * ``` + * case '{ ... ${expr @ Expr(value)}: T ...} => + * // expr: Expr[T] + * // value: T + * ``` + * + * To directly get the value of an expression `expr: Expr[T]` consider using `expr.value`/`expr.valueOrError` insead. + */ + def unapply[T](x: Expr[T])(using FromExpr[T])(using Quotes): Option[T] = + scala.Predef.summon[FromExpr[T]].unapply(x) + + /** Creates an expression that will construct a copy of this sequence * * Transforms a sequence of expression * `Seq(e1, e2, ...)` where `ei: Expr[T]` @@ -43,7 +58,7 @@ object Expr { def ofSeq[T](xs: Seq[Expr[T]])(using Type[T])(using Quotes): Expr[Seq[T]] = Varargs(xs) - /** Lifts this list of expressions into an expression of a list + /** Creates an expression that will construct a copy of this list * * Transforms a list of expression * `List(e1, e2, ...)` where `ei: Expr[T]` @@ -53,7 +68,7 @@ object Expr { def ofList[T](xs: Seq[Expr[T]])(using Type[T])(using Quotes): Expr[List[T]] = if (xs.isEmpty) Expr(Nil) else '{ List(${Varargs(xs)}: _*) } - /** Lifts this sequence of expressions into an expression of a tuple + /** Creates an expression that will construct a copy of this tuple * * Transforms a sequence of expression * `Seq(e1, e2, ...)` where `ei: Expr[Any]` diff --git a/library/src-bootstrapped/scala/quoted/FromExpr.scala b/library/src-bootstrapped/scala/quoted/FromExpr.scala new file mode 100644 index 000000000000..467c2b494a4a --- /dev/null +++ b/library/src-bootstrapped/scala/quoted/FromExpr.scala @@ -0,0 +1,528 @@ +package scala.quoted + +/** A type class for types that can convert a `quoted.Expr[T]` to a `T`. + * + * - Converts expression containg literal values to their values: + * - `'{1}` -> `1`, `'{2}` -> `2`, ... + * - For all primitive types and `String` + * - Converts an expression that constructs a copy of its value. + * - This expression must be some kind of datastructure (`Some`, `List`, `Either`, ...) + * - Calls to `new X` or `X.apply` can be lifted into its value + * - Arguments of constructors can be recursively unlifted + */ +trait FromExpr[T] { + + /** Return the value of the expression. + * + * Returns `None` if the expression does not represent a value or possibly contains side effects. + * Otherwise returns the `Some` of the value. + */ + def unapply(x: Expr[T])(using Quotes): Option[T] + +} + +object FromExpr { + + /** Default implementation of `FromExpr[Boolean]` + * - Unlifts `'{true}` into `Some(ture)` + * - Unlifts `'{false}` into `Some(false)` + * - Otherwise unlifts to `None` + */ + given BooleanFromExpr[T <: Boolean]: FromExpr[T] = new PrimitiveFromExpr + + /** Default implementation of `FromExpr[Byte]` + * - Unlifts `'{n}` into `Some(n)` for a literal `n` of type `Byte` + * - Otherwise unlifts to `None` + */ + given ByteFromExpr[T <: Byte]: FromExpr[T] = new PrimitiveFromExpr + + /** Default implementation of `FromExpr[Short]` + * - Unlifts `'{n}` into `Some(n)` for a literal `n` of type `Short` + * - Otherwise unlifts to `None` + */ + given ShortFromExpr[T <: Short]: FromExpr[T] = new PrimitiveFromExpr + + /** Default implementation of `FromExpr[Int]` + * - Unlifts `'{n}` into `Some(n)` for a literal `n` of type `Int` + * - Otherwise unlifts to `None` + */ + given IntFromExpr[T <: Int]: FromExpr[T] = new PrimitiveFromExpr + + /** Default implementation of `FromExpr[Long]` + * - Unlifts `'{n}` into `Some(n)` for a literal `n` of type `Long` + * - Otherwise unlifts to `None` + */ + given LongFromExpr[T <: Long]: FromExpr[T] = new PrimitiveFromExpr + + /** Default implementation of `FromExpr[Float]` + * - Unlifts `'{n}` into `Some(n)` for a literal `n` of type `Float` + * - Otherwise unlifts to `None` + */ + given FloatFromExpr[T <: Float]: FromExpr[T] = new PrimitiveFromExpr + + /** Default implementation of `FromExpr[Double]` + * - Unlifts `'{n}` into `Some(n)` for a literal `n` of type `Double` + * - Otherwise unlifts to `None` + */ + given DoubleFromExpr[T <: Double]: FromExpr[T] = new PrimitiveFromExpr + + /** Default implementation of `FromExpr[Char]` + * - Unlifts `'{c}` into `Some(c)` for a literal `c` of type `Char` + * - Otherwise unlifts to `None` + */ + given CharFromExpr[T <: Char]: FromExpr[T] = new PrimitiveFromExpr + + /** Default implementation of `FromExpr[String]` + * - Unlifts `'{str}` into `Some(str)` for a literal `str` of type `String` + * - Otherwise unlifts to `None` + */ + given StringFromExpr[T <: String]: FromExpr[T] = new PrimitiveFromExpr + + /** Lift a quoted primitive value `'{ x }` into `x` */ + private class PrimitiveFromExpr[T <: Boolean | Byte | Short | Int | Long | Float | Double | Char | String] extends FromExpr[T] { + def unapply(expr: Expr[T])(using Quotes) = + import quotes.reflect._ + def rec(tree: Term): Option[T] = tree match { + case Literal(c) if c.value != null => Some(c.value.asInstanceOf[T]) + case Block(Nil, e) => rec(e) + case Typed(e, _) => rec(e) + case Inlined(_, Nil, e) => rec(e) + case _ => None + } + rec(Term.of(expr)) + } + + /** Default implementation of `FromExpr[Option]` + * - Unlifts `'{Some(x)}` into `Some(Some(x))` if `x` is unliftable + * - Unlifts `'{None}` into `Some(None)` + * - Otherwise unlifts to `None` + */ + given OptionFromExpr[T](using Type[T], FromExpr[T]): FromExpr[Option[T]] with { + def unapply(x: Expr[Option[T]])(using Quotes) = x match { + case '{ Option[T](${Expr(y)}) } => Some(Option(y)) + case '{ None } => Some(None) + case '{ ${Expr(opt)} : Some[T] } => Some(opt) + case _ => None + } + } + + /** Default implementation of `FromExpr[None]` + * - Unlifts `'{None}` into `Some(None)` + * - Otherwise unlifts to `None` + */ + given NoneFromExpr: FromExpr[None.type] with { + def unapply(x: Expr[None.type])(using Quotes) = x match { + case '{ None } => Some(None) + case _ => None + } + } + + /** Default implementation of `FromExpr[Some]` + * - Unlifts `'{Some(x)}` into `Some(Some(x))` if `x` is unliftable + * - Otherwise unlifts to `None` + */ + given SomeFromExpr[T](using Type[T], FromExpr[T]): FromExpr[Some[T]] with { + def unapply(x: Expr[Some[T]])(using Quotes) = x match { + case '{ new Some[T](${Expr(y)}) } => Some(Some(y)) + case '{ Some[T](${Expr(y)}) } => Some(Some(y)) + case _ => None + } + } + + /** Default implementation of `FromExpr[StringContext]` + * - Unlifts `'{StringContext(args: _*)}` into `Some(StringContext(args: _*))` if `args` is explicit and each one is liftable + * - Otherwise unlifts to `None` + */ + given StringContextFromExpr: FromExpr[StringContext] with { + def unapply(x: Expr[StringContext])(using Quotes) = x match { + case '{ new StringContext(${Varargs(Consts(args))}: _*) } => Some(StringContext(args: _*)) + case '{ StringContext(${Varargs(Consts(args))}: _*) } => Some(StringContext(args: _*)) + case _ => None + } + } + + /** Default implementation of `FromExpr[EmptyTuple]` + * - Unlifts `'{EmptyTuple}` into `Some(EmptyTuple)` + * - Otherwise unlifts to `None` + */ + given EmptyTupleFromExpr: FromExpr[EmptyTuple.type] with { + def unapply(x: Expr[EmptyTuple.type])(using Quotes) = x match { + case '{ EmptyTuple } => Some(EmptyTuple) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple1[...]]` + * - Unlifts `'{Tuple1(x1)}` into `Some(Tuple1(x1))` if `x1` is unliftable + * - Otherwise unlifts to `None` + */ + given Tuple1FromExpr[T1](using Type[T1], FromExpr[T1]): FromExpr[Tuple1[T1]] with { + def unapply(x: Expr[Tuple1[T1]])(using Quotes) = x match { + case '{ new Tuple1[T1](${Expr(y)}) } => Some(Tuple1(y)) + case '{ Tuple1[T1](${Expr(y)}) } => Some(Tuple1(y)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple2[...]]` + * - Unlifts `'{Tuple2(x1, x2)}` into `Some(Tuple2(x1, x2))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple2FromExpr[T1, T2](using Type[T1], Type[T2], FromExpr[T1], FromExpr[T2]): FromExpr[Tuple2[T1, T2]] with { + def unapply(x: Expr[Tuple2[T1, T2]])(using Quotes) = x match { + case '{ new Tuple2[T1, T2](${Expr(y1)}, ${Expr(y2)}) } => Some(Tuple2(y1, y2)) + case '{ Tuple2[T1, T2](${Expr(y1)}, ${Expr(y2)}) } => Some(Tuple2(y1, y2)) + case '{ (${Expr(y1)}: T1) -> (${Expr(y2)}: T2) } => Some(Tuple2(y1, y2)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple3[...]]` + * - Unlifts `'{Tuple3(x1, x2, x3)}` into `Some(Tuple3(x1, x2, x3))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple3FromExpr[T1, T2, T3](using Type[T1], Type[T2], Type[T3], FromExpr[T1], FromExpr[T2], FromExpr[T3]): FromExpr[Tuple3[T1, T2, T3]] with { + def unapply(x: Expr[Tuple3[T1, T2, T3]])(using Quotes) = x match { + case '{ new Tuple3[T1, T2, T3](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}) } => Some(Tuple3(y1, y2, y3)) + case '{ Tuple3[T1, T2, T3](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}) } => Some(Tuple3(y1, y2, y3)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple4[...]]` + * - Unlifts `'{Tuple4(x1, ..., x4)}` into `Some(Tuple4(x1, ..., x4))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple4FromExpr[T1, T2, T3, T4](using Type[T1], Type[T2], Type[T3], Type[T4], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4]): FromExpr[Tuple4[T1, T2, T3, T4]] with { + def unapply(x: Expr[Tuple4[T1, T2, T3, T4]])(using Quotes) = x match { + case '{ new Tuple4[T1, T2, T3, T4](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}) } => Some(Tuple4(y1, y2, y3, y4)) + case '{ Tuple4[T1, T2, T3, T4](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}) } => Some(Tuple4(y1, y2, y3, y4)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple5[...]]` + * - Unlifts `'{Tuple5(x1, ..., x5)}` into `Some(Tuple5(x1, ..., x5))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple5FromExpr[T1, T2, T3, T4, T5](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5]): FromExpr[Tuple5[T1, T2, T3, T4, T5]] with { + def unapply(x: Expr[Tuple5[T1, T2, T3, T4, T5]])(using Quotes) = x match { + case '{ new Tuple5[T1, T2, T3, T4, T5](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}) } => Some(Tuple5(y1, y2, y3, y4, y5)) + case '{ Tuple5[T1, T2, T3, T4, T5](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}) } => Some(Tuple5(y1, y2, y3, y4, y5)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple6[...]]` + * - Unlifts `'{Tuple6(x1, ..., x6)}` into `Some(Tuple6(x1, ..., x6))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple6FromExpr[T1, T2, T3, T4, T5, T6](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6]): FromExpr[Tuple6[T1, T2, T3, T4, T5, T6]] with { + def unapply(x: Expr[Tuple6[T1, T2, T3, T4, T5, T6]])(using Quotes) = x match { + case '{ new Tuple6[T1, T2, T3, T4, T5, T6](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}) } => Some(Tuple6(y1, y2, y3, y4, y5, y6)) + case '{ Tuple6[T1, T2, T3, T4, T5, T6](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}) } => Some(Tuple6(y1, y2, y3, y4, y5, y6)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple7[...]]` + * - Unlifts `'{Tuple7(x1, ..., x7)}` into `Some(Tuple7(x1, ..., x7))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple7FromExpr[T1, T2, T3, T4, T5, T6, T7](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6], FromExpr[T7]): FromExpr[Tuple7[T1, T2, T3, T4, T5, T6, T7]] with { + def unapply(x: Expr[Tuple7[T1, T2, T3, T4, T5, T6, T7]])(using Quotes) = x match { + case '{ new Tuple7[T1, T2, T3, T4, T5, T6, T7](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}) } => Some(Tuple7(y1, y2, y3, y4, y5, y6, y7)) + case '{ Tuple7[T1, T2, T3, T4, T5, T6, T7](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}) } => Some(Tuple7(y1, y2, y3, y4, y5, y6, y7)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple8[...]]` + * - Unlifts `'{Tuple8(x1, ..., x8)}` into `Some(Tuple8(x1, ..., x8))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple8FromExpr[T1, T2, T3, T4, T5, T6, T7, T8](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6], FromExpr[T7], FromExpr[T8]): FromExpr[Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] with { + def unapply(x: Expr[Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]])(using Quotes) = x match { + case '{ new Tuple8[T1, T2, T3, T4, T5, T6, T7, T8](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}) } => Some(Tuple8(y1, y2, y3, y4, y5, y6, y7, y8)) + case '{ Tuple8[T1, T2, T3, T4, T5, T6, T7, T8](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}) } => Some(Tuple8(y1, y2, y3, y4, y5, y6, y7, y8)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple9[...]]` + * - Unlifts `'{Tuple9(x1, ..., x9)}` into `Some(Tuple9(x1, ..., x9))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple9FromExpr[T1, T2, T3, T4, T5, T6, T7, T8, T9](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6], FromExpr[T7], FromExpr[T8], FromExpr[T9]): FromExpr[Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] with { + def unapply(x: Expr[Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]])(using Quotes) = x match { + case '{ new Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}) } => Some(Tuple9(y1, y2, y3, y4, y5, y6, y7, y8, y9)) + case '{ Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}) } => Some(Tuple9(y1, y2, y3, y4, y5, y6, y7, y8, y9)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple10[...]]` + * - Unlifts `'{Tuple0(x1, ..., x10)}` into `Some(Tuple0(x1, ..., x10))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple10FromExpr[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6], FromExpr[T7], FromExpr[T8], FromExpr[T9], FromExpr[T10]): FromExpr[Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] with { + def unapply(x: Expr[Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]])(using Quotes) = x match { + case '{ new Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}) } => Some(Tuple10(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10)) + case '{ Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}) } => Some(Tuple10(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple11[...]]` + * - Unlifts `'{Tuple1(x1, ..., x11)}` into `Some(Tuple1(x1, ..., x11))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple11FromExpr[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6], FromExpr[T7], FromExpr[T8], FromExpr[T9], FromExpr[T10], FromExpr[T11]): FromExpr[Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]] with { + def unapply(x: Expr[Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]])(using Quotes) = x match { + case '{ new Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}) } => Some(Tuple11(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11)) + case '{ Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}) } => Some(Tuple11(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple12[...]]` + * - Unlifts `'{Tuple2(x1, ..., x12)}` into `Some(Tuple2(x1, ..., x12))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple12FromExpr[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6], FromExpr[T7], FromExpr[T8], FromExpr[T9], FromExpr[T10], FromExpr[T11], FromExpr[T12]): FromExpr[Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]] with { + def unapply(x: Expr[Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]])(using Quotes) = x match { + case '{ new Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}) } => Some(Tuple12(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12)) + case '{ Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}) } => Some(Tuple12(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple13[...]]` + * - Unlifts `'{Tuple3(x1, ..., x13)}` into `Some(Tuple3(x1, ..., x13))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple13FromExpr[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6], FromExpr[T7], FromExpr[T8], FromExpr[T9], FromExpr[T10], FromExpr[T11], FromExpr[T12], FromExpr[T13]): FromExpr[Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]] with { + def unapply(x: Expr[Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]])(using Quotes) = x match { + case '{ new Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}) } => Some(Tuple13(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13)) + case '{ Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}) } => Some(Tuple13(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple14[...]]` + * - Unlifts `'{Tuple4(x1, ..., x14)}` into `Some(Tuple4(x1, ..., x14))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple14FromExpr[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6], FromExpr[T7], FromExpr[T8], FromExpr[T9], FromExpr[T10], FromExpr[T11], FromExpr[T12], FromExpr[T13], FromExpr[T14]): FromExpr[Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]] with { + def unapply(x: Expr[Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]])(using Quotes) = x match { + case '{ new Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}) } => Some(Tuple14(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14)) + case '{ Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}) } => Some(Tuple14(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple15[...]]` + * - Unlifts `'{Tuple5(x1, ..., x15)}` into `Some(Tuple5(x1, ..., x15))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple15FromExpr[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6], FromExpr[T7], FromExpr[T8], FromExpr[T9], FromExpr[T10], FromExpr[T11], FromExpr[T12], FromExpr[T13], FromExpr[T14], FromExpr[T15]): FromExpr[Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]] with { + def unapply(x: Expr[Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]])(using Quotes) = x match { + case '{ new Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}, ${Expr(y15)}) } => Some(Tuple15(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15)) + case '{ Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}, ${Expr(y15)}) } => Some(Tuple15(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple16[...]]` + * - Unlifts `'{Tuple6(x1, ..., x16)}` into `Some(Tuple6(x1, ..., x16))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple16FromExpr[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6], FromExpr[T7], FromExpr[T8], FromExpr[T9], FromExpr[T10], FromExpr[T11], FromExpr[T12], FromExpr[T13], FromExpr[T14], FromExpr[T15], FromExpr[T16]): FromExpr[Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]] with { + def unapply(x: Expr[Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]])(using Quotes) = x match { + case '{ new Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}, ${Expr(y15)}, ${Expr(y16)}) } => Some(Tuple16(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16)) + case '{ Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}, ${Expr(y15)}, ${Expr(y16)}) } => Some(Tuple16(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple17[...]]` + * - Unlifts `'{Tuple7(x1, ..., x17)}` into `Some(Tuple7(x1, ..., x17))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple17FromExpr[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6], FromExpr[T7], FromExpr[T8], FromExpr[T9], FromExpr[T10], FromExpr[T11], FromExpr[T12], FromExpr[T13], FromExpr[T14], FromExpr[T15], FromExpr[T16], FromExpr[T17]): FromExpr[Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]] with { + def unapply(x: Expr[Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]])(using Quotes) = x match { + case '{ new Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}, ${Expr(y15)}, ${Expr(y16)}, ${Expr(y17)}) } => Some(Tuple17(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17)) + case '{ Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}, ${Expr(y15)}, ${Expr(y16)}, ${Expr(y17)}) } => Some(Tuple17(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple18[...]]` + * - Unlifts `'{Tuple8(x1, ..., x18)}` into `Some(Tuple8(x1, ..., x18))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple18FromExpr[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6], FromExpr[T7], FromExpr[T8], FromExpr[T9], FromExpr[T10], FromExpr[T11], FromExpr[T12], FromExpr[T13], FromExpr[T14], FromExpr[T15], FromExpr[T16], FromExpr[T17], FromExpr[T18]): FromExpr[Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]] with { + def unapply(x: Expr[Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]])(using Quotes) = x match { + case '{ new Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}, ${Expr(y15)}, ${Expr(y16)}, ${Expr(y17)}, ${Expr(y18)}) } => Some(Tuple18(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18)) + case '{ Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}, ${Expr(y15)}, ${Expr(y16)}, ${Expr(y17)}, ${Expr(y18)}) } => Some(Tuple18(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple19[...]]` + * - Unlifts `'{Tuple9(x1, ..., x19)}` into `Some(Tuple9(x1, ..., x19))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple19FromExpr[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6], FromExpr[T7], FromExpr[T8], FromExpr[T9], FromExpr[T10], FromExpr[T11], FromExpr[T12], FromExpr[T13], FromExpr[T14], FromExpr[T15], FromExpr[T16], FromExpr[T17], FromExpr[T18], FromExpr[T19]): FromExpr[Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]] with { + def unapply(x: Expr[Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]])(using Quotes) = x match { + case '{ new Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}, ${Expr(y15)}, ${Expr(y16)}, ${Expr(y17)}, ${Expr(y18)}, ${Expr(y19)}) } => Some(Tuple19(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19)) + case '{ Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}, ${Expr(y15)}, ${Expr(y16)}, ${Expr(y17)}, ${Expr(y18)}, ${Expr(y19)}) } => Some(Tuple19(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple20[...]]` + * - Unlifts `'{Tuple0(x1, ..., x20)}` into `Some(Tuple0(x1, ..., x20))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple20FromExpr[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6], FromExpr[T7], FromExpr[T8], FromExpr[T9], FromExpr[T10], FromExpr[T11], FromExpr[T12], FromExpr[T13], FromExpr[T14], FromExpr[T15], FromExpr[T16], FromExpr[T17], FromExpr[T18], FromExpr[T19], FromExpr[T20]): FromExpr[Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]] with { + def unapply(x: Expr[Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]])(using Quotes) = x match { + case '{ new Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}, ${Expr(y15)}, ${Expr(y16)}, ${Expr(y17)}, ${Expr(y18)}, ${Expr(y19)}, ${Expr(y20)}) } => Some(Tuple20(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20)) + case '{ Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}, ${Expr(y15)}, ${Expr(y16)}, ${Expr(y17)}, ${Expr(y18)}, ${Expr(y19)}, ${Expr(y20)}) } => Some(Tuple20(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple21[...]]` + * - Unlifts `'{Tuple1(x1, ..., x21)}` into `Some(Tuple1(x1, ..., x21))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple21FromExpr[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], Type[T21], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6], FromExpr[T7], FromExpr[T8], FromExpr[T9], FromExpr[T10], FromExpr[T11], FromExpr[T12], FromExpr[T13], FromExpr[T14], FromExpr[T15], FromExpr[T16], FromExpr[T17], FromExpr[T18], FromExpr[T19], FromExpr[T20], FromExpr[T21]): FromExpr[Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]] with { + def unapply(x: Expr[Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]])(using Quotes) = x match { + case '{ new Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}, ${Expr(y15)}, ${Expr(y16)}, ${Expr(y17)}, ${Expr(y18)}, ${Expr(y19)}, ${Expr(y20)}, ${Expr(y21)}) } => Some(Tuple21(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20, y21)) + case '{ Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}, ${Expr(y15)}, ${Expr(y16)}, ${Expr(y17)}, ${Expr(y18)}, ${Expr(y19)}, ${Expr(y20)}, ${Expr(y21)}) } => Some(Tuple21(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20, y21)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Tuple22[...]]` + * - Unlifts `'{Tuple2(x1, ..., x22)}` into `Some(Tuple2(x1, ..., x22))` if all `xi` are unliftable + * - Otherwise unlifts to `None` + */ + given Tuple22FromExpr[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], Type[T21], Type[T22], FromExpr[T1], FromExpr[T2], FromExpr[T3], FromExpr[T4], FromExpr[T5], FromExpr[T6], FromExpr[T7], FromExpr[T8], FromExpr[T9], FromExpr[T10], FromExpr[T11], FromExpr[T12], FromExpr[T13], FromExpr[T14], FromExpr[T15], FromExpr[T16], FromExpr[T17], FromExpr[T18], FromExpr[T19], FromExpr[T20], FromExpr[T21], FromExpr[T22]): FromExpr[Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]] with { + def unapply(x: Expr[Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]])(using Quotes) = x match { + case '{ new Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}, ${Expr(y15)}, ${Expr(y16)}, ${Expr(y17)}, ${Expr(y18)}, ${Expr(y19)}, ${Expr(y20)}, ${Expr(y21)}, ${Expr(y22)}) } => Some(Tuple22(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20, y21, y22)) + case '{ Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](${Expr(y1)}, ${Expr(y2)}, ${Expr(y3)}, ${Expr(y4)}, ${Expr(y5)}, ${Expr(y6)}, ${Expr(y7)}, ${Expr(y8)}, ${Expr(y9)}, ${Expr(y10)}, ${Expr(y11)}, ${Expr(y12)}, ${Expr(y13)}, ${Expr(y14)}, ${Expr(y15)}, ${Expr(y16)}, ${Expr(y17)}, ${Expr(y18)}, ${Expr(y19)}, ${Expr(y20)}, ${Expr(y21)}, ${Expr(y22)}) } => Some(Tuple22(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20, y21, y22)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Seq]` + * - Unlifts `'{Seq(x1, ..., xn)}` into `Some(Seq(x1, ..., xn))` if all `xi` are unliftable + * - Unlifts sequences that come out of varargs + * - Otherwise unlifts to `None` + */ + given SeqFromExpr[T](using Type[T], FromExpr[T]): FromExpr[Seq[T]] with { + def unapply(x: Expr[Seq[T]])(using Quotes) = x match { + case Varargs(Exprs(elems)) => Some(elems) + case '{ scala.Seq[T](${Varargs(Exprs(elems))}: _*) } => Some(elems) + case '{ scala.collection.immutable.Seq[T](${Varargs(Exprs(elems))}: _*) } => Some(elems) + case '{ ${Expr(x)}: List[T] } => Some(x) + case _ => None + } + } + + /** Default implementation of `FromExpr[Nil]` + * - Unlifts `'{Nil}` into `Some(Nil)` + * - Otherwise unlifts to `None` + */ + given NilFromExpr: FromExpr[Nil.type] with { + def unapply(x: Expr[Nil.type])(using Quotes) = x match { + case '{ scala.Nil } | '{ scala.collection.immutable.Nil } => Some(Nil) + case _ => None + } + } + + /** Default implementation of `FromExpr[List]` + * - Unlifts `'{List(x1, ..., xn)}` into `Some(List(x1, ..., xn))` if all `xi` are unliftable + * - Unlifts `'{List.empty}` into `Some(Nil)` + * - Unlifts `'{Nil}` into `Some(Nil)` + * - Otherwise unlifts to `None` + */ + given ListFromExpr[T](using Type[T], FromExpr[T]): FromExpr[List[T]] with { + def unapply(x: Expr[List[T]])(using Quotes) = x match { + case '{ scala.List[T](${Varargs(Exprs(elems))}: _*) } => Some(elems.toList) + case '{ scala.List.empty[T] } => Some(Nil) + case '{ Nil } => Some(Nil) + case '{ scala.collection.immutable.List[T](${Varargs(Exprs(elems))}: _*) } => Some(elems.toList) + case '{ scala.collection.immutable.List.empty[T] } => Some(Nil) + case _ => None + } + } + + /** Default implementation of `FromExpr[Set]` + * - Unlifts `'{Set(x1, ..., xn)}` into `Some(Set(x1, ..., xn))` if all `xi` are unliftable + * - Unlifts `'{Set.empty}` into `Some(Set())` + * - Otherwise unlifts to `None` + */ + given SetFromExpr[T](using Type[T], FromExpr[T]): FromExpr[Set[T]] with { + def unapply(x: Expr[Set[T]])(using Quotes) = x match { + case '{ Set[T](${Varargs(Exprs(elems))}: _*) } => Some(elems.toSet) + case '{ Set.empty[T] } => Some(Set.empty[T]) + case '{ scala.collection.immutable.Set[T](${Varargs(Exprs(elems))}: _*) } => Some(elems.toSet) + case '{ scala.collection.immutable.Set.empty[T] } => Some(Set.empty[T]) + case _ => None + } + } + + /** Default implementation of `FromExpr[Map]` + * - Unlifts `'{Map(x1, ..., xn)}` into `Some(Map(x1, ..., xn))` if all `xi` are unliftable + * - Unlifts `'{Map.empty}` into `Some(Map())` + * - Otherwise unlifts to `None` + */ + given MapFromExpr[T, U](using Type[T], Type[U], FromExpr[T], FromExpr[U]): FromExpr[Map[T, U]] with { + def unapply(x: Expr[Map[T, U]])(using Quotes) = x match { + case '{ Map[T, U](${Varargs(Exprs(elems))}: _*) } => Some(elems.toMap) + case '{ Map.empty[T, U] } => Some(Map.empty) + case '{ scala.collection.immutable.Map[T, U](${Varargs(Exprs(elems))}: _*) } => Some(elems.toMap) + case '{ scala.collection.immutable.Map.empty[T, U] } => Some(Map.empty) + case _ => None + } + } + + /** Default implementation of `FromExpr[Either]` + * - Unlifts `'{Left(x)}` into `Some(Left(x))` if `x` is unliftable + * - Unlifts `'{Right(x)}` into `Some(Right(x))` if `x` is unliftable + * - Otherwise unlifts to `None` + */ + given EitherFromExpr[L, R](using Type[L], Type[R], FromExpr[L], FromExpr[R]): FromExpr[Either[L, R]] with { + def unapply(x: Expr[Either[L, R]])(using Quotes) = x match { + case '{ $x: Left[L, R] } => x.value + case '{ $x: Right[L, R] } => x.value + case _ => None + } + } + + /** Default implementation of `FromExpr[Left]` + * - Unlifts `'{Left(x)}` into `Some(Left(x))` if `x` is unliftable + * - Otherwise unlifts to `None` + */ + given LeftFromExpr[L, R](using Type[L], Type[R], FromExpr[L]): FromExpr[Left[L, R]] with { + def unapply(x: Expr[Left[L, R]])(using Quotes) = x match { + case '{ Left[L, R](${Expr(x)}) } => Some(Left(x)) + case _ => None + } + } + + /** Default implementation of `FromExpr[Right]` + * - Unlifts `'{Right(x)}` into `Some(Right(x))` if `x` is unliftable + * - Otherwise unlifts to `None` + */ + given RightFromExpr[L, R](using Type[L], Type[R], FromExpr[R]): FromExpr[Right[L, R]] with { + def unapply(x: Expr[Right[L, R]])(using Quotes) = x match { + case '{ Right[L, R](${Expr(x)}) } => Some(Right(x)) + case _ => None + } + } + +} diff --git a/library/src-bootstrapped/scala/quoted/Liftable.scala b/library/src-bootstrapped/scala/quoted/Liftable.scala deleted file mode 100644 index 531e12c40913..000000000000 --- a/library/src-bootstrapped/scala/quoted/Liftable.scala +++ /dev/null @@ -1,438 +0,0 @@ -package scala.quoted - -import scala.reflect.ClassTag - -/** A type class for types that can be turned to `quoted.Expr[T]` - * without going through an explicit `'{...}` operation. - */ -trait Liftable[T] { - - /** Lift a value into an expression containing the construction of that value */ - def toExpr(x: T): Quotes ?=> Expr[T] - -} - -/** Some liftable base types. To be completed with at least all types - * that are valid Scala literals. The actual implementation of these - * typed could be in terms of `ast.tpd.Literal`; the test `quotable.scala` - * gives an alternative implementation using just the basic staging system. - */ -object Liftable { - - // IMPORTANT Keep in sync with tests/run-staging/liftables.scala - - /** Default liftable for Boolean */ - given BooleanLiftable[T <: Boolean]: Liftable[T] with { - def toExpr(x: T) = - import quotes.reflect._ - Literal(Constant.Boolean(x)).asExpr.asInstanceOf[Expr[T]] - } - - /** Default liftable for Byte */ - given ByteLiftable[T <: Byte]: Liftable[T] with { - def toExpr(x: T) = - import quotes.reflect._ - Literal(Constant.Byte(x)).asExpr.asInstanceOf[Expr[T]] - } - - /** Default liftable for Short */ - given ShortLiftable[T <: Short]: Liftable[T] with { - def toExpr(x: T) = - import quotes.reflect._ - Literal(Constant.Short(x)).asExpr.asInstanceOf[Expr[T]] - } - - /** Default liftable for Int */ - given IntLiftable[T <: Int]: Liftable[T] with { - def toExpr(x: T) = - import quotes.reflect._ - Literal(Constant.Int(x)).asExpr.asInstanceOf[Expr[T]] - } - - /** Default liftable for Long */ - given LongLiftable[T <: Long]: Liftable[T] with { - def toExpr(x: T) = - import quotes.reflect._ - Literal(Constant.Long(x)).asExpr.asInstanceOf[Expr[T]] - } - - /** Default liftable for Float */ - given FloatLiftable[T <: Float]: Liftable[T] with { - def toExpr(x: T) = - import quotes.reflect._ - Literal(Constant.Float(x)).asExpr.asInstanceOf[Expr[T]] - } - - /** Default liftable for Double */ - given DoubleLiftable[T <: Double]: Liftable[T] with { - def toExpr(x: T) = - import quotes.reflect._ - Literal(Constant.Double(x)).asExpr.asInstanceOf[Expr[T]] - } - - /** Default liftable for Char */ - given CharLiftable[T <: Char]: Liftable[T] with { - def toExpr(x: T) = - import quotes.reflect._ - Literal(Constant.Char(x)).asExpr.asInstanceOf[Expr[T]] - } - - /** Default liftable for String */ - given StringLiftable[T <: String]: Liftable[T] with { - def toExpr(x: T) = - import quotes.reflect._ - Literal(Constant.String(x)).asExpr.asInstanceOf[Expr[T]] - } - - /** Default liftable for Class[T] */ - given ClassLiftable[T]: Liftable[Class[T]] with { - def toExpr(x: Class[T]) = { - import quotes.reflect._ - Ref(defn.Predef_classOf).appliedToType(TypeRepr.typeConstructorOf(x)).asExpr.asInstanceOf[Expr[Class[T]]] - } - } - - /** Default liftable for ClassTag[T] */ - given ClassTagLiftable[T: Type]: Liftable[ClassTag[T]] with { - def toExpr(ct: ClassTag[T]): Quotes ?=> Expr[ClassTag[T]] = - '{ ClassTag[T](${Expr(ct.runtimeClass.asInstanceOf[Class[T]])}) } - } - - /** Default liftable for Array[T] */ - given ArrayLiftable[T: Type: Liftable: ClassTag]: Liftable[Array[T]] with { - def toExpr(arr: Array[T]): Quotes ?=> Expr[Array[T]] = - '{ Array[T](${Expr(arr.toSeq)}: _*)(${Expr(summon[ClassTag[T]])}) } - } - - /** Default liftable for Array[Boolean] */ - given ArrayOfBooleanLiftable: Liftable[Array[Boolean]] with { - def toExpr(array: Array[Boolean]): Quotes ?=> Expr[Array[Boolean]] = - if (array.length == 0) '{ Array.emptyBooleanArray } - else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } - } - - /** Default liftable for Array[Byte] */ - given ArrayOfByteLiftable: Liftable[Array[Byte]] with { - def toExpr(array: Array[Byte]): Quotes ?=> Expr[Array[Byte]] = - if (array.length == 0) '{ Array.emptyByteArray } - else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } - } - - /** Default liftable for Array[Short] */ - given ArrayOfShortLiftable: Liftable[Array[Short]] with { - def toExpr(array: Array[Short]): Quotes ?=> Expr[Array[Short]] = - if (array.length == 0) '{ Array.emptyShortArray } - else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } - } - - /** Default liftable for Array[Char] */ - given ArrayOfCharLiftable: Liftable[Array[Char]] with { - def toExpr(array: Array[Char]): Quotes ?=> Expr[Array[Char]] = - if (array.length == 0) '{ Array.emptyCharArray } - else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } - } - - /** Default liftable for Array[Int] */ - given ArrayOfIntLiftable: Liftable[Array[Int]] with { - def toExpr(array: Array[Int]): Quotes ?=> Expr[Array[Int]] = - if (array.length == 0) '{ Array.emptyIntArray } - else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } - } - - /** Default liftable for Array[Long] */ - given ArrayOfLongLiftable: Liftable[Array[Long]] with { - def toExpr(array: Array[Long]): Quotes ?=> Expr[Array[Long]] = - if (array.length == 0) '{ Array.emptyLongArray } - else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } - } - - /** Default liftable for Array[Float] */ - given ArrayOfFloatLiftable: Liftable[Array[Float]] with { - def toExpr(array: Array[Float]): Quotes ?=> Expr[Array[Float]] = - if (array.length == 0) '{ Array.emptyFloatArray } - else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } - } - - /** Default liftable for Array[Double] */ - given ArrayOfDoubleLiftable: Liftable[Array[Double]] with { - def toExpr(array: Array[Double]): Quotes ?=> Expr[Array[Double]] = - if (array.length == 0) '{ Array.emptyDoubleArray } - else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } - } - - /** Default liftable for IArray[T] */ - given IArrayLiftable[T: Type](using ltArray: Liftable[Array[T]]): Liftable[IArray[T]] with { - def toExpr(iarray: IArray[T]): Quotes ?=> Expr[IArray[T]] = - '{ ${ltArray.toExpr(iarray.asInstanceOf[Array[T]])}.asInstanceOf[IArray[T]] } - } - - /** Default liftable for Seq[T] */ - given SeqLiftable[T: Type: Liftable]: Liftable[Seq[T]] with { - def toExpr(xs: Seq[T]): Quotes ?=> Expr[Seq[T]] = - Expr.ofSeq(xs.map(summon[Liftable[T]].toExpr)) - } - - /** Default liftable for List[T] */ - given ListLiftable[T: Type: Liftable]: Liftable[List[T]] with { - def toExpr(xs: List[T]): Quotes ?=> Expr[List[T]] = - Expr.ofList(xs.map(summon[Liftable[T]].toExpr)) - } - - /** Default liftable for Nil.type */ - given NilLiftable: Liftable[Nil.type] with { - def toExpr(xs: Nil.type): Quotes ?=> Expr[Nil.type] = - '{ Nil } - } - - /** Default liftable for Set[T] */ - given SetLiftable[T: Type: Liftable]: Liftable[Set[T]] with { - def toExpr(set: Set[T]): Quotes ?=> Expr[Set[T]] = - '{ Set(${Expr(set.toSeq)}: _*) } - } - - /** Default liftable for Map[T, U] */ - given MapLiftable[T: Type: Liftable, U: Type: Liftable]: Liftable[Map[T, U]] with { - def toExpr(map: Map[T, U]): Quotes ?=> Expr[Map[T, U]] = - '{ Map(${Expr(map.toSeq)}: _*) } - } - - /** Default liftable for Option[T] */ - given OptionLiftable[T: Type: Liftable]: Liftable[Option[T]] with { - def toExpr(x: Option[T]): Quotes ?=> Expr[Option[T]] = x match { - case x: Some[T] => Expr(x) - case None => Expr(None) - } - } - - /** Default liftable for Some[T] */ - given SomeLiftable[T: Type: Liftable]: Liftable[Some[T]] with { - def toExpr(x: Some[T]): Quotes ?=> Expr[Some[T]] = - '{ Some[T](${Expr(x.get)}) } - } - - /** Default liftable for None.type */ - given NoneLiftable: Liftable[None.type] with { - def toExpr(x: None.type): Quotes ?=> Expr[None.type] = - '{ None } - } - - /** Default liftable for Either[L, R] */ - given EitherLiftable[L: Type: Liftable, R: Type: Liftable]: Liftable[Either[L, R]] with { - def toExpr(x: Either[L, R]): Quotes ?=> Expr[Either[L, R]] = x match - case x: Left[L, R] => Expr(x) - case x: Right[L, R] => Expr(x) - } - - /** Default liftable for Left[L, R] */ - given LeftLiftable[L: Type: Liftable, R: Type]: Liftable[Left[L, R]] with { - def toExpr(x: Left[L, R]): Quotes ?=> Expr[Left[L, R]] = - '{ Left[L, R](${Expr(x.value)}) } - } - - /** Default liftable for Right[L, R] */ - given RightLiftable[L: Type, R: Type: Liftable]: Liftable[Right[L, R]] with { - def toExpr(x: Right[L, R]): Quotes ?=> Expr[Right[L, R]] = - '{ Right[L, R](${Expr(x.value)}) } - } - - /** Default liftable for EmptyTuple.type */ - given EmptyTupleLiftable: Liftable[EmptyTuple.type] = new { - def toExpr(tup: EmptyTuple.type) = - '{ EmptyTuple } - } - - /** Default liftable for Tuple1[T1] */ - given Tuple1Liftable[T1: Type: Liftable]: Liftable[Tuple1[T1]] = new { - def toExpr(tup: Tuple1[T1]) = - '{ Tuple1(${Expr(tup._1)}) } - } - - /** Default liftable for Tuple2[T1, T2] */ - given Tuple2Liftable[T1: Type: Liftable, T2: Type: Liftable]: Liftable[Tuple2[T1, T2]] = new { - def toExpr(tup: Tuple2[T1, T2]) = - '{ (${Expr(tup._1)}, ${Expr(tup._2)}) } - } - - /** Default liftable for Tuple3[T1, T2, T3] */ - given Tuple3Liftable[T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable]: Liftable[Tuple3[T1, T2, T3]] = new { - def toExpr(tup: Tuple3[T1, T2, T3]) = - '{ (${Expr(tup._1)}, ${Expr(tup._2)}, ${Expr(tup._3)}) } - } - - /** Default liftable for Tuple4[T1, T2, T3, T4] */ - given Tuple4Liftable[T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable]: Liftable[Tuple4[T1, T2, T3, T4]] = new { - def toExpr(tup: Tuple4[T1, T2, T3, T4]) = - '{ (${Expr(tup._1)}, ${Expr(tup._2)}, ${Expr(tup._3)}, ${Expr(tup._4)}) } - } - - /** Default liftable for Tuple5[T1, T2, T3, T4, T5] */ - given Tuple5Liftable[T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable]: Liftable[Tuple5[T1, T2, T3, T4, T5]] = new { - def toExpr(tup: Tuple5[T1, T2, T3, T4, T5]) = { - val (x1, x2, x3, x4, x5) = tup - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}) } - } - } - - /** Default liftable for Tuple6[T1, T2, T3, T4, T5, T6] */ - given Tuple6Liftable[T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}) } - } - } - - /** Default liftable for Tuple7[T1, T2, T3, T4, T5, T6, T7] */ - given Tuple7Liftable[T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}) } - } - } - - /** Default liftable for Tuple8[T1, T2, T3, T4, T5, T6, T7, T8] */ - given Tuple8Liftable[T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}) } - } - } - - /** Default liftable for Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9] */ - given Tuple9Liftable[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]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}) } - } - } - - /** Default liftable for Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10] */ - given Tuple10Liftable[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]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}) } - } - } - - /** Default liftable for Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11] */ - given Tuple11Liftable[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]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}) } - } - } - - /** Default liftable for Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12] */ - given Tuple12Liftable[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]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}) } - } - } - - /** Default liftable for Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13] */ - given Tuple13Liftable[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]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}) } - } - } - - /** Default liftable for Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14] */ - given Tuple14Liftable[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]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}) } - } - } - - /** Default liftable for Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15] */ - given Tuple15Liftable[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]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}, ${Expr(x15)}) } - } - } - - /** Default liftable for Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16] */ - given Tuple16Liftable[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]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}, ${Expr(x15)}, ${Expr(x16)}) } - } - } - - /** Default liftable for Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17] */ - given Tuple17Liftable[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]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}, ${Expr(x15)}, ${Expr(x16)}, ${Expr(x17)}) } - } - } - - /** Default liftable for Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18] */ - given Tuple18Liftable[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]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}, ${Expr(x15)}, ${Expr(x16)}, ${Expr(x17)}, ${Expr(x18)}) } - } - } - - /** Default liftable for Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19] */ - given Tuple19Liftable[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]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}, ${Expr(x15)}, ${Expr(x16)}, ${Expr(x17)}, ${Expr(x18)}, ${Expr(x19)}) } - } - } - - /** Default liftable for Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20] */ - given Tuple20Liftable[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]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}, ${Expr(x15)}, ${Expr(x16)}, ${Expr(x17)}, ${Expr(x18)}, ${Expr(x19)}, ${Expr(x20)}) } - } - } - - /** Default liftable for Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21] */ - given Tuple21Liftable[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]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}, ${Expr(x15)}, ${Expr(x16)}, ${Expr(x17)}, ${Expr(x18)}, ${Expr(x19)}, ${Expr(x20)}, ${Expr(x21)}) } - } - } - - /** Default liftable for Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22] */ - given Tuple22Liftable[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]: 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 - '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}, ${Expr(x15)}, ${Expr(x16)}, ${Expr(x17)}, ${Expr(x18)}, ${Expr(x19)}, ${Expr(x20)}, ${Expr(x21)}, ${Expr(x22)}) } - } - } - - /** Default liftable for H *: T */ - given TupleConsLiftable [H: Type: Liftable, T <: Tuple: Type: Liftable]: Liftable[H *: T] = new { - def toExpr(tup: H *: T): Quotes ?=> Expr[H *: T] = - '{ ${summon[Liftable[H]].toExpr(tup.head)} *: ${summon[Liftable[T]].toExpr(tup.tail)} } - // '{ ${Expr(tup.head)} *: ${Expr(tup.tail)} } // TODO figure out why this fails during CI documentation - } - - /** Default liftable for BigInt */ - given BigIntLiftable: Liftable[BigInt] with { - def toExpr(x: BigInt): Quotes ?=> Expr[BigInt] = - '{ BigInt(${Expr(x.toByteArray)}) } - } - - /** Default liftable for BigDecimal using the default MathContext */ - given BigDecimalLiftable: Liftable[BigDecimal] with { - def toExpr(x: BigDecimal): Quotes ?=> Expr[BigDecimal] = - '{ BigDecimal(${Expr(x.toString)}) } - } - - /** Default liftable for StringContext */ - given StringContextLiftable: Liftable[StringContext] with { - def toExpr(stringContext: StringContext): Quotes ?=> Expr[StringContext] = - val parts = Varargs(stringContext.parts.map(Expr(_))) - '{ StringContext($parts: _*) } - } - -} diff --git a/library/src-bootstrapped/scala/quoted/ToExpr.scala b/library/src-bootstrapped/scala/quoted/ToExpr.scala new file mode 100644 index 000000000000..db974f945a19 --- /dev/null +++ b/library/src-bootstrapped/scala/quoted/ToExpr.scala @@ -0,0 +1,433 @@ +package scala.quoted + +import scala.reflect.ClassTag + +/** A type class for types that can convert a value of `T` into `quoted.Expr[T]` + * an expression that will create a copy of the value. + */ +trait ToExpr[T] { + + /** Lift a value into an expression containing the construction of that value */ + def apply(x: T)(using Quotes): Expr[T] + +} + +object ToExpr { + + // IMPORTANT Keep in sync with tests/run-staging/liftables.scala + + /** Default implemetation of `ToExpr[Boolean]` */ + given BooleanToExpr[T <: Boolean]: ToExpr[T] with { + def apply(x: T)(using Quotes) = + import quotes.reflect._ + Literal(Constant.Boolean(x)).asExpr.asInstanceOf[Expr[T]] + } + + /** Default implemetation of `ToExpr[Byte]` */ + given ByteToExpr[T <: Byte]: ToExpr[T] with { + def apply(x: T)(using Quotes) = + import quotes.reflect._ + Literal(Constant.Byte(x)).asExpr.asInstanceOf[Expr[T]] + } + + /** Default implemetation of `ToExpr[Short]` */ + given ShortToExpr[T <: Short]: ToExpr[T] with { + def apply(x: T)(using Quotes) = + import quotes.reflect._ + Literal(Constant.Short(x)).asExpr.asInstanceOf[Expr[T]] + } + + /** Default implemetation of `ToExpr[Int]` */ + given IntToExpr[T <: Int]: ToExpr[T] with { + def apply(x: T)(using Quotes) = + import quotes.reflect._ + Literal(Constant.Int(x)).asExpr.asInstanceOf[Expr[T]] + } + + /** Default implemetation of `ToExpr[Long]` */ + given LongToExpr[T <: Long]: ToExpr[T] with { + def apply(x: T)(using Quotes) = + import quotes.reflect._ + Literal(Constant.Long(x)).asExpr.asInstanceOf[Expr[T]] + } + + /** Default implemetation of `ToExpr[Float]` */ + given FloatToExpr[T <: Float]: ToExpr[T] with { + def apply(x: T)(using Quotes) = + import quotes.reflect._ + Literal(Constant.Float(x)).asExpr.asInstanceOf[Expr[T]] + } + + /** Default implemetation of `ToExpr[Double]` */ + given DoubleToExpr[T <: Double]: ToExpr[T] with { + def apply(x: T)(using Quotes) = + import quotes.reflect._ + Literal(Constant.Double(x)).asExpr.asInstanceOf[Expr[T]] + } + + /** Default implemetation of `ToExpr[Char]` */ + given CharToExpr[T <: Char]: ToExpr[T] with { + def apply(x: T)(using Quotes) = + import quotes.reflect._ + Literal(Constant.Char(x)).asExpr.asInstanceOf[Expr[T]] + } + + /** Default implemetation of `ToExpr[String]` */ + given StringToExpr[T <: String]: ToExpr[T] with { + def apply(x: T)(using Quotes) = + import quotes.reflect._ + Literal(Constant.String(x)).asExpr.asInstanceOf[Expr[T]] + } + + /** Default implemetation of `ToExpr[Class[T]]` */ + given ClassToExpr[T]: ToExpr[Class[T]] with { + def apply(x: Class[T])(using Quotes) = { + import quotes.reflect._ + Ref(defn.Predef_classOf).appliedToType(TypeRepr.typeConstructorOf(x)).asExpr.asInstanceOf[Expr[Class[T]]] + } + } + + /** Default implemetation of `ToExpr[ClassTag[T]]` */ + given ClassTagToExpr[T: Type]: ToExpr[ClassTag[T]] with { + def apply(ct: ClassTag[T])(using Quotes): Expr[ClassTag[T]] = + '{ ClassTag[T](${Expr(ct.runtimeClass.asInstanceOf[Class[T]])}) } + } + + /** Default implemetation of `ToExpr[Array[T]]` */ + given ArrayToExpr[T: Type: ToExpr: ClassTag]: ToExpr[Array[T]] with { + def apply(arr: Array[T])(using Quotes): Expr[Array[T]] = + '{ Array[T](${Expr(arr.toSeq)}: _*)(${Expr(summon[ClassTag[T]])}) } + } + + /** Default implemetation of `ToExpr[Array[Boolean]]` */ + given ArrayOfBooleanToExpr: ToExpr[Array[Boolean]] with { + def apply(array: Array[Boolean])(using Quotes): Expr[Array[Boolean]] = + if (array.length == 0) '{ Array.emptyBooleanArray } + else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } + } + + /** Default implemetation of `ToExpr[Array[Byte]]` */ + given ArrayOfByteToExpr: ToExpr[Array[Byte]] with { + def apply(array: Array[Byte])(using Quotes): Expr[Array[Byte]] = + if (array.length == 0) '{ Array.emptyByteArray } + else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } + } + + /** Default implemetation of `ToExpr[Array[Short]]` */ + given ArrayOfShortToExpr: ToExpr[Array[Short]] with { + def apply(array: Array[Short])(using Quotes): Expr[Array[Short]] = + if (array.length == 0) '{ Array.emptyShortArray } + else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } + } + + /** Default implemetation of `ToExpr[Array[Char]]` */ + given ArrayOfCharToExpr: ToExpr[Array[Char]] with { + def apply(array: Array[Char])(using Quotes): Expr[Array[Char]] = + if (array.length == 0) '{ Array.emptyCharArray } + else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } + } + + /** Default implemetation of `ToExpr[Array[Int]]` */ + given ArrayOfIntToExpr: ToExpr[Array[Int]] with { + def apply(array: Array[Int])(using Quotes): Expr[Array[Int]] = + if (array.length == 0) '{ Array.emptyIntArray } + else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } + } + + /** Default implemetation of `ToExpr[Array[Long]]` */ + given ArrayOfLongToExpr: ToExpr[Array[Long]] with { + def apply(array: Array[Long])(using Quotes): Expr[Array[Long]] = + if (array.length == 0) '{ Array.emptyLongArray } + else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } + } + + /** Default implemetation of `ToExpr[Array[Float]]` */ + given ArrayOfFloatToExpr: ToExpr[Array[Float]] with { + def apply(array: Array[Float])(using Quotes): Expr[Array[Float]] = + if (array.length == 0) '{ Array.emptyFloatArray } + else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } + } + + /** Default implemetation of `ToExpr[Array[Double]]` */ + given ArrayOfDoubleToExpr: ToExpr[Array[Double]] with { + def apply(array: Array[Double])(using Quotes): Expr[Array[Double]] = + if (array.length == 0) '{ Array.emptyDoubleArray } + else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } + } + + /** Default implemetation of `ToExpr[IArray[T]]` */ + given IArrayToExpr[T: Type](using ltArray: ToExpr[Array[T]]): ToExpr[IArray[T]] with { + def apply(iarray: IArray[T])(using Quotes): Expr[IArray[T]] = + '{ ${ltArray.apply(iarray.asInstanceOf[Array[T]])}.asInstanceOf[IArray[T]] } + } + + /** Default implemetation of `ToExpr[Seq[T]]` */ + given SeqToExpr[T: Type: ToExpr]: ToExpr[Seq[T]] with { + def apply(xs: Seq[T])(using Quotes): Expr[Seq[T]] = + Expr.ofSeq(xs.map(summon[ToExpr[T]].apply)) + } + + /** Default implemetation of `ToExpr[List[T]]` */ + given ListToExpr[T: Type: ToExpr]: ToExpr[List[T]] with { + def apply(xs: List[T])(using Quotes): Expr[List[T]] = + Expr.ofList(xs.map(summon[ToExpr[T]].apply)) + } + + /** Default implemetation of `ToExpr[Nil.type]` */ + given NilToExpr: ToExpr[Nil.type] with { + def apply(xs: Nil.type)(using Quotes): Expr[Nil.type] = + '{ Nil } + } + + /** Default implemetation of `ToExpr[Set[T]]` */ + given SetToExpr[T: Type: ToExpr]: ToExpr[Set[T]] with { + def apply(set: Set[T])(using Quotes): Expr[Set[T]] = + '{ Set(${Expr(set.toSeq)}: _*) } + } + + /** Default implemetation of `ToExpr[Map[T, U]]` */ + given MapToExpr[T: Type: ToExpr, U: Type: ToExpr]: ToExpr[Map[T, U]] with { + def apply(map: Map[T, U])(using Quotes): Expr[Map[T, U]] = + '{ Map(${Expr(map.toSeq)}: _*) } + } + + /** Default implemetation of `ToExpr[Option[T]]` */ + given OptionToExpr[T: Type: ToExpr]: ToExpr[Option[T]] with { + def apply(x: Option[T])(using Quotes): Expr[Option[T]] = x match { + case x: Some[T] => Expr(x) + case None => Expr(None) + } + } + + /** Default implemetation of `ToExpr[Some[T]]` */ + given SomeToExpr[T: Type: ToExpr]: ToExpr[Some[T]] with { + def apply(x: Some[T])(using Quotes): Expr[Some[T]] = + '{ Some[T](${Expr(x.get)}) } + } + + /** Default implemetation of `ToExpr[None.type]` */ + given NoneToExpr: ToExpr[None.type] with { + def apply(x: None.type)(using Quotes): Expr[None.type] = + '{ None } + } + + /** Default implemetation of `ToExpr[Either[L, R]]` */ + given EitherToExpr[L: Type: ToExpr, R: Type: ToExpr]: ToExpr[Either[L, R]] with { + def apply(x: Either[L, R])(using Quotes): Expr[Either[L, R]] = x match + case x: Left[L, R] => Expr(x) + case x: Right[L, R] => Expr(x) + } + + /** Default implemetation of `ToExpr[Left[L, R]]` */ + given LeftToExpr[L: Type: ToExpr, R: Type]: ToExpr[Left[L, R]] with { + def apply(x: Left[L, R])(using Quotes): Expr[Left[L, R]] = + '{ Left[L, R](${Expr(x.value)}) } + } + + /** Default implemetation of `ToExpr[Right[L, R]]` */ + given RightToExpr[L: Type, R: Type: ToExpr]: ToExpr[Right[L, R]] with { + def apply(x: Right[L, R])(using Quotes): Expr[Right[L, R]] = + '{ Right[L, R](${Expr(x.value)}) } + } + + /** Default implemetation of `ToExpr[EmptyTuple.type]` */ + given EmptyTupleToExpr: ToExpr[EmptyTuple.type] with { + def apply(tup: EmptyTuple.type)(using Quotes) = + '{ EmptyTuple } + } + + /** Default implemetation of `ToExpr[Tuple1[T1]]` */ + given Tuple1ToExpr[T1: Type: ToExpr]: ToExpr[Tuple1[T1]] with { + def apply(tup: Tuple1[T1])(using Quotes) = + '{ Tuple1(${Expr(tup._1)}) } + } + + /** Default implemetation of `ToExpr[Tuple2[T1, T2]]` */ + given Tuple2ToExpr[T1: Type: ToExpr, T2: Type: ToExpr]: ToExpr[Tuple2[T1, T2]] with { + def apply(tup: Tuple2[T1, T2])(using Quotes) = + '{ (${Expr(tup._1)}, ${Expr(tup._2)}) } + } + + /** Default implemetation of `ToExpr[Tuple3[T1, T2, T3]]` */ + given Tuple3ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr]: ToExpr[Tuple3[T1, T2, T3]] with { + def apply(tup: Tuple3[T1, T2, T3])(using Quotes) = + '{ (${Expr(tup._1)}, ${Expr(tup._2)}, ${Expr(tup._3)}) } + } + + /** Default implemetation of `ToExpr[Tuple4[T1, T2, T3, T4]]` */ + given Tuple4ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr]: ToExpr[Tuple4[T1, T2, T3, T4]] with { + def apply(tup: Tuple4[T1, T2, T3, T4])(using Quotes) = + '{ (${Expr(tup._1)}, ${Expr(tup._2)}, ${Expr(tup._3)}, ${Expr(tup._4)}) } + } + + /** Default implemetation of `ToExpr[Tuple5[T1, T2, T3, T4, T5]]` */ + given Tuple5ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr]: ToExpr[Tuple5[T1, T2, T3, T4, T5]] with { + def apply(tup: Tuple5[T1, T2, T3, T4, T5])(using Quotes) = { + val (x1, x2, x3, x4, x5) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple6[T1, T2, T3, T4, T5, T6]]` */ + given Tuple6ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr]: ToExpr[Tuple6[T1, T2, T3, T4, T5, T6]] with { + def apply(tup: Tuple6[T1, T2, T3, T4, T5, T6])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple7[T1, T2, T3, T4, T5, T6, T7]]` */ + given Tuple7ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr, T7: Type: ToExpr]: ToExpr[Tuple7[T1, T2, T3, T4, T5, T6, T7]] with { + def apply(tup: Tuple7[T1, T2, T3, T4, T5, T6, T7])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6, x7) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]` */ + given Tuple8ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr, T7: Type: ToExpr, T8: Type: ToExpr]: ToExpr[Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] with { + def apply(tup: Tuple8[T1, T2, T3, T4, T5, T6, T7, T8])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6, x7, x8) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]` */ + given Tuple9ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr, T7: Type: ToExpr, T8: Type: ToExpr, T9: Type: ToExpr]: ToExpr[Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] with { + def apply(tup: Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]` */ + given Tuple10ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr, T7: Type: ToExpr, T8: Type: ToExpr, T9: Type: ToExpr, T10: Type: ToExpr]: ToExpr[Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] with { + def apply(tup: Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]]` */ + given Tuple11ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr, T7: Type: ToExpr, T8: Type: ToExpr, T9: Type: ToExpr, T10: Type: ToExpr, T11: Type: ToExpr]: ToExpr[Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]] with { + def apply(tup: Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]]` */ + given Tuple12ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr, T7: Type: ToExpr, T8: Type: ToExpr, T9: Type: ToExpr, T10: Type: ToExpr, T11: Type: ToExpr, T12: Type: ToExpr]: ToExpr[Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]] with { + def apply(tup: Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]]` */ + given Tuple13ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr, T7: Type: ToExpr, T8: Type: ToExpr, T9: Type: ToExpr, T10: Type: ToExpr, T11: Type: ToExpr, T12: Type: ToExpr, T13: Type: ToExpr]: ToExpr[Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]] with { + def apply(tup: Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]]` */ + given Tuple14ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr, T7: Type: ToExpr, T8: Type: ToExpr, T9: Type: ToExpr, T10: Type: ToExpr, T11: Type: ToExpr, T12: Type: ToExpr, T13: Type: ToExpr, T14: Type: ToExpr]: ToExpr[Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]] with { + def apply(tup: Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]]` */ + given Tuple15ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr, T7: Type: ToExpr, T8: Type: ToExpr, T9: Type: ToExpr, T10: Type: ToExpr, T11: Type: ToExpr, T12: Type: ToExpr, T13: Type: ToExpr, T14: Type: ToExpr, T15: Type: ToExpr]: ToExpr[Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]] with { + def apply(tup: Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}, ${Expr(x15)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]]` */ + given Tuple16ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr, T7: Type: ToExpr, T8: Type: ToExpr, T9: Type: ToExpr, T10: Type: ToExpr, T11: Type: ToExpr, T12: Type: ToExpr, T13: Type: ToExpr, T14: Type: ToExpr, T15: Type: ToExpr, T16: Type: ToExpr]: ToExpr[Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]] with { + def apply(tup: Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}, ${Expr(x15)}, ${Expr(x16)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]]` */ + given Tuple17ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr, T7: Type: ToExpr, T8: Type: ToExpr, T9: Type: ToExpr, T10: Type: ToExpr, T11: Type: ToExpr, T12: Type: ToExpr, T13: Type: ToExpr, T14: Type: ToExpr, T15: Type: ToExpr, T16: Type: ToExpr, T17: Type: ToExpr]: ToExpr[Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]] with { + def apply(tup: Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}, ${Expr(x15)}, ${Expr(x16)}, ${Expr(x17)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]]` */ + given Tuple18ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr, T7: Type: ToExpr, T8: Type: ToExpr, T9: Type: ToExpr, T10: Type: ToExpr, T11: Type: ToExpr, T12: Type: ToExpr, T13: Type: ToExpr, T14: Type: ToExpr, T15: Type: ToExpr, T16: Type: ToExpr, T17: Type: ToExpr, T18: Type: ToExpr]: ToExpr[Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]] with { + def apply(tup: Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}, ${Expr(x15)}, ${Expr(x16)}, ${Expr(x17)}, ${Expr(x18)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]]` */ + given Tuple19ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr, T7: Type: ToExpr, T8: Type: ToExpr, T9: Type: ToExpr, T10: Type: ToExpr, T11: Type: ToExpr, T12: Type: ToExpr, T13: Type: ToExpr, T14: Type: ToExpr, T15: Type: ToExpr, T16: Type: ToExpr, T17: Type: ToExpr, T18: Type: ToExpr, T19: Type: ToExpr]: ToExpr[Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]] with { + def apply(tup: Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}, ${Expr(x15)}, ${Expr(x16)}, ${Expr(x17)}, ${Expr(x18)}, ${Expr(x19)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]]` */ + given Tuple20ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr, T7: Type: ToExpr, T8: Type: ToExpr, T9: Type: ToExpr, T10: Type: ToExpr, T11: Type: ToExpr, T12: Type: ToExpr, T13: Type: ToExpr, T14: Type: ToExpr, T15: Type: ToExpr, T16: Type: ToExpr, T17: Type: ToExpr, T18: Type: ToExpr, T19: Type: ToExpr, T20: Type: ToExpr]: ToExpr[Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]] with { + def apply(tup: Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}, ${Expr(x15)}, ${Expr(x16)}, ${Expr(x17)}, ${Expr(x18)}, ${Expr(x19)}, ${Expr(x20)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]]` */ + given Tuple21ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr, T7: Type: ToExpr, T8: Type: ToExpr, T9: Type: ToExpr, T10: Type: ToExpr, T11: Type: ToExpr, T12: Type: ToExpr, T13: Type: ToExpr, T14: Type: ToExpr, T15: Type: ToExpr, T16: Type: ToExpr, T17: Type: ToExpr, T18: Type: ToExpr, T19: Type: ToExpr, T20: Type: ToExpr, T21: Type: ToExpr]: ToExpr[Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]] with { + def apply(tup: Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}, ${Expr(x15)}, ${Expr(x16)}, ${Expr(x17)}, ${Expr(x18)}, ${Expr(x19)}, ${Expr(x20)}, ${Expr(x21)}) } + } + } + + /** Default implemetation of `ToExpr[Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]]` */ + given Tuple22ToExpr[T1: Type: ToExpr, T2: Type: ToExpr, T3: Type: ToExpr, T4: Type: ToExpr, T5: Type: ToExpr, T6: Type: ToExpr, T7: Type: ToExpr, T8: Type: ToExpr, T9: Type: ToExpr, T10: Type: ToExpr, T11: Type: ToExpr, T12: Type: ToExpr, T13: Type: ToExpr, T14: Type: ToExpr, T15: Type: ToExpr, T16: Type: ToExpr, T17: Type: ToExpr, T18: Type: ToExpr, T19: Type: ToExpr, T20: Type: ToExpr, T21: Type: ToExpr, T22: Type: ToExpr]: ToExpr[Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]] with { + def apply(tup: Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22])(using Quotes) = { + val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22) = tup + '{ (${Expr(x1)}, ${Expr(x2)}, ${Expr(x3)}, ${Expr(x4)}, ${Expr(x5)}, ${Expr(x6)}, ${Expr(x7)}, ${Expr(x8)}, ${Expr(x9)}, ${Expr(x10)}, ${Expr(x11)}, ${Expr(x12)}, ${Expr(x13)}, ${Expr(x14)}, ${Expr(x15)}, ${Expr(x16)}, ${Expr(x17)}, ${Expr(x18)}, ${Expr(x19)}, ${Expr(x20)}, ${Expr(x21)}, ${Expr(x22)}) } + } + } + + /** Default implemetation of `ToExpr[H *: T]` */ + given TupleConsToExpr [H: Type: ToExpr, T <: Tuple: Type: ToExpr]: ToExpr[H *: T] with { + def apply(tup: H *: T)(using Quotes): Expr[H *: T] = + '{ ${summon[ToExpr[H]].apply(tup.head)} *: ${summon[ToExpr[T]].apply(tup.tail)} } + // '{ ${Expr(tup.head)} *: ${Expr(tup.tail)} } // TODO figure out why this fails during CI documentation + } + + /** Default implemetation of `ToExpr[BigInt]` */ + given BigIntToExpr: ToExpr[BigInt] with { + def apply(x: BigInt)(using Quotes): Expr[BigInt] = + '{ BigInt(${Expr(x.toByteArray)}) } + } + + /** Default implemetation of `ToExpr[BigDecimal using the default MathContext]` */ + given BigDecimalToExpr: ToExpr[BigDecimal] with { + def apply(x: BigDecimal)(using Quotes): Expr[BigDecimal] = + '{ BigDecimal(${Expr(x.toString)}) } + } + + /** Default implemetation of `ToExpr[StringContext]` */ + given StringContextToExpr: ToExpr[StringContext] with { + def apply(stringContext: StringContext)(using Quotes): Expr[StringContext] = + val parts = Varargs(stringContext.parts.map(Expr(_))) + '{ StringContext($parts: _*) } + } + +} diff --git a/library/src-bootstrapped/scala/quoted/Unliftable.scala b/library/src-bootstrapped/scala/quoted/Unliftable.scala deleted file mode 100644 index 9c4c1d9100ec..000000000000 --- a/library/src-bootstrapped/scala/quoted/Unliftable.scala +++ /dev/null @@ -1,528 +0,0 @@ -package scala.quoted - -/** A type class for types that can convert a `quoted.Expr[T]` to a `T`. - * - * - Converts expression containg literal values to their values: - * - `'{1}` -> `1`, `'{2}` -> `2`, ... - * - For all primitive types and `String` - * - Converts an expression that constructs a value into its value. - * - This expression must be some kind of datastructure (`Some`, `List`, `Either`, ...) - * - Calls to `new X` or `X.apply` can be lifted into its value - * - Arguments of constructors can be recursively unlifted - */ -trait Unliftable[T] { - - /** Return the value of the expression. - * - * Returns `None` if the expression does not contain a value or contains side effects. - * Otherwise returns the `Some` of the value. - */ - def fromExpr(x: Expr[T]): Quotes ?=> Option[T] - -} - -object Unliftable { - - /** Default unliftable for Boolean - * - Unlifts `'{true}` into `Some(ture)` - * - Unlifts `'{false}` into `Some(false)` - * - Otherwise unlifts to `None` - */ - given BooleanUnliftable[T <: Boolean]: Unliftable[T] = new PrimitiveUnliftable - - /** Default unliftable for Byte - * - Unlifts `'{n}` into `Some(n)` for a literal `n` of type `Byte` - * - Otherwise unlifts to `None` - */ - given ByteUnliftable[T <: Byte]: Unliftable[T] = new PrimitiveUnliftable - - /** Default unliftable for Short - * - Unlifts `'{n}` into `Some(n)` for a literal `n` of type `Short` - * - Otherwise unlifts to `None` - */ - given ShortUnliftable[T <: Short]: Unliftable[T] = new PrimitiveUnliftable - - /** Default unliftable for Int - * - Unlifts `'{n}` into `Some(n)` for a literal `n` of type `Int` - * - Otherwise unlifts to `None` - */ - given IntUnliftable[T <: Int]: Unliftable[T] = new PrimitiveUnliftable - - /** Default unliftable for Long - * - Unlifts `'{n}` into `Some(n)` for a literal `n` of type `Long` - * - Otherwise unlifts to `None` - */ - given LongUnliftable[T <: Long]: Unliftable[T] = new PrimitiveUnliftable - - /** Default unliftable for Float - * - Unlifts `'{n}` into `Some(n)` for a literal `n` of type `Float` - * - Otherwise unlifts to `None` - */ - given FloatUnliftable[T <: Float]: Unliftable[T] = new PrimitiveUnliftable - - /** Default unliftable for Double - * - Unlifts `'{n}` into `Some(n)` for a literal `n` of type `Double` - * - Otherwise unlifts to `None` - */ - given DoubleUnliftable[T <: Double]: Unliftable[T] = new PrimitiveUnliftable - - /** Default unliftable for Char - * - Unlifts `'{c}` into `Some(c)` for a literal `c` of type `Char` - * - Otherwise unlifts to `None` - */ - given CharUnliftable[T <: Char]: Unliftable[T] = new PrimitiveUnliftable - - /** Default unliftable for String - * - Unlifts `'{str}` into `Some(str)` for a literal `str` of type `String` - * - Otherwise unlifts to `None` - */ - given StringUnliftable[T <: String]: Unliftable[T] = new PrimitiveUnliftable - - /** Lift a quoted primitive value `'{ x }` into `x` */ - private class PrimitiveUnliftable[T <: Boolean | Byte | Short | Int | Long | Float | Double | Char | String] extends Unliftable[T] { - def fromExpr(expr: Expr[T]) = - import quotes.reflect._ - def rec(tree: Term): Option[T] = tree match { - case Literal(c) if c.value != null => Some(c.value.asInstanceOf[T]) - case Block(Nil, e) => rec(e) - case Typed(e, _) => rec(e) - case Inlined(_, Nil, e) => rec(e) - case _ => None - } - rec(Term.of(expr)) - } - - /** Default unliftable for Option - * - Unlifts `'{Some(x)}` into `Some(Some(x))` if `x` is unliftable - * - Unlifts `'{None}` into `Some(None)` - * - Otherwise unlifts to `None` - */ - given OptionUnliftable[T](using Type[T], Unliftable[T]): Unliftable[Option[T]] = new { - def fromExpr(x: Expr[Option[T]]) = x match { - case '{ Option[T](${Unlifted(y)}) } => Some(Option(y)) - case '{ None } => Some(None) - case '{ ${Unlifted(opt)} : Some[T] } => Some(opt) - case _ => None - } - } - - /** Default unliftable for None - * - Unlifts `'{None}` into `Some(None)` - * - Otherwise unlifts to `None` - */ - given NoneUnliftable: Unliftable[None.type] = new { - def fromExpr(x: Expr[None.type]) = x match { - case '{ None } => Some(None) - case _ => None - } - } - - /** Default unliftable for Some - * - Unlifts `'{Some(x)}` into `Some(Some(x))` if `x` is unliftable - * - Otherwise unlifts to `None` - */ - given SomeUnliftable[T](using Type[T], Unliftable[T]): Unliftable[Some[T]] = new { - def fromExpr(x: Expr[Some[T]]) = x match { - case '{ new Some[T](${Unlifted(y)}) } => Some(Some(y)) - case '{ Some[T](${Unlifted(y)}) } => Some(Some(y)) - case _ => None - } - } - - /** Default unliftable for StringContext - * - Unlifts `'{StringContext(args: _*)}` into `Some(StringContext(args: _*))` if `args` is explicit and each one is liftable - * - Otherwise unlifts to `None` - */ - given StringContextUnliftable: Unliftable[StringContext] = new { - def fromExpr(x: Expr[StringContext]) = x match { - case '{ new StringContext(${Varargs(Consts(args))}: _*) } => Some(StringContext(args: _*)) - case '{ StringContext(${Varargs(Consts(args))}: _*) } => Some(StringContext(args: _*)) - case _ => None - } - } - - /** Default unliftable for EmptyTuple - * - Unlifts `'{EmptyTuple}` into `Some(EmptyTuple)` - * - Otherwise unlifts to `None` - */ - given EmptyTupleUnliftable: Unliftable[EmptyTuple.type] = new { - def fromExpr(x: Expr[EmptyTuple.type]) = x match { - case '{ EmptyTuple } => Some(EmptyTuple) - case _ => None - } - } - - /** Default unliftable for Tuple1 - * - Unlifts `'{Tuple1(x1)}` into `Some(Tuple1(x1))` if `x1` is unliftable - * - Otherwise unlifts to `None` - */ - given Tuple1Unliftable[T1](using Type[T1], Unliftable[T1]): Unliftable[Tuple1[T1]] = new { - def fromExpr(x: Expr[Tuple1[T1]]) = x match { - case '{ new Tuple1[T1](${Unlifted(y)}) } => Some(Tuple1(y)) - case '{ Tuple1[T1](${Unlifted(y)}) } => Some(Tuple1(y)) - case _ => None - } - } - - /** Default unliftable for Tuple2 - * - Unlifts `'{Tuple2(x1, x2)}` into `Some(Tuple2(x1, x2))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple2Unliftable[T1, T2](using Type[T1], Type[T2], Unliftable[T1], Unliftable[T2]): Unliftable[Tuple2[T1, T2]] = new { - def fromExpr(x: Expr[Tuple2[T1, T2]]) = x match { - case '{ new Tuple2[T1, T2](${Unlifted(y1)}, ${Unlifted(y2)}) } => Some(Tuple2(y1, y2)) - case '{ Tuple2[T1, T2](${Unlifted(y1)}, ${Unlifted(y2)}) } => Some(Tuple2(y1, y2)) - case '{ (${Unlifted(y1)}: T1) -> (${Unlifted(y2)}: T2) } => Some(Tuple2(y1, y2)) - case _ => None - } - } - - /** Default unliftable for Tuple3 - * - Unlifts `'{Tuple3(x1, x2, x3)}` into `Some(Tuple3(x1, x2, x3))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple3Unliftable[T1, T2, T3](using Type[T1], Type[T2], Type[T3], Unliftable[T1], Unliftable[T2], Unliftable[T3]): Unliftable[Tuple3[T1, T2, T3]] = new { - def fromExpr(x: Expr[Tuple3[T1, T2, T3]]) = x match { - case '{ new Tuple3[T1, T2, T3](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}) } => Some(Tuple3(y1, y2, y3)) - case '{ Tuple3[T1, T2, T3](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}) } => Some(Tuple3(y1, y2, y3)) - case _ => None - } - } - - /** Default unliftable for Tuple4 - * - Unlifts `'{Tuple4(x1, ..., x4)}` into `Some(Tuple4(x1, ..., x4))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple4Unliftable[T1, T2, T3, T4](using Type[T1], Type[T2], Type[T3], Type[T4], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4]): Unliftable[Tuple4[T1, T2, T3, T4]] = new { - def fromExpr(x: Expr[Tuple4[T1, T2, T3, T4]]) = x match { - case '{ new Tuple4[T1, T2, T3, T4](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}) } => Some(Tuple4(y1, y2, y3, y4)) - case '{ Tuple4[T1, T2, T3, T4](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}) } => Some(Tuple4(y1, y2, y3, y4)) - case _ => None - } - } - - /** Default unliftable for Tuple5 - * - Unlifts `'{Tuple5(x1, ..., x5)}` into `Some(Tuple5(x1, ..., x5))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple5Unliftable[T1, T2, T3, T4, T5](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5]): Unliftable[Tuple5[T1, T2, T3, T4, T5]] = new { - def fromExpr(x: Expr[Tuple5[T1, T2, T3, T4, T5]]) = x match { - case '{ new Tuple5[T1, T2, T3, T4, T5](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}) } => Some(Tuple5(y1, y2, y3, y4, y5)) - case '{ Tuple5[T1, T2, T3, T4, T5](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}) } => Some(Tuple5(y1, y2, y3, y4, y5)) - case _ => None - } - } - - /** Default unliftable for Tuple6 - * - Unlifts `'{Tuple6(x1, ..., x6)}` into `Some(Tuple6(x1, ..., x6))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple6Unliftable[T1, T2, T3, T4, T5, T6](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6]): Unliftable[Tuple6[T1, T2, T3, T4, T5, T6]] = new { - def fromExpr(x: Expr[Tuple6[T1, T2, T3, T4, T5, T6]]) = x match { - case '{ new Tuple6[T1, T2, T3, T4, T5, T6](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}) } => Some(Tuple6(y1, y2, y3, y4, y5, y6)) - case '{ Tuple6[T1, T2, T3, T4, T5, T6](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}) } => Some(Tuple6(y1, y2, y3, y4, y5, y6)) - case _ => None - } - } - - /** Default unliftable for Tuple7 - * - Unlifts `'{Tuple7(x1, ..., x7)}` into `Some(Tuple7(x1, ..., x7))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple7Unliftable[T1, T2, T3, T4, T5, T6, T7](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6], Unliftable[T7]): Unliftable[Tuple7[T1, T2, T3, T4, T5, T6, T7]] = new { - def fromExpr(x: Expr[Tuple7[T1, T2, T3, T4, T5, T6, T7]]) = x match { - case '{ new Tuple7[T1, T2, T3, T4, T5, T6, T7](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}) } => Some(Tuple7(y1, y2, y3, y4, y5, y6, y7)) - case '{ Tuple7[T1, T2, T3, T4, T5, T6, T7](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}) } => Some(Tuple7(y1, y2, y3, y4, y5, y6, y7)) - case _ => None - } - } - - /** Default unliftable for Tuple8 - * - Unlifts `'{Tuple8(x1, ..., x8)}` into `Some(Tuple8(x1, ..., x8))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple8Unliftable[T1, T2, T3, T4, T5, T6, T7, T8](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6], Unliftable[T7], Unliftable[T8]): Unliftable[Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] = new { - def fromExpr(x: Expr[Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]) = x match { - case '{ new Tuple8[T1, T2, T3, T4, T5, T6, T7, T8](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}) } => Some(Tuple8(y1, y2, y3, y4, y5, y6, y7, y8)) - case '{ Tuple8[T1, T2, T3, T4, T5, T6, T7, T8](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}) } => Some(Tuple8(y1, y2, y3, y4, y5, y6, y7, y8)) - case _ => None - } - } - - /** Default unliftable for Tuple9 - * - Unlifts `'{Tuple9(x1, ..., x9)}` into `Some(Tuple9(x1, ..., x9))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple9Unliftable[T1, T2, T3, T4, T5, T6, T7, T8, T9](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6], Unliftable[T7], Unliftable[T8], Unliftable[T9]): Unliftable[Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] = new { - def fromExpr(x: Expr[Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]) = x match { - case '{ new Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}) } => Some(Tuple9(y1, y2, y3, y4, y5, y6, y7, y8, y9)) - case '{ Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}) } => Some(Tuple9(y1, y2, y3, y4, y5, y6, y7, y8, y9)) - case _ => None - } - } - - /** Default unliftable for Tuple10 - * - Unlifts `'{Tuple0(x1, ..., x10)}` into `Some(Tuple0(x1, ..., x10))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple10Unliftable[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6], Unliftable[T7], Unliftable[T8], Unliftable[T9], Unliftable[T10]): Unliftable[Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] = new { - def fromExpr(x: Expr[Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]) = x match { - case '{ new Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}) } => Some(Tuple10(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10)) - case '{ Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}) } => Some(Tuple10(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10)) - case _ => None - } - } - - /** Default unliftable for Tuple11 - * - Unlifts `'{Tuple1(x1, ..., x11)}` into `Some(Tuple1(x1, ..., x11))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple11Unliftable[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6], Unliftable[T7], Unliftable[T8], Unliftable[T9], Unliftable[T10], Unliftable[T11]): Unliftable[Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]] = new { - def fromExpr(x: Expr[Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]]) = x match { - case '{ new Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}) } => Some(Tuple11(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11)) - case '{ Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}) } => Some(Tuple11(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11)) - case _ => None - } - } - - /** Default unliftable for Tuple12 - * - Unlifts `'{Tuple2(x1, ..., x12)}` into `Some(Tuple2(x1, ..., x12))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple12Unliftable[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6], Unliftable[T7], Unliftable[T8], Unliftable[T9], Unliftable[T10], Unliftable[T11], Unliftable[T12]): Unliftable[Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]] = new { - def fromExpr(x: Expr[Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]]) = x match { - case '{ new Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}) } => Some(Tuple12(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12)) - case '{ Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}) } => Some(Tuple12(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12)) - case _ => None - } - } - - /** Default unliftable for Tuple13 - * - Unlifts `'{Tuple3(x1, ..., x13)}` into `Some(Tuple3(x1, ..., x13))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple13Unliftable[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6], Unliftable[T7], Unliftable[T8], Unliftable[T9], Unliftable[T10], Unliftable[T11], Unliftable[T12], Unliftable[T13]): Unliftable[Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]] = new { - def fromExpr(x: Expr[Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]]) = x match { - case '{ new Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}) } => Some(Tuple13(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13)) - case '{ Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}) } => Some(Tuple13(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13)) - case _ => None - } - } - - /** Default unliftable for Tuple14 - * - Unlifts `'{Tuple4(x1, ..., x14)}` into `Some(Tuple4(x1, ..., x14))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple14Unliftable[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6], Unliftable[T7], Unliftable[T8], Unliftable[T9], Unliftable[T10], Unliftable[T11], Unliftable[T12], Unliftable[T13], Unliftable[T14]): Unliftable[Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]] = new { - def fromExpr(x: Expr[Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]]) = x match { - case '{ new Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}) } => Some(Tuple14(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14)) - case '{ Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}) } => Some(Tuple14(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14)) - case _ => None - } - } - - /** Default unliftable for Tuple15 - * - Unlifts `'{Tuple5(x1, ..., x15)}` into `Some(Tuple5(x1, ..., x15))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple15Unliftable[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6], Unliftable[T7], Unliftable[T8], Unliftable[T9], Unliftable[T10], Unliftable[T11], Unliftable[T12], Unliftable[T13], Unliftable[T14], Unliftable[T15]): Unliftable[Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]] = new { - def fromExpr(x: Expr[Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]]) = x match { - case '{ new Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}, ${Unlifted(y15)}) } => Some(Tuple15(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15)) - case '{ Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}, ${Unlifted(y15)}) } => Some(Tuple15(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15)) - case _ => None - } - } - - /** Default unliftable for Tuple16 - * - Unlifts `'{Tuple6(x1, ..., x16)}` into `Some(Tuple6(x1, ..., x16))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple16Unliftable[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6], Unliftable[T7], Unliftable[T8], Unliftable[T9], Unliftable[T10], Unliftable[T11], Unliftable[T12], Unliftable[T13], Unliftable[T14], Unliftable[T15], Unliftable[T16]): Unliftable[Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]] = new { - def fromExpr(x: Expr[Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]]) = x match { - case '{ new Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}, ${Unlifted(y15)}, ${Unlifted(y16)}) } => Some(Tuple16(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16)) - case '{ Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}, ${Unlifted(y15)}, ${Unlifted(y16)}) } => Some(Tuple16(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16)) - case _ => None - } - } - - /** Default unliftable for Tuple17 - * - Unlifts `'{Tuple7(x1, ..., x17)}` into `Some(Tuple7(x1, ..., x17))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple17Unliftable[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6], Unliftable[T7], Unliftable[T8], Unliftable[T9], Unliftable[T10], Unliftable[T11], Unliftable[T12], Unliftable[T13], Unliftable[T14], Unliftable[T15], Unliftable[T16], Unliftable[T17]): Unliftable[Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]] = new { - def fromExpr(x: Expr[Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]]) = x match { - case '{ new Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}, ${Unlifted(y15)}, ${Unlifted(y16)}, ${Unlifted(y17)}) } => Some(Tuple17(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17)) - case '{ Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}, ${Unlifted(y15)}, ${Unlifted(y16)}, ${Unlifted(y17)}) } => Some(Tuple17(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17)) - case _ => None - } - } - - /** Default unliftable for Tuple18 - * - Unlifts `'{Tuple8(x1, ..., x18)}` into `Some(Tuple8(x1, ..., x18))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple18Unliftable[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6], Unliftable[T7], Unliftable[T8], Unliftable[T9], Unliftable[T10], Unliftable[T11], Unliftable[T12], Unliftable[T13], Unliftable[T14], Unliftable[T15], Unliftable[T16], Unliftable[T17], Unliftable[T18]): Unliftable[Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]] = new { - def fromExpr(x: Expr[Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]]) = x match { - case '{ new Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}, ${Unlifted(y15)}, ${Unlifted(y16)}, ${Unlifted(y17)}, ${Unlifted(y18)}) } => Some(Tuple18(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18)) - case '{ Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}, ${Unlifted(y15)}, ${Unlifted(y16)}, ${Unlifted(y17)}, ${Unlifted(y18)}) } => Some(Tuple18(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18)) - case _ => None - } - } - - /** Default unliftable for Tuple19 - * - Unlifts `'{Tuple9(x1, ..., x19)}` into `Some(Tuple9(x1, ..., x19))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple19Unliftable[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6], Unliftable[T7], Unliftable[T8], Unliftable[T9], Unliftable[T10], Unliftable[T11], Unliftable[T12], Unliftable[T13], Unliftable[T14], Unliftable[T15], Unliftable[T16], Unliftable[T17], Unliftable[T18], Unliftable[T19]): Unliftable[Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]] = new { - def fromExpr(x: Expr[Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]]) = x match { - case '{ new Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}, ${Unlifted(y15)}, ${Unlifted(y16)}, ${Unlifted(y17)}, ${Unlifted(y18)}, ${Unlifted(y19)}) } => Some(Tuple19(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19)) - case '{ Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}, ${Unlifted(y15)}, ${Unlifted(y16)}, ${Unlifted(y17)}, ${Unlifted(y18)}, ${Unlifted(y19)}) } => Some(Tuple19(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19)) - case _ => None - } - } - - /** Default unliftable for Tuple20 - * - Unlifts `'{Tuple0(x1, ..., x20)}` into `Some(Tuple0(x1, ..., x20))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple20Unliftable[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6], Unliftable[T7], Unliftable[T8], Unliftable[T9], Unliftable[T10], Unliftable[T11], Unliftable[T12], Unliftable[T13], Unliftable[T14], Unliftable[T15], Unliftable[T16], Unliftable[T17], Unliftable[T18], Unliftable[T19], Unliftable[T20]): Unliftable[Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]] = new { - def fromExpr(x: Expr[Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]]) = x match { - case '{ new Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}, ${Unlifted(y15)}, ${Unlifted(y16)}, ${Unlifted(y17)}, ${Unlifted(y18)}, ${Unlifted(y19)}, ${Unlifted(y20)}) } => Some(Tuple20(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20)) - case '{ Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}, ${Unlifted(y15)}, ${Unlifted(y16)}, ${Unlifted(y17)}, ${Unlifted(y18)}, ${Unlifted(y19)}, ${Unlifted(y20)}) } => Some(Tuple20(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20)) - case _ => None - } - } - - /** Default unliftable for Tuple21 - * - Unlifts `'{Tuple1(x1, ..., x21)}` into `Some(Tuple1(x1, ..., x21))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple21Unliftable[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], Type[T21], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6], Unliftable[T7], Unliftable[T8], Unliftable[T9], Unliftable[T10], Unliftable[T11], Unliftable[T12], Unliftable[T13], Unliftable[T14], Unliftable[T15], Unliftable[T16], Unliftable[T17], Unliftable[T18], Unliftable[T19], Unliftable[T20], Unliftable[T21]): Unliftable[Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]] = new { - def fromExpr(x: Expr[Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]]) = x match { - case '{ new Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}, ${Unlifted(y15)}, ${Unlifted(y16)}, ${Unlifted(y17)}, ${Unlifted(y18)}, ${Unlifted(y19)}, ${Unlifted(y20)}, ${Unlifted(y21)}) } => Some(Tuple21(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20, y21)) - case '{ Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}, ${Unlifted(y15)}, ${Unlifted(y16)}, ${Unlifted(y17)}, ${Unlifted(y18)}, ${Unlifted(y19)}, ${Unlifted(y20)}, ${Unlifted(y21)}) } => Some(Tuple21(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20, y21)) - case _ => None - } - } - - /** Default unliftable for Tuple22 - * - Unlifts `'{Tuple2(x1, ..., x22)}` into `Some(Tuple2(x1, ..., x22))` if all `xi` are unliftable - * - Otherwise unlifts to `None` - */ - given Tuple22Unliftable[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], Type[T21], Type[T22], Unliftable[T1], Unliftable[T2], Unliftable[T3], Unliftable[T4], Unliftable[T5], Unliftable[T6], Unliftable[T7], Unliftable[T8], Unliftable[T9], Unliftable[T10], Unliftable[T11], Unliftable[T12], Unliftable[T13], Unliftable[T14], Unliftable[T15], Unliftable[T16], Unliftable[T17], Unliftable[T18], Unliftable[T19], Unliftable[T20], Unliftable[T21], Unliftable[T22]): Unliftable[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 fromExpr(x: Expr[Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]]) = x match { - case '{ new Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}, ${Unlifted(y15)}, ${Unlifted(y16)}, ${Unlifted(y17)}, ${Unlifted(y18)}, ${Unlifted(y19)}, ${Unlifted(y20)}, ${Unlifted(y21)}, ${Unlifted(y22)}) } => Some(Tuple22(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20, y21, y22)) - case '{ Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](${Unlifted(y1)}, ${Unlifted(y2)}, ${Unlifted(y3)}, ${Unlifted(y4)}, ${Unlifted(y5)}, ${Unlifted(y6)}, ${Unlifted(y7)}, ${Unlifted(y8)}, ${Unlifted(y9)}, ${Unlifted(y10)}, ${Unlifted(y11)}, ${Unlifted(y12)}, ${Unlifted(y13)}, ${Unlifted(y14)}, ${Unlifted(y15)}, ${Unlifted(y16)}, ${Unlifted(y17)}, ${Unlifted(y18)}, ${Unlifted(y19)}, ${Unlifted(y20)}, ${Unlifted(y21)}, ${Unlifted(y22)}) } => Some(Tuple22(y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20, y21, y22)) - case _ => None - } - } - - /** Default unliftable for Seq - * - Unlifts `'{Seq(x1, ..., xn)}` into `Some(Seq(x1, ..., xn))` if all `xi` are unliftable - * - Unlifts sequences that come out of varargs - * - Otherwise unlifts to `None` - */ - given SeqUnliftable[T](using Type[T], Unliftable[T]): Unliftable[Seq[T]] = new { - def fromExpr(x: Expr[Seq[T]]) = x match { - case Varargs(Unlifted(elems)) => Some(elems) - case '{ scala.Seq[T](${Varargs(Unlifted(elems))}: _*) } => Some(elems) - case '{ scala.collection.immutable.Seq[T](${Varargs(Unlifted(elems))}: _*) } => Some(elems) - case '{ ${Unlifted(x)}: List[T] } => Some(x) - case _ => None - } - } - - /** Default unliftable for Nil - * - Unlifts `'{Nil}` into `Some(Nil)` - * - Otherwise unlifts to `None` - */ - given NilUnliftable: Unliftable[Nil.type] = new { - def fromExpr(x: Expr[Nil.type]) = x match { - case '{ scala.Nil } | '{ scala.collection.immutable.Nil } => Some(Nil) - case _ => None - } - } - - /** Default unliftable for List - * - Unlifts `'{List(x1, ..., xn)}` into `Some(List(x1, ..., xn))` if all `xi` are unliftable - * - Unlifts `'{List.empty}` into `Some(Nil)` - * - Unlifts `'{Nil}` into `Some(Nil)` - * - Otherwise unlifts to `None` - */ - given ListUnliftable[T](using Type[T], Unliftable[T]): Unliftable[List[T]] = new { - def fromExpr(x: Expr[List[T]]) = x match { - case '{ scala.List[T](${Varargs(Unlifted(elems))}: _*) } => Some(elems.toList) - case '{ scala.List.empty[T] } => Some(Nil) - case '{ Nil } => Some(Nil) - case '{ scala.collection.immutable.List[T](${Varargs(Unlifted(elems))}: _*) } => Some(elems.toList) - case '{ scala.collection.immutable.List.empty[T] } => Some(Nil) - case _ => None - } - } - - /** Default unliftable for Set - * - Unlifts `'{Set(x1, ..., xn)}` into `Some(Set(x1, ..., xn))` if all `xi` are unliftable - * - Unlifts `'{Set.empty}` into `Some(Set())` - * - Otherwise unlifts to `None` - */ - given SetUnliftable[T](using Type[T], Unliftable[T]): Unliftable[Set[T]] = new { - def fromExpr(x: Expr[Set[T]]) = x match { - case '{ Set[T](${Varargs(Unlifted(elems))}: _*) } => Some(elems.toSet) - case '{ Set.empty[T] } => Some(Set.empty[T]) - case '{ scala.collection.immutable.Set[T](${Varargs(Unlifted(elems))}: _*) } => Some(elems.toSet) - case '{ scala.collection.immutable.Set.empty[T] } => Some(Set.empty[T]) - case _ => None - } - } - - /** Default unliftable for Map - * - Unlifts `'{Map(x1, ..., xn)}` into `Some(Map(x1, ..., xn))` if all `xi` are unliftable - * - Unlifts `'{Map.empty}` into `Some(Map())` - * - Otherwise unlifts to `None` - */ - given MapUnliftable[T, U](using Type[T], Type[U], Unliftable[T], Unliftable[U]): Unliftable[Map[T, U]] = new { - def fromExpr(x: Expr[Map[T, U]]) = x match { - case '{ Map[T, U](${Varargs(Unlifted(elems))}: _*) } => Some(elems.toMap) - case '{ Map.empty[T, U] } => Some(Map.empty) - case '{ scala.collection.immutable.Map[T, U](${Varargs(Unlifted(elems))}: _*) } => Some(elems.toMap) - case '{ scala.collection.immutable.Map.empty[T, U] } => Some(Map.empty) - case _ => None - } - } - - /** Default unliftable for Either - * - Unlifts `'{Left(x)}` into `Some(Left(x))` if `x` is unliftable - * - Unlifts `'{Right(x)}` into `Some(Right(x))` if `x` is unliftable - * - Otherwise unlifts to `None` - */ - given EitherUnliftable[L, R](using Type[L], Type[R], Unliftable[L], Unliftable[R]): Unliftable[Either[L, R]] = new { - def fromExpr(x: Expr[Either[L, R]]) = x match { - case '{ $x: Left[L, R] } => x.unlift - case '{ $x: Right[L, R] } => x.unlift - case _ => None - } - } - - /** Default unliftable for Left - * - Unlifts `'{Left(x)}` into `Some(Left(x))` if `x` is unliftable - * - Otherwise unlifts to `None` - */ - given LeftUnliftable[L, R](using Type[L], Type[R], Unliftable[L]): Unliftable[Left[L, R]] = new { - def fromExpr(x: Expr[Left[L, R]]) = x match { - case '{ Left[L, R](${Unlifted(x)}) } => Some(Left(x)) - case _ => None - } - } - - /** Default unliftable for Right - * - Unlifts `'{Right(x)}` into `Some(Right(x))` if `x` is unliftable - * - Otherwise unlifts to `None` - */ - given RightUnliftable[L, R](using Type[L], Type[R], Unliftable[R]): Unliftable[Right[L, R]] = new { - def fromExpr(x: Expr[Right[L, R]]) = x match { - case '{ Right[L, R](${Unlifted(x)}) } => Some(Right(x)) - case _ => None - } - } - -} diff --git a/library/src-non-bootstrapped/scala/quoted/FromExpr.scala b/library/src-non-bootstrapped/scala/quoted/FromExpr.scala new file mode 100644 index 000000000000..a6165d22b130 --- /dev/null +++ b/library/src-non-bootstrapped/scala/quoted/FromExpr.scala @@ -0,0 +1,4 @@ +package scala.quoted + +trait FromExpr[T]: + def unapply(x: Expr[T])(using Quotes): Option[T] diff --git a/library/src-non-bootstrapped/scala/quoted/Unliftable.scala b/library/src-non-bootstrapped/scala/quoted/Unliftable.scala deleted file mode 100644 index 1739c04e9cba..000000000000 --- a/library/src-non-bootstrapped/scala/quoted/Unliftable.scala +++ /dev/null @@ -1,4 +0,0 @@ -package scala.quoted - -trait Unliftable[T]: - def fromExpr(x: Expr[T]): Quotes ?=> Option[T] diff --git a/library/src/scala/quoted/Const.scala b/library/src/scala/quoted/Const.scala index 2ab8fecccffe..2b19792e127d 100644 --- a/library/src/scala/quoted/Const.scala +++ b/library/src/scala/quoted/Const.scala @@ -16,7 +16,7 @@ object Const { * // value: T * ``` * - * To directly unlift an expression `expr: Expr[T]` consider using `expr.unlift`/`expr.unliftOrError` insead. + * To directly unlift an expression `expr: Expr[T]` consider using `expr.value`/`expr.valueOrError` insead. */ def unapply[T](expr: Expr[T])(using Quotes): Option[T] = { import quotes.reflect._ diff --git a/library/src/scala/quoted/Consts.scala b/library/src/scala/quoted/Consts.scala index 8d27c76140e7..5b2708185412 100644 --- a/library/src/scala/quoted/Consts.scala +++ b/library/src/scala/quoted/Consts.scala @@ -15,7 +15,7 @@ object Consts { * } * ``` * - * To directly unlift all expressions in a sequence `exprs: Seq[Expr[T]]` consider using `exprs.map(_.unlift)`/`exprs.map(_.unliftOrError)` insead. + * To directly unlift all expressions in a sequence `exprs: Seq[Expr[T]]` consider using `exprs.map(_.value)`/`exprs.map(_.valueOrError)` insead. */ def unapply[T](exprs: Seq[Expr[T]])(using Quotes): Option[Seq[T]] = exprs.foldRight(Option(List.empty[T])) { (elem, acc) => diff --git a/library/src/scala/quoted/Exprs.scala b/library/src/scala/quoted/Exprs.scala new file mode 100644 index 000000000000..7e71ab411055 --- /dev/null +++ b/library/src/scala/quoted/Exprs.scala @@ -0,0 +1,28 @@ +package scala.quoted + +object Exprs: + + /** Matches literal sequence of literal constant value expressions and return a sequence of values. + * + * Usage: + * ```scala + * inline def sum(args: Int*): Int = ${ sumExpr('args) } + * def sumExpr(argsExpr: Expr[Seq[Int]])(using Quotes): Expr[Int] = argsExpr match + * case Varargs(Exprs(args)) => + * case Varargs(Exprs(args)) => + * // args: Seq[Int] + * ... + * } + * ``` + * To directly get the value of all expressions in a sequence `exprs: Seq[Expr[T]]` consider using `exprs.map(_.value)`/`exprs.map(_.valueOrError)` insead. + */ + def unapply[T](exprs: Seq[Expr[T]])(using FromExpr[T])(using Quotes): Option[Seq[T]] = + val builder = Seq.newBuilder[T] + val iter = exprs.iterator + while iter.hasNext do + iter.next().value match + case Some(value) => builder += value + case _ => return None + Some(builder.result()) + +end Exprs diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index 8c8a324af7a8..c28c6ddeaf2c 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -33,24 +33,27 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => */ def matches(that: Expr[Any]): Boolean - /** Return the unlifted value of this expression. + /** Return the value of this expression. * - * Returns `None` if the expression does not contain a value or contains side effects. + * Returns `None` if the expression does not represent a value or possibly contains side effects. * Otherwise returns the `Some` of the value. */ - def unlift(using Unliftable[T]): Option[T] = - summon[Unliftable[T]].fromExpr(self)(using Quotes.this) + def value(using FromExpr[T]): Option[T] = + given Quotes = Quotes.this + summon[FromExpr[T]].unapply(self) - /** Return the unlifted value of this expression. + /** Return the value of this expression. * - * Emits an error and throws if the expression does not contain a value or contains side effects. + * Emits an error and throws if the expression does not represent a value or possibly contains side effects. * Otherwise returns the value. */ - def unliftOrError(using Unliftable[T]): T = + def valueOrError(using FromExpr[T]): T = + val fromExpr = summon[FromExpr[T]] def reportError = - val msg = s"Expected a known value. \n\nThe value of: ${self.show}\ncould not be unlifted using $unlift" + val msg = s"Expected a known value. \n\nThe value of: ${self.show}\ncould not be extracted using $fromExpr" reflect.report.throwError(msg, self) - summon[Unliftable[T]].fromExpr(self)(using Quotes.this).getOrElse(reportError) + given Quotes = Quotes.this + fromExpr.unapply(self).getOrElse(reportError) end extension diff --git a/library/src/scala/quoted/Unlifted.scala b/library/src/scala/quoted/Unlifted.scala deleted file mode 100644 index 980316ced032..000000000000 --- a/library/src/scala/quoted/Unlifted.scala +++ /dev/null @@ -1,42 +0,0 @@ -package scala.quoted - -/** Value expressions */ -object Unlifted { - - /** Matches expressions containing values and extracts the value. - * - * Usage: - * ``` - * case '{ ... ${expr @ Unlifted(value)}: T ...} => - * // expr: Expr[T] - * // value: T - * ``` - * - * To directly unlift an expression `expr: Expr[T]` consider using `expr.unlift`/`expr.unliftOrError` insead. - */ - def unapply[T](expr: Expr[T])(using Unliftable[T])(using Quotes): Option[T] = - summon[Unliftable[T]].fromExpr(expr) - - /** Matches literal sequence of literal constant value expressions and return a sequence of values. - * - * Usage: - * ```scala - * inline def sum(args: Int*): Int = ${ sumExpr('args) } - * def sumExpr(argsExpr: Expr[Seq[Int]])(using Quotes): Expr[Int] = argsExpr match - * case Varargs(Unlifted(args)) => - * // args: Seq[Int] - * ... - * } - * ``` - * To directly unlift all expressions in a sequence `exprs: Seq[Expr[T]]` consider using `exprs.map(_.unlift)`/`exprs.map(_.unliftOrError)` insead. - */ - def unapply[T](exprs: Seq[Expr[T]])(using Unliftable[T])(using Quotes): Option[Seq[T]] = - val builder = Seq.newBuilder[T] - val iter = exprs.iterator - while iter.hasNext do - iter.next() match - case Unlifted(value) => builder += value - case _ => return None - Some(builder.result()) - -} diff --git a/tests/bench/power-macro/PowerMacro.scala b/tests/bench/power-macro/PowerMacro.scala index 80936d29e69e..9462d2b71afd 100644 --- a/tests/bench/power-macro/PowerMacro.scala +++ b/tests/bench/power-macro/PowerMacro.scala @@ -5,7 +5,7 @@ object PowerMacro { inline def power(inline n: Long, x: Double) = ${ powerCode('n, 'x) } def powerCode(n: Expr[Long], x: Expr[Double])(using Quotes): Expr[Double] = - powerCode(n.unliftOrError, x) + powerCode(n.valueOrError, x) def powerCode(n: Long, x: Expr[Double])(using Quotes): Expr[Double] = if (n == 0) '{1.0} diff --git a/tests/neg-macros/BigFloat/BigFloatFromDigitsImpl_1.scala b/tests/neg-macros/BigFloat/BigFloatFromDigitsImpl_1.scala index eefa9ef9087d..a1ecc31b776e 100644 --- a/tests/neg-macros/BigFloat/BigFloatFromDigitsImpl_1.scala +++ b/tests/neg-macros/BigFloat/BigFloatFromDigitsImpl_1.scala @@ -5,7 +5,7 @@ import scala.quoted._ object BigFloatFromDigitsImpl: def apply(digits: Expr[String])(using Quotes): Expr[BigFloat] = - digits.unlift match + digits.value match case Some(ds) => try val BigFloat(m, e) = BigFloat(ds) diff --git a/tests/neg-macros/BigFloat/BigFloat_1.scala b/tests/neg-macros/BigFloat/BigFloat_1.scala index 54ff41a6e61a..4d256f4394d8 100644 --- a/tests/neg-macros/BigFloat/BigFloat_1.scala +++ b/tests/neg-macros/BigFloat/BigFloat_1.scala @@ -43,8 +43,8 @@ object BigFloat extends App { // Should be in StdLib: - given Liftable[BigInt] with { - def toExpr(x: BigInt) = + given ToExpr[BigInt] with { + def apply(x: BigInt)(using Quotes) = '{BigInt(${Expr(x.toString)})} } } diff --git a/tests/neg-macros/GenericNumLits/EvenFromDigitsImpl_1.scala b/tests/neg-macros/GenericNumLits/EvenFromDigitsImpl_1.scala index 25917e75f5ca..1d2e484daa5d 100644 --- a/tests/neg-macros/GenericNumLits/EvenFromDigitsImpl_1.scala +++ b/tests/neg-macros/GenericNumLits/EvenFromDigitsImpl_1.scala @@ -4,7 +4,7 @@ import scala.quoted._ import Even._ object EvenFromDigitsImpl: - def apply(digits: Expr[String])(using Quotes): Expr[Even] = digits.unlift match { + def apply(digits: Expr[String])(using Quotes): Expr[Even] = digits.value match { case Some(ds) => val ev = try evenFromDigits(ds) diff --git a/tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala b/tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala index 80212dc3106f..6aa873114fa2 100644 --- a/tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala +++ b/tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala @@ -6,10 +6,10 @@ object E { inline def eval[T](inline x: E[T]): T = ${ impl('x) } - def impl[T: Type](x: Expr[E[T]]) (using Quotes): Expr[T] = x.unliftOrError.lift + def impl[T: Type](x: Expr[E[T]]) (using Quotes): Expr[T] = x.valueOrError.lift - implicit def ev1[T: Type]: Unliftable[E[T]] = new Unliftable { - def fromExpr(x: Expr[E[T]]) = x match { + implicit def ev1[T: Type]: FromExpr[E[T]] = new FromExpr { + def unapply(x: Expr[E[T]])(using Quotes) = x match { case '{ I(${Const(n)}) } => Some(I(n).asInstanceOf[E[T]]) case '{ Plus[T](${Value(x)}, ${Value(y)})(using $op) } if op.matches('{Plus2.IPlus}) => Some(Plus(x, y)(using Plus2.IPlus.asInstanceOf[Plus2[T]]).asInstanceOf[E[T]]) case _ => None @@ -17,7 +17,7 @@ object E { } object Value { - def unapply[T](expr: Expr[T])(using Unliftable[T], Quotes): Option[T] = expr.unlift + def unapply[T](expr: Expr[T])(using FromExpr[T], Quotes): Option[T] = expr.value } } diff --git a/tests/neg-macros/inline-option/Macro_1.scala b/tests/neg-macros/inline-option/Macro_1.scala index 5c72f72a80f5..53754d5629ce 100644 --- a/tests/neg-macros/inline-option/Macro_1.scala +++ b/tests/neg-macros/inline-option/Macro_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Macro { - def impl(opt: Expr[Option[Int]]) (using Quotes): Expr[Int] = opt.unliftOrError match { + def impl(opt: Expr[Option[Int]]) (using Quotes): Expr[Int] = opt.valueOrError match { case Some(i) => Expr(i) case None => '{-1} } diff --git a/tests/neg-macros/inline-tuples-1/Macro_1.scala b/tests/neg-macros/inline-tuples-1/Macro_1.scala index ea67c9351426..76ba8fcb0dc0 100644 --- a/tests/neg-macros/inline-tuples-1/Macro_1.scala +++ b/tests/neg-macros/inline-tuples-1/Macro_1.scala @@ -2,26 +2,26 @@ import scala.quoted._ object Macros { - def tup1(tup: Expr[Tuple1[Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup2(tup: Expr[Tuple2[Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup3(tup: Expr[Tuple3[Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup4(tup: Expr[Tuple4[Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup5(tup: Expr[Tuple5[Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup6(tup: Expr[Tuple6[Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup7(tup: Expr[Tuple7[Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup8(tup: Expr[Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup9(tup: Expr[Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup10(tup: Expr[Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup11(tup: Expr[Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup12(tup: Expr[Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup13(tup: Expr[Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup14(tup: Expr[Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup15(tup: Expr[Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup16(tup: Expr[Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup17(tup: Expr[Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup18(tup: Expr[Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup19(tup: Expr[Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup20(tup: Expr[Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup21(tup: Expr[Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup22(tup: Expr[Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup1(tup: Expr[Tuple1[Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup2(tup: Expr[Tuple2[Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup3(tup: Expr[Tuple3[Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup4(tup: Expr[Tuple4[Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup5(tup: Expr[Tuple5[Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup6(tup: Expr[Tuple6[Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup7(tup: Expr[Tuple7[Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup8(tup: Expr[Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup9(tup: Expr[Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup10(tup: Expr[Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup11(tup: Expr[Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup12(tup: Expr[Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup13(tup: Expr[Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup14(tup: Expr[Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup15(tup: Expr[Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup16(tup: Expr[Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup17(tup: Expr[Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup18(tup: Expr[Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup19(tup: Expr[Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup20(tup: Expr[Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup21(tup: Expr[Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup22(tup: Expr[Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) } diff --git a/tests/neg-macros/quote-error-2/Macro_1.scala b/tests/neg-macros/quote-error-2/Macro_1.scala index cf24b02ada36..103780f321a4 100644 --- a/tests/neg-macros/quote-error-2/Macro_1.scala +++ b/tests/neg-macros/quote-error-2/Macro_1.scala @@ -3,7 +3,7 @@ import quoted._ object Macro_1 { inline def foo(inline b: Boolean): Unit = ${ fooImpl('b) } def fooImpl(b: Expr[Boolean])(using Quotes): Expr[Unit] = - '{println(${msg(b.unliftOrError)})} + '{println(${msg(b.valueOrError)})} def msg(b: Boolean)(using Quotes): Expr[String] = if (b) '{"foo(true)"} diff --git a/tests/neg-macros/quote-error/Macro_1.scala b/tests/neg-macros/quote-error/Macro_1.scala index bc5c3042fd64..967257130303 100644 --- a/tests/neg-macros/quote-error/Macro_1.scala +++ b/tests/neg-macros/quote-error/Macro_1.scala @@ -3,6 +3,6 @@ import quoted._ object Macro_1 { inline def foo(inline b: Boolean): Unit = ${fooImpl('b)} def fooImpl(b: Expr[Boolean])(using Quotes) : Expr[Unit] = - if (b.unliftOrError) '{println("foo(true)")} + if (b.valueOrError) '{println("foo(true)")} else { quotes.reflect.report.error("foo cannot be called with false"); '{ ??? } } } diff --git a/tests/neg-macros/quote-exception/Macro_1.scala b/tests/neg-macros/quote-exception/Macro_1.scala index 1ab799afce14..c2d1287aea0f 100644 --- a/tests/neg-macros/quote-exception/Macro_1.scala +++ b/tests/neg-macros/quote-exception/Macro_1.scala @@ -3,6 +3,6 @@ import quoted._ object Macro_1 { inline def foo(inline b: Boolean): Unit = ${fooImpl('b)} def fooImpl(b: Expr[Boolean]) (using Quotes): Expr[Unit] = - if (b.unliftOrError) '{println("foo(true)")} + if (b.valueOrError) '{println("foo(true)")} else ??? } diff --git a/tests/neg-macros/quote-whitebox/Macro_1.scala b/tests/neg-macros/quote-whitebox/Macro_1.scala index 995d9c9870f0..273e755426a2 100644 --- a/tests/neg-macros/quote-whitebox/Macro_1.scala +++ b/tests/neg-macros/quote-whitebox/Macro_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Macros { transparent inline def defaultOf(inline str: String): Any = ${ defaultOfImpl('str) } - def defaultOfImpl(str: Expr[String]) (using Quotes): Expr[Any] = str.unliftOrError match { + def defaultOfImpl(str: Expr[String]) (using Quotes): Expr[Any] = str.valueOrError match { case "int" => '{1} case "string" => '{"a"} } diff --git a/tests/neg-macros/reflect-inline/assert_1.scala b/tests/neg-macros/reflect-inline/assert_1.scala index 139818b8547e..32abbfe3ea17 100644 --- a/tests/neg-macros/reflect-inline/assert_1.scala +++ b/tests/neg-macros/reflect-inline/assert_1.scala @@ -5,6 +5,6 @@ object api { ${ stripImpl('x) } private def stripImpl(x: Expr[String])(using Quotes): Expr[String] = - Expr(x.unliftOrError.stripMargin) + Expr(x.valueOrError.stripMargin) } diff --git a/tests/pos-macros/macro-docs.scala b/tests/pos-macros/macro-docs.scala index d31138f38b73..8d741ff07e06 100644 --- a/tests/pos-macros/macro-docs.scala +++ b/tests/pos-macros/macro-docs.scala @@ -1,25 +1,25 @@ import scala.quoted._ -object MacrosMD_Liftable { +object MacrosMD_ToExpr { - given Liftable[Boolean] with { - def toExpr(b: Boolean) = + given ToExpr[Boolean] with { + def apply(b: Boolean)(using Quotes) = if (b) '{ true } else '{ false } } - given Liftable[Int] with { - def toExpr(n: Int) = n match { + given ToExpr[Int] with { + def apply(n: Int)(using Quotes) = n match { case Int.MinValue => '{ Int.MinValue } - case _ if n < 0 => '{ - ${ toExpr(-n) } } + case _ if n < 0 => '{ - ${ apply(-n) } } case 0 => '{ 0 } - case _ if n % 2 == 0 => '{ ${ toExpr(n / 2) } * 2 } - case _ => '{ ${ toExpr(n / 2) } * 2 + 1 } + case _ if n % 2 == 0 => '{ ${ apply(n / 2) } * 2 } + case _ => '{ ${ apply(n / 2) } * 2 + 1 } } } - given [T: Liftable : Type]: Liftable[List[T]] with { - def toExpr(xs: List[T]) = xs match { - case head :: tail => '{ ${ Expr(head) } :: ${ toExpr(tail) } } + given [T: ToExpr : Type]: ToExpr[List[T]] with { + def apply(xs: List[T])(using Quotes) = xs match { + case head :: tail => '{ ${ Expr(head) } :: ${ apply(tail) } } case Nil => '{ Nil: List[T] } } } diff --git a/tests/pos-macros/nil-liftable.scala b/tests/pos-macros/nil-liftable.scala index 40746dcf1e17..490291bc48f7 100644 --- a/tests/pos-macros/nil-liftable.scala +++ b/tests/pos-macros/nil-liftable.scala @@ -1,7 +1,7 @@ import scala.quoted._ class Test: - given NilIsLiftable: Liftable[Nil.type] = new Liftable[Nil.type] { - def toExpr(xs: Nil.type): Quotes ?=> Expr[Nil.type] = + given NilToExpr: ToExpr[Nil.type] with { + def apply(xs: Nil.type)(using Quotes): Expr[Nil.type] = '{ Nil } } diff --git a/tests/pos-macros/power-macro/Macro_1.scala b/tests/pos-macros/power-macro/Macro_1.scala index 7840b3d45204..b809890370d1 100644 --- a/tests/pos-macros/power-macro/Macro_1.scala +++ b/tests/pos-macros/power-macro/Macro_1.scala @@ -6,7 +6,7 @@ object PowerMacro { inline def power(inline n: Long, x: Double) = ${powerCode('n, 'x)} def powerCode(n: Expr[Long], x: Expr[Double]) (using Quotes): Expr[Double] = - powerCode(n.unliftOrError, x) + powerCode(n.valueOrError, x) def powerCode(n: Long, x: Expr[Double])(using Quotes): Expr[Double] = if (n == 0) '{1.0} diff --git a/tests/pos-macros/quote-lift.scala b/tests/pos-macros/quote-lift.scala index 3bb85a133f1d..92dd80ef1941 100644 --- a/tests/pos-macros/quote-lift.scala +++ b/tests/pos-macros/quote-lift.scala @@ -2,12 +2,12 @@ import scala.quoted._ class Test(using Quotes) { - '{ ${implicitly[Liftable[Int]].toExpr(1)} } + '{ ${implicitly[ToExpr[Int]].apply(1)} } { - import Liftable._ + import ToExpr._ - '{ ${summon[Liftable[Int]].toExpr(1)} } + '{ ${summon[ToExpr[Int]].apply(1)} } '{ ${Expr(1)} } diff --git a/tests/pos-macros/quote-liftable-list-2.scala b/tests/pos-macros/quote-liftable-list-2.scala index 8071e5771fee..713b1f771766 100644 --- a/tests/pos-macros/quote-liftable-list-2.scala +++ b/tests/pos-macros/quote-liftable-list-2.scala @@ -2,8 +2,8 @@ import scala.quoted._ object Test { - implicit def ListIsLiftableOr[T: Type, U: Type]: Liftable[List[T | U]] = new { - def toExpr(xs: List[T | U]) = '{ Nil: List[T | U] } + implicit def ListIsToExprOr[T: Type, U: Type]: ToExpr[List[T | U]] = new { + def apply(xs: List[T | U])(using Quotes) = '{ Nil: List[T | U] } } } diff --git a/tests/pos-macros/quote-liftable-list-3.scala b/tests/pos-macros/quote-liftable-list-3.scala index 4118df7d92a7..1aeba2c365c8 100644 --- a/tests/pos-macros/quote-liftable-list-3.scala +++ b/tests/pos-macros/quote-liftable-list-3.scala @@ -2,8 +2,8 @@ import scala.quoted._ object Test { - implicit def ListIsLiftableAnd[T: Type, U: Type]: Liftable[List[T & U]] = new { - def toExpr(xs: List[T & U]) = '{ Nil: List[T & U] } + implicit def ListToExprAnd[T: Type, U: Type]: ToExpr[List[T & U]] = new { + def apply(xs: List[T & U])(using Quotes) = '{ Nil: List[T & U] } } } diff --git a/tests/pos-macros/quote-liftable-list.scala b/tests/pos-macros/quote-liftable-list.scala index c2c4af24341b..a670855fcd07 100644 --- a/tests/pos-macros/quote-liftable-list.scala +++ b/tests/pos-macros/quote-liftable-list.scala @@ -2,8 +2,8 @@ import scala.quoted._ object Test { - implicit def ListIsLiftable[T: Liftable: Type]: Liftable[List[T]] = new { - def toExpr(xs: List[T]) = '{ Nil: List[T] } + implicit def ListIsToExpr[T: ToExpr: Type]: ToExpr[List[T]] = new { + def apply(xs: List[T])(using Quotes) = '{ Nil: List[T] } } } diff --git a/tests/pos-macros/quote-liftable.scala b/tests/pos-macros/quote-liftable.scala index d83ddfe5557a..034a13c51f6a 100644 --- a/tests/pos-macros/quote-liftable.scala +++ b/tests/pos-macros/quote-liftable.scala @@ -4,24 +4,24 @@ def test(using Quotes) = { given Quotes = ??? - implicit def IntIsLiftable: Liftable[Int] = new { - def toExpr(n: Int) = n match { + implicit def IntIsToExpr: ToExpr[Int] = new { + def apply(n: Int)(using Quotes) = n match { case Int.MinValue => '{Int.MinValue} - case _ if n < 0 => '{- ${toExpr(n)}} + case _ if n < 0 => '{- ${apply(n)}} case 0 => '{0} - case _ if n % 2 == 0 => '{ ${toExpr(n / 2)} * 2 } - case _ => '{ ${toExpr(n / 2)} * 2 + 1 } + case _ if n % 2 == 0 => '{ ${apply(n / 2)} * 2 } + case _ => '{ ${apply(n / 2)} * 2 + 1 } } } - implicit def BooleanIsLiftable: Liftable[Boolean] = new { - implicit def toExpr(b: Boolean) = + implicit def BooleanToExpr: ToExpr[Boolean] = new { + implicit def apply(b: Boolean)(using Quotes) = if (b) '{true} else '{false} } - implicit def ListIsLiftable[T: Liftable: Type]: Liftable[List[T]] = new { - def toExpr(xs: List[T]) = xs match { - case x :: xs1 => '{ ${ Expr(x) } :: ${ toExpr(xs1) } } + implicit def ListToExpr[T: ToExpr: Type]: ToExpr[List[T]] = new { + def apply(xs: List[T])(using Quotes) = xs match { + case x :: xs1 => '{ ${ Expr(x) } :: ${ apply(xs1) } } case Nil => '{Nil: List[T]} } } diff --git a/tests/pos-macros/quote-nested-object/Macro_1.scala b/tests/pos-macros/quote-nested-object/Macro_1.scala index f4b1456d4931..6894a8409641 100644 --- a/tests/pos-macros/quote-nested-object/Macro_1.scala +++ b/tests/pos-macros/quote-nested-object/Macro_1.scala @@ -9,7 +9,7 @@ object Macro { inline def plus(inline n: Int, m: Int): Int = ${ plus('n, 'm) } def plus(n: Expr[Int], m: Expr[Int]) (using Quotes): Expr[Int] = - if (n.unliftOrError == 0) m + if (n.valueOrError == 0) m else '{ ${n} + $m } object Implementation2 { @@ -17,7 +17,7 @@ object Macro { inline def plus(inline n: Int, m: Int): Int = ${ plus('n, 'm) } def plus(n: Expr[Int], m: Expr[Int]) (using Quotes): Expr[Int] = - if (n.unliftOrError == 0) m + if (n.valueOrError == 0) m else '{ ${n} + $m } } } diff --git a/tests/pos-macros/quote-whitebox-2/Macro_1.scala b/tests/pos-macros/quote-whitebox-2/Macro_1.scala index 6ba6fc66e5c8..351f6c1216ba 100644 --- a/tests/pos-macros/quote-whitebox-2/Macro_1.scala +++ b/tests/pos-macros/quote-whitebox-2/Macro_1.scala @@ -6,7 +6,7 @@ object Macro { transparent inline def charOrString(inline str: String): Any = ${ impl('str) } def impl(strExpr: Expr[String]) (using Quotes)= - val str = strExpr.unliftOrError + val str = strExpr.valueOrError if (str.length == 1) Expr(str.charAt(0)) else Expr(str) } diff --git a/tests/pos-staging/quote-0.scala b/tests/pos-staging/quote-0.scala index f27198d2d1b4..e999bf127a02 100644 --- a/tests/pos-staging/quote-0.scala +++ b/tests/pos-staging/quote-0.scala @@ -16,7 +16,7 @@ object Macros { inline def power(inline n: Int, x: Double) = ${ powerCode('n, 'x) } def powerCode(n: Expr[Int], x: Expr[Double]) (using Quotes): Expr[Double] = - powerCode(n.unliftOrError, x) + powerCode(n.valueOrError, x) def powerCode(n: Int, x: Expr[Double])(using Quotes): Expr[Double] = if (n == 0) '{1.0} diff --git a/tests/run-macros/BigFloat/BigFloatFromDigitsImpl_1.scala b/tests/run-macros/BigFloat/BigFloatFromDigitsImpl_1.scala index 50016a5df4cb..d77cf6334f2f 100644 --- a/tests/run-macros/BigFloat/BigFloatFromDigitsImpl_1.scala +++ b/tests/run-macros/BigFloat/BigFloatFromDigitsImpl_1.scala @@ -5,7 +5,7 @@ import scala.quoted._ object BigFloatFromDigitsImpl: def apply(digits: Expr[String])(using Quotes): Expr[BigFloat] = - digits.unlift match + digits.value match case Some(ds) => try val BigFloat(m, e) = BigFloat(ds) diff --git a/tests/run-macros/BigFloat/BigFloat_1.scala b/tests/run-macros/BigFloat/BigFloat_1.scala index 54ff41a6e61a..4d256f4394d8 100644 --- a/tests/run-macros/BigFloat/BigFloat_1.scala +++ b/tests/run-macros/BigFloat/BigFloat_1.scala @@ -43,8 +43,8 @@ object BigFloat extends App { // Should be in StdLib: - given Liftable[BigInt] with { - def toExpr(x: BigInt) = + given ToExpr[BigInt] with { + def apply(x: BigInt)(using Quotes) = '{BigInt(${Expr(x.toString)})} } } diff --git a/tests/run-macros/enum-nat-macro/Macros_2.scala b/tests/run-macros/enum-nat-macro/Macros_2.scala index 66b05be034fe..19339ef403e8 100644 --- a/tests/run-macros/enum-nat-macro/Macros_2.scala +++ b/tests/run-macros/enum-nat-macro/Macros_2.scala @@ -25,6 +25,6 @@ import Nat._ case 0 => acc case n => inner[Succ[N]](n - 1, '{Succ($acc)}) - val i = int.unliftOrError + val i = int.valueOrError require(i >= 0) inner[Zero.type](i, '{Zero}) diff --git a/tests/run-macros/expr-map-3/Macro_1.scala b/tests/run-macros/expr-map-3/Macro_1.scala index 5eb4e70aa794..4ca27b8ace5e 100644 --- a/tests/run-macros/expr-map-3/Macro_1.scala +++ b/tests/run-macros/expr-map-3/Macro_1.scala @@ -9,7 +9,7 @@ private def stringRewriter(e: Expr[Any])(using Quotes): Expr[Any] = private object StringRewriter extends ExprMap { def transform[T](e: Expr[T])(using Type[T])(using Quotes): Expr[T] = e match - case '{ ${Unlifted(s)}: String } => + case '{ ${Expr(s)}: String } => // checkIfValid(s) val s2: String & T = s Expr(s2) diff --git a/tests/run-macros/flops-rewrite-2/Macro_1.scala b/tests/run-macros/flops-rewrite-2/Macro_1.scala index fe4d5a9436ac..8c6a0f49ecc0 100644 --- a/tests/run-macros/flops-rewrite-2/Macro_1.scala +++ b/tests/run-macros/flops-rewrite-2/Macro_1.scala @@ -12,14 +12,14 @@ private def rewriteMacro[T: Type](x: Expr[T])(using Quotes): Expr[T] = { postTransform = List( Transformation[Int] { case '{ plus($x, $y) } => - (x.unlift, y.unlift) match { + (x.value, y.value) match { case (Some(0), _) => y case (Some(a), Some(b)) => Expr(a + b) case (_, Some(_)) => '{ $y + $x } case _ => '{ $x + $y } } case '{ times($x, $y) } => - (x.unlift, y.unlift) match { + (x.value, y.value) match { case (Some(0), _) => '{0} case (Some(1), _) => y case (Some(a), Some(b)) => Expr(a * b) diff --git a/tests/run-macros/flops-rewrite-3/Macro_1.scala b/tests/run-macros/flops-rewrite-3/Macro_1.scala index 71910eba5932..406b0af22c82 100644 --- a/tests/run-macros/flops-rewrite-3/Macro_1.scala +++ b/tests/run-macros/flops-rewrite-3/Macro_1.scala @@ -11,14 +11,14 @@ private def rewriteMacro[T: Type](x: Expr[T])(using Quotes): Expr[T] = { val rewriter = Rewriter().withFixPoint.withPost( Transformation.safe[Int] { case '{ plus($x, $y) } => - (x.unlift, y.unlift) match { + (x.value, y.value) match { case (Some(0), _) => y case (Some(a), Some(b)) => Expr(a + b) case (_, Some(_)) => '{ $y + $x } case _ => '{ $x + $y } } case '{ times($x, $y) } => - (x.unlift, y.unlift) match { + (x.value, y.value) match { case (Some(0), _) => '{0} case (Some(1), _) => y case (Some(a), Some(b)) => Expr(a * b) 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 eefeb60a4388..726e2d82c8a3 100644 --- a/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala +++ b/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala @@ -44,7 +44,7 @@ object TypeToolbox { inline def fieldIn[T](inline mem: String): String = ${fieldInImpl[T]('mem)} private def fieldInImpl[T: Type](mem: Expr[String])(using Quotes) : Expr[String] = { import quotes.reflect._ - val field = TypeTree.of[T].symbol.field(mem.unliftOrError) + val field = TypeTree.of[T].symbol.field(mem.valueOrError) Expr(if field.isNoSymbol then "" else field.name) } @@ -58,7 +58,7 @@ object TypeToolbox { inline def methodIn[T](inline mem: String): Seq[String] = ${methodInImpl[T]('mem)} private def methodInImpl[T: Type](mem: Expr[String])(using Quotes) : Expr[Seq[String]] = { import quotes.reflect._ - Expr(TypeTree.of[T].symbol.classMethod(mem.unliftOrError).map(_.name)) + Expr(TypeTree.of[T].symbol.classMethod(mem.valueOrError).map(_.name)) } inline def methodsIn[T]: Seq[String] = ${methodsInImpl[T]} @@ -70,7 +70,7 @@ object TypeToolbox { inline def method[T](inline mem: String): Seq[String] = ${methodImpl[T]('mem)} private def methodImpl[T: Type](mem: Expr[String])(using Quotes) : Expr[Seq[String]] = { import quotes.reflect._ - Expr(TypeTree.of[T].symbol.method(mem.unliftOrError).map(_.name)) + Expr(TypeTree.of[T].symbol.method(mem.valueOrError).map(_.name)) } inline def methods[T]: Seq[String] = ${methodsImpl[T]} diff --git a/tests/run-macros/i4734/Macro_1.scala b/tests/run-macros/i4734/Macro_1.scala index a938536e7cf5..e9cca32ca0ce 100644 --- a/tests/run-macros/i4734/Macro_1.scala +++ b/tests/run-macros/i4734/Macro_1.scala @@ -6,7 +6,7 @@ object Macros { ${ unrolledForeachImpl('seq, 'f, 'unrollSize) } def unrolledForeachImpl(seq: Expr[IndexedSeq[Int]], f: Expr[Int => Unit], unrollSizeExpr: Expr[Int]) (using Quotes): Expr[Unit] = - unrolledForeachImpl(seq, f, unrollSizeExpr.unliftOrError) + unrolledForeachImpl(seq, f, unrollSizeExpr.valueOrError) def unrolledForeachImpl(seq: Expr[IndexedSeq[Int]], f: Expr[Int => Unit], unrollSize: Int)(using Quotes): Expr[Unit] = '{ val size = ($seq).length diff --git a/tests/run-macros/i4735/Macro_1.scala b/tests/run-macros/i4735/Macro_1.scala index 5182b9dc41cd..482652a37192 100644 --- a/tests/run-macros/i4735/Macro_1.scala +++ b/tests/run-macros/i4735/Macro_1.scala @@ -14,7 +14,7 @@ object Macro { while (i < size) { println(" start loop") ${ - for (j <- new UnrolledRange(0, unrollSize.unliftOrError)) '{ + for (j <- new UnrolledRange(0, unrollSize.valueOrError)) '{ val element = ($seq)(i + ${Expr(j)}) ${Expr.betaReduce('{$f(element)})} // or `($f)(element)` if `f` should not be inlined } diff --git a/tests/run-macros/i4803/Macro_1.scala b/tests/run-macros/i4803/Macro_1.scala index f0c7ed23b235..3e4c6e58cf8e 100644 --- a/tests/run-macros/i4803/Macro_1.scala +++ b/tests/run-macros/i4803/Macro_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ object PowerMacro { def powerCode(x: Expr[Double], n: Expr[Long]) (using Quotes): Expr[Double] = - powerCode(x, n.unliftOrError) + powerCode(x, n.valueOrError) def powerCode(x: Expr[Double], n: Long) (using Quotes): Expr[Double] = if (n == 0) '{1.0} diff --git a/tests/run-macros/i4803b/Macro_1.scala b/tests/run-macros/i4803b/Macro_1.scala index 58c9d90ef338..b205c6d3047c 100644 --- a/tests/run-macros/i4803b/Macro_1.scala +++ b/tests/run-macros/i4803b/Macro_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ object PowerMacro { def powerCode(x: Expr[Double], n: Expr[Long]) (using Quotes): Expr[Double] = - powerCode(x, n.unliftOrError) + powerCode(x, n.valueOrError) def powerCode(x: Expr[Double], n: Long) (using Quotes): Expr[Double] = if (n == 0) '{1.0} diff --git a/tests/run-macros/i4803c/Macro_1.scala b/tests/run-macros/i4803c/Macro_1.scala index a583db7a52ba..26fe7f71bf7b 100644 --- a/tests/run-macros/i4803c/Macro_1.scala +++ b/tests/run-macros/i4803c/Macro_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ object PowerMacro { def powerCode(x: Expr[Double], n: Expr[Long]) (using Quotes): Expr[Double] = - powerCode(x, n.unliftOrError) + powerCode(x, n.valueOrError) def powerCode(x: Expr[Double], n: Long) (using Quotes): Expr[Double] = if (n == 0) '{1.0} diff --git a/tests/run-macros/i5188a/Macro_1.scala b/tests/run-macros/i5188a/Macro_1.scala index b44b7c3d919e..58a51d476312 100644 --- a/tests/run-macros/i5188a/Macro_1.scala +++ b/tests/run-macros/i5188a/Macro_1.scala @@ -2,5 +2,5 @@ import scala.quoted._ object Lib { inline def sum(inline args: Int*): Int = ${ impl('args) } - def impl(args: Expr[Seq[Int]]) (using Quotes): Expr[Int] = Expr(args.unliftOrError.sum) + def impl(args: Expr[Seq[Int]]) (using Quotes): Expr[Int] = Expr(args.valueOrError.sum) } diff --git a/tests/run-macros/i6201/macro_1.scala b/tests/run-macros/i6201/macro_1.scala index ff68c1eb9fc1..9dd1bc6a9fe9 100644 --- a/tests/run-macros/i6201/macro_1.scala +++ b/tests/run-macros/i6201/macro_1.scala @@ -4,10 +4,10 @@ extension (inline x: String) inline def strip: String = ${ stripImpl('x) } def stripImpl(x: Expr[String])(using Quotes) : Expr[String] = - Expr(x.unliftOrError.stripMargin) + Expr(x.valueOrError.stripMargin) inline def isHello(inline x: String): Boolean = ${ isHelloImpl('x) } def isHelloImpl(x: Expr[String])(using Quotes) : Expr[Boolean] = - if (x.unliftOrError == "hello") Expr(true) else Expr(false) + if (x.valueOrError == "hello") Expr(true) else Expr(false) diff --git a/tests/run-macros/i6765-c/Macro_1.scala b/tests/run-macros/i6765-c/Macro_1.scala index 87c26e55b7d7..d8f3d3baf7bb 100644 --- a/tests/run-macros/i6765-c/Macro_1.scala +++ b/tests/run-macros/i6765-c/Macro_1.scala @@ -3,6 +3,6 @@ import scala.quoted._ inline def foo(inline n: Int) = ${fooImpl('n)} def fooImpl(n: Expr[Int])(using Quotes) = { - val res = Expr.ofList(List.tabulate(n.unliftOrError)(i => Expr("#" + i))) + val res = Expr.ofList(List.tabulate(n.valueOrError)(i => Expr("#" + i))) '{ ${Expr(res.show)} + "\n" + $res.toString + "\n" } } diff --git a/tests/run-macros/i7964/Macro_1.scala b/tests/run-macros/i7964/Macro_1.scala index a630efca35b3..c2054c4372b6 100644 --- a/tests/run-macros/i7964/Macro_1.scala +++ b/tests/run-macros/i7964/Macro_1.scala @@ -1,6 +1,6 @@ import scala.quoted._ -enum Num { // TODO derive a quoted.Unliftable +enum Num { // TODO derive a quoted.FromExpr case One case Two } diff --git a/tests/run-macros/i8671/Macro_1.scala b/tests/run-macros/i8671/Macro_1.scala index 8ce8b4b7973d..21adda3e15e8 100644 --- a/tests/run-macros/i8671/Macro_1.scala +++ b/tests/run-macros/i8671/Macro_1.scala @@ -13,11 +13,11 @@ object FileName { def createFileName(fileName: Expr[String])(using Quotes): Expr[FileName] = import quotes.reflect.report - fileName.unlift match { + fileName.value match { case Some(s) => fileNameFromString(s) match { case Right(fn) => - '{FileName.unsafe(${Expr(fn.name)})} // Or `Expr(fn)` if there is a `Liftable[FileName]` + '{FileName.unsafe(${Expr(fn.name)})} // Or `Expr(fn)` if there is a `ToExpr[FileName]` case Left(_) => report.throwError(s"$s is not a valid file name! It must not contain a /", fileName) } diff --git a/tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala b/tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala index 8a60903682b4..d88b2e53f2c7 100644 --- a/tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala +++ b/tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala @@ -7,10 +7,10 @@ object E { inline def eval[T](inline x: E[T]): T = ${ impl('x) } def impl[T: Type](expr: Expr[E[T]]) (using Quotes): Expr[T] = - expr.unliftOrError.lift + expr.valueOrError.lift - implicit def ev1[T: Type]: Unliftable[E[T]] = new Unliftable { // TODO use type class derivation - def fromExpr(x: Expr[E[T]]) = (x match { + implicit def ev1[T: Type]: FromExpr[E[T]] = new FromExpr { // TODO use type class derivation + def unapply(x: Expr[E[T]])(using Quotes) = (x match { case '{ I(${Const(n)}) } => Some(I(n)) case '{ D(${Const(n)}) } => Some(D(n)) case '{ Plus[Int](${Value(x)}, ${Value(y)})(using $op) } => Some(Plus(x, y)(using Plus2.IPlus)) @@ -22,7 +22,7 @@ object E { } object Value { - def unapply[T](expr: Expr[T])(using Unliftable[T], Quotes): Option[T] = expr.unlift + def unapply[T](expr: Expr[T])(using FromExpr[T], Quotes): Option[T] = expr.value } } diff --git a/tests/run-macros/inline-option/Macro_1.scala b/tests/run-macros/inline-option/Macro_1.scala index ba6e799257e3..4656859286ac 100644 --- a/tests/run-macros/inline-option/Macro_1.scala +++ b/tests/run-macros/inline-option/Macro_1.scala @@ -3,11 +3,11 @@ import scala.quoted._ object Macros { - def impl(opt: Expr[Option[Int]]) (using Quotes): Expr[Int] = opt.unliftOrError match { + def impl(opt: Expr[Option[Int]]) (using Quotes): Expr[Int] = opt.valueOrError match { case Some(i) => Expr(i) case None => '{-1} } - def impl2(opt: Expr[Option[Option[Int]]]) (using Quotes): Expr[Int] = impl(Expr(opt.unliftOrError.flatten)) + def impl2(opt: Expr[Option[Option[Int]]]) (using Quotes): Expr[Int] = impl(Expr(opt.valueOrError.flatten)) } diff --git a/tests/run-macros/inline-tuples-1/Macro_1.scala b/tests/run-macros/inline-tuples-1/Macro_1.scala index ea67c9351426..76ba8fcb0dc0 100644 --- a/tests/run-macros/inline-tuples-1/Macro_1.scala +++ b/tests/run-macros/inline-tuples-1/Macro_1.scala @@ -2,26 +2,26 @@ import scala.quoted._ object Macros { - def tup1(tup: Expr[Tuple1[Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup2(tup: Expr[Tuple2[Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup3(tup: Expr[Tuple3[Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup4(tup: Expr[Tuple4[Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup5(tup: Expr[Tuple5[Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup6(tup: Expr[Tuple6[Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup7(tup: Expr[Tuple7[Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup8(tup: Expr[Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup9(tup: Expr[Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup10(tup: Expr[Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup11(tup: Expr[Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup12(tup: Expr[Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup13(tup: Expr[Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup14(tup: Expr[Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup15(tup: Expr[Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup16(tup: Expr[Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup17(tup: Expr[Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup18(tup: Expr[Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup19(tup: Expr[Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup20(tup: Expr[Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup21(tup: Expr[Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) - def tup22(tup: Expr[Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup1(tup: Expr[Tuple1[Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup2(tup: Expr[Tuple2[Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup3(tup: Expr[Tuple3[Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup4(tup: Expr[Tuple4[Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup5(tup: Expr[Tuple5[Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup6(tup: Expr[Tuple6[Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup7(tup: Expr[Tuple7[Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup8(tup: Expr[Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup9(tup: Expr[Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup10(tup: Expr[Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup11(tup: Expr[Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup12(tup: Expr[Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup13(tup: Expr[Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup14(tup: Expr[Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup15(tup: Expr[Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup16(tup: Expr[Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup17(tup: Expr[Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup18(tup: Expr[Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup19(tup: Expr[Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup20(tup: Expr[Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup21(tup: Expr[Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) + def tup22(tup: Expr[Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError.productIterator.map(_.asInstanceOf[Int]).sum) } diff --git a/tests/run-macros/inline-tuples-2/Macro_1.scala b/tests/run-macros/inline-tuples-2/Macro_1.scala index 586df3c1a1cf..6cbd8d929df4 100644 --- a/tests/run-macros/inline-tuples-2/Macro_1.scala +++ b/tests/run-macros/inline-tuples-2/Macro_1.scala @@ -3,8 +3,8 @@ import scala.quoted._ object Macros { - def impl(tup: Expr[Tuple1[Int]]) (using Quotes): Expr[Int] = Expr(tup.unliftOrError._1) + def impl(tup: Expr[Tuple1[Int]]) (using Quotes): Expr[Int] = Expr(tup.valueOrError._1) - def impl2(tup: Expr[Tuple1[Tuple1[Int]]]) (using Quotes): Expr[Int] = impl(Expr(tup.unliftOrError._1)) + def impl2(tup: Expr[Tuple1[Tuple1[Int]]]) (using Quotes): Expr[Int] = impl(Expr(tup.valueOrError._1)) } diff --git a/tests/run-macros/inline-varargs-1/Macro_1.scala b/tests/run-macros/inline-varargs-1/Macro_1.scala index b65d5544d429..3dcd8b211931 100644 --- a/tests/run-macros/inline-varargs-1/Macro_1.scala +++ b/tests/run-macros/inline-varargs-1/Macro_1.scala @@ -2,5 +2,5 @@ import scala.quoted._ object Macros { - def sum(nums: Expr[Int]*) (using Quotes): Expr[Int] = Expr(nums.map(_.unliftOrError).sum) + def sum(nums: Expr[Int]*) (using Quotes): Expr[Int] = Expr(nums.map(_.valueOrError).sum) } diff --git a/tests/run-macros/power-macro/Macro_1.scala b/tests/run-macros/power-macro/Macro_1.scala index 6395040475a4..98b288fe6838 100644 --- a/tests/run-macros/power-macro/Macro_1.scala +++ b/tests/run-macros/power-macro/Macro_1.scala @@ -4,7 +4,7 @@ import scala.quoted._ inline def power(x: Double, inline n: Int) = ${ powerCode1('x, 'n) } private def powerCode1(using Quotes)(x: Expr[Double], n: Expr[Int]): Expr[Double] = - powerCode(x, n.unliftOrError) + powerCode(x, n.valueOrError) private def powerCode(using Quotes)(x: Expr[Double], n: Int): Expr[Double] = if (n == 0) Expr(1.0) diff --git a/tests/run-macros/quote-and-splice/Macros_1.scala b/tests/run-macros/quote-and-splice/Macros_1.scala index 0646f53854f0..ea94b51d5365 100644 --- a/tests/run-macros/quote-and-splice/Macros_1.scala +++ b/tests/run-macros/quote-and-splice/Macros_1.scala @@ -6,7 +6,7 @@ object Macros { def macro1Impl (using Quotes)= '{3} inline def macro2(inline p: Boolean) = ${ macro2Impl('p) } - def macro2Impl(p: Expr[Boolean]) (using Quotes)= if (p.unliftOrError) '{3} else '{4} + def macro2Impl(p: Expr[Boolean]) (using Quotes)= if (p.valueOrError) '{3} else '{4} inline def macro3(n: Int) = ${ macro3Impl('n) } def macro3Impl(p: Expr[Int]) (using Quotes)= '{ 2 + $p } @@ -20,7 +20,7 @@ object Macros { inline def power(inline n: Int, x: Double) = ${ powerCode('n, 'x) } def powerCode(n: Expr[Int], x: Expr[Double]) (using Quotes): Expr[Double] = - powerCode(n.unliftOrError, x) + powerCode(n.valueOrError, x) def powerCode(n: Int, x: Expr[Double]) (using Quotes): Expr[Double] = if (n == 0) '{1.0} diff --git a/tests/run-macros/quote-matcher-power/Macro_1.scala b/tests/run-macros/quote-matcher-power/Macro_1.scala index 25b5834cd331..32780c456e37 100644 --- a/tests/run-macros/quote-matcher-power/Macro_1.scala +++ b/tests/run-macros/quote-matcher-power/Macro_1.scala @@ -4,7 +4,7 @@ import scala.quoted._ object Macros { def power_s(x: Expr[Double], n: Expr[Int]) (using Quotes): Expr[Double] = - power_s(x, n.unliftOrError) + power_s(x, n.valueOrError) def power_s(x: Expr[Double], n: Int) (using Quotes): Expr[Double] = if (n == 0) '{1.0} diff --git a/tests/run-macros/quote-matcher-string-interpolator-2/quoted_1.scala b/tests/run-macros/quote-matcher-string-interpolator-2/quoted_1.scala index ce276260446f..8660cdc7575b 100644 --- a/tests/run-macros/quote-matcher-string-interpolator-2/quoted_1.scala +++ b/tests/run-macros/quote-matcher-string-interpolator-2/quoted_1.scala @@ -9,8 +9,8 @@ object Macros { private def impl(self: Expr[StringContext], args: Expr[Seq[String]])(using Quotes): Expr[String] = { (self, args) match { case ('{ StringContext(${Varargs(parts)}: _*) }, Varargs(args1)) => - val strParts = parts.map(_.unliftOrError.reverse) - val strArgs = args1.map(_.unliftOrError) + val strParts = parts.map(_.valueOrError.reverse) + val strArgs = args1.map(_.valueOrError) Expr(StringContext(strParts: _*).s(strArgs: _*)) case _ => ??? } diff --git a/tests/run-macros/quote-simple-macro/quoted_1.scala b/tests/run-macros/quote-simple-macro/quoted_1.scala index abb42b8c09c7..0bc43021a8a6 100644 --- a/tests/run-macros/quote-simple-macro/quoted_1.scala +++ b/tests/run-macros/quote-simple-macro/quoted_1.scala @@ -2,5 +2,5 @@ import scala.quoted._ object Macros { inline def foo(inline i: Int, dummy: Int, j: Int): Int = ${ bar('i, 'j) } - def bar(x: Expr[Int], y: Expr[Int]) (using Quotes): Expr[Int] = '{ ${Expr(x.unliftOrError)} + $y } + def bar(x: Expr[Int], y: Expr[Int]) (using Quotes): Expr[Int] = '{ ${Expr(x.valueOrError)} + $y } } diff --git a/tests/run-macros/quote-unrolled-foreach/quoted_1.scala b/tests/run-macros/quote-unrolled-foreach/quoted_1.scala index 0f217201b8d0..b218f135fe9f 100644 --- a/tests/run-macros/quote-unrolled-foreach/quoted_1.scala +++ b/tests/run-macros/quote-unrolled-foreach/quoted_1.scala @@ -7,7 +7,7 @@ object Macro { ${unrolledForeachImpl('unrollSize, 'seq, 'f)} private def unrolledForeachImpl(unrollSizeExpr: Expr[Int], seq: Expr[Array[Int]], f: Expr[Int => Unit]) (using Quotes): Expr[Unit] = - unrolledForeachImpl(unrollSizeExpr.unliftOrError, seq, f) + unrolledForeachImpl(unrollSizeExpr.valueOrError, seq, f) private def unrolledForeachImpl(unrollSize: Int, seq: Expr[Array[Int]], f: Expr[Int => Unit])(using Quotes): Expr[Unit] = '{ val size = $seq.length diff --git a/tests/run-macros/quote-whitebox/Macro_1.scala b/tests/run-macros/quote-whitebox/Macro_1.scala index 995d9c9870f0..273e755426a2 100644 --- a/tests/run-macros/quote-whitebox/Macro_1.scala +++ b/tests/run-macros/quote-whitebox/Macro_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Macros { transparent inline def defaultOf(inline str: String): Any = ${ defaultOfImpl('str) } - def defaultOfImpl(str: Expr[String]) (using Quotes): Expr[Any] = str.unliftOrError match { + def defaultOfImpl(str: Expr[String]) (using Quotes): Expr[Any] = str.valueOrError match { case "int" => '{1} case "string" => '{"a"} } diff --git a/tests/run-macros/quoted-expr-block/quoted_1.scala b/tests/run-macros/quoted-expr-block/quoted_1.scala index 6ffacf315399..d392ef9b29dc 100644 --- a/tests/run-macros/quoted-expr-block/quoted_1.scala +++ b/tests/run-macros/quoted-expr-block/quoted_1.scala @@ -5,5 +5,5 @@ inline def replicate(inline times: Int, code: => Any) = ${replicateImpl('times, private def replicateImpl(times: Expr[Int], code: Expr[Any]) (using Quotes)= { @annotation.tailrec def loop(n: Int, accum: List[Expr[Any]]): List[Expr[Any]] = if (n > 0) loop(n - 1, code :: accum) else accum - Expr.block(loop(times.unliftOrError, Nil), '{}) + Expr.block(loop(times.valueOrError, Nil), '{}) } diff --git a/tests/run-macros/quoted-matching-docs-2/Macro_1.scala b/tests/run-macros/quoted-matching-docs-2/Macro_1.scala index 6e46ec391876..cb8ceb59fe66 100644 --- a/tests/run-macros/quoted-matching-docs-2/Macro_1.scala +++ b/tests/run-macros/quoted-matching-docs-2/Macro_1.scala @@ -25,7 +25,7 @@ private def sumExpr(args1: Seq[Expr[Int]])(using Quotes): Expr[Int] = { case arg => Seq(arg) } val args2 = args1.flatMap(flatSumArgs) - val staticSum: Int = args2.map(_.unlift.getOrElse(0)).sum - val dynamicSum: Seq[Expr[Int]] = args2.filter(_.unlift.isEmpty) + val staticSum: Int = args2.map(_.value.getOrElse(0)).sum + val dynamicSum: Seq[Expr[Int]] = args2.filter(_.value.isEmpty) dynamicSum.foldLeft(Expr(staticSum))((acc, arg) => '{ $acc + $arg }) } diff --git a/tests/run-macros/quoted-matching-docs/Macro_1.scala b/tests/run-macros/quoted-matching-docs/Macro_1.scala index 1ff0871bb396..bd4423e99fd8 100644 --- a/tests/run-macros/quoted-matching-docs/Macro_1.scala +++ b/tests/run-macros/quoted-matching-docs/Macro_1.scala @@ -12,8 +12,8 @@ private def sumExpr(argsExpr: Expr[Seq[Int]])(using Quotes) : Expr[Int] = { case Varargs(Consts(args)) => // args is of type Seq[Int] Expr(args.sum) // precompute result of sum case Varargs(argExprs) => // argExprs is of type Seq[Expr[Int]] - val staticSum: Int = argExprs.map(_.unlift.getOrElse(0)).sum - val dynamicSum: Seq[Expr[Int]] = argExprs.filter(_.unlift.isEmpty) + val staticSum: Int = argExprs.map(_.value.getOrElse(0)).sum + val dynamicSum: Seq[Expr[Int]] = argExprs.filter(_.value.isEmpty) dynamicSum.foldLeft(Expr(staticSum))((acc, arg) => '{ $acc + $arg }) case _ => '{ $argsExpr.sum } diff --git a/tests/run-macros/quoted-pattern-open-expr-simple-eval/Macro_1.scala b/tests/run-macros/quoted-pattern-open-expr-simple-eval/Macro_1.scala index 4d041dbd9c3f..096911841e9a 100644 --- a/tests/run-macros/quoted-pattern-open-expr-simple-eval/Macro_1.scala +++ b/tests/run-macros/quoted-pattern-open-expr-simple-eval/Macro_1.scala @@ -7,7 +7,7 @@ private def evalExpr(using Quotes)(e: Expr[Int]): Expr[Int] = { case '{ val y: Int = $x; $body(y): Int } => evalExpr(Expr.betaReduce('{$body(${evalExpr(x)})})) case '{ ($x: Int) * ($y: Int) } => - (x.unlift, y.unlift) match + (x.value, y.value) match case (Some(a), Some(b)) => Expr(a * b) case _ => e case _ => e diff --git a/tests/run-macros/reflect-inline/assert_1.scala b/tests/run-macros/reflect-inline/assert_1.scala index 87ca1e499e58..d6b115529ea6 100644 --- a/tests/run-macros/reflect-inline/assert_1.scala +++ b/tests/run-macros/reflect-inline/assert_1.scala @@ -5,12 +5,12 @@ object api { ${ stripImpl('x) } private def stripImpl(x: Expr[String])(using Quotes): Expr[String] = - Expr(augmentString(x.unliftOrError).stripMargin) + Expr(augmentString(x.valueOrError).stripMargin) inline def typeChecks(inline x: String): Boolean = ${ typeChecksImpl('{scala.compiletime.testing.typeChecks(x)}) } private def typeChecksImpl(b: Expr[Boolean])(using Quotes): Expr[Boolean] = { - if (b.unliftOrError) Expr(true) else Expr(false) + if (b.valueOrError) Expr(true) else Expr(false) } } diff --git a/tests/run-macros/tasty-interpolation-1/Macro.scala b/tests/run-macros/tasty-interpolation-1/Macro.scala index 180d7687abdb..e8be14e75d97 100644 --- a/tests/run-macros/tasty-interpolation-1/Macro.scala +++ b/tests/run-macros/tasty-interpolation-1/Macro.scala @@ -76,8 +76,8 @@ abstract class MacroStringInterpolator[T] { } } - protected implicit def StringContextIsLiftable: Liftable[StringContext] = new Liftable[StringContext] { - def toExpr(strCtx: StringContext) = '{StringContext(${Expr(strCtx.parts.toSeq)}: _*)} + protected implicit def StringContextIsToExpr: ToExpr[StringContext] = new ToExpr[StringContext] { + def apply(strCtx: StringContext)(using Quotes) = '{StringContext(${Expr(strCtx.parts.toSeq)}: _*)} } protected class NotStaticlyKnownError(msg: String, expr: Expr[Any]) extends Exception(msg) diff --git a/tests/run-macros/tasty-string-interpolation-reporter-test/Macros_1.scala b/tests/run-macros/tasty-string-interpolation-reporter-test/Macros_1.scala index a7621efe40dc..509b55acb397 100644 --- a/tests/run-macros/tasty-string-interpolation-reporter-test/Macros_1.scala +++ b/tests/run-macros/tasty-string-interpolation-reporter-test/Macros_1.scala @@ -52,7 +52,7 @@ object Macro { private def fooCore(parts: Seq[Expr[String]], args: Seq[Expr[Any]], reporter: Reporter)(using Quotes): Expr[String] = { for ((part, idx) <- parts.zipWithIndex) { - val v = part.unliftOrError + val v = part.valueOrError if (v.contains("#")) reporter.errorOnPart("Cannot use #", idx) } diff --git a/tests/run-macros/xml-interpolation-3/XmlQuote_1.scala b/tests/run-macros/xml-interpolation-3/XmlQuote_1.scala index d96d63972613..0dae5174e017 100644 --- a/tests/run-macros/xml-interpolation-3/XmlQuote_1.scala +++ b/tests/run-macros/xml-interpolation-3/XmlQuote_1.scala @@ -12,7 +12,7 @@ object XmlQuote { } def impl(receiver: Expr[StringContext], args: Expr[Seq[Any]])(using Quotes): Expr[Xml] = { - val string = receiver.unliftOrError.parts.mkString("??") + val string = receiver.valueOrError.parts.mkString("??") '{new Xml(${Expr(string)}, $args.toList)} } } diff --git a/tests/run-macros/xml-interpolation-5/Macros_1.scala b/tests/run-macros/xml-interpolation-5/Macros_1.scala index 14eba46b3e1a..889696b0335f 100644 --- a/tests/run-macros/xml-interpolation-5/Macros_1.scala +++ b/tests/run-macros/xml-interpolation-5/Macros_1.scala @@ -26,7 +26,7 @@ object XmlQuote { def impl(receiver: Expr[SCOps.StringContext], args: Expr[Seq[Any]])(using Quotes): Expr[Xml] = { val string = receiver match { - case '{ SCOps(${Unlifted(sc)}) } => Expr(sc.parts.mkString("??")) + case '{ SCOps(${Expr(sc)}) } => Expr(sc.parts.mkString("??")) } '{new Xml(${string}, $args.toList)} } diff --git a/tests/run-macros/xml-interpolation-6/Macros_1.scala b/tests/run-macros/xml-interpolation-6/Macros_1.scala index 0810b30058e4..f723a57123c1 100644 --- a/tests/run-macros/xml-interpolation-6/Macros_1.scala +++ b/tests/run-macros/xml-interpolation-6/Macros_1.scala @@ -26,7 +26,7 @@ object XmlQuote { def impl(receiver: Expr[SCOps.StringContext], args: Expr[Seq[Any]])(using Quotes): Expr[Xml] = { val string = receiver match { - case '{ SCOps(${Unlifted(sc)}): SCOps.StringContext } => sc.parts.mkString("??") + case '{ SCOps(${Expr(sc)}): SCOps.StringContext } => sc.parts.mkString("??") } '{new Xml(${Expr(string)}, $args.toList)} } diff --git a/tests/run-macros/xml-interpolation-7/Macros_1.scala b/tests/run-macros/xml-interpolation-7/Macros_1.scala index 19e2b5654898..d41af1bb8d2e 100644 --- a/tests/run-macros/xml-interpolation-7/Macros_1.scala +++ b/tests/run-macros/xml-interpolation-7/Macros_1.scala @@ -26,7 +26,7 @@ object XmlQuote { def impl(receiver: Expr[XMLOps.StringContext], args: Expr[Seq[Any]])(using Quotes): Expr[Xml] = { val string = receiver match { - case '{ XMLOps.xml(${Unlifted(sc)}) } => sc.parts.mkString("??") + case '{ XMLOps.xml(${Expr(sc)}) } => sc.parts.mkString("??") } '{new Xml(${Expr(string)}, $args.toList)} } diff --git a/tests/run-staging/i3847-b.scala b/tests/run-staging/i3847-b.scala index ac64211e8fed..c25b31e36866 100644 --- a/tests/run-staging/i3847-b.scala +++ b/tests/run-staging/i3847-b.scala @@ -3,9 +3,9 @@ import scala.quoted.staging._ import scala.reflect.ClassTag object Arrays { - implicit def ArrayIsLiftable[T: Liftable](implicit t: Type[T], qctx: Quotes): Liftable[Array[List[T]]] = { - new Liftable[Array[List[T]]] { - def toExpr(arr: Array[List[T]]) = '{ + implicit def ArrayIsToExpr[T: ToExpr](implicit t: Type[T], qctx: Quotes): ToExpr[Array[List[T]]] = { + new ToExpr[Array[List[T]]] { + def apply(arr: Array[List[T]])(using Quotes) = '{ new Array[List[T]](${Expr(arr.length)}) // TODO add elements } diff --git a/tests/run-staging/i3847.scala b/tests/run-staging/i3847.scala index 832feee4c943..8d15d1d8d895 100644 --- a/tests/run-staging/i3847.scala +++ b/tests/run-staging/i3847.scala @@ -3,9 +3,9 @@ import scala.quoted.staging._ import scala.reflect.ClassTag 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]) = '{ + implicit def ArrayIsToExpr[T: ToExpr](implicit t: Type[T], ct: Expr[ClassTag[T]]): ToExpr[Array[T]] = { + new ToExpr[Array[T]] { + def apply(arr: Array[T])(using Quotes) = '{ new Array[t.Underlying](${Expr(arr.length)})($ct) // TODO add elements } diff --git a/tests/run-staging/multi-staging.check b/tests/run-staging/multi-staging.check index 027f6b4b6189..5d12306ba4ef 100644 --- a/tests/run-staging/multi-staging.check +++ b/tests/run-staging/multi-staging.check @@ -1,5 +1,5 @@ stage1 code: ((q1: scala.quoted.Quotes) ?=> { val x1: scala.Int = 2 - scala.quoted.runtime.Expr.quote[scala.Int](1.+(scala.quoted.runtime.Expr.nestedSplice[scala.Int](q1)(((evidence$5: scala.quoted.Quotes) ?=> scala.quoted.Expr.apply[scala.Int](x1)(scala.quoted.Liftable.IntLiftable[scala.Int])(evidence$5))))).apply(using q1) + scala.quoted.runtime.Expr.quote[scala.Int](1.+(scala.quoted.runtime.Expr.nestedSplice[scala.Int](q1)(((evidence$5: scala.quoted.Quotes) ?=> scala.quoted.Expr.apply[scala.Int](x1)(scala.quoted.ToExpr.IntToExpr[scala.Int])(evidence$5))))).apply(using q1) }) 3 diff --git a/tests/run-staging/quote-lib.scala b/tests/run-staging/quote-lib.scala index b45e6df2d75c..042fa58c17c7 100644 --- a/tests/run-staging/quote-lib.scala +++ b/tests/run-staging/quote-lib.scala @@ -110,19 +110,19 @@ object Test { package liftable { - import scala.quoted.Liftable + import scala.quoted.ToExpr import scala.reflect.ClassTag object Exprs { implicit class LiftExprOps[T](x: T) extends AnyVal { - def toExpr(using Liftable[T], Quotes): Expr[T] = - summon[Liftable[T]].toExpr(x) + def apply(using ToExpr[T], Quotes): Expr[T] = + summon[ToExpr[T]].apply(x) } } object Units { - implicit def UnitIsLiftable: Liftable[Unit] = new Liftable[Unit] { - def toExpr(x: Unit) = '{} + implicit def UnitIsToExpr: ToExpr[Unit] = new ToExpr[Unit] { + def apply(x: Unit)(using Quotes) = '{} } } @@ -143,14 +143,14 @@ package liftable { object Lists { - implicit class LiftedOps[T: Liftable](list: Expr[List[T]])(implicit t: Type[T]) { + implicit class LiftedOps[T: ToExpr](list: Expr[List[T]])(implicit t: Type[T]) { def foldLeft[U](acc: Expr[U])(f: Expr[(U, T) => U])(implicit u: Type[U], qctx: Quotes): Expr[U] = '{ ($list).foldLeft[U]($acc)($f) } def foreach(f: Expr[T => Unit])(using Quotes): Expr[Unit] = '{ ($list).foreach($f) } } - implicit class UnrolledOps[T: Liftable](list: List[T])(implicit t: Type[T], qctx: Quotes) { + implicit class UnrolledOps[T: ToExpr](list: List[T])(implicit t: Type[T], qctx: Quotes) { def unrolledFoldLeft[U](acc: Expr[U])(f: Expr[(U, T) => U])(implicit u: Type[U]): Expr[U] = list match { case x :: xs => xs.unrolledFoldLeft('{ ($f).apply($acc, ${Expr(x)}) })(f) case Nil => acc diff --git a/tests/run-staging/quote-unrolled-foreach.scala b/tests/run-staging/quote-unrolled-foreach.scala index b697c99846c6..0c66ba34fa3c 100644 --- a/tests/run-staging/quote-unrolled-foreach.scala +++ b/tests/run-staging/quote-unrolled-foreach.scala @@ -117,8 +117,8 @@ object Test { } } - implicit object ArrayIntIsLiftable extends Liftable[Array[Int]] { - override def toExpr(x: Array[Int]) = '{ + implicit object ArrayIntIsToExpr extends ToExpr[Array[Int]] { + override def apply(x: Array[Int])(using Quotes) = '{ val array = new Array[Int](${Expr(x.length)}) ${ foreachInRange(0, x.length)(i => '{ array(${Expr(i)}) = ${Expr(x(i))}}) } array diff --git a/tests/run-staging/quote-valueof-list.scala b/tests/run-staging/quote-valueof-list.scala index 102c1d593060..8ae1534188b9 100644 --- a/tests/run-staging/quote-valueof-list.scala +++ b/tests/run-staging/quote-valueof-list.scala @@ -7,8 +7,8 @@ object Test { def main(args: Array[String]): Unit = withQuotes { - implicit def UnliftableInt: Unliftable[Int] = new { - def fromExpr(n: Expr[Int]) = n match { + implicit def FromExprInt: FromExpr[Int] = new { + def unapply(n: Expr[Int])(using Quotes) = n match { case '{ 0 } => Some(0) case '{ 1 } => Some(1) case '{ 2 } => Some(1) @@ -16,45 +16,45 @@ object Test { } } - implicit def UnliftableBoolean: Unliftable[Boolean] = new Unliftable[Boolean] { - def fromExpr(b: Expr[Boolean]) = b match { + implicit def FromExprBoolean: FromExpr[Boolean] = new { + def unapply(b: Expr[Boolean])(using Quotes) = b match { case '{ true } => Some(true) case '{ false } => Some(false) case _ => None } } - implicit def UnliftableList[T: Unliftable: Type]: Unliftable[List[T]] = new { - def fromExpr(xs: Expr[List[T]]) = (xs: Expr[Any]) match { + implicit def FromExprList[T: FromExpr: Type]: FromExpr[List[T]] = new { + def unapply(xs: Expr[List[T]])(using Quotes) = (xs: Expr[Any]) match { case '{ ($xs1: List[T]).::($x) } => - for { head <- x.unlift; tail <- xs1.unlift } + for { head <- x.value; tail <- xs1.value } yield head :: tail case '{ Nil } => Some(Nil) case _ => None } } - implicit def UnliftableOption[T: Unliftable: Type]: Unliftable[Option[T]] = new { - def fromExpr(expr: Expr[Option[T]]) = expr match { - case '{ Some[T]($x) } => for (v <- x.unlift) yield Some(v) + implicit def FromExprOption[T: FromExpr: Type]: FromExpr[Option[T]] = new { + def unapply(expr: Expr[Option[T]])(using Quotes) = expr match { + case '{ Some[T]($x) } => for (v <- x.value) yield Some(v) case '{ None } => Some(None) case _ => None } } - println(('{0}).unlift) - println(('{1}).unlift) - println(('{ println(); 1 }).unlift) + println(('{0}).value) + println(('{1}).value) + println(('{ println(); 1 }).value) - println(('{true}).unlift) - println(('{false}).unlift) - println(('{ println(); false }).unlift) + println(('{true}).value) + println(('{false}).value) + println(('{ println(); false }).value) - println(('{ Nil }: Expr[List[String]]).unlift) - println(('{ "a" :: "b" :: "c" :: Nil }: Expr[List[String]]).unlift) + println(('{ Nil }: Expr[List[String]]).value) + println(('{ "a" :: "b" :: "c" :: Nil }: Expr[List[String]]).value) - println(('{ None }: Expr[Option[Int]]).unlift) - println(('{ Some("abc") }: Expr[Option[String]]).unlift) + println(('{ None }: Expr[Option[Int]]).value) + println(('{ Some("abc") }: Expr[Option[String]]).value) } } diff --git a/tests/run-staging/quote-valueof.scala b/tests/run-staging/quote-valueof.scala index 01e41069226e..d4276228b3fc 100644 --- a/tests/run-staging/quote-valueof.scala +++ b/tests/run-staging/quote-valueof.scala @@ -6,16 +6,16 @@ object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) def main(args: Array[String]): Unit = withQuotes { - println(('{true}).unlift) - println(('{1}).unlift) - println(('{2: Byte}).unlift) - println(('{3: Short}).unlift) - println(('{4}).unlift) - println(('{5L}).unlift) - println(('{true}).unlift) - println(('{3.56f}).unlift) - println(('{34.5d}).unlift) - println(('{ 'a' }).unlift) - println(('{"abc"}).unlift) + println(('{true}).value) + println(('{1}).value) + println(('{2: Byte}).value) + println(('{3: Short}).value) + println(('{4}).value) + println(('{5L}).value) + println(('{true}).value) + println(('{3.56f}).value) + println(('{34.5d}).value) + println(('{ 'a' }).value) + println(('{"abc"}).value) } } diff --git a/tests/run-staging/shonan-hmm-simple.scala b/tests/run-staging/shonan-hmm-simple.scala index 5b40b7d878e7..31cb274b34f2 100644 --- a/tests/run-staging/shonan-hmm-simple.scala +++ b/tests/run-staging/shonan-hmm-simple.scala @@ -32,15 +32,15 @@ class RingComplex[U](u: Ring[U]) extends Ring[Complex[U]]: val mul = (x, y) => Complex(u.sub(u.mul(x.re, y.re), u.mul(x.im, y.im)), u.add(u.mul(x.re, y.im), u.mul(x.im, y.re))) sealed trait PV[T]: - def expr(using Liftable[T], Quotes): Expr[T] + def expr(using ToExpr[T], Quotes): Expr[T] case class Sta[T](x: T) extends PV[T]: - def expr(using Liftable[T], Quotes): Expr[T] = Expr(x) + def expr(using ToExpr[T], Quotes): Expr[T] = Expr(x) case class Dyn[T](x: Expr[T]) extends PV[T]: - def expr(using Liftable[T], Quotes): Expr[T] = x + def expr(using ToExpr[T], Quotes): Expr[T] = x -class RingPV[U: Liftable](u: Ring[U], eu: Ring[Expr[U]])(using Quotes) extends Ring[PV[U]]: +class RingPV[U: ToExpr](u: Ring[U], eu: Ring[Expr[U]])(using Quotes) extends Ring[PV[U]]: val zero: PV[U] = Sta(u.zero) val one: PV[U] = Sta(u.one) val add = (x: PV[U], y: PV[U]) => (x, y) match @@ -63,8 +63,8 @@ class RingPV[U: Liftable](u: Ring[U], eu: Ring[Expr[U]])(using Quotes) extends R case class Complex[T](re: T, im: T) object Complex: - implicit def isLiftable[T: Type: Liftable]: Liftable[Complex[T]] = new Liftable[Complex[T]]: - def toExpr(comp: Complex[T]) = '{Complex(${Expr(comp.re)}, ${Expr(comp.im)})} + implicit def isToExpr[T: Type: ToExpr]: ToExpr[Complex[T]] = new ToExpr[Complex[T]]: + def apply(comp: Complex[T])(using Quotes) = '{Complex(${Expr(comp.re)}, ${Expr(comp.im)})} case class Vec[Idx, T](size: Idx, get: Idx => T): def map[U](f: T => U): Vec[Idx, U] = Vec(size, i => f(get(i))) @@ -172,7 +172,7 @@ object Test: println(run(resCode4).apply(arr1)) println() - import Complex.isLiftable + import Complex.isToExpr def blasExprComplexPVInt(using Quotes) = new Blas1[Int, Complex[PV[Int]]](new RingComplex(new RingPV[Int](new RingInt, new RingIntExpr)), new StaticVecOps) def resCode5(using Quotes): Expr[Array[Complex[Int]] => Complex[Int]] = '{ arr => diff --git a/tests/run-staging/shonan-hmm/Complex.scala b/tests/run-staging/shonan-hmm/Complex.scala index 48f39314b59a..cf71da66da1b 100644 --- a/tests/run-staging/shonan-hmm/Complex.scala +++ b/tests/run-staging/shonan-hmm/Complex.scala @@ -4,8 +4,8 @@ import scala.quoted._ case class Complex[T](re: T, im: T) object Complex { - implicit def complexIsLiftable[T: Type: Liftable]: Liftable[Complex[T]] = new Liftable { - def toExpr(c: Complex[T]) = '{ Complex(${Expr(c.re)}, ${Expr(c.im)}) } + implicit def complexIsToExpr[T: Type: ToExpr]: ToExpr[Complex[T]] = new ToExpr { + def apply(c: Complex[T])(using Quotes) = '{ Complex(${Expr(c.re)}, ${Expr(c.im)}) } } def of_complex_expr(x: Expr[Complex[Int]])(using Quotes): Complex[Expr[Int]] = Complex('{$x.re}, '{$x.im}) diff --git a/tests/run-staging/shonan-hmm/Lifters.scala b/tests/run-staging/shonan-hmm/Lifters.scala index 94381a84aff0..bfe71c6cd750 100644 --- a/tests/run-staging/shonan-hmm/Lifters.scala +++ b/tests/run-staging/shonan-hmm/Lifters.scala @@ -9,21 +9,21 @@ object Lifters { '{ ClassTag(${Expr(summon[ClassTag[T]].runtimeClass.asInstanceOf[Class[T]])}) } } - implicit def ArrayIsLiftable[T : Type: ClassTag](implicit l: Liftable[T]): Liftable[Array[T]] = new Liftable[Array[T]] { - def toExpr(x: Array[T]) = '{ + implicit def ArrayIsToExpr[T : Type: ClassTag](implicit l: ToExpr[T]): ToExpr[Array[T]] = new ToExpr[Array[T]] { + def apply(x: Array[T])(using Quotes) = '{ val array = new Array[T](${Expr(x.length)})(${implicitly[Expr[ClassTag[T]]]}) ${initArray(x, 'array)} } } - implicit def IntArrayIsLiftable: Liftable[Array[Int]] = new Liftable[Array[Int]] { - def toExpr(x: Array[Int]) = '{ + implicit def IntArrayIsToExpr: ToExpr[Array[Int]] = new ToExpr[Array[Int]] { + def apply(x: Array[Int])(using Quotes) = '{ val array = new Array[Int](${Expr(x.length)}) ${initArray(x, 'array)} } } - private def initArray[T : Liftable : Type](arr: Array[T], array: Expr[Array[T]])(using Quotes): Expr[Array[T]] = { + private def initArray[T : ToExpr : Type](arr: Array[T], array: Expr[Array[T]])(using Quotes): Expr[Array[T]] = { UnrolledExpr.block( arr.zipWithIndex.map { case (x, i) => '{ $array(${Expr(i)}) = ${Expr(x)} } diff --git a/tests/run-staging/shonan-hmm/PV.scala b/tests/run-staging/shonan-hmm/PV.scala index a68158f9f5ed..46e56b7d4ab7 100644 --- a/tests/run-staging/shonan-hmm/PV.scala +++ b/tests/run-staging/shonan-hmm/PV.scala @@ -8,10 +8,10 @@ case class Sta[T](x: T) extends PV[T] case class Dyn[T](x: Expr[T]) extends PV[T] object Dyn: - def apply[T: Liftable](x: T)(using Quotes): Dyn[T] = Dyn(Expr(x)) + def apply[T: ToExpr](x: T)(using Quotes): Dyn[T] = Dyn(Expr(x)) object Dyns { - def dyn[T: Liftable](pv: PV[T])(using Quotes): Expr[T] = pv match { + def dyn[T: ToExpr](pv: PV[T])(using Quotes): Expr[T] = pv match { case Sta(x) => Expr(x) case Dyn(x) => x } diff --git a/tests/run-staging/shonan-hmm/Ring.scala b/tests/run-staging/shonan-hmm/Ring.scala index 594a4b60cc84..4b88955d7d6e 100644 --- a/tests/run-staging/shonan-hmm/Ring.scala +++ b/tests/run-staging/shonan-hmm/Ring.scala @@ -43,7 +43,7 @@ case class RingComplex[U](u: Ring[U]) extends Ring[Complex[U]] { override def toString(): String = s"RingComplex($u)" } -case class RingPV[U: Liftable](staRing: Ring[U], dynRing: Ring[Expr[U]])(using Quotes) extends Ring[PV[U]] { +case class RingPV[U: ToExpr](staRing: Ring[U], dynRing: Ring[Expr[U]])(using Quotes) extends Ring[PV[U]] { type T = PV[U] val dyn = Dyns.dyn[U] diff --git a/tests/run-staging/shonan-hmm/UnrolledExpr.scala b/tests/run-staging/shonan-hmm/UnrolledExpr.scala index 773508e2f0a7..eb52ac72b8a0 100644 --- a/tests/run-staging/shonan-hmm/UnrolledExpr.scala +++ b/tests/run-staging/shonan-hmm/UnrolledExpr.scala @@ -3,7 +3,7 @@ import Lifters._ object UnrolledExpr { - implicit class Unrolled[T: Liftable, It <: Iterable[T]](xs: It) { + implicit class Unrolled[T: ToExpr, It <: Iterable[T]](xs: It) { def unrolled: UnrolledExpr[T, It] = new UnrolledExpr(xs) } @@ -18,7 +18,7 @@ object UnrolledExpr { } -class UnrolledExpr[T: Liftable, It <: Iterable[T]](xs: It) { +class UnrolledExpr[T: ToExpr, It <: Iterable[T]](xs: It) { import UnrolledExpr._ def foreach[U](f: T => Expr[U])(using Quotes): Expr[Unit] = block(xs.map(f), '{}) diff --git a/tests/run-staging/shonan-hmm/VecROp.scala b/tests/run-staging/shonan-hmm/VecROp.scala index b4f1eaf3e902..1182df2479f4 100644 --- a/tests/run-staging/shonan-hmm/VecROp.scala +++ b/tests/run-staging/shonan-hmm/VecROp.scala @@ -45,7 +45,7 @@ class VecRStaDim[T: Type](r: Ring[T])(using Quotes) extends VecROp[Int, T, Expr[ override def toString(): String = s"VecRStaDim($r)" } -class VecRStaDyn[T : Type : Liftable](r: Ring[PV[T]])(using Quotes) extends VecROp[PV[Int], PV[T], Expr[Unit]] { +class VecRStaDyn[T : Type : ToExpr](r: Ring[PV[T]])(using Quotes) extends VecROp[PV[Int], PV[T], Expr[Unit]] { val VSta: VecROp[Int, PV[T], Expr[Unit]] = new VecRStaDim(r) val VDyn = new VecRDyn val dyn = Dyns.dyn[T] diff --git a/tests/run-staging/tasty-extractors-constants-2/quoted_1.scala b/tests/run-staging/tasty-extractors-constants-2/quoted_1.scala index 70d6aed1f832..8ac1aacb46f1 100644 --- a/tests/run-staging/tasty-extractors-constants-2/quoted_1.scala +++ b/tests/run-staging/tasty-extractors-constants-2/quoted_1.scala @@ -41,7 +41,7 @@ object Macros { } def power(n: Expr[Int], x: Expr[Double])(using Quotes): Expr[Double] = { - n.unlift match { + n.value match { case Some(n1) => powerCode(n1, x) case _ => '{ dynamicPower($n, $x) } } diff --git a/tests/run-staging/unliftables.scala b/tests/run-staging/unliftables.scala index 893817fa0885..68e6137ae610 100644 --- a/tests/run-staging/unliftables.scala +++ b/tests/run-staging/unliftables.scala @@ -3,102 +3,102 @@ import scala.quoted.staging._ object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) def main(args: Array[String]): Unit = withQuotes { - println('{ true }.unlift) - println('{ false }.unlift) + println('{ true }.value) + println('{ false }.value) println() - println('{ 3: Byte }.unlift) - println('{ 4: Short }.unlift) - println('{ 5: Int }.unlift) - println('{ 6: Long }.unlift) - println('{ 7.1: Float }.unlift) - println('{ 8.1: Double }.unlift) + println('{ 3: Byte }.value) + println('{ 4: Short }.value) + println('{ 5: Int }.value) + println('{ 6: Long }.value) + println('{ 7.1: Float }.value) + println('{ 8.1: Double }.value) println() - println(('{ 4 }: Expr[4]).unlift) - println(('{ 5L }: Expr[5L]).unlift) - println(('{ 8.2 }: Expr[8.2]).unlift) + println(('{ 4 }: Expr[4]).value) + println(('{ 5L }: Expr[5L]).value) + println(('{ 8.2 }: Expr[8.2]).value) println() - println('{ 'a' }.unlift) - println(('{ 'b' }: Expr['b']).unlift) - println('{ "abc" }.unlift) - println(('{ "def" }: Expr["def"]).unlift) + println('{ 'a' }.value) + println(('{ 'b' }: Expr['b']).value) + println('{ "abc" }.value) + println(('{ "def" }: Expr["def"]).value) println() // TODO? - // println('{ classOf[String] }.unlift) - // println('{ ClassTag(classOf[String]) }.unlift) + // println('{ classOf[String] }.value) + // println('{ ClassTag(classOf[String]) }.value) // println() - println('{ Seq(1, 2, 3) }.unlift) - println('{ scala.Seq(1, 2, 3) }.unlift) - println('{ scala.collection.immutable.Seq(1, 2, 3) }.unlift) + println('{ Seq(1, 2, 3) }.value) + println('{ scala.Seq(1, 2, 3) }.value) + println('{ scala.collection.immutable.Seq(1, 2, 3) }.value) println() - println('{ Nil }.unlift) - println('{ scala.Nil }.unlift) - println('{ scala.collection.immutable.Nil }.unlift) - println('{ List.empty[Int] }.unlift) - println('{ scala.List.empty[Int] }.unlift) - println('{ scala.collection.immutable.List.empty[Int] }.unlift) - println('{ List(1, 2, 3) }.unlift) - println('{ scala.List(1, 2, 3) }.unlift) - println('{ scala.collection.immutable.List(1, 2, 3) }.unlift) + println('{ Nil }.value) + println('{ scala.Nil }.value) + println('{ scala.collection.immutable.Nil }.value) + println('{ List.empty[Int] }.value) + println('{ scala.List.empty[Int] }.value) + println('{ scala.collection.immutable.List.empty[Int] }.value) + println('{ List(1, 2, 3) }.value) + println('{ scala.List(1, 2, 3) }.value) + println('{ scala.collection.immutable.List(1, 2, 3) }.value) println() - println('{ Set.empty[Int] }.unlift) - println('{ scala.collection.immutable.Set.empty[Int] }.unlift) - println('{ Set(1, 2, 3) }.unlift) - println('{ scala.collection.immutable.Set(1, 2, 3) }.unlift) + println('{ Set.empty[Int] }.value) + println('{ scala.collection.immutable.Set.empty[Int] }.value) + println('{ Set(1, 2, 3) }.value) + println('{ scala.collection.immutable.Set(1, 2, 3) }.value) println() - println('{ Map(1 -> 2, 2 -> 3) }.unlift) - println('{ scala.collection.immutable.Map(1 -> 2, 2 -> 3) }.unlift) + println('{ Map(1 -> 2, 2 -> 3) }.value) + println('{ scala.collection.immutable.Map(1 -> 2, 2 -> 3) }.value) println() - println('{ None }.unlift) - println('{ Some(3) }.unlift) - println('{ None: Option[Int] }.unlift) - println('{ Some(3): Option[Int] }.unlift) - println('{ Option(3) }.unlift) - println('{ Option[String](null) }.unlift) + println('{ None }.value) + println('{ Some(3) }.value) + println('{ None: Option[Int] }.value) + println('{ Some(3): Option[Int] }.value) + println('{ Option(3) }.value) + println('{ Option[String](null) }.value) println() - println('{ Left(1) }.unlift) - println('{ Right(2) }.unlift) - println('{ Left(3): Either[Int, Int] }.unlift) - println('{ Right(4): Either[Int, Int] }.unlift) + println('{ Left(1) }.value) + println('{ Right(2) }.value) + println('{ Left(3): Either[Int, Int] }.value) + println('{ Right(4): Either[Int, Int] }.value) println() // TODO - // println('{ BigInt("422") }.unlift) - // println('{ BigInt("422", 10) }.unlift) - // println('{ BigInt(1, Array[Byte](10,23)) }.unlift) + // println('{ BigInt("422") }.value) + // println('{ BigInt("422", 10) }.value) + // println('{ BigInt(1, Array[Byte](10,23)) }.value) // ... println() // TODO - // println('{ BigDecimal("422.54") }.unlift) + // println('{ BigDecimal("422.54") }.value) // ... println() - println('{ StringContext("a", "b") }.unlift) + println('{ StringContext("a", "b") }.value) println() - println('{ EmptyTuple }.unlift) - println('{ Tuple1(1) }.unlift) - println('{ (1, 2) }.unlift) - println('{ 1 -> 2 }.unlift) - println('{ (1, 2, 3) }.unlift) - println('{ (1, 2, 3, 4) }.unlift) - println('{ (1, 2, 3, 4, 5) }.unlift) - println('{ (1, 2, 3, 4, 5, 6) }.unlift) - println('{ (1, 2, 3, 4, 5, 6, 7) }.unlift) - println('{ (1, 2, 3, 4, 5, 6, 7, 8) }.unlift) - println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9) }.unlift) - println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) }.unlift) - println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) }.unlift) - println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) }.unlift) - println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13) }.unlift) - println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) }.unlift) - println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) }.unlift) - println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) }.unlift) - println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17) }.unlift) - println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18) }.unlift) - println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19) }.unlift) - println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) }.unlift) - println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21) }.unlift) - println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22) }.unlift) + println('{ EmptyTuple }.value) + println('{ Tuple1(1) }.value) + println('{ (1, 2) }.value) + println('{ 1 -> 2 }.value) + println('{ (1, 2, 3) }.value) + println('{ (1, 2, 3, 4) }.value) + println('{ (1, 2, 3, 4, 5) }.value) + println('{ (1, 2, 3, 4, 5, 6) }.value) + println('{ (1, 2, 3, 4, 5, 6, 7) }.value) + println('{ (1, 2, 3, 4, 5, 6, 7, 8) }.value) + println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9) }.value) + println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) }.value) + println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) }.value) + println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) }.value) + println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13) }.value) + println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) }.value) + println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) }.value) + println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) }.value) + println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17) }.value) + println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18) }.value) + println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19) }.value) + println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) }.value) + println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21) }.value) + println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22) }.value) // TODO - // println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23) }.unlift) - // println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24) }.unlift) - // println('{ (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) }.unlift) + // println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23) }.value) + // println('{ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24) }.value) + // println('{ (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) }.value) } }