@@ -29,33 +29,25 @@ class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
29
29
* the class parents with specialized versions.
30
30
*/
31
31
def transformInfo (tp : Type , sym : Symbol )(implicit ctx : Context ) = tp match {
32
- case tp : ClassInfo
33
- if ! sym.is(Flags .Package ) &&
34
- ! blacklistedSymbols.contains(sym) &&
35
- (tp.decls ne EmptyScope )
36
- => {
37
- var newApplys : List [Symbol ] = Nil
32
+ case tp : ClassInfo if ! sym.is(Flags .Package ) && (tp.decls ne EmptyScope ) => {
33
+ var newApplys = Map .empty[Name , Symbol ]
38
34
39
35
val newParents = tp.parents.mapConserve { parent =>
40
36
List (0 , 1 , 2 , 3 ).flatMap { arity =>
41
37
val func = defn.FunctionClass (arity)
42
- if (! parent.isRef (func)) Nil
38
+ if (! parent.derivesFrom (func)) Nil
43
39
else {
44
40
val typeParams = tp.typeRef.baseArgInfos(func)
45
41
val interface = specInterface(typeParams)
46
42
47
43
if (interface.exists) {
48
- val specializedApply = {
49
- val specializedMethodName = specializedName(nme.apply, typeParams)
50
- ctx.newSymbol(
51
- sym,
52
- specializedMethodName,
53
- Flags .Override | Flags .Method ,
54
- interface.info.decls.lookup(specializedMethodName).info
55
- )
44
+ if (tp.decls.lookup(nme.apply).exists) {
45
+ val specializedMethodName = nme.apply.specializedFunction(typeParams.last, typeParams.init)
46
+ newApplys = newApplys + (specializedMethodName -> interface)
56
47
}
57
- newApplys = specializedApply :: newApplys
58
- List (interface.typeRef)
48
+
49
+ if (parent.isRef(func)) List (interface.typeRef)
50
+ else Nil
59
51
}
60
52
else Nil
61
53
}
@@ -66,9 +58,18 @@ class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
66
58
67
59
def newDecls =
68
60
if (newApplys.isEmpty) tp.decls
69
- else newApplys.foldLeft(tp.decls.cloneScope) {
70
- (scope, sym) => scope.enter(sym); scope
71
- }
61
+ else
62
+ newApplys.toList.map { case (name, interface) =>
63
+ ctx.newSymbol(
64
+ sym,
65
+ name,
66
+ Flags .Override | Flags .Method ,
67
+ interface.info.decls.lookup(name).info
68
+ )
69
+ }
70
+ .foldLeft(tp.decls.cloneScope) {
71
+ (scope, sym) => scope.enter(sym); scope
72
+ }
72
73
73
74
tp.derivedClassInfo(
74
75
classParents = newParents,
@@ -88,13 +89,22 @@ class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
88
89
val applyBuf = new mutable.ListBuffer [Tree ]
89
90
val newBody = tree.body.mapConserve {
90
91
case dt : DefDef if dt.name == nme.apply && dt.vparamss.length == 1 => {
91
- val specializedApply = tree.symbol.enclosingClass.info.decls.lookup {
92
- specializedName(
93
- nme.apply,
94
- dt.vparamss.head.map(_.symbol.info) :+ dt.tpe.widen.finalResultType
95
- )
92
+ val specName = nme.apply.specializedFunction(
93
+ dt.tpe.widen.finalResultType,
94
+ dt.vparamss.head.map(_.symbol.info)
95
+ )
96
+
97
+ val specializedApply = tree.symbol.enclosingClass.info.decls.lookup(specName)// member(specName).symbol
98
+ // val specializedApply = tree.symbol.enclosingClass.info.member(specName).symbol
99
+
100
+ if (false ) {
101
+ println(tree.symbol.enclosingClass.show)
102
+ println(" '" + specName.show + " '" )
103
+ println(specializedApply)
104
+ println(specializedApply.exists)
96
105
}
97
106
107
+
98
108
if (specializedApply.exists) {
99
109
val apply = specializedApply.asTerm
100
110
val specializedDecl =
@@ -103,7 +113,6 @@ class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
103
113
.changeOwner(dt.symbol, apply)
104
114
.subst(dt.vparamss.flatten.map(_.symbol), vrefss.flatten.map(_.symbol))
105
115
})
106
-
107
116
applyBuf += specializedDecl
108
117
109
118
// create a forwarding to the specialized apply
@@ -147,7 +156,7 @@ class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
147
156
val params = (fun.tpe.widen.firstParamTypes :+ tree.tpe).map(_.widenSingleton.dealias)
148
157
val specializedApply = specializedName(nme.apply, params)
149
158
150
- if (! params.exists(_.isInstanceOf [ExprType ]) && defn. FunctionClass (args.length) .info.member (specializedApply).exists) {
159
+ if (! params.exists(_.isInstanceOf [ExprType ]) && fun.symbol.owner .info.decls.lookup (specializedApply).exists) {
151
160
val newSel = fun match {
152
161
case Select (qual, _) =>
153
162
qual.select(specializedApply)
@@ -174,7 +183,7 @@ class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
174
183
@ inline private def specInterface (typeParams : List [Type ])(implicit ctx : Context ) = {
175
184
val specName =
176
185
(" JFunction" + (typeParams.length - 1 )).toTermName
177
- .specializedFor (typeParams, typeParams.map(_.typeSymbol.name), Nil , Nil )
186
+ .specializedFunction (typeParams.last , typeParams.init )
178
187
179
188
ctx.getClassIfDefined(" scala.compat.java8." .toTermName ++ specName)
180
189
}
0 commit comments