@@ -1329,6 +1329,8 @@ class Definitions {
13291329
13301330 @ tu lazy val TupleType : Array [TypeRef | Null ] = mkArityArray(" scala.Tuple" , MaxTupleArity , 1 )
13311331
1332+ def SpecialisedTuple (base : Symbol , args : List [Type ]): Symbol = base.owner.requiredClass(base.name.specializedName(args))
1333+
13321334 private class FunType (prefix : String ):
13331335 private var classRefs : Array [TypeRef | Null ] = new Array (22 )
13341336 def apply (n : Int ): TypeRef =
@@ -1587,6 +1589,20 @@ class Definitions {
15871589 def isFunctionType (tp : Type )(using Context ): Boolean =
15881590 isNonRefinedFunction(tp.dropDependentRefinement)
15891591
1592+ private def withSpecMethods (cls : ClassSymbol , bases : List [Name ], paramTypes : Set [TypeRef ]) =
1593+ for base <- bases; tp <- paramTypes do
1594+ cls.enter(newSymbol(cls, base.specializedName(List (tp)), Method , ExprType (tp)))
1595+ cls
1596+
1597+ @ tu lazy val Tuple1 : ClassSymbol = withSpecMethods(requiredClass(" scala.Tuple1" ), List (nme._1), Tuple1SpecializedParamTypes )
1598+ @ tu lazy val Tuple2 : ClassSymbol = withSpecMethods(requiredClass(" scala.Tuple2" ), List (nme._1, nme._2), Tuple2SpecializedParamTypes )
1599+
1600+ @ tu lazy val TupleSpecializedClasses : Set [Symbol ] = Set (Tuple1 , Tuple2 )
1601+ @ tu lazy val Tuple1SpecializedParamTypes : Set [TypeRef ] = Set (IntType , LongType , DoubleType )
1602+ @ tu lazy val Tuple2SpecializedParamTypes : Set [TypeRef ] = Set (IntType , LongType , DoubleType , CharType , BooleanType )
1603+ @ tu lazy val Tuple1SpecializedParamClasses : PerRun [Set [Symbol ]] = new PerRun (Tuple1SpecializedParamTypes .map(_.symbol))
1604+ @ tu lazy val Tuple2SpecializedParamClasses : PerRun [Set [Symbol ]] = new PerRun (Tuple2SpecializedParamTypes .map(_.symbol))
1605+
15901606 // Specialized type parameters defined for scala.Function{0,1,2}.
15911607 @ tu lazy val Function1SpecializedParamTypes : collection.Set [TypeRef ] =
15921608 Set (IntType , LongType , FloatType , DoubleType )
@@ -1610,6 +1626,12 @@ class Definitions {
16101626 @ tu lazy val Function2SpecializedReturnClasses : PerRun [collection.Set [Symbol ]] =
16111627 new PerRun (Function2SpecializedReturnTypes .map(_.symbol))
16121628
1629+ def isSpecializableTuple (base : Symbol , args : List [Type ])(using Context ): Boolean =
1630+ args.length <= 2 && base.isClass && TupleSpecializedClasses .exists(base.asClass.derivesFrom) && args.match
1631+ case List (x) => Tuple1SpecializedParamClasses ().contains(x.typeSymbol)
1632+ case List (x, y) => Tuple2SpecializedParamClasses ().contains(x.typeSymbol) && Tuple2SpecializedParamClasses ().contains(y.typeSymbol)
1633+ case _ => false
1634+
16131635 def isSpecializableFunction (cls : ClassSymbol , paramTypes : List [Type ], retType : Type )(using Context ): Boolean =
16141636 paramTypes.length <= 2
16151637 && (cls.derivesFrom(FunctionClass (paramTypes.length)) || isByNameFunctionClass(cls))
0 commit comments