Skip to content

Commit

Permalink
Rename scala.runtime.{Tuple => Tuples}
Browse files Browse the repository at this point in the history
To avoid confusion with scala.Tuple. Part of scala#10602.
  • Loading branch information
smarter committed Jan 5, 2021
1 parent 1405778 commit aaa6ec1
Show file tree
Hide file tree
Showing 18 changed files with 872 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Apply {

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

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

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

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

@Benchmark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ class Conversions {

@Benchmark
def tupleToArray(): Array[Object] = {
runtime.Tuple.toArray(tuple)
runtime.Tuples.toArray(tuple)
}

@Benchmark
def tupleToIArray(): IArray[Object] = {
runtime.Tuple.toIArray(tuple)
runtime.Tuples.toIArray(tuple)
}

@Benchmark
def tupleFromArray(): Tuple = {
runtime.Tuple.fromArray(array)
runtime.Tuples.fromArray(array)
}

@Benchmark
def tupleFromIArray(): Tuple = {
runtime.Tuple.fromIArray(iarray)
runtime.Tuples.fromIArray(iarray)
}

@Benchmark
def productToArray(): Array[Object] = {
runtime.Tuple.productToArray(tuple.asInstanceOf[Product])
runtime.Tuples.productToArray(tuple.asInstanceOf[Product])
}

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

@Benchmark
def tupleMap(): Tuple = {
runtime.Tuple.map[Id](tuple, [T] => (x:T) => x.asInstanceOf[String].updated(0, 'a').asInstanceOf[T])
runtime.Tuples.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 @@ -21,7 +21,7 @@ class Tail {

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

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

@Benchmark
def tupleZip(): Tuple = {
runtime.Tuple.zip(tuple1, tuple2)
runtime.Tuples.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 @@ -23,7 +23,7 @@ class Drop {

@Benchmark
def tupleDrop(): Tuple = {
runtime.Tuple.drop(tuple, half)
runtime.Tuples.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 @@ -23,7 +23,7 @@ class Split {

@Benchmark
def tupleSplit(): (Tuple, Tuple) = {
runtime.Tuple.splitAt(tuple, half)
runtime.Tuples.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 @@ -23,7 +23,7 @@ class Take {

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

@Benchmark
Expand Down
28 changes: 14 additions & 14 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -867,20 +867,20 @@ class Definitions {

def TupleXXL_fromIterator(using Context): Symbol = TupleXXLModule.requiredMethod("fromIterator")

@tu lazy val RuntimeTupleModule: Symbol = 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")
lazy val RuntimeTuple_isInstanceOfTuple: Symbol = RuntimeTupleModule.requiredMethod("isInstanceOfTuple")
lazy val RuntimeTuple_isInstanceOfEmptyTuple: Symbol = RuntimeTupleModule.requiredMethod("isInstanceOfEmptyTuple")
lazy val RuntimeTuple_isInstanceOfNonEmptyTuple: Symbol = RuntimeTupleModule.requiredMethod("isInstanceOfNonEmptyTuple")
@tu lazy val RuntimeTuplesModule: Symbol = requiredModule("scala.runtime.Tuples")
@tu lazy val RuntimeTuplesModuleClass: Symbol = RuntimeTuplesModule.moduleClass
lazy val RuntimeTuples_consIterator: Symbol = RuntimeTuplesModule.requiredMethod("consIterator")
lazy val RuntimeTuples_concatIterator: Symbol = RuntimeTuplesModule.requiredMethod("concatIterator")
lazy val RuntimeTuples_apply: Symbol = RuntimeTuplesModule.requiredMethod("apply")
lazy val RuntimeTuples_cons: Symbol = RuntimeTuplesModule.requiredMethod("cons")
lazy val RuntimeTuples_size: Symbol = RuntimeTuplesModule.requiredMethod("size")
lazy val RuntimeTuples_tail: Symbol = RuntimeTuplesModule.requiredMethod("tail")
lazy val RuntimeTuples_concat: Symbol = RuntimeTuplesModule.requiredMethod("concat")
lazy val RuntimeTuples_toArray: Symbol = RuntimeTuplesModule.requiredMethod("toArray")
lazy val RuntimeTuples_productToArray: Symbol = RuntimeTuplesModule.requiredMethod("productToArray")
lazy val RuntimeTuples_isInstanceOfTuple: Symbol = RuntimeTuplesModule.requiredMethod("isInstanceOfTuple")
lazy val RuntimeTuples_isInstanceOfEmptyTuple: Symbol = RuntimeTuplesModule.requiredMethod("isInstanceOfEmptyTuple")
lazy val RuntimeTuples_isInstanceOfNonEmptyTuple: Symbol = RuntimeTuplesModule.requiredMethod("isInstanceOfNonEmptyTuple")

// Annotation base classes
@tu lazy val AnnotationClass: ClassSymbol = requiredClass("scala.annotation.Annotation")
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)(using Context): tpd.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)
if (!tree.symbol.exists || tree.symbol.owner != defn.RuntimeTuplesModuleClass) tree
else if (tree.symbol == defn.RuntimeTuples_cons) transformTupleCons(tree)
else if (tree.symbol == defn.RuntimeTuples_tail) transformTupleTail(tree)
else if (tree.symbol == defn.RuntimeTuples_size) transformTupleSize(tree)
else if (tree.symbol == defn.RuntimeTuples_concat) transformTupleConcat(tree)
else if (tree.symbol == defn.RuntimeTuples_apply) transformTupleApply(tree)
else if (tree.symbol == defn.RuntimeTuples_toArray) transformTupleToArray(tree)
else tree

private def transformTupleCons(tree: tpd.Apply)(using 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.RuntimeTuple_consIterator).appliedToArgs(head :: tail :: Nil)
val fullIterator = ref(defn.RuntimeTuples_consIterator).appliedToArgs(head :: tail :: Nil)
evalOnce(fullIterator) { it =>
knownTupleFromIterator(tpes.length, it).asInstance(tree.tpe)
}
}
case _ =>
// No optimization, keep:
// scala.runtime.Tuple.cons(tail, head)
// scala.runtime.Tuples.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:
// scala.runtime.Tuple.tail(tup)
// scala.runtime.Tuples.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.RuntimeTuple_concatIterator).appliedToArgs(tree.args)
val fullIterator = ref(defn.RuntimeTuples_concatIterator).appliedToArgs(tree.args)
evalOnce(fullIterator) { it =>
knownTupleFromIterator(n + m, it).asInstance(tree.tpe)
}
}
case _ =>
// No optimization, keep:
// scala.runtime.Tuple.cons(self, that)
// scala.runtime.Tuples.cons(self, that)
tree
}
}
Expand All @@ -161,7 +161,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
tree
case _ =>
// No optimization, keep:
// scala.runtime.Tuple.apply(tup, n)
// scala.runtime.Tuples.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)
// scala.runtime.Tuple.productToArray(tup.asInstanceOf[Product])
ref(defn.RuntimeTuple_productToArray).appliedTo(tup.asInstance(defn.ProductClass.typeRef))
// scala.runtime.Tuples.productToArray(tup.asInstanceOf[Product])
ref(defn.RuntimeTuples_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:
// scala.runtime.Tuple.toArray(tup)
// scala.runtime.Tuples.toArray(tup)
tree
}
}
Expand Down
16 changes: 8 additions & 8 deletions compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,17 @@ object TypeTestsCasts {
*
* expr.isInstanceOf[A | B] ~~> expr.isInstanceOf[A] | expr.isInstanceOf[B]
* expr.isInstanceOf[A & B] ~~> expr.isInstanceOf[A] & expr.isInstanceOf[B]
* expr.isInstanceOf[Tuple] ~~> scala.runtime.Tuple.isInstanceOfTuple(expr)
* expr.isInstanceOf[EmptyTuple] ~~> scala.runtime.Tuple.isInstanceOfEmptyTuple(expr)
* expr.isInstanceOf[NonEmptyTuple] ~~> scala.runtime.Tuple.isInstanceOfNonEmptyTuple(expr)
* expr.isInstanceOf[*:[_, _]] ~~> scala.runtime.Tuple.isInstanceOfNonEmptyTuple(expr)
* expr.isInstanceOf[Tuple] ~~> scala.runtime.Tuples.isInstanceOfTuple(expr)
* expr.isInstanceOf[EmptyTuple] ~~> scala.runtime.Tuples.isInstanceOfEmptyTuple(expr)
* expr.isInstanceOf[NonEmptyTuple] ~~> scala.runtime.Tuples.isInstanceOfNonEmptyTuple(expr)
* expr.isInstanceOf[*:[_, _]] ~~> scala.runtime.Tuples.isInstanceOfNonEmptyTuple(expr)
*
* The transform happens before erasure of `testType`, thus cannot be merged
* with `transformIsInstanceOf`, which depends on erased type of `testType`.
*/
def transformTypeTest(expr: Tree, testType: Type, flagUnrelated: Boolean): Tree = testType.dealias match {
case tref: TermRef if tref.symbol == defn.EmptyTupleModule =>
ref(defn.RuntimeTuple_isInstanceOfEmptyTuple).appliedTo(expr)
ref(defn.RuntimeTuples_isInstanceOfEmptyTuple).appliedTo(expr)
case _: SingletonType =>
expr.isInstance(testType).withSpan(tree.span)
case OrType(tp1, tp2) =>
Expand All @@ -343,11 +343,11 @@ object TypeTestsCasts {
.and(isArrayTest(e))
}
case tref: TypeRef if tref.symbol == defn.TupleClass =>
ref(defn.RuntimeTuple_isInstanceOfTuple).appliedTo(expr)
ref(defn.RuntimeTuples_isInstanceOfTuple).appliedTo(expr)
case tref: TypeRef if tref.symbol == defn.NonEmptyTupleClass =>
ref(defn.RuntimeTuple_isInstanceOfNonEmptyTuple).appliedTo(expr)
ref(defn.RuntimeTuples_isInstanceOfNonEmptyTuple).appliedTo(expr)
case AppliedType(tref: TypeRef, _) if tref.symbol == defn.PairClass =>
ref(defn.RuntimeTuple_isInstanceOfNonEmptyTuple).appliedTo(expr)
ref(defn.RuntimeTuples_isInstanceOfNonEmptyTuple).appliedTo(expr)
case _ =>
val erasedTestType = erasure(testType)
transformIsInstanceOf(expr, erasedTestType, erasedTestType, flagUnrelated)
Expand Down
Loading

0 comments on commit aaa6ec1

Please sign in to comment.