@@ -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