@@ -18,23 +18,23 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
18
18
19
19
/** Transforms the type to include decls for specialized applys */
20
20
override def transformInfo (tp : Type , sym : Symbol )(using Context ) = tp match {
21
- case tp : ClassInfo if ! sym.is(Flags .Package ) && derivesFromFn012(sym) =>
21
+ case tp : ClassInfo if ! sym.is(Flags .Package ) =>
22
22
val newApplys = new mutable.ListBuffer [Symbol ]
23
23
24
24
var arity = 0
25
25
while (arity < 3 ) {
26
26
val func = defn.FunctionClass (arity)
27
27
if (tp.derivesFrom(func)) {
28
- val paramTypes = tp.cls.typeRef.baseType(func).argInfos
29
- val isSpecializable =
28
+ lazy val paramTypes = tp.cls.typeRef.baseType(func).argInfos
29
+ def isSpecializable =
30
30
defn.isSpecializableFunction(
31
31
sym.asClass,
32
32
paramTypes.init,
33
33
paramTypes.last
34
34
)
35
35
36
36
val apply = tp.decls.lookup(nme.apply)
37
- if (isSpecializable && apply.exists ) {
37
+ if (apply.exists && isSpecializable ) {
38
38
val specializedMethodName = specializedName(nme.apply, paramTypes)
39
39
val applySpecialized = newSymbol(
40
40
sym,
@@ -70,7 +70,11 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
70
70
71
71
val applyBuf = new mutable.ListBuffer [Tree ]
72
72
val newBody = tree.body.mapConserve {
73
- case ddef : DefDef if ddef.name == nme.apply && ddef.vparamss.length == 1 =>
73
+ case ddef : DefDef
74
+ if ddef.name == nme.apply &&
75
+ ddef.vparamss.length == 1 &&
76
+ ddef.vparamss.head.length < 3
77
+ =>
74
78
val paramTypes = ddef.vparamss.head.map(_.symbol.info)
75
79
val retType = ddef.tpe.widen.finalResultType
76
80
@@ -94,7 +98,8 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
94
98
case x => x
95
99
}
96
100
97
- cpy.Template (tree)(body = applyBuf.toList ::: newBody)
101
+ if applyBuf.isEmpty then tree
102
+ else cpy.Template (tree)(body = applyBuf.toList ::: newBody)
98
103
}
99
104
100
105
/** Dispatch to specialized `apply`s in user code when available */
0 commit comments