@@ -32,49 +32,39 @@ class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
32
32
case tp : ClassInfo if ! sym.is(Flags .Package ) && (tp.decls ne EmptyScope ) => {
33
33
var newApplys = Map .empty[Name , Symbol ]
34
34
35
- val newParents = tp.parents.mapConserve { parent =>
36
- List (0 , 1 , 2 , 3 ).flatMap { arity =>
35
+ tp.parents.foreach { parent =>
36
+ List (0 , 1 , 2 , 3 ).foreach { arity =>
37
37
val func = defn.FunctionClass (arity)
38
38
if (! parent.derivesFrom(func)) Nil
39
39
else {
40
40
val typeParams = tp.cls.typeRef.baseType(func).argInfos
41
- val interface = specInterface(typeParams)
41
+ val interface = specInterface(typeParams)
42
42
43
43
if (interface.exists) {
44
44
if (tp.decls.lookup(nme.apply).exists) {
45
45
val specializedMethodName = nme.apply.specializedFunction(typeParams.last, typeParams.init)
46
- newApplys = newApplys + (specializedMethodName -> interface)
46
+ newApplys += (specializedMethodName -> interface)
47
47
}
48
-
49
- if (parent.isRef(func)) List (interface.typeRef)
50
- else Nil
51
48
}
52
- else Nil
53
49
}
54
50
}
55
- .headOption
56
- .getOrElse(parent)
57
51
}
58
52
59
53
def newDecls =
60
- if (newApplys.isEmpty) tp.decls
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
- }
54
+ newApplys.toList.map { case (name, interface) =>
55
+ ctx.newSymbol(
56
+ sym,
57
+ name,
58
+ Flags .Override | Flags .Method ,
59
+ interface.info.decls.lookup(name).info
60
+ )
61
+ }
62
+ .foldLeft(tp.decls.cloneScope) {
63
+ (scope, sym) => scope.enter(sym); scope
64
+ }
73
65
74
- tp.derivedClassInfo(
75
- classParents = newParents,
76
- decls = newDecls
77
- )
66
+ if (newApplys.isEmpty) tp
67
+ else tp.derivedClassInfo(decls = newDecls)
78
68
}
79
69
80
70
case _ => tp
@@ -95,15 +85,6 @@ class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
95
85
)
96
86
97
87
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)
105
- }
106
-
107
88
108
89
if (specializedApply.exists) {
109
90
val apply = specializedApply.asTerm
@@ -126,22 +107,7 @@ class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
126
107
case x => x
127
108
}
128
109
129
- val missing : List [TypeTree ] = List (0 , 1 , 2 , 3 ).flatMap { arity =>
130
- val func = defn.FunctionClass (arity)
131
- val tr = tree.symbol.enclosingClass.typeRef
132
-
133
- if (! tr.parents.exists(_.isRef(func))) Nil
134
- else {
135
- val typeParams = tr.baseType(func).argInfos
136
- val interface = specInterface(typeParams)
137
-
138
- if (interface.exists) List (interface.info)
139
- else Nil
140
- }
141
- }.map(TypeTree _)
142
-
143
110
cpy.Template (tree)(
144
- parents = tree.parents ++ missing,
145
111
body = applyBuf.toList ++ newBody
146
112
)
147
113
}
0 commit comments