File tree Expand file tree Collapse file tree 5 files changed +6
-28
lines changed
compiler/src/dotty/tools/dotc
tests/run-with-compiler/staged-tuples Expand file tree Collapse file tree 5 files changed +6
-28
lines changed Original file line number Diff line number Diff line change @@ -818,7 +818,6 @@ class Definitions {
818818 lazy val DynamicTuple_concatIterator : Symbol = DynamicTupleModule .requiredMethod(" concatIterator" )
819819 lazy val DynamicTuple_dynamicApply : Symbol = DynamicTupleModule .requiredMethod(" dynamicApply" )
820820 lazy val DynamicTuple_dynamicCons : Symbol = DynamicTupleModule .requiredMethod(" dynamicCons" )
821- lazy val DynamicTuple_dynamicHead : Symbol = DynamicTupleModule .requiredMethod(" dynamicHead" )
822821 lazy val DynamicTuple_dynamicSize : Symbol = DynamicTupleModule .requiredMethod(" dynamicSize" )
823822 lazy val DynamicTuple_dynamicTail : Symbol = DynamicTupleModule .requiredMethod(" dynamicTail" )
824823 lazy val DynamicTuple_dynamicConcat : Symbol = DynamicTupleModule .requiredMethod(" dynamicConcat" )
Original file line number Diff line number Diff line change @@ -26,7 +26,6 @@ class GenericTuples extends MiniPhase with IdentityDenotTransformer {
2626
2727 override def transformApply (tree : tpd.Apply )(implicit ctx : Context ): tpd.Tree = {
2828 if (tree.symbol == defn.DynamicTuple_dynamicCons ) transformTupleCons(tree)
29- else if (tree.symbol == defn.DynamicTuple_dynamicHead ) transformTupleHead(tree)
3029 else if (tree.symbol == defn.DynamicTuple_dynamicTail ) transformTupleTail(tree)
3130 else if (tree.symbol == defn.DynamicTuple_dynamicSize ) transformTupleSize(tree)
3231 else if (tree.symbol == defn.DynamicTuple_dynamicConcat ) transformTupleConcat(tree)
@@ -96,23 +95,6 @@ class GenericTuples extends MiniPhase with IdentityDenotTransformer {
9695 }
9796 }
9897
99- private def transformTupleHead (tree : tpd.Apply )(implicit ctx : Context ): Tree = {
100- val Apply (TypeApply (_, tpt :: Nil ), tup :: Nil ) = tree
101- tupleTypes(tpt.tpe) match { // TODO tupleBoundedTypes
102- case Some (tpes) =>
103- if (tpes.size <= Definitions .MaxTupleArity ) {
104- // tup._1
105- Typed (tup, TypeTree (defn.tupleType(tpes))).select(nme.selectorName(0 ))
106- } else {
107- // tup.asInstanceOf[TupleXXL].productElement(0)
108- tup.asInstance(defn.TupleXXLType ).select(nme.productElement).appliedTo(Literal (Constant (0 )))
109- }
110- case None =>
111- // DynamicTuple.dynamicHead(tup)
112- tree
113- }
114- }
115-
11698 private def transformTupleSize (tree : tpd.Apply )(implicit ctx : Context ): Tree = {
11799 tree.tpe.tryNormalize match {
118100 case tp : ConstantType => Literal (tp.value)
Original file line number Diff line number Diff line change @@ -66,14 +66,15 @@ object Tuple {
6666sealed trait NonEmptyTuple extends Tuple {
6767 import Tuple ._
6868
69+ inline def apply [This >: this .type <: NonEmptyTuple ](n : Int ): Elem [This , n.type ] =
70+ DynamicTuple .dynamicApply[This , n.type ](this , n)
71+
6972 inline def head [This >: this .type <: NonEmptyTuple ]: Head [This ] =
70- DynamicTuple .dynamicHead [This ](this )
73+ DynamicTuple .dynamicApply [This , 0 ](this , 0 )
7174
7275 inline def tail [This >: this .type <: NonEmptyTuple ]: Tail [This ] =
7376 DynamicTuple .dynamicTail[This ](this )
7477
75- inline def apply [This >: this .type <: NonEmptyTuple ](n : Int ): Elem [This , n.type ] =
76- DynamicTuple .dynamicApply[This , n.type ](this , n)
7778}
7879
7980@ showAsInfix
Original file line number Diff line number Diff line change @@ -226,9 +226,6 @@ object DynamicTuple {
226226 case self : Product => self.productArity.asInstanceOf [Size [This ]]
227227 }
228228
229- def dynamicHead [This <: NonEmptyTuple ] (self : This ): Head [This ] =
230- self.asInstanceOf [Product ].productElement(0 ).asInstanceOf [Head [This ]]
231-
232229 def dynamicTail [This <: NonEmptyTuple ] (self : This ): Tail [This ] = {
233230 type Result = Tail [This ]
234231 val res = (self : Any ) match {
@@ -245,7 +242,6 @@ object DynamicTuple {
245242 type Result = Elem [This , N ]
246243 val res = (self : Any ) match {
247244 case self : Unit => throw new IndexOutOfBoundsException (n.toString)
248- case self : TupleXXL => self.elems(n)
249245 case self : Product => self.productElement(n)
250246 }
251247 res.asInstanceOf [Result ]
Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ object StagedTuple {
7979 }
8080
8181 def headStaged [Tup <: NonEmptyTuple : Type ](tup : Expr [Tup ], size : Option [Int ]): Expr [Head [Tup ]] = {
82- if (! specialize) ' {dynamicHead ($tup)}
82+ if (! specialize) ' {dynamicApply ($tup, 0 )}
8383 else {
8484 val resVal = size match {
8585 case Some (1 ) =>
@@ -95,7 +95,7 @@ object StagedTuple {
9595 case Some (n) if n > MaxSpecialized =>
9696 ' {$ {tup.as[TupleXXL ] }.elems(0 )}
9797 case None =>
98- ' {dynamicHead ($tup)}
98+ ' {dynamicApply ($tup, 0 )}
9999 }
100100 resVal.as[Head [Tup ]]
101101 }
You can’t perform that action at this time.
0 commit comments