@@ -11,88 +11,41 @@ import scala.collection.mutable
11
11
/** Specializes classes that inherit from `FunctionN` where there exists a
12
12
* specialized form.
13
13
*/
14
- class SpecializeFunctions extends MiniPhase with InfoTransformer {
14
+ class SpecializeFunctions extends MiniPhase {
15
15
import ast .tpd ._
16
16
val phaseName = " specializeFunctions"
17
17
override def runsAfter = Set (ElimByName .name)
18
18
19
19
override def isEnabled (using Context ): Boolean =
20
20
! ctx.settings.scalajs.value
21
21
22
- override def infoMayChange (sym : Symbol )(using Context ): Boolean =
23
- ! sym.is(Flags .Package ) && sym.isClass && sym.isDefinedInCurrentRun
24
-
25
- /** Transforms the type to include decls for specialized applys */
26
- override def transformInfo (tp : Type , sym : Symbol )(using Context ) = tp match {
27
- case tp : ClassInfo =>
28
- val apply = tp.decls.lookup(nme.apply)
29
- if (! apply.exists) return tp
30
-
31
- var newApplys : List [Symbol ] = Nil
32
-
33
- var arity = 0
34
- while (arity < 3 ) {
35
- val func = defn.SpecializableFunctions (arity)
36
- if (sym != func && sym.derivesFrom(func)) {
37
- val baseType = tp.cls.typeRef.baseType(func)
38
- val paramTypes = baseType.argInfos
39
- val argTypes = paramTypes.init
40
- val retType = paramTypes.last
41
-
42
- val isSpecializable = defn.isSpecializableFunction(sym.asClass, argTypes, retType)
43
- if (! isSpecializable) return tp
44
-
45
- val apply = baseType.member(nme.apply)
46
- val overrideApply = tp.decls.find { sym =>
47
- sym.is(Flags .Method , butNot = Flags .Deferred ) && sym.name == nme.apply && sym.info.matches(apply.info)
48
- }
49
-
50
- if (overrideApply.exists) {
51
- val specializedMethodName : Name = nme.apply.specializedFunction(retType, argTypes)
52
- val applySpecialized = newSymbol(
53
- sym,
54
- specializedMethodName,
55
- overrideApply.flags | Flags .Synthetic ,
56
- overrideApply.info
57
- )
58
-
59
- newApplys ::= applySpecialized
60
- }
61
- }
62
- arity += 1
63
- }
64
-
65
- if (newApplys.isEmpty) tp
66
- else {
67
- val scope = tp.decls.cloneScope
68
- newApplys.toList.foreach { sym => scope.enter(sym) }
69
- tp.derivedClassInfo(decls = scope)
70
- }
71
-
72
- case _ => tp
73
- }
74
-
75
22
/** Create forwarders from the generic applys to the specialized ones.
76
23
*/
77
24
override def transformDefDef (ddef : DefDef )(using Context ) = {
78
25
val sym = ddef.symbol
79
26
80
27
if ddef.name != nme.apply
28
+ || sym.is(Flags .Deferred )
81
29
|| ddef.vparamss.length != 1
82
30
|| ddef.vparamss.head.length > 2
83
31
|| ! sym.owner.isClass
84
- || ! derivesFromFn012(sym.owner.asClass)
85
32
then
86
33
return ddef
87
34
88
35
val cls = sym.owner.asClass
89
36
val paramTypes = ddef.vparamss.head.map(_.symbol.info)
90
- val retType = ddef.tpe.widen.finalResultType
91
-
37
+ val retType = sym.info.finalResultType
92
38
val specName = nme.apply.specializedFunction(retType, paramTypes)
93
- val specializedApply = cls.asClass.info.decls.lookup(specName)
94
39
95
- if (! specializedApply.exists) return ddef
40
+ val isSpecializable = defn.isSpecializableFunction(cls, paramTypes, retType)
41
+ if (! isSpecializable || cls.info.decls.lookup(specName).exists) return ddef
42
+
43
+ val specializedApply = newSymbol(
44
+ cls,
45
+ specName,
46
+ sym.flags | Flags .Synthetic ,
47
+ sym.info
48
+ ).entered
96
49
97
50
val specializedDecl =
98
51
DefDef (specializedApply.asTerm, vparamss => {
0 commit comments