Skip to content

Commit 05eaa84

Browse files
committed
Try partial inlining
1 parent ab85854 commit 05eaa84

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

+1
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,7 @@ class Definitions {
807807
lazy val DynamicTupleModule: Symbol = ctx.requiredModule("scala.runtime.DynamicTuple")
808808
lazy val DynamicTuple_consIterator: Symbol = DynamicTupleModule.requiredMethod("consIterator")
809809
lazy val DynamicTuple_dynamicTail: Symbol = DynamicTupleModule.requiredMethod("dynamicTail")
810+
lazy val DynamicTuple_dynamicCons: Symbol = DynamicTupleModule.requiredMethod("dynamicCons")
810811

811812
// Annotation base classes
812813
lazy val AnnotationType: TypeRef = ctx.requiredClassRef("scala.annotation.Annotation")

compiler/src/dotty/tools/dotc/transform/GenericTuples.scala

+11-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import MegaPhase._
1515
import Types._
1616
import dotty.tools.dotc.ast.tpd
1717

18-
1918
import scala.annotation.tailrec
2019

2120
/** TODO
@@ -26,17 +25,20 @@ class GenericTuples extends MiniPhase with IdentityDenotTransformer {
2625
def phaseName: String = "genericTuples"
2726

2827
override def transformApply(tree: tpd.Apply)(implicit ctx: Context): tpd.Tree = {
29-
if (tree.symbol == defn.Tuple_cons) transformTupleCons(tree)
28+
if (tree.symbol == defn.DynamicTuple_dynamicCons) transformTupleCons(tree)
3029
else super.transformApply(tree)
3130
}
3231

32+
33+
3334
// override def transformTypeApply(tree: tpd.TypeApply)(implicit ctx: Context): tpd.Tree = {
3435
// if (tree.symbol == defn.NonEmptyTuple_tail) transformTupleTail(tree)
3536
// else super.transformTypeApply(tree)
3637
// }
3738

3839
private def transformTupleCons(tree: tpd.Apply)(implicit ctx: Context): Tree = {
39-
val TypeApply(Select(qual, _), headType :: tailType :: Nil) = tree.fun
40+
val TypeApply(_, headType :: tailType :: Nil) = tree.fun
41+
val tail :: head :: Nil = tree.args
4042
tupleTypes(tree.tpe) match {
4143
case Some(tpes) =>
4244
val size = tpes.size
@@ -46,21 +48,22 @@ class GenericTuples extends MiniPhase with IdentityDenotTransformer {
4648
val tailType =
4749
if (size == 1) defn.UnitType
4850
else defn.TupleType(size - 1).appliedTo(tpes.tail)
49-
evalOnce(Typed(qual, TypeTree(tailType))) { tup =>
50-
val elements = tree.args.head :: (0 until size - 1).map(i => tup.select(nme.selectorName(i))).toList
51+
evalOnce(Typed(tail, TypeTree(tailType))) { tup =>
52+
val elements = head :: (0 until size - 1).map(i => tup.select(nme.selectorName(i))).toList
5153
knownTupleFromElements(tpes, elements)
5254
}
5355
} else {
5456
// val it = Iterator.single(head) ++ tail.asInstanceOf[Product].productIterator
5557
// TupleN(it.next(), ..., it.next())
56-
val fullIterator = ref(defn.DynamicTuple_consIterator).appliedToArgs(tree.args.head :: qual :: Nil)
58+
val fullIterator = ref(defn.DynamicTuple_consIterator).appliedToArgs(head :: tail :: Nil)
5759
evalOnce(fullIterator) { it =>
5860
knownTupleFromIterator(tpes.length, it).asInstance(tree.tpe)
5961
}
6062
}
6163
case _ =>
62-
// DynamicTuple.dynamic_*:(tail, head)
63-
ref(defn.DynamicTupleModule).select("dynamic_*:".toTermName).appliedToTypeTrees(tailType :: headType :: Nil).appliedToArgs(qual :: tree.args).asInstance(tree.tpe)
64+
// DynamicTuple.dynamicCons:(tail, head)
65+
tree
66+
// ref(defn.DynamicTupleModule).select("dynamicCons".toTermName).appliedToTypeTrees(tailType :: headType :: Nil).appliedToArgs(qual :: tree.args).asInstance(tree.tpe)
6467
}
6568
}
6669

library/src-3.x/scala/Tuple.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ sealed trait Tuple extends Any {
3232
DynamicTuple.dynamicToArray(this)
3333
}
3434

35-
def *: [H, This >: this.type <: Tuple] (x: H): H *: This = ???
35+
inline def *: [H, This >: this.type <: Tuple] (x: H): H *: This =
36+
DynamicTuple.dynamicCons[This, H](this, x)
3637

3738
inline def ++ [This >: this.type <: Tuple](that: Tuple): Concat[This, that.type] = {
3839
type Result = Concat[This, that.type]

library/src-3.x/scala/runtime/DynamicTuple.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ object DynamicTuple {
199199
arr
200200
}
201201

202-
def dynamic_*: [This <: Tuple, H] (self: Tuple, x: H): H *: This = {
202+
def dynamicCons[This <: Tuple, H] (self: Tuple, x: H): H *: This = {
203203
type Result = H *: This
204204
(self: Any) match {
205205
case () =>

0 commit comments

Comments
 (0)