Skip to content

Commit e7847aa

Browse files
Merge pull request #8335 from dotty-staging/rename-dynamictuple-to-runtime-tuple
Rename Dynamic tuple to scala.runtime.Tuple
2 parents dd7b841 + b74d6ac commit e7847aa

File tree

15 files changed

+119
-105
lines changed

15 files changed

+119
-105
lines changed

bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Apply.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Apply {
2222

2323
@Benchmark
2424
def tupleApply(): Any = {
25-
DynamicTuple.apply(tuple, index)
25+
runtime.Tuple.apply(tuple, index)
2626
}
2727

2828
@Benchmark

bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Concat.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ class Concat {
2828

2929
@Benchmark
3030
def tupleConcat(): Tuple = {
31-
DynamicTuple.concat(tuple1, tuple2)
31+
runtime.Tuple.concat(tuple1, tuple2)
3232
}
3333
}

bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Cons.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Cons {
2424

2525
@Benchmark
2626
def tupleCons(): Tuple = {
27-
DynamicTuple.cons("elem", tuple)
27+
runtime.Tuple.cons("elem", tuple)
2828
}
2929

3030
@Benchmark

bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Conversions.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,27 @@ class Conversions {
2424

2525
@Benchmark
2626
def tupleToArray(): Array[Object] = {
27-
DynamicTuple.toArray(tuple)
27+
runtime.Tuple.toArray(tuple)
2828
}
2929

3030
@Benchmark
3131
def tupleToIArray(): IArray[Object] = {
32-
DynamicTuple.toIArray(tuple)
32+
runtime.Tuple.toIArray(tuple)
3333
}
3434

3535
@Benchmark
3636
def tupleFromArray(): Tuple = {
37-
DynamicTuple.fromArray(array)
37+
runtime.Tuple.fromArray(array)
3838
}
3939

4040
@Benchmark
4141
def tupleFromIArray(): Tuple = {
42-
DynamicTuple.fromIArray(iarray)
42+
runtime.Tuple.fromIArray(iarray)
4343
}
4444

4545
@Benchmark
4646
def productToArray(): Array[Object] = {
47-
DynamicTuple.productToArray(tuple.asInstanceOf[Product])
47+
runtime.Tuple.productToArray(tuple.asInstanceOf[Product])
4848
}
4949

5050
@Benchmark

bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Map.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Map {
3030

3131
@Benchmark
3232
def tupleMap(): Tuple = {
33-
DynamicTuple.map[Id](tuple, [T] => (x:T) => x.asInstanceOf[String].updated(0, 'a').asInstanceOf[T])
33+
runtime.Tuple.map[Id](tuple, [T] => (x:T) => x.asInstanceOf[String].updated(0, 'a').asInstanceOf[T])
3434
}
3535

3636
@Benchmark

bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Tail.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Tail {
2222

2323
@Benchmark
2424
def tupleTail(): Tuple = {
25-
DynamicTuple.tail(tuple)
25+
runtime.Tuple.tail(tuple)
2626
}
2727

2828
@Benchmark

bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Zip.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Zip {
2828

2929
@Benchmark
3030
def tupleZip(): Tuple = {
31-
DynamicTuple.zip(tuple1, tuple2)
31+
runtime.Tuple.zip(tuple1, tuple2)
3232
}
3333

3434
@Benchmark

bench-run/src/main/scala/tuples/Drop.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Drop {
2424

2525
@Benchmark
2626
def tupleDrop(): Tuple = {
27-
DynamicTuple.drop(tuple, half)
27+
runtime.Tuple.drop(tuple, half)
2828
}
2929

3030
@Benchmark

bench-run/src/main/scala/tuples/Split.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Split {
2424

2525
@Benchmark
2626
def tupleSplit(): (Tuple, Tuple) = {
27-
DynamicTuple.splitAt(tuple, half)
27+
runtime.Tuple.splitAt(tuple, half)
2828
}
2929

3030
@Benchmark

bench-run/src/main/scala/tuples/Take.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Take {
2424

2525
@Benchmark
2626
def tupleTake(): Tuple = {
27-
DynamicTuple.take(tuple, half)
27+
runtime.Tuple.take(tuple, half)
2828
}
2929

3030
@Benchmark

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -754,17 +754,17 @@ class Definitions {
754754

755755
def TupleXXL_fromIterator(implicit ctx: Context): Symbol = TupleXXLModule.requiredMethod("fromIterator")
756756

757-
@tu lazy val DynamicTupleModule: Symbol = ctx.requiredModule("scala.runtime.DynamicTuple")
758-
@tu lazy val DynamicTupleModuleClass: Symbol = DynamicTupleModule.moduleClass
759-
lazy val DynamicTuple_consIterator: Symbol = DynamicTupleModule.requiredMethod("consIterator")
760-
lazy val DynamicTuple_concatIterator: Symbol = DynamicTupleModule.requiredMethod("concatIterator")
761-
lazy val DynamicTuple_apply: Symbol = DynamicTupleModule.requiredMethod("apply")
762-
lazy val DynamicTuple_cons: Symbol = DynamicTupleModule.requiredMethod("cons")
763-
lazy val DynamicTuple_size: Symbol = DynamicTupleModule.requiredMethod("size")
764-
lazy val DynamicTuple_tail: Symbol = DynamicTupleModule.requiredMethod("tail")
765-
lazy val DynamicTuple_concat: Symbol = DynamicTupleModule.requiredMethod("concat")
766-
lazy val DynamicTuple_toArray: Symbol = DynamicTupleModule.requiredMethod("toArray")
767-
lazy val DynamicTuple_productToArray: Symbol = DynamicTupleModule.requiredMethod("productToArray")
757+
@tu lazy val RuntimeTupleModule: Symbol = ctx.requiredModule("scala.runtime.Tuple")
758+
@tu lazy val RuntimeTupleModuleClass: Symbol = RuntimeTupleModule.moduleClass
759+
lazy val RuntimeTuple_consIterator: Symbol = RuntimeTupleModule.requiredMethod("consIterator")
760+
lazy val RuntimeTuple_concatIterator: Symbol = RuntimeTupleModule.requiredMethod("concatIterator")
761+
lazy val RuntimeTuple_apply: Symbol = RuntimeTupleModule.requiredMethod("apply")
762+
lazy val RuntimeTuple_cons: Symbol = RuntimeTupleModule.requiredMethod("cons")
763+
lazy val RuntimeTuple_size: Symbol = RuntimeTupleModule.requiredMethod("size")
764+
lazy val RuntimeTuple_tail: Symbol = RuntimeTupleModule.requiredMethod("tail")
765+
lazy val RuntimeTuple_concat: Symbol = RuntimeTupleModule.requiredMethod("concat")
766+
lazy val RuntimeTuple_toArray: Symbol = RuntimeTupleModule.requiredMethod("toArray")
767+
lazy val RuntimeTuple_productToArray: Symbol = RuntimeTupleModule.requiredMethod("productToArray")
768768

769769
@tu lazy val TupledFunctionTypeRef: TypeRef = ctx.requiredClassRef("scala.TupledFunction")
770770
def TupledFunctionClass(implicit ctx: Context): ClassSymbol = TupledFunctionTypeRef.symbol.asClass

compiler/src/dotty/tools/dotc/transform/TupleOptimizations.scala

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
2424
def phaseName: String = "genericTuples"
2525

2626
override def transformApply(tree: tpd.Apply)(implicit ctx: Context): tpd.Tree =
27-
if (!tree.symbol.exists || tree.symbol.owner != defn.DynamicTupleModuleClass) tree
28-
else if (tree.symbol == defn.DynamicTuple_cons) transformTupleCons(tree)
29-
else if (tree.symbol == defn.DynamicTuple_tail) transformTupleTail(tree)
30-
else if (tree.symbol == defn.DynamicTuple_size) transformTupleSize(tree)
31-
else if (tree.symbol == defn.DynamicTuple_concat) transformTupleConcat(tree)
32-
else if (tree.symbol == defn.DynamicTuple_apply) transformTupleApply(tree)
33-
else if (tree.symbol == defn.DynamicTuple_toArray) transformTupleToArray(tree)
27+
if (!tree.symbol.exists || tree.symbol.owner != defn.RuntimeTupleModuleClass) tree
28+
else if (tree.symbol == defn.RuntimeTuple_cons) transformTupleCons(tree)
29+
else if (tree.symbol == defn.RuntimeTuple_tail) transformTupleTail(tree)
30+
else if (tree.symbol == defn.RuntimeTuple_size) transformTupleSize(tree)
31+
else if (tree.symbol == defn.RuntimeTuple_concat) transformTupleConcat(tree)
32+
else if (tree.symbol == defn.RuntimeTuple_apply) transformTupleApply(tree)
33+
else if (tree.symbol == defn.RuntimeTuple_toArray) transformTupleToArray(tree)
3434
else tree
3535

3636
private def transformTupleCons(tree: tpd.Apply)(implicit ctx: Context): Tree = {
@@ -49,14 +49,14 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
4949
else {
5050
// val it = Iterator.single(head) ++ tail.asInstanceOf[Product].productIterator
5151
// TupleN+1(it.next(), ..., it.next())
52-
val fullIterator = ref(defn.DynamicTuple_consIterator).appliedToArgs(head :: tail :: Nil)
52+
val fullIterator = ref(defn.RuntimeTuple_consIterator).appliedToArgs(head :: tail :: Nil)
5353
evalOnce(fullIterator) { it =>
5454
knownTupleFromIterator(tpes.length, it).asInstance(tree.tpe)
5555
}
5656
}
5757
case _ =>
5858
// No optimization, keep:
59-
// DynamicTuple.cons(tail, head)
59+
// scala.runtime.Tuple.cons(tail, head)
6060
tree
6161
}
6262
}
@@ -93,7 +93,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
9393
tup.asInstance(defn.TupleXXLClass.typeRef).select("tailXXL".toTermName)
9494
case None =>
9595
// No optimization, keep:
96-
// DynamicTuple.tail(tup)
96+
// scala.runtime.Tuple.tail(tup)
9797
tree
9898
}
9999
}
@@ -127,14 +127,14 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
127127
else {
128128
// val it = self.asInstanceOf[Product].productIterator ++ that.asInstanceOf[Product].productIterator
129129
// TupleN+M(it.next(), ..., it.next())
130-
val fullIterator = ref(defn.DynamicTuple_concatIterator).appliedToArgs(tree.args)
130+
val fullIterator = ref(defn.RuntimeTuple_concatIterator).appliedToArgs(tree.args)
131131
evalOnce(fullIterator) { it =>
132132
knownTupleFromIterator(n + m, it).asInstance(tree.tpe)
133133
}
134134
}
135135
case _ =>
136136
// No optimization, keep:
137-
// DynamicTuple.cons(self, that)
137+
// scala.runtime.Tuple.cons(self, that)
138138
tree
139139
}
140140
}
@@ -161,7 +161,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
161161
tree
162162
case _ =>
163163
// No optimization, keep:
164-
// DynamicTuple.apply(tup, n)
164+
// scala.runtime.Tuple.apply(tup, n)
165165
tree
166166
}
167167
}
@@ -175,14 +175,14 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
175175
// Array.emptyObjectArray
176176
ref(defn.ArrayModule).select("emptyObjectArray".toTermName).ensureApplied
177177
else if (size <= MaxTupleArity)
178-
// DynamicTuple.productToArray(tup.asInstanceOf[Product])
179-
ref(defn.DynamicTuple_productToArray).appliedTo(tup.asInstance(defn.ProductClass.typeRef))
178+
// scala.runtime.Tuple.productToArray(tup.asInstanceOf[Product])
179+
ref(defn.RuntimeTuple_productToArray).appliedTo(tup.asInstance(defn.ProductClass.typeRef))
180180
else
181181
// tup.asInstanceOf[TupleXXL].elems.clone()
182182
tup.asInstance(defn.TupleXXLClass.typeRef).select(nme.toArray)
183183
case None =>
184184
// No optimization, keep:
185-
// DynamicTuple.toArray(tup)
185+
// scala.runtime.Tuple.toArray(tup)
186186
tree
187187
}
188188
}

library/src/scala/Tuple.scala

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ sealed trait Tuple extends Any {
1111

1212
/** Create a copy this tuple as an Array */
1313
inline def toArray: Array[Object] =
14-
DynamicTuple.toArray(this)
14+
scala.runtime.Tuple.toArray(this)
1515

1616
/** Create a copy this tuple as an IArray */
1717
inline def toIArray: IArray[Object] =
18-
DynamicTuple.toIArray(this)
18+
scala.runtime.Tuple.toIArray(this)
1919

2020
/** Return a new tuple by prepending the element to `this` tuple.
2121
* This opteration is O(this.size)
2222
*/
2323
inline def *: [H, This >: this.type <: Tuple] (x: H): H *: This =
24-
DynamicTuple.cons(x, this).asInstanceOf[H *: This]
24+
scala.runtime.Tuple.cons(x, this).asInstanceOf[H *: This]
2525

2626
/** Return a new tuple by concatenating `this` tuple with `that` tuple.
2727
* This opteration is O(this.size + that.size)
2828
*/
2929
inline def ++ [This >: this.type <: Tuple](that: Tuple): Concat[This, that.type] =
30-
DynamicTuple.concat(this, that).asInstanceOf[Concat[This, that.type]]
30+
scala.runtime.Tuple.concat(this, that).asInstanceOf[Concat[This, that.type]]
3131

3232
/** Return the size (or arity) of the tuple */
3333
inline def size[This >: this.type <: Tuple]: Size[This] =
34-
DynamicTuple.size(this).asInstanceOf[Size[This]]
34+
scala.runtime.Tuple.size(this).asInstanceOf[Size[This]]
3535

3636
/** Given two tuples, `(a1, ..., an)` and `(a1, ..., an)`, returns a tuple
3737
* `((a1, b1), ..., (an, bn))`. If the two tuples have different sizes,
@@ -41,35 +41,35 @@ sealed trait Tuple extends Any {
4141
* `(A1, B1) *: ... *: (Ai, Bi) *: Tuple`
4242
*/
4343
inline def zip[This >: this.type <: Tuple, T2 <: Tuple](t2: T2): Zip[This, T2] =
44-
DynamicTuple.zip(this, t2).asInstanceOf[Zip[This, T2]]
44+
scala.runtime.Tuple.zip(this, t2).asInstanceOf[Zip[This, T2]]
4545

4646
/** Called on a tuple `(a1, ..., an)`, returns a new tuple `(f(a1), ..., f(an))`.
4747
* The result is typed as `(F[A1], ..., F[An])` if the tuple type is fully known.
4848
* If the tuple is of the form `a1 *: ... *: Tuple` (that is, the tail is not known
4949
* to be the cons type.
5050
*/
5151
inline def map[F[_]](f: [t] => t => F[t]): Map[this.type, F] =
52-
DynamicTuple.map(this, f).asInstanceOf[Map[this.type, F]]
52+
scala.runtime.Tuple.map(this, f).asInstanceOf[Map[this.type, F]]
5353

5454
/** Given a tuple `(a1, ..., am)`, returns the tuple `(a1, ..., an)` consisting
5555
* of its first n elements.
5656
*/
5757
inline def take[This >: this.type <: Tuple](n: Int): Take[This, n.type] =
58-
DynamicTuple.take(this, n).asInstanceOf[Take[This, n.type]]
58+
scala.runtime.Tuple.take(this, n).asInstanceOf[Take[This, n.type]]
5959

6060

6161
/** Given a tuple `(a1, ..., am)`, returns the tuple `(an+1, ..., am)` consisting
6262
* all its elements except the first n ones.
6363
*/
6464
inline def drop[This >: this.type <: Tuple](n: Int): Drop[This, n.type] =
65-
DynamicTuple.drop(this, n).asInstanceOf[Drop[This, n.type]]
65+
scala.runtime.Tuple.drop(this, n).asInstanceOf[Drop[This, n.type]]
6666

6767
/** Given a tuple `(a1, ..., am)`, returns a pair of the tuple `(a1, ..., an)`
6868
* consisting of the first n elements, and the tuple `(an+1, ..., am)` consisting
6969
* of the remaining elements.
7070
*/
7171
inline def splitAt[This >: this.type <: Tuple](n: Int): Split[This, n.type] =
72-
DynamicTuple.splitAt(this, n).asInstanceOf[Split[This, n.type]]
72+
scala.runtime.Tuple.splitAt(this, n).asInstanceOf[Split[This, n.type]]
7373
}
7474

7575
object Tuple {
@@ -165,7 +165,7 @@ object Tuple {
165165
case xs: Array[Object] => xs
166166
case xs => xs.map(_.asInstanceOf[Object])
167167
}
168-
DynamicTuple.fromArray(xs2).asInstanceOf[Tuple]
168+
scala.runtime.Tuple.fromArray(xs2).asInstanceOf[Tuple]
169169
}
170170

171171
/** Convert an immutable array into a tuple of unknown arity and types */
@@ -176,12 +176,12 @@ object Tuple {
176176
// TODO support IArray.map
177177
xs.asInstanceOf[Array[T]].map(_.asInstanceOf[Object]).asInstanceOf[IArray[Object]]
178178
}
179-
DynamicTuple.fromIArray(xs2).asInstanceOf[Tuple]
179+
scala.runtime.Tuple.fromIArray(xs2).asInstanceOf[Tuple]
180180
}
181181

182182
/** Convert a Product into a tuple of unknown arity and types */
183183
def fromProduct(product: Product): Tuple =
184-
runtime.DynamicTuple.fromProduct(product)
184+
scala.runtime.Tuple.fromProduct(product)
185185

186186
def fromProductTyped[P <: Product](p: P)(using m: scala.deriving.Mirror.ProductOf[P]): m.MirroredElemTypes =
187187
Tuple.fromArray(p.productIterator.toArray).asInstanceOf[m.MirroredElemTypes] // TODO use toIArray of Object to avoid double/triple array copy
@@ -195,17 +195,17 @@ sealed trait NonEmptyTuple extends Tuple {
195195
* Equivalent to productElement but with a precise return type.
196196
*/
197197
inline def apply[This >: this.type <: NonEmptyTuple](n: Int): Elem[This, n.type] =
198-
DynamicTuple.apply(this, n).asInstanceOf[Elem[This, n.type]]
198+
scala.runtime.Tuple.apply(this, n).asInstanceOf[Elem[This, n.type]]
199199

200200
/** Get the head of this tuple */
201201
inline def head[This >: this.type <: NonEmptyTuple]: Head[This] =
202-
DynamicTuple.apply(this, 0).asInstanceOf[Head[This]]
202+
scala.runtime.Tuple.apply(this, 0).asInstanceOf[Head[This]]
203203

204204
/** Get the tail of this tuple.
205205
* This opteration is O(this.size)
206206
*/
207207
inline def tail[This >: this.type <: NonEmptyTuple]: Tail[This] =
208-
DynamicTuple.tail(this).asInstanceOf[Tail[This]]
208+
scala.runtime.Tuple.tail(this).asInstanceOf[Tail[This]]
209209

210210
}
211211

0 commit comments

Comments
 (0)