@@ -1326,6 +1326,12 @@ class Definitions {
1326
1326
1327
1327
@ tu lazy val TupleType : Array [TypeRef | Null ] = mkArityArray(" scala.Tuple" , MaxTupleArity , 1 )
1328
1328
1329
+ def isSpecializedTuple (cls : Symbol )(using Context ): Boolean =
1330
+ cls.isClass && TupleSpecializedClasses .exists(tupleCls => cls.name.isSpecializedNameOf(tupleCls.name))
1331
+
1332
+ def SpecializedTuple (base : Symbol , args : List [Type ])(using Context ): Symbol =
1333
+ base.owner.requiredClass(base.name.specializedName(args))
1334
+
1329
1335
private class FunType (prefix : String ):
1330
1336
private var classRefs : Array [TypeRef | Null ] = new Array (22 )
1331
1337
def apply (n : Int ): TypeRef =
@@ -1584,6 +1590,20 @@ class Definitions {
1584
1590
def isFunctionType (tp : Type )(using Context ): Boolean =
1585
1591
isNonRefinedFunction(tp.dropDependentRefinement)
1586
1592
1593
+ private def withSpecMethods (cls : ClassSymbol , bases : List [Name ], paramTypes : Set [TypeRef ]) =
1594
+ for base <- bases; tp <- paramTypes do
1595
+ cls.enter(newSymbol(cls, base.specializedName(List (tp)), Method , ExprType (tp)))
1596
+ cls
1597
+
1598
+ @ tu lazy val Tuple1 : ClassSymbol = withSpecMethods(requiredClass(" scala.Tuple1" ), List (nme._1), Tuple1SpecializedParamTypes )
1599
+ @ tu lazy val Tuple2 : ClassSymbol = withSpecMethods(requiredClass(" scala.Tuple2" ), List (nme._1, nme._2), Tuple2SpecializedParamTypes )
1600
+
1601
+ @ tu lazy val TupleSpecializedClasses : Set [Symbol ] = Set (Tuple1 , Tuple2 )
1602
+ @ tu lazy val Tuple1SpecializedParamTypes : Set [TypeRef ] = Set (IntType , LongType , DoubleType )
1603
+ @ tu lazy val Tuple2SpecializedParamTypes : Set [TypeRef ] = Set (IntType , LongType , DoubleType , CharType , BooleanType )
1604
+ @ tu lazy val Tuple1SpecializedParamClasses : PerRun [Set [Symbol ]] = new PerRun (Tuple1SpecializedParamTypes .map(_.symbol))
1605
+ @ tu lazy val Tuple2SpecializedParamClasses : PerRun [Set [Symbol ]] = new PerRun (Tuple2SpecializedParamTypes .map(_.symbol))
1606
+
1587
1607
// Specialized type parameters defined for scala.Function{0,1,2}.
1588
1608
@ tu lazy val Function1SpecializedParamTypes : collection.Set [TypeRef ] =
1589
1609
Set (IntType , LongType , FloatType , DoubleType )
@@ -1607,6 +1627,13 @@ class Definitions {
1607
1627
@ tu lazy val Function2SpecializedReturnClasses : PerRun [collection.Set [Symbol ]] =
1608
1628
new PerRun (Function2SpecializedReturnTypes .map(_.symbol))
1609
1629
1630
+ def isSpecializableTuple (base : Symbol , args : List [Type ])(using Context ): Boolean =
1631
+ args.length <= 2 && base.isClass && TupleSpecializedClasses .exists(base.asClass.derivesFrom) && args.match
1632
+ case List (x) => Tuple1SpecializedParamClasses ().contains(x.classSymbol)
1633
+ case List (x, y) => Tuple2SpecializedParamClasses ().contains(x.classSymbol) && Tuple2SpecializedParamClasses ().contains(y.classSymbol)
1634
+ case _ => false
1635
+ && base.owner.denot.info.member(base.name.specializedName(args)).exists // when dotc compiles the stdlib there are no specialised classes
1636
+
1610
1637
def isSpecializableFunction (cls : ClassSymbol , paramTypes : List [Type ], retType : Type )(using Context ): Boolean =
1611
1638
paramTypes.length <= 2
1612
1639
&& (cls.derivesFrom(FunctionClass (paramTypes.length)) || isByNameFunctionClass(cls))
0 commit comments