Skip to content

Commit 326c6e7

Browse files
committed
Adapt macro tuple test to scala.runtime.Tuple
Remove use of deprecated scala.runtime.DynamicTuple
1 parent 5aec4f8 commit 326c6e7

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

tests/run-staging/staged-tuples/StagedTuple.scala

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ import scala.quoted._
44

55
import scala.runtime.TupleXXL
66

7+
import scala.runtime.Tuple.MaxSpecialized
8+
79
object StagedTuple {
810
import Tuple.Concat
911
import Tuple.Head
1012
import Tuple.Tail
1113
import Tuple.Size
1214
import Tuple.Elem
13-
import scala.runtime.DynamicTuple._
1415

1516
private final val specialize = true
1617

1718
def toArrayStaged(tup: Expr[Tuple], size: Option[Int])(using QuoteContext): Expr[Array[Object]] = {
18-
if (!specialize) '{dynamicToArray($tup)}
19+
if (!specialize) '{scala.runtime.Tuple.toArray($tup)}
1920
else size match {
2021
case Some(0) =>
2122
'{Array.emptyObjectArray}
@@ -30,12 +31,12 @@ object StagedTuple {
3031
case Some(n) =>
3132
'{ ${tup.as[TupleXXL]}.toArray }
3233
case None =>
33-
'{dynamicToArray($tup)}
34+
'{scala.runtime.Tuple.toArray($tup)}
3435
}
3536
}
3637

3738
def fromArrayStaged[T <: Tuple : Type](xs: Expr[Array[Object]], size: Option[Int])(using QuoteContext): Expr[T] = {
38-
if (!specialize) '{dynamicFromArray[T]($xs)}
39+
if (!specialize) '{scala.runtime.Tuple.fromArray($xs)}.as[T]
3940
else xs.bind { xs =>
4041
val tup: Expr[Any] = size match {
4142
case Some(0) => '{}
@@ -62,24 +63,24 @@ object StagedTuple {
6263
case Some(21) => '{Tuple21($xs(0), $xs(1), $xs(2), $xs(3), $xs(4), $xs(5), $xs(6), $xs(7), $xs(8), $xs(9), $xs(10), $xs(11), $xs(12), $xs(13), $xs(14), $xs(15), $xs(16), $xs(17), $xs(18), $xs(19), $xs(20))}
6364
case Some(22) => '{Tuple22($xs(0), $xs(1), $xs(2), $xs(3), $xs(4), $xs(5), $xs(6), $xs(7), $xs(8), $xs(9), $xs(10), $xs(11), $xs(12), $xs(13), $xs(14), $xs(15), $xs(16), $xs(17), $xs(18), $xs(19), $xs(20), $xs(21))}
6465
case Some(_) => '{TupleXXL($xs)}
65-
case None => '{dynamicFromArray[T]($xs)}
66+
case None => '{scala.runtime.Tuple.fromArray($xs)}
6667
}
6768
tup.as[T]
6869
}
6970
}
7071

7172
def sizeStaged[Res <: Int : Type](tup: Expr[Tuple], size: Option[Int])(using QuoteContext): Expr[Res] = {
7273
val res =
73-
if (!specialize) '{dynamicSize($tup)}
74+
if (!specialize) '{scala.runtime.Tuple.size($tup)}
7475
else size match {
7576
case Some(n) => Expr(n)
76-
case None => '{dynamicSize($tup)}
77+
case None => '{scala.runtime.Tuple.size($tup)}
7778
}
7879
res.as[Res]
7980
}
8081

8182
def headStaged[Tup <: NonEmptyTuple : Type](tup: Expr[Tup], size: Option[Int])(using QuoteContext): Expr[Head[Tup]] = {
82-
if (!specialize) '{dynamicApply[Tup, 0]($tup, 0)}
83+
if (!specialize) '{scala.runtime.Tuple.apply($tup, 0)}.as[Head[Tup]]
8384
else {
8485
val resVal = size match {
8586
case Some(1) =>
@@ -95,14 +96,14 @@ object StagedTuple {
9596
case Some(n) if n > MaxSpecialized =>
9697
'{${tup.as[TupleXXL] }.elems(0)}
9798
case None =>
98-
'{dynamicApply($tup, 0)}
99+
'{scala.runtime.Tuple.apply($tup, 0)}
99100
}
100101
resVal.as[Head[Tup]]
101102
}
102103
}
103104

104105
def tailStaged[Tup <: NonEmptyTuple : Type](tup: Expr[Tup], size: Option[Int])(using QuoteContext): Expr[Tail[Tup]] = {
105-
if (!specialize) '{dynamicTail[Tup]($tup)}
106+
if (!specialize) '{scala.runtime.Tuple.tail($tup)}.as[Tail[Tup]]
106107
else {
107108
val res = size match {
108109
case Some(1) =>
@@ -119,21 +120,21 @@ object StagedTuple {
119120
val arr = toArrayStaged(tup, size)
120121
fromArrayStaged[Tail[Tup]]('{ $arr.tail }, Some(n - 1))
121122
case None =>
122-
'{dynamicTail($tup)}
123+
'{scala.runtime.Tuple.tail($tup)}
123124
}
124125
res.as[Tail[Tup]]
125126
}
126127
}
127128

128129
def applyStaged[Tup <: NonEmptyTuple : Type, N <: Int : Type](tup: Expr[Tup], size: Option[Int], n: Expr[N], nValue: Option[Int])(using qctx: QuoteContext): Expr[Elem[Tup, N]] = {
129130

130-
if (!specialize) '{dynamicApply($tup, $n)}
131+
if (!specialize) '{scala.runtime.Tuple.apply($tup, $n)}.as[Elem[Tup, N]]
131132
else {
132133
def fallbackApply(): Expr[Elem[Tup, N]] = nValue match {
133134
case Some(n) =>
134135
qctx.error("index out of bounds: " + n, tup)
135136
'{ throw new IndexOutOfBoundsException(${Expr(n.toString)}) }
136-
case None => '{dynamicApply($tup, $n)}
137+
case None => '{scala.runtime.Tuple.apply($tup, $n)}.as[Elem[Tup, N]]
137138
}
138139
val res = size match {
139140
case Some(1) =>
@@ -185,7 +186,7 @@ object StagedTuple {
185186
}
186187

187188
def consStaged[T <: Tuple & Singleton : Type, H : Type](self: Expr[T], x: Expr[H], tailSize: Option[Int])(using QuoteContext): Expr[H *: T] =
188-
if (!specialize) '{dynamicCons[H, T]($x, $self)}
189+
if (!specialize) '{scala.runtime.Tuple.cons($x, $self)}.as[H *: T]
189190
else {
190191
val res = tailSize match {
191192
case Some(0) =>
@@ -199,13 +200,13 @@ object StagedTuple {
199200
case Some(4) =>
200201
self.as[Tuple4[_, _, _, _]].bind(t => '{Tuple5($x, $t._1, $t._2, $t._3, $t._4)})
201202
case _ =>
202-
'{dynamicCons[H, T]($x, $self)}
203+
'{scala.runtime.Tuple.cons($x, $self)}
203204
}
204205
res.as[H *: T]
205206
}
206207

207208
def concatStaged[Self <: Tuple & Singleton : Type, That <: Tuple & Singleton : Type](self: Expr[Self], selfSize: Option[Int], that: Expr[That], thatSize: Option[Int])(using QuoteContext): Expr[Concat[Self, That]] = {
208-
if (!specialize) '{dynamicConcat[Self, That]($self, $that)}
209+
if (!specialize) '{scala.runtime.Tuple.concat($self, $that)}.as[Concat[Self, That]]
209210
else {
210211
def genericConcat(xs: Expr[Tuple], ys: Expr[Tuple]): Expr[Tuple] =
211212
// TODO remove ascriptions when #6126 is fixed
@@ -247,7 +248,7 @@ object StagedTuple {
247248
if (thatSize.contains(0)) self
248249
else genericConcat(self, that)
249250
case None =>
250-
'{dynamicConcat($self, $that)}
251+
'{scala.runtime.Tuple.concat($self, $that)}
251252
}
252253
res.as[Concat[Self, That]]
253254
}

0 commit comments

Comments
 (0)