Skip to content

Commit 819e0b1

Browse files
Merge pull request #10246 from dotty-staging/encode-quote-pattern-match-directly-on-quote-context
Encode quote pattern matches directly on QuoteContext
2 parents 7b80d8a + 330cc0b commit 819e0b1

File tree

10 files changed

+165
-114
lines changed

10 files changed

+165
-114
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,8 @@ class Definitions {
796796

797797
@tu lazy val QuoteContextClass: ClassSymbol = requiredClass("scala.quoted.QuoteContext")
798798
@tu lazy val QuoteContextInternalClass: ClassSymbol = requiredClass("scala.internal.quoted.QuoteContextInternal")
799+
@tu lazy val QuoteContextInternalClass_ExprMatch: Symbol = QuoteContextInternalClass.requiredMethod("ExprMatch")
800+
@tu lazy val QuoteContextInternalClass_TypeMatch: Symbol = QuoteContextInternalClass.requiredMethod("TypeMatch")
799801

800802
@tu lazy val LiftableModule: Symbol = requiredModule("scala.quoted.Liftable")
801803
@tu lazy val LiftableModule_BooleanLiftable: Symbol = LiftableModule.requiredMethod("BooleanLiftable")
@@ -821,14 +823,6 @@ class Definitions {
821823
@tu lazy val InternalQuotedPatterns_patternTypeAnnot: ClassSymbol = InternalQuotedPatterns.requiredClass("patternType")
822824
@tu lazy val InternalQuotedPatterns_fromAboveAnnot: ClassSymbol = InternalQuotedPatterns.requiredClass("fromAbove")
823825

824-
@tu lazy val InternalQuotedExprModule: Symbol = requiredModule("scala.internal.quoted.Expr")
825-
@tu lazy val InternalQuotedExpr_unapply: Symbol = InternalQuotedExprModule.requiredMethod(nme.unapply)
826-
@tu lazy val InternalQuotedExpr_null: Symbol = InternalQuotedExprModule.requiredMethod(nme.null_)
827-
@tu lazy val InternalQuotedExpr_unit: Symbol = InternalQuotedExprModule.requiredMethod(nme.Unit)
828-
829-
@tu lazy val InternalQuotedTypeModule: Symbol = requiredModule("scala.internal.quoted.Type")
830-
@tu lazy val InternalQuotedType_unapply: Symbol = InternalQuotedTypeModule.requiredMethod(nme.unapply)
831-
832826
@tu lazy val QuotedTypeClass: ClassSymbol = requiredClass("scala.quoted.Type")
833827
@tu lazy val QuotedType_splice: Symbol = QuotedTypeClass.requiredType(tpnme.Underlying)
834828

compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,11 +2639,19 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, scala.intern
26392639
val tree = PickledQuotes.unpickleTypeTree(pickledQuote)(using reflect.rootContext)
26402640
new scala.internal.quoted.Type(tree, hash).asInstanceOf[scala.quoted.Type[T]]
26412641

2642-
def exprMatch(scrutinee: scala.quoted.Expr[Any], pattern: scala.quoted.Expr[Any]): Option[Tuple] =
2643-
treeMatch(scrutinee.unseal(using this), pattern.unseal(using this))
2644-
2645-
def typeMatch(scrutinee: scala.quoted.Type[?], pattern: scala.quoted.Type[?]): Option[Tuple] =
2646-
treeMatch(reflect.TypeTree.of(using scrutinee), reflect.TypeTree.of(using pattern))
2642+
object ExprMatch extends ExprMatchModule:
2643+
def unapply[TypeBindings <: Tuple, Tup <: Tuple](scrutinee: scala.quoted.Expr[Any])(using pattern: scala.quoted.Expr[Any]): Option[Tup] =
2644+
val scrutineeTree = scrutinee.unseal(using QuoteContextImpl.this)
2645+
val patternTree = pattern.unseal(using QuoteContextImpl.this)
2646+
treeMatch(scrutineeTree, patternTree).asInstanceOf[Option[Tup]]
2647+
end ExprMatch
2648+
2649+
object TypeMatch extends TypeMatchModule:
2650+
def unapply[TypeBindings <: Tuple, Tup <: Tuple](scrutinee: scala.quoted.Type[?])(using pattern: scala.quoted.Type[?]): Option[Tup] =
2651+
val scrutineeTree = reflect.TypeTree.of(using scrutinee)
2652+
val patternTree = reflect.TypeTree.of(using pattern)
2653+
treeMatch(scrutineeTree, patternTree).asInstanceOf[Option[Tup]]
2654+
end TypeMatch
26472655

26482656
private def treeMatch(scrutinee: reflect.Tree, pattern: reflect.Tree): Option[Tuple] = {
26492657
import reflect._

compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,14 +458,17 @@ trait QuotesAndSplices {
458458
if splices.isEmpty then ref(defn.EmptyTupleModule.termRef)
459459
else typed(untpd.Tuple(splices.map(x => untpd.TypedSplice(replaceBindingsInTree.transform(x)))).withSpan(quoted.span), patType)
460460

461-
val unapplySym = if (tree.quoted.isTerm) defn.InternalQuotedExpr_unapply else defn.InternalQuotedType_unapply
462461
val quoteClass = if (tree.quoted.isTerm) defn.QuotedExprClass else defn.QuotedTypeClass
463462
val quotedPattern =
464463
if (tree.quoted.isTerm) ref(defn.InternalQuoted_exprQuote.termRef).appliedToType(defn.AnyType).appliedTo(shape).select(nme.apply).appliedTo(qctx)
465464
else ref(defn.QuotedTypeModule_apply.termRef).appliedToTypeTree(shape).select(nme.apply).appliedTo(qctx)
465+
466+
val matchModule = if tree.quoted.isTerm then defn.QuoteContextInternalClass_ExprMatch else defn.QuoteContextInternalClass_TypeMatch
467+
val unapplyFun = qctx.asInstance(defn.QuoteContextInternalClass.typeRef).select(matchModule).select(nme.unapply)
468+
466469
UnApply(
467-
fun = ref(unapplySym.termRef).appliedToTypeTrees(typeBindingsTuple :: TypeTree(patType) :: Nil),
468-
implicits = quotedPattern :: qctx :: Nil,
470+
fun = unapplyFun.appliedToTypeTrees(typeBindingsTuple :: TypeTree(patType) :: Nil),
471+
implicits = quotedPattern :: Nil,
469472
patterns = splicePat :: Nil,
470473
proto = quoteClass.typeRef.appliedTo(replaceBindings(quoted1.tpe) & quotedPt))
471474
}

library/src-bootstrapped/scala/internal/quoted/Expr.scala

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,3 @@ final class Expr[Tree](val tree: Tree, val scopeId: Int) extends scala.quoted.Ex
2929
override def hashCode: Int = tree.hashCode
3030
override def toString: String = "'{ ... }"
3131
}
32-
33-
object Expr {
34-
35-
/** Pattern matches an the scrutineeExpr against the patternExpr and returns a tuple
36-
* with the matched holes if successful.
37-
*
38-
* Examples:
39-
* - `Matcher.unapply('{ f(0, myInt) })('{ f(0, myInt) }, _)`
40-
* will return `Some(())` (where `()` is a tuple of arity 0)
41-
* - `Matcher.unapply('{ f(0, myInt) })('{ f(patternHole[Int], patternHole[Int]) }, _)`
42-
* will return `Some(Tuple2('{0}, '{ myInt }))`
43-
* - `Matcher.unapply('{ f(0, "abc") })('{ f(0, patternHole[Int]) }, _)`
44-
* will return `None` due to the missmatch of types in the hole
45-
*
46-
* Holes:
47-
* - scala.internal.Quoted.patternHole[T]: hole that matches an expression `x` of type `Expr[U]`
48-
* if `U <:< T` and returns `x` as part of the match.
49-
*
50-
* @param scrutineeExpr `Expr[Any]` on which we are pattern matching
51-
* @param patternExpr `Expr[Any]` containing the pattern tree
52-
* @param hasTypeSplices `Boolean` notify if the pattern has type splices
53-
* @param qctx the current QuoteContext
54-
* @return None if it did not match, `Some(tup)` if it matched where `tup` contains `Expr[Ti]``
55-
*/
56-
def unapply[TypeBindings <: Tuple, Tup <: Tuple](scrutineeExpr: scala.quoted.Expr[Any])
57-
(using patternExpr: scala.quoted.Expr[Any], qctx: QuoteContext): Option[Tup] = {
58-
qctx.asInstanceOf[QuoteContextInternal].exprMatch(scrutineeExpr, patternExpr).asInstanceOf[Option[Tup]]
59-
}
60-
61-
}

library/src-bootstrapped/scala/internal/quoted/Type.scala

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,3 @@ final class Type[Tree](val typeTree: Tree, val scopeId: Int) extends scala.quote
2424
override def hashCode: Int = typeTree.hashCode
2525
override def toString: String = "'[ ... ]"
2626
}
27-
28-
object Type {
29-
30-
/** Pattern matches an the scrutineeType against the patternType and returns a tuple
31-
* with the matched holes if successful.
32-
*
33-
* @param scrutineeType `Type[_]` on which we are pattern matching
34-
* @param patternType `Type[_]` containing the pattern tree
35-
* @param hasTypeSplices `Boolean` notify if the pattern has type splices
36-
* @param qctx the current QuoteContext
37-
* @return None if it did not match, `Some(tup)` if it matched where `tup` contains `Type[Ti]``
38-
*/
39-
def unapply[TypeBindings <: Tuple, Tup <: Tuple](scrutineeType: scala.quoted.Type[_])
40-
(using patternType: scala.quoted.Type[_], qctx: QuoteContext): Option[Tup] = {
41-
qctx.asInstanceOf[QuoteContextInternal].typeMatch(scrutineeType, patternType).asInstanceOf[Option[Tup]]
42-
}
43-
44-
}

library/src-bootstrapped/scala/quoted/Expr.scala

Lines changed: 100 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ abstract class Expr[+T] private[scala] {
1818
* ```
1919
*/
2020
final def matches(that: Expr[Any])(using qctx: QuoteContext): Boolean =
21-
!scala.internal.quoted.Expr.unapply[EmptyTuple, EmptyTuple](this)(using that, qctx).isEmpty
21+
val ExprMatch = qctx.asInstanceOf[scala.internal.quoted.QuoteContextInternal].ExprMatch
22+
ExprMatch.unapply[EmptyTuple, EmptyTuple](this)(using that).nonEmpty
2223

2324
/** Checked cast to a `quoted.Expr[U]` */
2425
def cast[U](using tp: scala.quoted.Type[U])(using qctx: QuoteContext): scala.quoted.Expr[U] = asExprOf[U]
@@ -121,57 +122,141 @@ object Expr {
121122
* `'{ ($e1, $e2, ...) }` typed as an `Expr[Tuple]`
122123
*/
123124
def ofTupleFromSeq(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] = {
124-
seq match {
125-
case Seq() =>
126-
'{ Tuple() }
127-
case Seq('{ $x1: t1 }) =>
128-
'{ Tuple1($x1) }
129-
case Seq('{ $x1: t1 }, '{ $x2: t2 }) =>
130-
'{ Tuple2($x1, $x2) }
131-
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }) =>
132-
'{ Tuple3($x1, $x2, $x3) }
125+
seq.size match {
126+
case 0 => '{ Tuple() }
127+
case 1 => ofTupleFromSeq1(seq)
128+
case 2 => ofTupleFromSeq2(seq)
129+
case 3 => ofTupleFromSeq3(seq)
130+
case 4 => ofTupleFromSeq4(seq)
131+
case 5 => ofTupleFromSeq5(seq)
132+
case 6 => ofTupleFromSeq6(seq)
133+
case 7 => ofTupleFromSeq7(seq)
134+
case 8 => ofTupleFromSeq8(seq)
135+
case 9 => ofTupleFromSeq9(seq)
136+
case 10 => ofTupleFromSeq10(seq)
137+
case 11 => ofTupleFromSeq11(seq)
138+
case 12 => ofTupleFromSeq12(seq)
139+
case 13 => ofTupleFromSeq13(seq)
140+
case 14 => ofTupleFromSeq14(seq)
141+
case 15 => ofTupleFromSeq15(seq)
142+
case 16 => ofTupleFromSeq16(seq)
143+
case 17 => ofTupleFromSeq17(seq)
144+
case 18 => ofTupleFromSeq18(seq)
145+
case 19 => ofTupleFromSeq19(seq)
146+
case 20 => ofTupleFromSeq20(seq)
147+
case 21 => ofTupleFromSeq21(seq)
148+
case 22 => ofTupleFromSeq22(seq)
149+
case _ => '{ Tuple.fromIArray(IArray(${Varargs(seq)}: _*)) }
150+
}
151+
}
152+
153+
private def ofTupleFromSeq1(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
154+
seq match
155+
case Seq('{ $x1: t1 }) => '{ Tuple1($x1) }
156+
157+
private def ofTupleFromSeq2(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
158+
seq match
159+
case Seq('{ $x1: t1 }, '{ $x2: t2 }) => '{ Tuple2($x1, $x2) }
160+
161+
private def ofTupleFromSeq3(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
162+
seq match
163+
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }) => '{ Tuple3($x1, $x2, $x3) }
164+
165+
private def ofTupleFromSeq4(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
166+
seq match
133167
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }) =>
134-
'{ Tuple4($x1, $x2, $x3, $x4) }
168+
'{ Tuple4($x1, $x2, $x3, $x4) }
169+
170+
private def ofTupleFromSeq5(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
171+
seq match
135172
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }) =>
136173
'{ Tuple5($x1, $x2, $x3, $x4, $x5) }
174+
175+
private def ofTupleFromSeq6(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
176+
seq match
137177
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }) =>
138178
'{ Tuple6($x1, $x2, $x3, $x4, $x5, $x6) }
179+
180+
private def ofTupleFromSeq7(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
181+
seq match
139182
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }) =>
140183
'{ Tuple7($x1, $x2, $x3, $x4, $x5, $x6, $x7) }
184+
185+
private def ofTupleFromSeq8(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
186+
seq match
141187
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }) =>
142188
'{ Tuple8($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8) }
189+
190+
private def ofTupleFromSeq9(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
191+
seq match
143192
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }) =>
144193
'{ Tuple9($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9) }
194+
195+
private def ofTupleFromSeq10(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
196+
seq match
145197
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }) =>
146198
'{ Tuple10($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10) }
199+
200+
private def ofTupleFromSeq11(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
201+
seq match
147202
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }) =>
148203
'{ Tuple11($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11) }
204+
205+
private def ofTupleFromSeq12(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
206+
seq match
149207
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }) =>
150208
'{ Tuple12($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12) }
209+
210+
private def ofTupleFromSeq13(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
211+
seq match
151212
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }) =>
152213
'{ Tuple13($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13) }
214+
215+
private def ofTupleFromSeq14(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
216+
seq match
153217
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }) =>
154218
'{ Tuple14($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14) }
219+
220+
private def ofTupleFromSeq15(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
221+
seq match
155222
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }, '{ $x15: t15 }) =>
156223
'{ Tuple15($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15) }
224+
225+
private def ofTupleFromSeq16(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
226+
seq match
157227
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }, '{ $x15: t15 }, '{ $x16: t16 }) =>
158228
'{ Tuple16($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16) }
229+
230+
private def ofTupleFromSeq17(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
231+
seq match
159232
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }, '{ $x15: t15 }, '{ $x16: t16 }, '{ $x17: t17 }) =>
160233
'{ Tuple17($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17) }
234+
235+
private def ofTupleFromSeq18(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
236+
seq match
161237
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }, '{ $x15: t15 }, '{ $x16: t16 }, '{ $x17: t17 }, '{ $x18: t18 }) =>
162238
'{ Tuple18($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18) }
239+
240+
private def ofTupleFromSeq19(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
241+
seq match
163242
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }, '{ $x15: t15 }, '{ $x16: t16 }, '{ $x17: t17 }, '{ $x18: t18 }, '{ $x19: t19 }) =>
164243
'{ Tuple19($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19) }
244+
245+
private def ofTupleFromSeq20(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
246+
seq match
165247
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }, '{ $x15: t15 }, '{ $x16: t16 }, '{ $x17: t17 }, '{ $x18: t18 }, '{ $x19: t19 }, '{ $x20: t20 }) =>
166248
'{ Tuple20($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20) }
249+
250+
private def ofTupleFromSeq21(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
251+
seq match
167252
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }, '{ $x15: t15 }, '{ $x16: t16 }, '{ $x17: t17 }, '{ $x18: t18 }, '{ $x19: t19 }, '{ $x20: t20 }, '{ $x21: t21 }) =>
168253
'{ Tuple21($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21) }
254+
255+
private def ofTupleFromSeq22(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] =
256+
seq match
169257
case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }, '{ $x15: t15 }, '{ $x16: t16 }, '{ $x17: t17 }, '{ $x18: t18 }, '{ $x19: t19 }, '{ $x20: t20 }, '{ $x21: t21 }, '{ $x22: t22 }) =>
170258
'{ Tuple22($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21, $x22) }
171-
case _ =>
172-
'{ Tuple.fromIArray(IArray(${Varargs(seq)}: _*)) }
173-
}
174-
}
259+
175260

176261
/** Given a tuple of the form `(Expr[A1], ..., Expr[An])`, outputs a tuple `Expr[(A1, ..., An)]`. */
177262
def ofTuple[T <: Tuple: Tuple.IsMappedBy[Expr]: Type](tup: T)(using qctx: QuoteContext): Expr[Tuple.InverseMap[T, Expr]] = {

0 commit comments

Comments
 (0)