diff --git a/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Apply.scala b/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Apply.scala index bc7189606348..a1c39f40bf48 100644 --- a/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Apply.scala +++ b/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Apply.scala @@ -22,7 +22,7 @@ class Apply { @Benchmark def tupleApply(): Any = { - DynamicTuple.apply(tuple, index) + runtime.Tuple.apply(tuple, index) } @Benchmark diff --git a/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Concat.scala b/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Concat.scala index efd09ec2f6f1..3dc15c632f61 100644 --- a/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Concat.scala +++ b/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Concat.scala @@ -28,6 +28,6 @@ class Concat { @Benchmark def tupleConcat(): Tuple = { - DynamicTuple.concat(tuple1, tuple2) + runtime.Tuple.concat(tuple1, tuple2) } } diff --git a/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Cons.scala b/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Cons.scala index 1772ab4ae908..adfa3d9694e8 100644 --- a/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Cons.scala +++ b/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Cons.scala @@ -24,7 +24,7 @@ class Cons { @Benchmark def tupleCons(): Tuple = { - DynamicTuple.cons("elem", tuple) + runtime.Tuple.cons("elem", tuple) } @Benchmark diff --git a/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Conversions.scala b/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Conversions.scala index b4bffb99b462..37b8eefc0592 100644 --- a/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Conversions.scala +++ b/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Conversions.scala @@ -24,27 +24,27 @@ class Conversions { @Benchmark def tupleToArray(): Array[Object] = { - DynamicTuple.toArray(tuple) + runtime.Tuple.toArray(tuple) } @Benchmark def tupleToIArray(): IArray[Object] = { - DynamicTuple.toIArray(tuple) + runtime.Tuple.toIArray(tuple) } @Benchmark def tupleFromArray(): Tuple = { - DynamicTuple.fromArray(array) + runtime.Tuple.fromArray(array) } @Benchmark def tupleFromIArray(): Tuple = { - DynamicTuple.fromIArray(iarray) + runtime.Tuple.fromIArray(iarray) } @Benchmark def productToArray(): Array[Object] = { - DynamicTuple.productToArray(tuple.asInstanceOf[Product]) + runtime.Tuple.productToArray(tuple.asInstanceOf[Product]) } @Benchmark diff --git a/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Map.scala b/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Map.scala index fe2add6247e4..b145e7508ea1 100644 --- a/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Map.scala +++ b/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Map.scala @@ -30,7 +30,7 @@ class Map { @Benchmark def tupleMap(): Tuple = { - DynamicTuple.map[Id](tuple, [T] => (x:T) => x.asInstanceOf[String].updated(0, 'a').asInstanceOf[T]) + runtime.Tuple.map[Id](tuple, [T] => (x:T) => x.asInstanceOf[String].updated(0, 'a').asInstanceOf[T]) } @Benchmark diff --git a/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Tail.scala b/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Tail.scala index f77dc98ee5ce..1446a02e05b4 100644 --- a/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Tail.scala +++ b/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Tail.scala @@ -22,7 +22,7 @@ class Tail { @Benchmark def tupleTail(): Tuple = { - DynamicTuple.tail(tuple) + runtime.Tuple.tail(tuple) } @Benchmark diff --git a/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Zip.scala b/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Zip.scala index 9193963ee15b..28c8789d6bee 100644 --- a/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Zip.scala +++ b/bench-run/src/main/scala/dotty/tools/benchmarks/tuples/Zip.scala @@ -28,7 +28,7 @@ class Zip { @Benchmark def tupleZip(): Tuple = { - DynamicTuple.zip(tuple1, tuple2) + runtime.Tuple.zip(tuple1, tuple2) } @Benchmark diff --git a/bench-run/src/main/scala/tuples/Drop.scala b/bench-run/src/main/scala/tuples/Drop.scala index bd1d2a439c6f..d9b8924b5324 100644 --- a/bench-run/src/main/scala/tuples/Drop.scala +++ b/bench-run/src/main/scala/tuples/Drop.scala @@ -24,7 +24,7 @@ class Drop { @Benchmark def tupleDrop(): Tuple = { - DynamicTuple.drop(tuple, half) + runtime.Tuple.drop(tuple, half) } @Benchmark diff --git a/bench-run/src/main/scala/tuples/Split.scala b/bench-run/src/main/scala/tuples/Split.scala index 40ed1f5ee7c3..23cbc0c23148 100644 --- a/bench-run/src/main/scala/tuples/Split.scala +++ b/bench-run/src/main/scala/tuples/Split.scala @@ -24,7 +24,7 @@ class Split { @Benchmark def tupleSplit(): (Tuple, Tuple) = { - DynamicTuple.splitAt(tuple, half) + runtime.Tuple.splitAt(tuple, half) } @Benchmark diff --git a/bench-run/src/main/scala/tuples/Take.scala b/bench-run/src/main/scala/tuples/Take.scala index 07e9fdd7b75a..ec3762e33889 100644 --- a/bench-run/src/main/scala/tuples/Take.scala +++ b/bench-run/src/main/scala/tuples/Take.scala @@ -24,7 +24,7 @@ class Take { @Benchmark def tupleTake(): Tuple = { - DynamicTuple.take(tuple, half) + runtime.Tuple.take(tuple, half) } @Benchmark diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 17328d4e5fbb..3873ee2e6249 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -754,17 +754,17 @@ class Definitions { def TupleXXL_fromIterator(implicit ctx: Context): Symbol = TupleXXLModule.requiredMethod("fromIterator") - @tu lazy val DynamicTupleModule: Symbol = ctx.requiredModule("scala.runtime.DynamicTuple") - @tu lazy val DynamicTupleModuleClass: Symbol = DynamicTupleModule.moduleClass - lazy val DynamicTuple_consIterator: Symbol = DynamicTupleModule.requiredMethod("consIterator") - lazy val DynamicTuple_concatIterator: Symbol = DynamicTupleModule.requiredMethod("concatIterator") - lazy val DynamicTuple_apply: Symbol = DynamicTupleModule.requiredMethod("apply") - lazy val DynamicTuple_cons: Symbol = DynamicTupleModule.requiredMethod("cons") - lazy val DynamicTuple_size: Symbol = DynamicTupleModule.requiredMethod("size") - lazy val DynamicTuple_tail: Symbol = DynamicTupleModule.requiredMethod("tail") - lazy val DynamicTuple_concat: Symbol = DynamicTupleModule.requiredMethod("concat") - lazy val DynamicTuple_toArray: Symbol = DynamicTupleModule.requiredMethod("toArray") - lazy val DynamicTuple_productToArray: Symbol = DynamicTupleModule.requiredMethod("productToArray") + @tu lazy val RuntimeTupleModule: Symbol = ctx.requiredModule("scala.runtime.Tuple") + @tu lazy val RuntimeTupleModuleClass: Symbol = RuntimeTupleModule.moduleClass + lazy val RuntimeTuple_consIterator: Symbol = RuntimeTupleModule.requiredMethod("consIterator") + lazy val RuntimeTuple_concatIterator: Symbol = RuntimeTupleModule.requiredMethod("concatIterator") + lazy val RuntimeTuple_apply: Symbol = RuntimeTupleModule.requiredMethod("apply") + lazy val RuntimeTuple_cons: Symbol = RuntimeTupleModule.requiredMethod("cons") + lazy val RuntimeTuple_size: Symbol = RuntimeTupleModule.requiredMethod("size") + lazy val RuntimeTuple_tail: Symbol = RuntimeTupleModule.requiredMethod("tail") + lazy val RuntimeTuple_concat: Symbol = RuntimeTupleModule.requiredMethod("concat") + lazy val RuntimeTuple_toArray: Symbol = RuntimeTupleModule.requiredMethod("toArray") + lazy val RuntimeTuple_productToArray: Symbol = RuntimeTupleModule.requiredMethod("productToArray") @tu lazy val TupledFunctionTypeRef: TypeRef = ctx.requiredClassRef("scala.TupledFunction") def TupledFunctionClass(implicit ctx: Context): ClassSymbol = TupledFunctionTypeRef.symbol.asClass diff --git a/compiler/src/dotty/tools/dotc/transform/TupleOptimizations.scala b/compiler/src/dotty/tools/dotc/transform/TupleOptimizations.scala index f649857f3e61..06fe98a0cc51 100644 --- a/compiler/src/dotty/tools/dotc/transform/TupleOptimizations.scala +++ b/compiler/src/dotty/tools/dotc/transform/TupleOptimizations.scala @@ -24,13 +24,13 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer { def phaseName: String = "genericTuples" override def transformApply(tree: tpd.Apply)(implicit ctx: Context): tpd.Tree = - if (!tree.symbol.exists || tree.symbol.owner != defn.DynamicTupleModuleClass) tree - else if (tree.symbol == defn.DynamicTuple_cons) transformTupleCons(tree) - else if (tree.symbol == defn.DynamicTuple_tail) transformTupleTail(tree) - else if (tree.symbol == defn.DynamicTuple_size) transformTupleSize(tree) - else if (tree.symbol == defn.DynamicTuple_concat) transformTupleConcat(tree) - else if (tree.symbol == defn.DynamicTuple_apply) transformTupleApply(tree) - else if (tree.symbol == defn.DynamicTuple_toArray) transformTupleToArray(tree) + if (!tree.symbol.exists || tree.symbol.owner != defn.RuntimeTupleModuleClass) tree + else if (tree.symbol == defn.RuntimeTuple_cons) transformTupleCons(tree) + else if (tree.symbol == defn.RuntimeTuple_tail) transformTupleTail(tree) + else if (tree.symbol == defn.RuntimeTuple_size) transformTupleSize(tree) + else if (tree.symbol == defn.RuntimeTuple_concat) transformTupleConcat(tree) + else if (tree.symbol == defn.RuntimeTuple_apply) transformTupleApply(tree) + else if (tree.symbol == defn.RuntimeTuple_toArray) transformTupleToArray(tree) else tree private def transformTupleCons(tree: tpd.Apply)(implicit ctx: Context): Tree = { @@ -49,14 +49,14 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer { else { // val it = Iterator.single(head) ++ tail.asInstanceOf[Product].productIterator // TupleN+1(it.next(), ..., it.next()) - val fullIterator = ref(defn.DynamicTuple_consIterator).appliedToArgs(head :: tail :: Nil) + val fullIterator = ref(defn.RuntimeTuple_consIterator).appliedToArgs(head :: tail :: Nil) evalOnce(fullIterator) { it => knownTupleFromIterator(tpes.length, it).asInstance(tree.tpe) } } case _ => // No optimization, keep: - // DynamicTuple.cons(tail, head) + // scala.runtime.Tuple.cons(tail, head) tree } } @@ -93,7 +93,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer { tup.asInstance(defn.TupleXXLClass.typeRef).select("tailXXL".toTermName) case None => // No optimization, keep: - // DynamicTuple.tail(tup) + // scala.runtime.Tuple.tail(tup) tree } } @@ -127,14 +127,14 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer { else { // val it = self.asInstanceOf[Product].productIterator ++ that.asInstanceOf[Product].productIterator // TupleN+M(it.next(), ..., it.next()) - val fullIterator = ref(defn.DynamicTuple_concatIterator).appliedToArgs(tree.args) + val fullIterator = ref(defn.RuntimeTuple_concatIterator).appliedToArgs(tree.args) evalOnce(fullIterator) { it => knownTupleFromIterator(n + m, it).asInstance(tree.tpe) } } case _ => // No optimization, keep: - // DynamicTuple.cons(self, that) + // scala.runtime.Tuple.cons(self, that) tree } } @@ -161,7 +161,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer { tree case _ => // No optimization, keep: - // DynamicTuple.apply(tup, n) + // scala.runtime.Tuple.apply(tup, n) tree } } @@ -175,14 +175,14 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer { // Array.emptyObjectArray ref(defn.ArrayModule).select("emptyObjectArray".toTermName).ensureApplied else if (size <= MaxTupleArity) - // DynamicTuple.productToArray(tup.asInstanceOf[Product]) - ref(defn.DynamicTuple_productToArray).appliedTo(tup.asInstance(defn.ProductClass.typeRef)) + // scala.runtime.Tuple.productToArray(tup.asInstanceOf[Product]) + ref(defn.RuntimeTuple_productToArray).appliedTo(tup.asInstance(defn.ProductClass.typeRef)) else // tup.asInstanceOf[TupleXXL].elems.clone() tup.asInstance(defn.TupleXXLClass.typeRef).select(nme.toArray) case None => // No optimization, keep: - // DynamicTuple.toArray(tup) + // scala.runtime.Tuple.toArray(tup) tree } } diff --git a/library/src/scala/Tuple.scala b/library/src/scala/Tuple.scala index d4417ce47c32..032364a0c14b 100644 --- a/library/src/scala/Tuple.scala +++ b/library/src/scala/Tuple.scala @@ -11,27 +11,27 @@ sealed trait Tuple extends Any { /** Create a copy this tuple as an Array */ inline def toArray: Array[Object] = - DynamicTuple.toArray(this) + scala.runtime.Tuple.toArray(this) /** Create a copy this tuple as an IArray */ inline def toIArray: IArray[Object] = - DynamicTuple.toIArray(this) + scala.runtime.Tuple.toIArray(this) /** Return a new tuple by prepending the element to `this` tuple. * This opteration is O(this.size) */ inline def *: [H, This >: this.type <: Tuple] (x: H): H *: This = - DynamicTuple.cons(x, this).asInstanceOf[H *: This] + scala.runtime.Tuple.cons(x, this).asInstanceOf[H *: This] /** Return a new tuple by concatenating `this` tuple with `that` tuple. * This opteration is O(this.size + that.size) */ inline def ++ [This >: this.type <: Tuple](that: Tuple): Concat[This, that.type] = - DynamicTuple.concat(this, that).asInstanceOf[Concat[This, that.type]] + scala.runtime.Tuple.concat(this, that).asInstanceOf[Concat[This, that.type]] /** Return the size (or arity) of the tuple */ inline def size[This >: this.type <: Tuple]: Size[This] = - DynamicTuple.size(this).asInstanceOf[Size[This]] + scala.runtime.Tuple.size(this).asInstanceOf[Size[This]] /** Given two tuples, `(a1, ..., an)` and `(a1, ..., an)`, returns a tuple * `((a1, b1), ..., (an, bn))`. If the two tuples have different sizes, @@ -41,7 +41,7 @@ sealed trait Tuple extends Any { * `(A1, B1) *: ... *: (Ai, Bi) *: Tuple` */ inline def zip[This >: this.type <: Tuple, T2 <: Tuple](t2: T2): Zip[This, T2] = - DynamicTuple.zip(this, t2).asInstanceOf[Zip[This, T2]] + scala.runtime.Tuple.zip(this, t2).asInstanceOf[Zip[This, T2]] /** Called on a tuple `(a1, ..., an)`, returns a new tuple `(f(a1), ..., f(an))`. * The result is typed as `(F[A1], ..., F[An])` if the tuple type is fully known. @@ -49,27 +49,27 @@ sealed trait Tuple extends Any { * to be the cons type. */ inline def map[F[_]](f: [t] => t => F[t]): Map[this.type, F] = - DynamicTuple.map(this, f).asInstanceOf[Map[this.type, F]] + scala.runtime.Tuple.map(this, f).asInstanceOf[Map[this.type, F]] /** Given a tuple `(a1, ..., am)`, returns the tuple `(a1, ..., an)` consisting * of its first n elements. */ inline def take[This >: this.type <: Tuple](n: Int): Take[This, n.type] = - DynamicTuple.take(this, n).asInstanceOf[Take[This, n.type]] + scala.runtime.Tuple.take(this, n).asInstanceOf[Take[This, n.type]] /** Given a tuple `(a1, ..., am)`, returns the tuple `(an+1, ..., am)` consisting * all its elements except the first n ones. */ inline def drop[This >: this.type <: Tuple](n: Int): Drop[This, n.type] = - DynamicTuple.drop(this, n).asInstanceOf[Drop[This, n.type]] + scala.runtime.Tuple.drop(this, n).asInstanceOf[Drop[This, n.type]] /** Given a tuple `(a1, ..., am)`, returns a pair of the tuple `(a1, ..., an)` * consisting of the first n elements, and the tuple `(an+1, ..., am)` consisting * of the remaining elements. */ inline def splitAt[This >: this.type <: Tuple](n: Int): Split[This, n.type] = - DynamicTuple.splitAt(this, n).asInstanceOf[Split[This, n.type]] + scala.runtime.Tuple.splitAt(this, n).asInstanceOf[Split[This, n.type]] } object Tuple { @@ -165,7 +165,7 @@ object Tuple { case xs: Array[Object] => xs case xs => xs.map(_.asInstanceOf[Object]) } - DynamicTuple.fromArray(xs2).asInstanceOf[Tuple] + scala.runtime.Tuple.fromArray(xs2).asInstanceOf[Tuple] } /** Convert an immutable array into a tuple of unknown arity and types */ @@ -176,12 +176,12 @@ object Tuple { // TODO support IArray.map xs.asInstanceOf[Array[T]].map(_.asInstanceOf[Object]).asInstanceOf[IArray[Object]] } - DynamicTuple.fromIArray(xs2).asInstanceOf[Tuple] + scala.runtime.Tuple.fromIArray(xs2).asInstanceOf[Tuple] } /** Convert a Product into a tuple of unknown arity and types */ def fromProduct(product: Product): Tuple = - runtime.DynamicTuple.fromProduct(product) + scala.runtime.Tuple.fromProduct(product) def fromProductTyped[P <: Product](p: P)(using m: scala.deriving.Mirror.ProductOf[P]): m.MirroredElemTypes = 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 { * Equivalent to productElement but with a precise return type. */ inline def apply[This >: this.type <: NonEmptyTuple](n: Int): Elem[This, n.type] = - DynamicTuple.apply(this, n).asInstanceOf[Elem[This, n.type]] + scala.runtime.Tuple.apply(this, n).asInstanceOf[Elem[This, n.type]] /** Get the head of this tuple */ inline def head[This >: this.type <: NonEmptyTuple]: Head[This] = - DynamicTuple.apply(this, 0).asInstanceOf[Head[This]] + scala.runtime.Tuple.apply(this, 0).asInstanceOf[Head[This]] /** Get the tail of this tuple. * This opteration is O(this.size) */ inline def tail[This >: this.type <: NonEmptyTuple]: Tail[This] = - DynamicTuple.tail(this).asInstanceOf[Tail[This]] + scala.runtime.Tuple.tail(this).asInstanceOf[Tail[This]] } diff --git a/library/src/scala/runtime/DynamicTupleOld.scala b/library/src/scala/runtime/DynamicTupleOld.scala new file mode 100644 index 000000000000..2950349f8a85 --- /dev/null +++ b/library/src/scala/runtime/DynamicTupleOld.scala @@ -0,0 +1,59 @@ +package scala.runtime + +@deprecated("Use scala.runtime.Tuple", "") +object DynamicTuple { + + inline val MaxSpecialized = 22 + + @deprecated("use toArray", "") + def dynamicToArray(self: Tuple): Array[Object] = scala.runtime.Tuple.toArray(self) + + @deprecated("use toIArray", "") + def dynamicToIArray(self: Tuple): IArray[Object] = scala.runtime.Tuple.toIArray(self) + + @deprecated("Use fromArray") + def dynamicFromArray[T <: Tuple](xs: Array[Object]): T = scala.runtime.Tuple.fromArray(xs).asInstanceOf[T] + + @deprecated("Use fromIArray", "") + def dynamicFromIArray[T <: Tuple](xs: IArray[Object]): T = scala.runtime.Tuple.fromIArray(xs).asInstanceOf[T] + + @deprecated("Use fromProduct", "") + def dynamicFromProduct[T <: Tuple](xs: Product): T = scala.runtime.Tuple.fromProduct(xs).asInstanceOf[T] + + @deprecated("Use cons", "") + def dynamicCons[H, This <: Tuple](x: H, self: This): H *: This = scala.runtime.Tuple.cons(x, self).asInstanceOf[H *: This] + + @deprecated("Use concat", "") + def dynamicConcat[This <: Tuple, That <: Tuple](self: This, that: That): scala.Tuple.Concat[This, That] = scala.runtime.Tuple.concat(self, that).asInstanceOf[scala.Tuple.Concat[This, That]] + + @deprecated("Use size", "") + def dynamicSize[This <: Tuple](self: This): scala.Tuple.Size[This] = scala.runtime.Tuple.size(self).asInstanceOf[scala.Tuple.Size[This]] + + @deprecated("Use tail", "") + def dynamicTail[This <: NonEmptyTuple](self: This): scala.Tuple.Tail[This] = scala.runtime.Tuple.tail(self).asInstanceOf[scala.Tuple.Tail[This]] + + @deprecated("Use apply", "") + def dynamicApply[This <: NonEmptyTuple, N <: Int](self: This, n: N): scala.Tuple.Elem[This, N] = scala.runtime.Tuple.apply(self, n).asInstanceOf[scala.Tuple.Elem[This, N]] + + @deprecated("Use zip", "") + def dynamicZip[This <: Tuple, T2 <: Tuple](t1: This, t2: T2): scala.Tuple.Zip[This, T2] = scala.runtime.Tuple.zip(t1, t2).asInstanceOf[scala.Tuple.Zip[This, T2]] + + @deprecated("Use map", "") + def dynamicMap[This <: Tuple, F[_]](self: This, f: [t] => t => F[t]): scala.Tuple.Map[This, F] = scala.runtime.Tuple.map(self, f).asInstanceOf[scala.Tuple.Map[This, F]] + + @deprecated("Use take", "") + def dynamicTake[This <: Tuple, N <: Int](self: This, n: N): scala.Tuple.Take[This, N] = scala.runtime.Tuple.take(self, n).asInstanceOf[scala.Tuple.Take[This, N]] + + @deprecated("Use drop", "") + def dynamicDrop[This <: Tuple, N <: Int](self: This, n: N): scala.Tuple.Drop[This, N] = scala.runtime.Tuple.drop(self, n).asInstanceOf[scala.Tuple.Drop[This, N]] + + @deprecated("Use splitAt", "") + def dynamicSplitAt[This <: Tuple, N <: Int](self: This, n: N): scala.Tuple.Split[This, N] = scala.runtime.Tuple.splitAt(self, n).asInstanceOf[scala.Tuple.Split[This, N]] + + def consIterator(head: Any, tail: Tuple): Iterator[Any] = + Iterator.single(head) ++ tail.asInstanceOf[Product].productIterator + + def concatIterator(tup1: Tuple, tup2: Tuple): Iterator[Any] = + tup1.asInstanceOf[Product].productIterator ++ tup2.asInstanceOf[Product].productIterator + +} diff --git a/library/src/scala/runtime/DynamicTuple.scala b/library/src/scala/runtime/Tuple.scala similarity index 91% rename from library/src/scala/runtime/DynamicTuple.scala rename to library/src/scala/runtime/Tuple.scala index 795cc3254ed7..895de0adcace 100644 --- a/library/src/scala/runtime/DynamicTuple.scala +++ b/library/src/scala/runtime/Tuple.scala @@ -1,11 +1,8 @@ package scala.runtime -// TODO: Rename to scala.runtime.Tuple -object DynamicTuple { - inline val MaxSpecialized = 22 +object Tuple { - @deprecated("use toArray", "") - def dynamicToArray(self: Tuple): Array[Object] = toArray(self) + inline val MaxSpecialized = 22 def toArray(self: Tuple): Array[Object] = (self: Any) match { case self: TupleXXL => self.toArray @@ -13,9 +10,6 @@ object DynamicTuple { case self: Unit => Array.emptyObjectArray } - @deprecated("use toIArray", "") - def dynamicToIArray(self: Tuple): IArray[Object] = toIArray(self) - def toIArray(self: Tuple): IArray[Object] = (self: Any) match { case self: TupleXXL => self.elems case self: Product => productToArray(self).asInstanceOf[IArray[Object]] @@ -32,9 +26,6 @@ object DynamicTuple { arr } - @deprecated("Use fromArray") - def dynamicFromArray[T <: Tuple](xs: Array[Object]): T = fromArray(xs).asInstanceOf[T] - def fromArray(xs: Array[Object]): Tuple = xs.length match { case 0 => () case 1 => Tuple1(xs(0)) @@ -62,16 +53,10 @@ object DynamicTuple { case _ => TupleXXL.fromIArray(xs.clone().asInstanceOf[IArray[Object]]).asInstanceOf[Tuple] } - @deprecated("Use fromIArray", "") - def dynamicFromIArray[T <: Tuple](xs: IArray[Object]): T = fromIArray(xs).asInstanceOf[T] - def fromIArray(xs: IArray[Object]): Tuple = if (xs.length <= 22) fromArray(xs.asInstanceOf[Array[Object]]) else TupleXXL.fromIArray(xs).asInstanceOf[Tuple] - @deprecated("Use fromProduct", "") - def dynamicFromProduct[T <: Tuple](xs: Product): T = fromProduct(xs).asInstanceOf[T] - def fromProduct(xs: Product): Tuple = (xs.productArity match { case 1 => xs match { @@ -260,17 +245,11 @@ object DynamicTuple { TupleXXL.fromIArray(arr.asInstanceOf[IArray[Object]]) } - @deprecated("Use cons", "") - def dynamicCons[H, This <: Tuple](x: H, self: This): H *: This = cons(x, self).asInstanceOf[H *: This] - def cons(x: Any, self: Tuple): Tuple = (self: Any) match { case xxl: TupleXXL => xxlCons(x, xxl).asInstanceOf[Tuple] case _ => specialCaseCons(x, self) } - @deprecated("Use concat", "") - def dynamicConcat[This <: Tuple, That <: Tuple](self: This, that: That): scala.Tuple.Concat[This, That] = concat(self, that).asInstanceOf[scala.Tuple.Concat[This, That]] - def concat[This <: Tuple, That <: Tuple](self: This, that: That): Tuple = { val selfSize: Int = self.size // If one of the tuples is empty, we can leave early @@ -298,9 +277,6 @@ object DynamicTuple { fromIArray(arr.asInstanceOf[IArray[Object]]) } - @deprecated("Use size", "") - def dynamicSize[This <: Tuple](self: This): scala.Tuple.Size[This] = size(self).asInstanceOf[scala.Tuple.Size[This]] - def size(self: Tuple): Int = (self: Any) match { case self: Unit => 0 case self: Product => self.productArity @@ -373,17 +349,11 @@ object DynamicTuple { } } - @deprecated("Use tail", "") - def dynamicTail[This <: NonEmptyTuple](self: This): scala.Tuple.Tail[This] = tail(self).asInstanceOf[scala.Tuple.Tail[This]] - def tail(self: NonEmptyTuple): Tuple = (self: Any) match { case xxl: TupleXXL => xxlTail(xxl) case _ => specialCaseTail(self) } - @deprecated("Use apply", "") - def dynamicApply[This <: NonEmptyTuple, N <: Int](self: This, n: N): scala.Tuple.Elem[This, N] = apply(self, n).asInstanceOf[scala.Tuple.Elem[This, N]] - def apply(self: NonEmptyTuple, n: Int): Any = { (self: Any) match { // case self: Unit => throw new IndexOutOfBoundsException(n.toString) @@ -402,9 +372,6 @@ object DynamicTuple { arr.asInstanceOf[IArray[Object]] } - @deprecated("Use zip", "") - def dynamicZip[This <: Tuple, T2 <: Tuple](t1: This, t2: T2): scala.Tuple.Zip[This, T2] = zip(t1, t2).asInstanceOf[scala.Tuple.Zip[This, T2]] - def zip(t1: Tuple, t2: Tuple): Tuple = { val t1Size: Int = t1.size val t2Size: Int = t2.size @@ -419,17 +386,11 @@ object DynamicTuple { ) } - @deprecated("Use map", "") - def dynamicMap[This <: Tuple, F[_]](self: This, f: [t] => t => F[t]): scala.Tuple.Map[This, F] = map(self, f).asInstanceOf[scala.Tuple.Map[This, F]] - def map[F[_]](self: Tuple, f: [t] => t => F[t]): Tuple = (self: Any) match { case self: Unit => () - case _ => Tuple.fromArray(self.asInstanceOf[Product].productIterator.map(f(_)).toArray) // TODO use toIArray of Object to avoid double/triple array copy + case _ => fromIArray(self.asInstanceOf[Product].productIterator.map(f(_).asInstanceOf[Object]).toArray.asInstanceOf[IArray[Object]]) // TODO use toIArray } - @deprecated("Use take", "") - def dynamicTake[This <: Tuple, N <: Int](self: This, n: N): scala.Tuple.Take[This, N] = take(self, n).asInstanceOf[scala.Tuple.Take[This, N]] - def take(self: Tuple, n: Int): Tuple = { if (n < 0) throw new IndexOutOfBoundsException(n.toString) val selfSize: Int = self.size @@ -451,9 +412,6 @@ object DynamicTuple { } } - @deprecated("Use drop", "") - def dynamicDrop[This <: Tuple, N <: Int](self: This, n: N): scala.Tuple.Drop[This, N] = drop(self, n).asInstanceOf[scala.Tuple.Drop[This, N]] - def drop(self: Tuple, n: Int): Tuple = { if (n < 0) throw new IndexOutOfBoundsException(n.toString) val size = self.size @@ -476,9 +434,6 @@ object DynamicTuple { } } - @deprecated("Use splitAt", "") - def dynamicSplitAt[This <: Tuple, N <: Int](self: This, n: N): scala.Tuple.Split[This, N] = splitAt(self, n).asInstanceOf[scala.Tuple.Split[This, N]] - def splitAt(self: Tuple, n: Int): (Tuple, Tuple) = { if (n < 0) throw new IndexOutOfBoundsException(n.toString) val size = self.size