diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index d2cdf88d1446..ce32f13c2892 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -197,6 +197,7 @@ class CompilationTests extends ParallelTesting { compileFile("tests/run-custom-args/i5256.scala", allowDeepSubtypes), compileFile("tests/run-custom-args/fors.scala", defaultOptions and "-strict"), compileFile("tests/run-custom-args/no-useless-forwarders.scala", defaultOptions and "-Xmixin-force-forwarders:false"), + compileFilesInDir("tests/run-deep-subtype", allowDeepSubtypes), compileFilesInDir("tests/run", defaultOptions) ).checkRuns() } diff --git a/library/src-3.x/scala/Tuple.scala b/library/src-3.x/scala/Tuple.scala index 994482d4e4c3..e6c3acda39b0 100644 --- a/library/src-3.x/scala/Tuple.scala +++ b/library/src-3.x/scala/Tuple.scala @@ -3,13 +3,15 @@ import annotation.showAsInfix import compiletime._ import internal._ +import scala.runtime.DynamicTuple + sealed trait Tuple extends Any { import Tuple._ inline def toArray: Array[Object] = inline constValueOpt[BoundedSize[this.type]] match { case Some(0) => - scala.runtime.DynamicTuple.empty$Array + DynamicTuple.empty$Array case Some(1) => val t = asInstanceOf[Tuple1[Object]] Array(t._1) @@ -22,12 +24,12 @@ sealed trait Tuple extends Any { case Some(4) => val t = asInstanceOf[Tuple4[Object, Object, Object, Object]] Array(t._1, t._2, t._3, t._4) - case Some(n) if n <= scala.runtime.DynamicTuple.MaxSpecialized => - to$Array(this, n) + case Some(n) if n <= DynamicTuple.MaxSpecialized => + DynamicTuple.to$Array(this, n) case Some(n) => asInstanceOf[TupleXXL].elems case None => - runtime.DynamicTuple.dynamicToArray(this) + DynamicTuple.dynamicToArray(this) } inline def *: [H, This >: this.type <: Tuple] (x: H): H *: This = { @@ -47,9 +49,9 @@ sealed trait Tuple extends Any { val t = asInstanceOf[Tuple4[_, _, _, _]] Tuple5(x, t._1, t._2, t._3, t._4).asInstanceOf[Result] case Some(n) => - knownTupleFromArray[H *: this.type](cons$Array(x, toArray)) + knownTupleFromArray[H *: this.type](DynamicTuple.cons$Array(x, toArray)) case _ => - runtime.DynamicTuple.dynamic_*:[This, H](this, x) + DynamicTuple.dynamic_*:[This, H](this, x) } } @@ -72,7 +74,7 @@ sealed trait Tuple extends Any { val u = that.asInstanceOf[Tuple2[_, _]] Tuple4(t._1, t._2, u._1, u._2).asInstanceOf[Result] case _ => - genericConcat[Result](this, that).asInstanceOf[Result] + knownTupleFromArray[Result](this.toArray ++ that.toArray) } case Some(3) => val t = asInstanceOf[Tuple3[_, _, _]] @@ -82,24 +84,21 @@ sealed trait Tuple extends Any { val u = that.asInstanceOf[Tuple1[_]] Tuple4(t._1, t._2, t._3, u._1).asInstanceOf[Result] case _ => - genericConcat[Result](this, that).asInstanceOf[Result] + knownTupleFromArray[Result](this.toArray ++ that.toArray) } case Some(_) => if (constValue[BoundedSize[that.type]] == 0) this.asInstanceOf[Result] - else genericConcat[Result](this, that).asInstanceOf[Result] + else knownTupleFromArray[Result](this.toArray ++ that.toArray) case None => - runtime.DynamicTuple.dynamic_++[This, that.type](this, that) + DynamicTuple.dynamic_++[This, that.type](this, that) } } - inline def genericConcat[T <: Tuple](xs: Tuple, ys: Tuple): Tuple = - knownTupleFromArray[T](xs.toArray ++ ys.toArray) - inline def size[This >: this.type <: Tuple]: Size[This] = { type Result = Size[This] inline constValueOpt[BoundedSize[this.type]] match { case Some(n) => n.asInstanceOf[Result] - case _ => runtime.DynamicTuple.dynamicSize(this) + case _ => DynamicTuple.dynamicSize(this) } } @@ -144,25 +143,7 @@ object Tuple { private[scala] type BoundedSize[X] = BoundedSizeRecur[X, 23] - val $emptyArray = Array[Object]() - - def to$Array(xs: Tuple, n: Int) = { - val arr = new Array[Object](n) - var i = 0 - var it = xs.asInstanceOf[Product].productIterator - while (i < n) { - arr(i) = it.next().asInstanceOf[Object] - i += 1 - } - arr - } - - def cons$Array[H](x: H, elems: Array[Object]): Array[Object] = { - val elems1 = new Array[Object](elems.length + 1) - elems1(0) = x.asInstanceOf[Object] - System.arraycopy(elems, 0, elems1, 1, elems.length) - elems1 - } + private[scala] val $emptyArray = Array[Object]() private[scala] inline def knownTupleFromArray[T <: Tuple](xs: Array[Object]): T = inline constValue[BoundedSize[T]] match { @@ -197,7 +178,7 @@ object Tuple { case xs: Array[Object] => xs case xs => xs.map(_.asInstanceOf[Object]) } - runtime.DynamicTuple.dynamicFromArray[Tuple](xs2) + DynamicTuple.dynamicFromArray[Tuple](xs2) } } @@ -220,13 +201,13 @@ sealed trait NonEmptyTuple extends Tuple { case Some(4) => val t = asInstanceOf[Tuple4[_, _, _, _]] t._1 - case Some(n) if n > 4 && n <= scala.runtime.DynamicTuple.MaxSpecialized => + case Some(n) if n > 4 && n <= DynamicTuple.MaxSpecialized => asInstanceOf[Product].productElement(0) - case Some(n) if n > scala.runtime.DynamicTuple.MaxSpecialized => + case Some(n) if n > DynamicTuple.MaxSpecialized => val t = asInstanceOf[TupleXXL] t.elems(0) case None => - scala.runtime.DynamicTuple.dynamicHead[this.type](this) + DynamicTuple.dynamicHead[this.type](this) } resVal.asInstanceOf[Result] } @@ -251,14 +232,14 @@ sealed trait NonEmptyTuple extends Tuple { case Some(n) if n > 5 => knownTupleFromArray[Result](toArray.tail) case None => - runtime.DynamicTuple.dynamicTail[This](this) + DynamicTuple.dynamicTail[This](this) } } inline def fallbackApply(n: Int) = inline constValueOpt[n.type] match { case Some(n: Int) => error("index out of bounds: ", n) - case None => runtime.DynamicTuple.dynamicApply[this.type, n.type](this, n) + case None => DynamicTuple.dynamicApply[this.type, n.type](this, n) } inline def apply[This >: this.type <: NonEmptyTuple](n: Int): Elem[This, n.type] = { @@ -294,13 +275,13 @@ sealed trait NonEmptyTuple extends Tuple { case Some(3) => t._4.asInstanceOf[Result] case _ => fallbackApply(n).asInstanceOf[Result] } - case Some(s) if s > 4 && s <= scala.runtime.DynamicTuple.MaxSpecialized => + case Some(s) if s > 4 && s <= DynamicTuple.MaxSpecialized => val t = asInstanceOf[Product] inline constValueOpt[n.type] match { case Some(n) if n >= 0 && n < s => t.productElement(n).asInstanceOf[Result] case _ => fallbackApply(n).asInstanceOf[Result] } - case Some(s) if s > scala.runtime.DynamicTuple.MaxSpecialized => + case Some(s) if s > DynamicTuple.MaxSpecialized => val t = asInstanceOf[TupleXXL] inline constValueOpt[n.type] match { case Some(n) if n >= 0 && n < s => t.elems(n).asInstanceOf[Result] diff --git a/tests/run-deep-subtype/Tuple-apply.scala b/tests/run-deep-subtype/Tuple-apply.scala new file mode 100644 index 000000000000..87cc173d10a3 --- /dev/null +++ b/tests/run-deep-subtype/Tuple-apply.scala @@ -0,0 +1,170 @@ +import scala.reflect.ClassTag + +object Test { + def main(args: Array[String]): Unit = { + + assert(1 == Tuple1(1).apply(0)) + assert(1 == (1, 2).apply(0)) + assert(2 == (1, 2).apply(1)) + assert(1 == (1, 2, 3).apply(0)) + assert(2 == (1, 2, 3).apply(1)) + assert(3 == (1, 2, 3).apply(2)) + assert(1 == (1, 2, 3, 4).apply(0)) + assert(2 == (1, 2, 3, 4).apply(1)) + assert(3 == (1, 2, 3, 4).apply(2)) + assert(4 == (1, 2, 3, 4).apply(3)) + assert(1 == (1, 2, 3, 4, 5).apply(0)) + assert(2 == (1, 2, 3, 4, 5).apply(1)) + assert(3 == (1, 2, 3, 4, 5).apply(2)) + assert(4 == (1, 2, 3, 4, 5).apply(3)) + assert(5 == (1, 2, 3, 4, 5).apply(4)) + // TODO improve performace +// assert(1 == (1, 2, 3, 4, 5, 6).apply(0)) +// assert(2 == (1, 2, 3, 4, 5, 6).apply(1)) +// assert(3 == (1, 2, 3, 4, 5, 6).apply(2)) +// assert(4 == (1, 2, 3, 4, 5, 6).apply(3)) +// assert(5 == (1, 2, 3, 4, 5, 6).apply(4)) +// assert(6 == (1, 2, 3, 4, 5, 6).apply(5)) +// assert(1 == (1, 2, 3, 4, 5, 6, 7).apply(0)) +// assert(2 == (1, 2, 3, 4, 5, 6, 7).apply(1)) +// assert(3 == (1, 2, 3, 4, 5, 6, 7).apply(2)) +// assert(4 == (1, 2, 3, 4, 5, 6, 7).apply(3)) +// assert(5 == (1, 2, 3, 4, 5, 6, 7).apply(4)) +// assert(6 == (1, 2, 3, 4, 5, 6, 7).apply(5)) +// assert(7 == (1, 2, 3, 4, 5, 6, 7).apply(6)) +// assert(1 == (1, 2, 3, 4, 5, 6, 7, 8).apply(0)) +// assert(2 == (1, 2, 3, 4, 5, 6, 7, 8).apply(1)) +// assert(3 == (1, 2, 3, 4, 5, 6, 7, 8).apply(2)) +// assert(4 == (1, 2, 3, 4, 5, 6, 7, 8).apply(3)) +// assert(5 == (1, 2, 3, 4, 5, 6, 7, 8).apply(4)) +// assert(6 == (1, 2, 3, 4, 5, 6, 7, 8).apply(5)) +// assert(7 == (1, 2, 3, 4, 5, 6, 7, 8).apply(6)) +// assert(8 == (1, 2, 3, 4, 5, 6, 7, 8).apply(7)) +// assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9).apply(0)) +// assert(2 == (1, 2, 3, 4, 5, 6, 7, 8, 9).apply(1)) +// assert(3 == (1, 2, 3, 4, 5, 6, 7, 8, 9).apply(2)) +// assert(4 == (1, 2, 3, 4, 5, 6, 7, 8, 9).apply(3)) +// assert(5 == (1, 2, 3, 4, 5, 6, 7, 8, 9).apply(4)) +// assert(6 == (1, 2, 3, 4, 5, 6, 7, 8, 9).apply(5)) +// assert(7 == (1, 2, 3, 4, 5, 6, 7, 8, 9).apply(6)) +// assert(8 == (1, 2, 3, 4, 5, 6, 7, 8, 9).apply(7)) +// assert(9 == (1, 2, 3, 4, 5, 6, 7, 8, 9).apply(8)) +// assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).apply(0)) +// assert(2 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).apply(1)) +// assert(3 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).apply(2)) +// assert(4 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).apply(3)) +// assert(5 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).apply(4)) +// assert(6 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).apply(5)) +// assert(7 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).apply(6)) +// assert(8 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).apply(7)) +// assert(9 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).apply(8)) +// assert(10 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).apply(9)) + + assert(1 == Tuple1(1).apply(0)) + assert(1 == (1, 2).apply(0)) + assert(1 == (1, 2, 3).apply(0)) + assert(1 == (1, 2, 3, 4).apply(0)) + assert(1 == (1, 2, 3, 4, 5).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24).apply(0)) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25).apply(0)) + + assert(1 == Tuple1(1).apply(0)) + assert(2 == (1, 2).apply(1)) + assert(3 == (1, 2, 3).apply(2)) + assert(4 == (1, 2, 3, 4).apply(3)) + assert(5 == (1, 2, 3, 4, 5).apply(4)) + assert(6 == (1, 2, 3, 4, 5, 6).apply(5)) + assert(7 == (1, 2, 3, 4, 5, 6, 7).apply(6)) + assert(8 == (1, 2, 3, 4, 5, 6, 7, 8).apply(7)) + assert(9 == (1, 2, 3, 4, 5, 6, 7, 8, 9).apply(8)) + assert(10 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).apply(9)) + assert(11 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11).apply(10)) + assert(12 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12).apply(11)) + assert(13 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13).apply(12)) + assert(14 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14).apply(13)) + assert(15 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).apply(14)) + assert(16 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16).apply(15)) + assert(17 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17).apply(16)) + assert(18 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18).apply(17)) + assert(19 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19).apply(18)) + assert(20 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20).apply(19)) + assert(21 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21).apply(20)) + assert(22 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22).apply(21)) + assert(23 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23).apply(22)) + assert(24 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24).apply(23)) + assert(25 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25).apply(24)) + + assert(1 == (1 *: ()).apply(0)) + assert(1 == (1 *: 2 *: ()).apply(0)) + assert(1 == (1 *: 2 *: 3 *: ()).apply(0)) + assert(1 == (1 *: 2 *: 3 *: 4 *: ()).apply(0)) + assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: ()).apply(0)) + assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: ()).apply(0)) + assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: ()).apply(0)) + // FIXME performace +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: 24 *: ()).apply(0)) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: 24 *: 25 *: ()).apply(0)) + + assert(1 == (1 *: ()).apply(0)) + assert(2 == (1 *: 2 *: ()).apply(1)) + assert(3 == (1 *: 2 *: 3 *: ()).apply(2)) + assert(4 == (1 *: 2 *: 3 *: 4 *: ()).apply(3)) + assert(5 == (1 *: 2 *: 3 *: 4 *: 5 *: ()).apply(4)) + assert(6 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: ()).apply(5)) + assert(7 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: ()).apply(6)) + // FIXME performace +// assert(8 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: ()).apply(7)) +// assert(9 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: ()).apply(8)) +// assert(10 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: ()).apply(9)) +// assert(11 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: ()).apply(10)) +// assert(12 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: ()).apply(11)) +// assert(13 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: ()).apply(12)) +// assert(14 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: ()).apply(13)) +// assert(15 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: ()).apply(14)) +// assert(16 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: ()).apply(15)) +// assert(17 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: ()).apply(16)) +// assert(18 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: ()).apply(17)) +// assert(19 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: ()).apply(18)) +// assert(20 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: ()).apply(19)) +// assert(21 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: ()).apply(20)) +// assert(22 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: ()).apply(21)) +// assert(23 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: ()).apply(22)) +// assert(24 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: 24 *: ()).apply(23)) +// assert(25 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: 24 *: 25 *: ()).apply(24)) + + } +} diff --git a/tests/run-deep-subtype/Tuple-head.scala b/tests/run-deep-subtype/Tuple-head.scala new file mode 100644 index 000000000000..8c8788278b62 --- /dev/null +++ b/tests/run-deep-subtype/Tuple-head.scala @@ -0,0 +1,67 @@ +import scala.reflect.ClassTag + +object Test { + def main(args: Array[String]): Unit = { + + def testArray[T: ClassTag](n: Int, elem: Int => T): Unit = { + val t: Int *: Tuple = 0 *: Tuple.fromArray(Array.tabulate(n)(elem)) + assert(0 == t.head) + } + + for (i <- 0 to 25) + testArray(i, j => j) + + assert(1 == Tuple1(1).head) + assert(1 == (1, 2).head) + assert(1 == (1, 2, 3).head) + assert(1 == (1, 2, 3, 4).head) + assert(1 == (1, 2, 3, 4, 5).head) + assert(1 == (1, 2, 3, 4, 5, 6).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24).head) + assert(1 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25).head) + + assert(1 == (1 *: ()).head) + assert(1 == (1 *: 2 *: ()).head) + assert(1 == (1 *: 2 *: 3 *: ()).head) + assert(1 == (1 *: 2 *: 3 *: 4 *: ()).head) + assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: ()).head) + assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: ()).head) + assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: ()).head) + assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: ()).head) + assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: ()).head) + assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: ()).head) + // FIXME performace +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: ()).head) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: ()).head) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: ()).head) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: ()).head) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: ()).head) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: ()).head) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: ()).head) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: ()).head) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: ()).head) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: ()).head) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: ()).head) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: ()).head) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: ()).head) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: 24 *: ()).head) +// assert(1 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: 24 *: 25 *: ()).head) + } +} diff --git a/tests/run-deep-subtype/Tuple-size.scala b/tests/run-deep-subtype/Tuple-size.scala new file mode 100644 index 000000000000..78785dc0a70f --- /dev/null +++ b/tests/run-deep-subtype/Tuple-size.scala @@ -0,0 +1,67 @@ +import scala.reflect.ClassTag + +object Test { + def main(args: Array[String]): Unit = { + + def testArray[T: ClassTag](n: Int, elem: Int => T): Unit = { + val t: Tuple = Tuple.fromArray(Array.tabulate(n)(elem)) + assert(n == t.size) + } + + for (i <- 0 to 25) + testArray(i, j => j) + + assert(1 == Tuple1(1).size) + assert(2 == (1, 2).size) + assert(3 == (1, 2, 3).size) + assert(4 == (1, 2, 3, 4).size) + assert(5 == (1, 2, 3, 4, 5).size) + assert(6 == (1, 2, 3, 4, 5, 6).size) + assert(7 == (1, 2, 3, 4, 5, 6, 7).size) + assert(8 == (1, 2, 3, 4, 5, 6, 7, 8).size) + assert(9 == (1, 2, 3, 4, 5, 6, 7, 8, 9).size) + assert(10 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).size) + assert(11 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11).size) + assert(12 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12).size) + assert(13 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13).size) + assert(14 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14).size) + assert(15 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).size) + assert(16 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16).size) + assert(17 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17).size) + assert(18 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18).size) + assert(19 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19).size) + assert(20 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20).size) + assert(21 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21).size) + assert(22 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22).size) + assert(23 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23).size) + assert(24 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24).size) + assert(25 == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25).size) + + assert(1 == (1 *: ()).size) + assert(2 == (1 *: 2 *: ()).size) + assert(3 == (1 *: 2 *: 3 *: ()).size) + assert(4 == (1 *: 2 *: 3 *: 4 *: ()).size) + assert(5 == (1 *: 2 *: 3 *: 4 *: 5 *: ()).size) + assert(6 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: ()).size) + assert(7 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: ()).size) + assert(8 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: ()).size) + assert(9 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: ()).size) + assert(10 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: ()).size) + // FIXME performace +// assert(11 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: ()).size) +// assert(12 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: ()).size) +// assert(13 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: ()).size) +// assert(14 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: ()).size) +// assert(15 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: ()).size) +// assert(16 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: ()).size) +// assert(17 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: ()).size) +// assert(18 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: ()).size) +// assert(19 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: ()).size) +// assert(20 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: ()).size) +// assert(21 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: ()).size) +// assert(22 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: ()).size) +// assert(23 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: ()).size) +// assert(24 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: 24 *: ()).size) +// assert(25 == (1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: 24 *: 25 *: ()).size) + } +} diff --git a/tests/run-deep-subtype/Tuple-tail.check b/tests/run-deep-subtype/Tuple-tail.check new file mode 100644 index 000000000000..b22fd91be7de --- /dev/null +++ b/tests/run-deep-subtype/Tuple-tail.check @@ -0,0 +1,61 @@ +() +(0) +(0,1) +(0,1,2) +(0,1,2,3) +(0,1,2,3,4) +(0,1,2,3,4,5) +(0,1,2,3,4,5,6) +(0,1,2,3,4,5,6,7) +(0,1,2,3,4,5,6,7,8) +(0,1,2,3,4,5,6,7,8,9) +(0,1,2,3,4,5,6,7,8,9,10) +(0,1,2,3,4,5,6,7,8,9,10,11) +(0,1,2,3,4,5,6,7,8,9,10,11,12) +(0,1,2,3,4,5,6,7,8,9,10,11,12,13) +(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14) +(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) +(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16) +(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17) +(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18) +(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19) +(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20) +(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21) +(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22) +(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) +(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24) +() +(2) +(2,3) +(2,3,4) +(2,3,4,5) +(2,3,4,5,6) +(2,3,4,5,6,7) +(2,3,4,5,6,7,8) +(2,3,4,5,6,7,8,9) +(2,3,4,5,6,7,8,9,10) +(2,3,4,5,6,7,8,9,10,11) +(2,3,4,5,6,7,8,9,10,11,12) +(2,3,4,5,6,7,8,9,10,11,12,13) +(2,3,4,5,6,7,8,9,10,11,12,13,14) +(2,3,4,5,6,7,8,9,10,11,12,13,14,15) +(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16) +(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17) +(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18) +(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19) +(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20) +(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21) +(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22) +(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) +(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24) +(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25) +() +(2) +(2,3) +(2,3,4) +(2,3,4,5) +(2,3,4,5,6) +(2,3,4,5,6,7) +(2,3,4,5,6,7,8) +(2,3,4,5,6,7,8,9) +(2,3,4,5,6,7,8,9,10) diff --git a/tests/run-deep-subtype/Tuple-tail.scala b/tests/run-deep-subtype/Tuple-tail.scala new file mode 100644 index 000000000000..896f33b29aa2 --- /dev/null +++ b/tests/run-deep-subtype/Tuple-tail.scala @@ -0,0 +1,67 @@ +import scala.reflect.ClassTag + +object Test { + def main(args: Array[String]): Unit = { + + def testArray[T: ClassTag](n: Int, elem: Int => T): Unit = { + val t: Int *: Tuple = 0 *: Tuple.fromArray(Array.tabulate(n)(elem)) + println(t.tail) + } + + for (i <- 0 to 25) + testArray(i, j => j) + + println(Tuple1(1).tail) + println((1, 2).tail) + println((1, 2, 3).tail) + println((1, 2, 3, 4).tail) + println((1, 2, 3, 4, 5).tail) + println((1, 2, 3, 4, 5, 6).tail) + println((1, 2, 3, 4, 5, 6, 7).tail) + println((1, 2, 3, 4, 5, 6, 7, 8).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9, 10).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24).tail) + println((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25).tail) + + println((1 *: ()).tail) + println((1 *: 2 *: ()).tail) + println((1 *: 2 *: 3 *: ()).tail) + println((1 *: 2 *: 3 *: 4 *: ()).tail) + println((1 *: 2 *: 3 *: 4 *: 5 *: ()).tail) + println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: ()).tail) + println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: ()).tail) + println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: ()).tail) + println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: ()).tail) + println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: ()).tail) + // FIXME performace +// println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: ()).tail) +// println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: ()).tail) +// println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: ()).tail) +// println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: ()).tail) +// println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: ()).tail) +// println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: ()).tail) +// println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: ()).tail) +// println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: ()).tail) +// println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: ()).tail) +// println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: ()).tail) +// println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: ()).tail) +// println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: ()).tail) +// println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: ()).tail) +// println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: 24 *: ()).tail) +// println((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: 24 *: 25 *: ()).tail) + } +} diff --git a/tests/run-deep-subtype/Tuple-toArray.check b/tests/run-deep-subtype/Tuple-toArray.check new file mode 100644 index 000000000000..247bee409b31 --- /dev/null +++ b/tests/run-deep-subtype/Tuple-toArray.check @@ -0,0 +1,62 @@ +[] +[0] +[0, 1] +[0, 1, 2] +[0, 1, 2, 3] +[0, 1, 2, 3, 4] +[0, 1, 2, 3, 4, 5] +[0, 1, 2, 3, 4, 5, 6] +[0, 1, 2, 3, 4, 5, 6, 7] +[0, 1, 2, 3, 4, 5, 6, 7, 8] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] +[] +[1] +[1, 2] +[1, 2, 3] +[1, 2, 3, 4] +[1, 2, 3, 4, 5] +[1, 2, 3, 4, 5, 6] +[1, 2, 3, 4, 5, 6, 7] +[1, 2, 3, 4, 5, 6, 7, 8] +[1, 2, 3, 4, 5, 6, 7, 8, 9] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25] +[1] +[1, 2] +[1, 2, 3] +[1, 2, 3, 4] +[1, 2, 3, 4, 5] +[1, 2, 3, 4, 5, 6] +[1, 2, 3, 4, 5, 6, 7] +[1, 2, 3, 4, 5, 6, 7, 8] +[1, 2, 3, 4, 5, 6, 7, 8, 9] +[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] diff --git a/tests/run-deep-subtype/Tuple-toArray.scala b/tests/run-deep-subtype/Tuple-toArray.scala new file mode 100644 index 000000000000..941121bd4ace --- /dev/null +++ b/tests/run-deep-subtype/Tuple-toArray.scala @@ -0,0 +1,70 @@ +import scala.reflect.ClassTag + +object Test { + def main(args: Array[String]): Unit = { + + def printArray(xs: Array[Object]): Unit = + println(java.util.Arrays.deepToString(xs)) + def testArray[T: ClassTag](n: Int, elem: Int => T): Unit = { + val t: Tuple = Tuple.fromArray(Array.tabulate(n)(elem)) + printArray(t.toArray) + } + + for (i <- 0 to 25) + testArray(i, j => j) + + printArray(().toArray) + printArray(Tuple1(1).toArray) + printArray((1, 2).toArray) + printArray((1, 2, 3).toArray) + printArray((1, 2, 3, 4).toArray) + printArray((1, 2, 3, 4, 5).toArray) + printArray((1, 2, 3, 4, 5, 6).toArray) + printArray((1, 2, 3, 4, 5, 6, 7).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9, 10).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24).toArray) + printArray((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25).toArray) + + printArray((1 *: ()).toArray) + printArray((1 *: 2 *: ()).toArray) + printArray((1 *: 2 *: 3 *: ()).toArray) + printArray((1 *: 2 *: 3 *: 4 *: ()).toArray) + printArray((1 *: 2 *: 3 *: 4 *: 5 *: ()).toArray) + printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: ()).toArray) + printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: ()).toArray) + printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: ()).toArray) + printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: ()).toArray) + printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: ()).toArray) + // FIXME performace +// printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: ()).toArray) +// printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: ()).toArray) +// printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: ()).toArray) +// printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: ()).toArray) +// printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: ()).toArray) +// printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: ()).toArray) +// printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: ()).toArray) +// printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: ()).toArray) +// printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: ()).toArray) +// printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: ()).toArray) +// printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: ()).toArray) +// printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: ()).toArray) +// printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: ()).toArray) +// printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: 24 *: ()).toArray) +// printArray((1 *: 2 *: 3 *: 4 *: 5 *: 6 *: 7 *: 8 *: 9 *: 10 *: 11 *: 12 *: 13 *: 14 *: 15 *: 16 *: 17 *: 18 *: 19 *: 20 *: 21 *: 22 *: 23 *: 24 *: 25 *: ()).toArray) + } +}