@@ -25,17 +25,18 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
25
25
while (arity < 3 ) {
26
26
val func = defn.FunctionClass (arity)
27
27
if (tp.derivesFrom(func)) {
28
- lazy val paramTypes = tp.cls.typeRef.baseType(func).argInfos
28
+ var specializedMethodName : Name = null
29
29
def isSpecializable =
30
- defn.isSpecializableFunction(
31
- sym.asClass,
32
- paramTypes.init,
33
- paramTypes.last
34
- )
30
+ val paramTypes = tp.cls.typeRef.baseType(func).argInfos
31
+ val argTypes = paramTypes.init
32
+ val retType = paramTypes.last
33
+ defn.isSpecializableFunction(sym.asClass, argTypes, retType) && {
34
+ specializedMethodName = nme.apply.specializedFunction(retType, argTypes)
35
+ true
36
+ }
35
37
36
38
val apply = tp.decls.lookup(nme.apply)
37
39
if (apply.exists && isSpecializable) {
38
- val specializedMethodName = specializedName(nme.apply, paramTypes)
39
40
val applySpecialized = newSymbol(
40
41
sym,
41
42
specializedMethodName,
@@ -78,7 +79,7 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
78
79
val paramTypes = ddef.vparamss.head.map(_.symbol.info)
79
80
val retType = ddef.tpe.widen.finalResultType
80
81
81
- val specName = specializedName( nme.apply, paramTypes :+ retType )
82
+ val specName = nme.apply.specializedFunction(retType , paramTypes)
82
83
val specializedApply = cls.info.decls.lookup(specName)
83
84
if (specializedApply.exists) {
84
85
val specializedDecl =
@@ -106,17 +107,18 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
106
107
override def transformApply (tree : Apply )(using Context ) =
107
108
tree match {
108
109
case Apply (fun, args) if fun.symbol.name == nme.apply =>
109
- val paramTypes = (fun.tpe.widen.firstParamTypes :+ tree.tpe).map(_.widenSingleton.dealias)
110
+ val argTypes = fun.tpe.widen.firstParamTypes.map(_.widenSingleton.dealias)
111
+ val retType = tree.tpe.widenSingleton.dealias
110
112
val isSpecializable =
111
113
defn.isSpecializableFunction(
112
114
fun.symbol.owner.asClass,
113
- paramTypes.init ,
114
- paramTypes.last
115
+ argTypes ,
116
+ retType
115
117
)
116
118
117
- if (! isSpecializable || paramTypes .exists(_.isInstanceOf [ExprType ])) return tree
119
+ if (! isSpecializable || argTypes .exists(_.isInstanceOf [ExprType ])) return tree
118
120
119
- val specializedApply = specializedName( nme.apply, paramTypes )
121
+ val specializedApply = nme.apply.specializedFunction(retType, argTypes )
120
122
val newSel = fun match {
121
123
case Select (qual, _) =>
122
124
qual.select(specializedApply)
@@ -134,9 +136,6 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
134
136
case _ => tree
135
137
}
136
138
137
- private def specializedName (name : Name , args : List [Type ])(using Context ) =
138
- name.specializedFunction(args.last, args.init)
139
-
140
139
private def derivesFromFn012 (sym : Symbol )(using Context ): Boolean =
141
140
sym.derivesFrom(defn.FunctionClass (0 )) ||
142
141
sym.derivesFrom(defn.FunctionClass (1 )) ||
0 commit comments