Skip to content

Commit 75de330

Browse files
Merge pull request #7260 from dotty-staging/move-special-quoted-lifters-inot-expr
Add quoted.Expr.{ofSeq, ofList, ofTuple}
2 parents 5f3e895 + 97c37bb commit 75de330

File tree

22 files changed

+119
-119
lines changed

22 files changed

+119
-119
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ object Liftable {
110110

111111
given [T: Type: Liftable] : Liftable[Seq[T]] = new Liftable[Seq[T]] {
112112
def toExpr(xs: Seq[T]): (given QuoteContext) => Expr[Seq[T]] =
113-
xs.map(summon[Liftable[T]].toExpr).toExprOfSeq
113+
Expr.ofSeq(xs.map(summon[Liftable[T]].toExpr))
114114
}
115115

116116
given [T: Type: Liftable] : Liftable[List[T]] = new Liftable[List[T]] {
117117
def toExpr(xs: List[T]): (given QuoteContext) => Expr[List[T]] =
118-
xs.map(summon[Liftable[T]].toExpr).toExprOfList
118+
Expr.ofList(xs.map(summon[Liftable[T]].toExpr))
119119
}
120120

121121
given [T: Type: Liftable] : Liftable[Set[T]] = new Liftable[Set[T]] {

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

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -4,99 +4,5 @@ package object quoted {
44

55
implicit object ExprOps {
66
def (x: T) toExpr[T: Liftable](given QuoteContext): Expr[T] = summon[Liftable[T]].toExpr(x)
7-
8-
/** Lifts this sequence of expressions into an expression of a sequence
9-
*
10-
* Transforms a sequence of expression
11-
* `Seq(e1, e2, ...)` where `ei: Expr[T]`
12-
* to an expression equivalent to
13-
* `'{ Seq($e1, $e2, ...) }` typed as an `Expr[Seq[T]]`
14-
*
15-
* Usage:
16-
* ```scala
17-
* '{ List(${List(1, 2, 3).toExprOfSeq}: _*) } // equvalent to '{ List(1, 2, 3) }
18-
* ```
19-
*/
20-
def (seq: Seq[Expr[T]]) toExprOfSeq[T](given tp: Type[T], qctx: QuoteContext): Expr[Seq[T]] = {
21-
import qctx.tasty._
22-
Repeated(seq.map(_.unseal).toList, tp.unseal).seal.asInstanceOf[Expr[Seq[T]]]
23-
}
24-
25-
/** Lifts this list of expressions into an expression of a list
26-
*
27-
* Transforms a list of expression
28-
* `List(e1, e2, ...)` where `ei: Expr[T]`
29-
* to an expression equivalent to
30-
* `'{ List($e1, $e2, ...) }` typed as an `Expr[List[T]]`
31-
*/
32-
def (list: List[Expr[T]]) toExprOfList[T](given Type[T], QuoteContext): Expr[List[T]] =
33-
if (list.isEmpty) '{ Nil } else '{ List(${list.toExprOfSeq}: _*) }
34-
35-
/** Lifts this sequence of expressions into an expression of a tuple
36-
*
37-
* Transforms a sequence of expression
38-
* `Seq(e1, e2, ...)` where `ei: Expr[_]`
39-
* to an expression equivalent to
40-
* `'{ ($e1, $e2, ...) }` typed as an `Expr[Tuple]`
41-
*/
42-
def (seq: Seq[Expr[_]]) toExprOfTuple(given QuoteContext): Expr[Tuple] = {
43-
seq match {
44-
case Seq() =>
45-
Expr.unitExpr
46-
case Seq('{ $x1: $t1 }) =>
47-
'{ Tuple1($x1) }
48-
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }) =>
49-
'{ Tuple2($x1, $x2) }
50-
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }) =>
51-
'{ Tuple3($x1, $x2, $x3) }
52-
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }) =>
53-
'{ Tuple4($x1, $x2, $x3, $x4) }
54-
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }) =>
55-
'{ Tuple5($x1, $x2, $x3, $x4, $x5) }
56-
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }) =>
57-
'{ Tuple6($x1, $x2, $x3, $x4, $x5, $x6) }
58-
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }) =>
59-
'{ Tuple7($x1, $x2, $x3, $x4, $x5, $x6, $x7) }
60-
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }) =>
61-
'{ Tuple8($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8) }
62-
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }) =>
63-
'{ Tuple9($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9) }
64-
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }) =>
65-
'{ Tuple10($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10) }
66-
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }, '{ $x11: $t11 }) =>
67-
'{ Tuple11($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11) }
68-
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 }) =>
69-
'{ Tuple12($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12) }
70-
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 }) =>
71-
'{ Tuple13($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13) }
72-
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 }) =>
73-
'{ Tuple14($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14) }
74-
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 }) =>
75-
'{ Tuple15($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15) }
76-
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 }) =>
77-
'{ Tuple16($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16) }
78-
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 }) =>
79-
'{ Tuple17($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17) }
80-
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 }) =>
81-
'{ Tuple18($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18) }
82-
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 }) =>
83-
'{ Tuple19($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19) }
84-
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 }) =>
85-
'{ Tuple20($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20) }
86-
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 }) =>
87-
'{ Tuple21($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21) }
88-
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 }) =>
89-
'{ Tuple22($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21, $x22) }
90-
case _ =>
91-
'{ Tuple.fromIArray(IArray(${seq.toExprOfSeq}: _*)) }
92-
}
93-
}
94-
95-
/** Given a tuple of the form `(Expr[A1], ..., Expr[An])`, outputs a tuple `Expr[(A1, ..., An)]`. */
96-
def (tup: T) toExprOfTuple[T <: Tuple: Tuple.IsMappedBy[Expr]: Type](given ctx: QuoteContext): Expr[Tuple.InverseMap[T, Expr]] = {
97-
import ctx.tasty._
98-
tup.asInstanceOf[Product].productIterator.toSeq.asInstanceOf[Seq[Expr[_]]].toExprOfTuple
99-
.cast[Tuple.InverseMap[T, Expr]]
100-
}
1017
}
1028
}

library/src/scala/quoted/Expr.scala

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,100 @@ package quoted {
6565
Block(statements.map(_.unseal), expr.unseal).seal.asInstanceOf[Expr[T]]
6666
}
6767

68+
/** Lifts this sequence of expressions into an expression of a sequence
69+
*
70+
* Transforms a sequence of expression
71+
* `Seq(e1, e2, ...)` where `ei: Expr[T]`
72+
* to an expression equivalent to
73+
* `'{ Seq($e1, $e2, ...) }` typed as an `Expr[Seq[T]]`
74+
*
75+
* Usage:
76+
* ```scala
77+
* '{ List(${Expr.ofSeq(List(1, 2, 3))}: _*) } // equvalent to '{ List(1, 2, 3) }
78+
* ```
79+
*/
80+
def ofSeq[T](xs: Seq[Expr[T]])(given tp: Type[T], qctx: QuoteContext): Expr[Seq[T]] = {
81+
import qctx.tasty._
82+
Repeated(xs.map(_.unseal).toList, tp.unseal).seal.asInstanceOf[Expr[Seq[T]]]
83+
}
84+
85+
86+
/** Lifts this list of expressions into an expression of a list
87+
*
88+
* Transforms a list of expression
89+
* `List(e1, e2, ...)` where `ei: Expr[T]`
90+
* to an expression equivalent to
91+
* `'{ List($e1, $e2, ...) }` typed as an `Expr[List[T]]`
92+
*/
93+
def ofList[T](xs: Seq[Expr[T]])(given Type[T], QuoteContext): Expr[List[T]] =
94+
if (xs.isEmpty) '{ Nil } else '{ List(${ofSeq(xs)}: _*) }
95+
96+
/** Lifts this sequence of expressions into an expression of a tuple
97+
*
98+
* Transforms a sequence of expression
99+
* `Seq(e1, e2, ...)` where `ei: Expr[_]`
100+
* to an expression equivalent to
101+
* `'{ ($e1, $e2, ...) }` typed as an `Expr[Tuple]`
102+
*/
103+
def ofTuple(seq: Seq[Expr[_]])(given QuoteContext): Expr[Tuple] = {
104+
seq match {
105+
case Seq() =>
106+
unitExpr
107+
case Seq('{ $x1: $t1 }) =>
108+
'{ Tuple1($x1) }
109+
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }) =>
110+
'{ Tuple2($x1, $x2) }
111+
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }) =>
112+
'{ Tuple3($x1, $x2, $x3) }
113+
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }) =>
114+
'{ Tuple4($x1, $x2, $x3, $x4) }
115+
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }) =>
116+
'{ Tuple5($x1, $x2, $x3, $x4, $x5) }
117+
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }) =>
118+
'{ Tuple6($x1, $x2, $x3, $x4, $x5, $x6) }
119+
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }) =>
120+
'{ Tuple7($x1, $x2, $x3, $x4, $x5, $x6, $x7) }
121+
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }) =>
122+
'{ Tuple8($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8) }
123+
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }) =>
124+
'{ Tuple9($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9) }
125+
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }) =>
126+
'{ Tuple10($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10) }
127+
case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }, '{ $x11: $t11 }) =>
128+
'{ Tuple11($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11) }
129+
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 }) =>
130+
'{ Tuple12($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12) }
131+
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 }) =>
132+
'{ Tuple13($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13) }
133+
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 }) =>
134+
'{ Tuple14($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14) }
135+
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 }) =>
136+
'{ Tuple15($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15) }
137+
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 }) =>
138+
'{ Tuple16($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16) }
139+
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 }) =>
140+
'{ Tuple17($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17) }
141+
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 }) =>
142+
'{ Tuple18($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18) }
143+
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 }) =>
144+
'{ Tuple19($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19) }
145+
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 }) =>
146+
'{ Tuple20($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20) }
147+
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 }) =>
148+
'{ Tuple21($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21) }
149+
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 }) =>
150+
'{ Tuple22($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21, $x22) }
151+
case _ =>
152+
'{ Tuple.fromIArray(IArray(${ofSeq(seq)}: _*)) }
153+
}
154+
}
155+
156+
/** Given a tuple of the form `(Expr[A1], ..., Expr[An])`, outputs a tuple `Expr[(A1, ..., An)]`. */
157+
def ofTuple[T <: Tuple: Tuple.IsMappedBy[Expr]: Type](tup: T) (given ctx: QuoteContext): Expr[Tuple.InverseMap[T, Expr]] = {
158+
import ctx.tasty._
159+
val elems: Seq[Expr[_]] = tup.asInstanceOf[Product].productIterator.toSeq.asInstanceOf[Seq[Expr[_]]]
160+
ofTuple(elems).cast[Tuple.InverseMap[T, Expr]]
161+
}
68162
}
69163

70164
}

tests/neg/toexproftuple.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import scala.quoted.given
44
inline def mcr: Any = ${mcrImpl}
55
def mcrImpl(given ctx: QuoteContext): Expr[Any] = {
66
val tpl: (Expr[1], Expr[2], Expr[3]) = ('{1}, '{2}, '{3})
7-
'{val res: (1, 3, 3) = ${tpl.toExprOfTuple}; res} // error
7+
'{val res: (1, 3, 3) = ${Expr.ofTuple(tpl)}; res} // error
88

99
val tpl2: (Expr[1], 2, Expr[3]) = ('{1}, 2, '{3})
10-
'{val res = ${tpl2.toExprOfTuple}; res} // error
10+
'{val res = ${Expr.ofTuple(tpl2)}; res} // error
1111
}

tests/pos/toexproftuple.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import scala.quoted.given
44
inline def mcr: Any = ${mcrImpl}
55
def mcrImpl(given ctx: QuoteContext): Expr[Any] = {
66
val tpl: (Expr[1], Expr[2], Expr[3]) = ('{1}, '{2}, '{3})
7-
'{val res: (1, 2, 3) = ${tpl.toExprOfTuple}; res}
7+
'{val res: (1, 2, 3) = ${Expr.ofTuple(tpl)}; res}
88
}

tests/run-macros/f-interpolator-neg/Macros_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ object Macro {
6969
}
7070
val parts = parts0.map { case Const(s) => s }
7171
dotty.internal.StringContextMacro.interpolate(parts.toList, args.toList, argsExpr, reporter) // Discard result
72-
errors.result().toExprOfList
72+
Expr.ofList(errors.result())
7373
}
7474
}

tests/run-macros/i6765-b/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import scala.quoted.given
44
inline def foo = ${fooImpl}
55

66
def fooImpl(given qctx: QuoteContext) = {
7-
val res = List('{"One"}).toExprOfList
7+
val res = Expr.ofList(List('{"One"}))
88
res.show.toExpr
99
}

tests/run-macros/i6765-c/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import scala.quoted.given
44
inline def foo(inline n: Int) = ${fooImpl(n)}
55

66
def fooImpl(n: Int)(given qctx: QuoteContext) = {
7-
val res = List.tabulate(n)(i => ("#" + i).toExpr).toExprOfList
7+
val res = Expr.ofList(List.tabulate(n)(i => ("#" + i).toExpr))
88
'{ ${res.show.toExpr} + "\n" + $res.toString + "\n" }
99
}

tests/run-macros/i6765/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ inline def foo = ${fooImpl}
55

66
def fooImpl(given qctx: QuoteContext) = {
77
import qctx.tasty._
8-
val res = List('{"One"}).toExprOfList
8+
val res = Expr.ofList(List('{"One"}))
99
res.show.toExpr
1010
}

tests/run-macros/i7008/macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ def mcrProxy(expr: Expr[Boolean])(given QuoteContext): Expr[Unit] = {
1414

1515
def mcrImpl[T](func: Expr[Seq[Box[T]] => Unit], expr: Expr[T])(given ctx: QuoteContext, tt: Type[T]): Expr[Unit] = {
1616
import ctx.tasty._
17-
val arg = Seq('{(Box($expr))}).toExprOfSeq
17+
val arg = Expr.ofSeq(Seq('{(Box($expr))}))
1818
func(arg)
1919
}

0 commit comments

Comments
 (0)