Skip to content
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
@@ -1,7 +1,6 @@
package dotty.tools.benchmarks.tuples

import org.openjdk.jmh.annotations._
import scala.runtime.DynamicTuple

@State(Scope.Thread)
class Apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dotty.tools.benchmarks.tuples

import org.openjdk.jmh.annotations._
import org.openjdk.jmh.infra.Blackhole
import scala.runtime.DynamicTuple

@State(Scope.Thread)
class Concat {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dotty.tools.benchmarks.tuples

import org.openjdk.jmh.annotations._
import scala.runtime.DynamicTuple

@State(Scope.Thread)
class Cons {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dotty.tools.benchmarks.tuples

import org.openjdk.jmh.annotations._
import scala.runtime.DynamicTuple

@State(Scope.Thread)
class Conversions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dotty.tools.benchmarks.tuples

import org.openjdk.jmh.annotations._
import scala.runtime.DynamicTuple

@State(Scope.Thread)
class Map {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dotty.tools.benchmarks.tuples

import org.openjdk.jmh.annotations._
import scala.runtime.DynamicTuple

@State(Scope.Thread)
class Tail {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dotty.tools.benchmarks.tuples

import org.openjdk.jmh.annotations._
import scala.runtime.DynamicTuple

@State(Scope.Thread)
class Zip {
Expand Down
1 change: 0 additions & 1 deletion bench-run/src/main/scala/tuples/Drop.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dotty.tools.benchmarks.tuples

import org.openjdk.jmh.annotations._
import scala.runtime.DynamicTuple

@State(Scope.Thread)
class Drop {
Expand Down
1 change: 0 additions & 1 deletion bench-run/src/main/scala/tuples/Split.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dotty.tools.benchmarks.tuples

import org.openjdk.jmh.annotations._
import scala.runtime.DynamicTuple

@State(Scope.Thread)
class Split {
Expand Down
1 change: 0 additions & 1 deletion bench-run/src/main/scala/tuples/Take.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dotty.tools.benchmarks.tuples

import org.openjdk.jmh.annotations._
import scala.runtime.DynamicTuple

@State(Scope.Thread)
class Take {
Expand Down
2 changes: 0 additions & 2 deletions library/src/scala/Tuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import annotation.showAsInfix
import compiletime._
import internal._

import scala.runtime.DynamicTuple

/** Tuple of arbitrary arity */
sealed trait Tuple extends Any {
import Tuple._
Expand Down
59 changes: 0 additions & 59 deletions library/src/scala/runtime/DynamicTupleOld.scala

This file was deleted.

35 changes: 18 additions & 17 deletions tests/run-staging/staged-tuples/StagedTuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import scala.quoted._

import scala.runtime.TupleXXL

import scala.runtime.Tuple.MaxSpecialized

object StagedTuple {
import Tuple.Concat
import Tuple.Head
import Tuple.Tail
import Tuple.Size
import Tuple.Elem
import scala.runtime.DynamicTuple._

private final val specialize = true

def toArrayStaged(tup: Expr[Tuple], size: Option[Int])(using QuoteContext): Expr[Array[Object]] = {
if (!specialize) '{dynamicToArray($tup)}
if (!specialize) '{scala.runtime.Tuple.toArray($tup)}
else size match {
case Some(0) =>
'{Array.emptyObjectArray}
Expand All @@ -30,12 +31,12 @@ object StagedTuple {
case Some(n) =>
'{ ${tup.as[TupleXXL]}.toArray }
case None =>
'{dynamicToArray($tup)}
'{scala.runtime.Tuple.toArray($tup)}
}
}

def fromArrayStaged[T <: Tuple : Type](xs: Expr[Array[Object]], size: Option[Int])(using QuoteContext): Expr[T] = {
if (!specialize) '{dynamicFromArray[T]($xs)}
if (!specialize) '{scala.runtime.Tuple.fromArray($xs)}.as[T]
else xs.bind { xs =>
val tup: Expr[Any] = size match {
case Some(0) => '{}
Expand All @@ -62,24 +63,24 @@ object StagedTuple {
case Some(21) => '{Tuple21($xs(0), $xs(1), $xs(2), $xs(3), $xs(4), $xs(5), $xs(6), $xs(7), $xs(8), $xs(9), $xs(10), $xs(11), $xs(12), $xs(13), $xs(14), $xs(15), $xs(16), $xs(17), $xs(18), $xs(19), $xs(20))}
case Some(22) => '{Tuple22($xs(0), $xs(1), $xs(2), $xs(3), $xs(4), $xs(5), $xs(6), $xs(7), $xs(8), $xs(9), $xs(10), $xs(11), $xs(12), $xs(13), $xs(14), $xs(15), $xs(16), $xs(17), $xs(18), $xs(19), $xs(20), $xs(21))}
case Some(_) => '{TupleXXL($xs)}
case None => '{dynamicFromArray[T]($xs)}
case None => '{scala.runtime.Tuple.fromArray($xs)}
}
tup.as[T]
}
}

def sizeStaged[Res <: Int : Type](tup: Expr[Tuple], size: Option[Int])(using QuoteContext): Expr[Res] = {
val res =
if (!specialize) '{dynamicSize($tup)}
if (!specialize) '{scala.runtime.Tuple.size($tup)}
else size match {
case Some(n) => Expr(n)
case None => '{dynamicSize($tup)}
case None => '{scala.runtime.Tuple.size($tup)}
}
res.as[Res]
}

def headStaged[Tup <: NonEmptyTuple : Type](tup: Expr[Tup], size: Option[Int])(using QuoteContext): Expr[Head[Tup]] = {
if (!specialize) '{dynamicApply[Tup, 0]($tup, 0)}
if (!specialize) '{scala.runtime.Tuple.apply($tup, 0)}.as[Head[Tup]]
else {
val resVal = size match {
case Some(1) =>
Expand All @@ -95,14 +96,14 @@ object StagedTuple {
case Some(n) if n > MaxSpecialized =>
'{${tup.as[TupleXXL] }.elems(0)}
case None =>
'{dynamicApply($tup, 0)}
'{scala.runtime.Tuple.apply($tup, 0)}
}
resVal.as[Head[Tup]]
}
}

def tailStaged[Tup <: NonEmptyTuple : Type](tup: Expr[Tup], size: Option[Int])(using QuoteContext): Expr[Tail[Tup]] = {
if (!specialize) '{dynamicTail[Tup]($tup)}
if (!specialize) '{scala.runtime.Tuple.tail($tup)}.as[Tail[Tup]]
else {
val res = size match {
case Some(1) =>
Expand All @@ -119,21 +120,21 @@ object StagedTuple {
val arr = toArrayStaged(tup, size)
fromArrayStaged[Tail[Tup]]('{ $arr.tail }, Some(n - 1))
case None =>
'{dynamicTail($tup)}
'{scala.runtime.Tuple.tail($tup)}
}
res.as[Tail[Tup]]
}
}

def applyStaged[Tup <: NonEmptyTuple : Type, N <: Int : Type](tup: Expr[Tup], size: Option[Int], n: Expr[N], nValue: Option[Int])(using qctx: QuoteContext): Expr[Elem[Tup, N]] = {

if (!specialize) '{dynamicApply($tup, $n)}
if (!specialize) '{scala.runtime.Tuple.apply($tup, $n)}.as[Elem[Tup, N]]
else {
def fallbackApply(): Expr[Elem[Tup, N]] = nValue match {
case Some(n) =>
qctx.error("index out of bounds: " + n, tup)
'{ throw new IndexOutOfBoundsException(${Expr(n.toString)}) }
case None => '{dynamicApply($tup, $n)}
case None => '{scala.runtime.Tuple.apply($tup, $n)}.as[Elem[Tup, N]]
}
val res = size match {
case Some(1) =>
Expand Down Expand Up @@ -185,7 +186,7 @@ object StagedTuple {
}

def consStaged[T <: Tuple & Singleton : Type, H : Type](self: Expr[T], x: Expr[H], tailSize: Option[Int])(using QuoteContext): Expr[H *: T] =
if (!specialize) '{dynamicCons[H, T]($x, $self)}
if (!specialize) '{scala.runtime.Tuple.cons($x, $self)}.as[H *: T]
else {
val res = tailSize match {
case Some(0) =>
Expand All @@ -199,13 +200,13 @@ object StagedTuple {
case Some(4) =>
self.as[Tuple4[_, _, _, _]].bind(t => '{Tuple5($x, $t._1, $t._2, $t._3, $t._4)})
case _ =>
'{dynamicCons[H, T]($x, $self)}
'{scala.runtime.Tuple.cons($x, $self)}
}
res.as[H *: T]
}

def concatStaged[Self <: Tuple & Singleton : Type, That <: Tuple & Singleton : Type](self: Expr[Self], selfSize: Option[Int], that: Expr[That], thatSize: Option[Int])(using QuoteContext): Expr[Concat[Self, That]] = {
if (!specialize) '{dynamicConcat[Self, That]($self, $that)}
if (!specialize) '{scala.runtime.Tuple.concat($self, $that)}.as[Concat[Self, That]]
else {
def genericConcat(xs: Expr[Tuple], ys: Expr[Tuple]): Expr[Tuple] =
// TODO remove ascriptions when #6126 is fixed
Expand Down Expand Up @@ -247,7 +248,7 @@ object StagedTuple {
if (thatSize.contains(0)) self
else genericConcat(self, that)
case None =>
'{dynamicConcat($self, $that)}
'{scala.runtime.Tuple.concat($self, $that)}
}
res.as[Concat[Self, That]]
}
Expand Down