Skip to content

Rename Dynamic tuple to scala.runtime.Tuple #8335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Apply {

@Benchmark
def tupleApply(): Any = {
DynamicTuple.apply(tuple, index)
runtime.Tuple.apply(tuple, index)
}

@Benchmark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ class Concat {

@Benchmark
def tupleConcat(): Tuple = {
DynamicTuple.concat(tuple1, tuple2)
runtime.Tuple.concat(tuple1, tuple2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Cons {

@Benchmark
def tupleCons(): Tuple = {
DynamicTuple.cons("elem", tuple)
runtime.Tuple.cons("elem", tuple)
}

@Benchmark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Tail {

@Benchmark
def tupleTail(): Tuple = {
DynamicTuple.tail(tuple)
runtime.Tuple.tail(tuple)
}

@Benchmark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Zip {

@Benchmark
def tupleZip(): Tuple = {
DynamicTuple.zip(tuple1, tuple2)
runtime.Tuple.zip(tuple1, tuple2)
}

@Benchmark
Expand Down
2 changes: 1 addition & 1 deletion bench-run/src/main/scala/tuples/Drop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Drop {

@Benchmark
def tupleDrop(): Tuple = {
DynamicTuple.drop(tuple, half)
runtime.Tuple.drop(tuple, half)
}

@Benchmark
Expand Down
2 changes: 1 addition & 1 deletion bench-run/src/main/scala/tuples/Split.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Split {

@Benchmark
def tupleSplit(): (Tuple, Tuple) = {
DynamicTuple.splitAt(tuple, half)
runtime.Tuple.splitAt(tuple, half)
}

@Benchmark
Expand Down
2 changes: 1 addition & 1 deletion bench-run/src/main/scala/tuples/Take.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Take {

@Benchmark
def tupleTake(): Tuple = {
DynamicTuple.take(tuple, half)
runtime.Tuple.take(tuple, half)
}

@Benchmark
Expand Down
22 changes: 11 additions & 11 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions compiler/src/dotty/tools/dotc/transform/TupleOptimizations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand All @@ -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
}
}
Expand Down
32 changes: 16 additions & 16 deletions library/src/scala/Tuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -41,35 +41,35 @@ 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.
* If the tuple is of the form `a1 *: ... *: Tuple` (that is, the tail is not known
* 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 {
Expand Down Expand Up @@ -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 */
Expand All @@ -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
Expand All @@ -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]]

}

Expand Down
Loading