@@ -6,8 +6,6 @@ import ast.Trees._, ast.tpd, core._
6
6
import Contexts .Context , Types ._ , Decorators ._ , Symbols ._ , DenotTransformers ._
7
7
import SymDenotations ._ , Scopes ._ , StdNames ._ , NameOps ._ , Names ._
8
8
9
- import scala .reflect .internal .util .Collections
10
-
11
9
/** This phase synthesizes specialized methods for FunctionN, this is done
12
10
* since there are no scala signatures in the bytecode for the specialized
13
11
* methods.
@@ -29,107 +27,29 @@ class SpecializedApplyMethods extends MiniPhaseTransform with InfoTransformer {
29
27
private [this ] var func2 : Symbol = _
30
28
31
29
private def init ()(implicit ctx : Context ): Unit = if (func0Applys eq null ) {
32
- def specApply (sym : Symbol , ret : Type , args : List [Type ])(implicit ctx : Context ) = {
33
- val all = args :+ ret
34
- val name = nme.apply.specializedFor(all, all.map(_.typeSymbol.name), Nil , Nil )
30
+ val definitions = ctx.definitions
31
+ import definitions ._
32
+
33
+ def specApply (sym : Symbol , args : List [Type ], ret : Type )(implicit ctx : Context ) = {
34
+ val name = nme.apply.specializedFunction(ret, args)
35
35
ctx.newSymbol(sym, name, Flags .Method , MethodType (args, ret))
36
36
}
37
37
38
- func0 = defn.FunctionClass (0 )
39
- func0Applys = List (
40
- specApply(func0, defn.UnitType , Nil ),
41
- specApply(func0, defn.ByteType , Nil ),
42
- specApply(func0, defn.ShortType , Nil ),
43
- specApply(func0, defn.IntType , Nil ),
44
- specApply(func0, defn.LongType , Nil ),
45
- specApply(func0, defn.CharType , Nil ),
46
- specApply(func0, defn.FloatType , Nil ),
47
- specApply(func0, defn.DoubleType , Nil ),
48
- specApply(func0, defn.BooleanType , Nil )
49
- )
50
- func1 = defn.FunctionClass (1 )
51
- func1Applys = List (
52
- specApply(func1, defn.UnitType , List (defn.IntType )),
53
- specApply(func1, defn.IntType , List (defn.IntType )),
54
- specApply(func1, defn.FloatType , List (defn.IntType )),
55
- specApply(func1, defn.LongType , List (defn.IntType )),
56
- specApply(func1, defn.DoubleType , List (defn.IntType )),
57
- specApply(func1, defn.UnitType , List (defn.LongType )),
58
- specApply(func1, defn.BooleanType , List (defn.LongType )),
59
- specApply(func1, defn.IntType , List (defn.LongType )),
60
- specApply(func1, defn.FloatType , List (defn.LongType )),
61
- specApply(func1, defn.LongType , List (defn.LongType )),
62
- specApply(func1, defn.DoubleType , List (defn.LongType )),
63
- specApply(func1, defn.UnitType , List (defn.FloatType )),
64
- specApply(func1, defn.BooleanType , List (defn.FloatType )),
65
- specApply(func1, defn.IntType , List (defn.FloatType )),
66
- specApply(func1, defn.FloatType , List (defn.FloatType )),
67
- specApply(func1, defn.LongType , List (defn.FloatType )),
68
- specApply(func1, defn.DoubleType , List (defn.FloatType )),
69
- specApply(func1, defn.UnitType , List (defn.DoubleType )),
70
- specApply(func1, defn.BooleanType , List (defn.DoubleType )),
71
- specApply(func1, defn.IntType , List (defn.DoubleType )),
72
- specApply(func1, defn.FloatType , List (defn.DoubleType )),
73
- specApply(func1, defn.LongType , List (defn.DoubleType )),
74
- specApply(func1, defn.DoubleType , List (defn.DoubleType ))
75
- )
38
+ func0 = FunctionClass (0 )
39
+ func0Applys = for (r <- ScalaValueTypes .toList) yield specApply(func0, Nil , r)
40
+
41
+ func1 = FunctionClass (1 )
42
+ func1Applys = for {
43
+ r <- List (UnitType , BooleanType , IntType , FloatType , LongType , DoubleType )
44
+ t1 <- List (IntType , LongType , FloatType , DoubleType )
45
+ } yield specApply(func1, List (t1), r)
46
+
76
47
func2 = defn.FunctionClass (2 )
77
- func2Applys = List (
78
- specApply(func2, defn.UnitType , List (defn.IntType , defn.IntType )),
79
- specApply(func2, defn.BooleanType , List (defn.IntType , defn.IntType )),
80
- specApply(func2, defn.IntType , List (defn.IntType , defn.IntType )),
81
- specApply(func2, defn.FloatType , List (defn.IntType , defn.IntType )),
82
- specApply(func2, defn.LongType , List (defn.IntType , defn.IntType )),
83
- specApply(func2, defn.DoubleType , List (defn.IntType , defn.IntType )),
84
- specApply(func2, defn.UnitType , List (defn.IntType , defn.LongType )),
85
- specApply(func2, defn.BooleanType , List (defn.IntType , defn.LongType )),
86
- specApply(func2, defn.IntType , List (defn.IntType , defn.LongType )),
87
- specApply(func2, defn.FloatType , List (defn.IntType , defn.LongType )),
88
- specApply(func2, defn.LongType , List (defn.IntType , defn.LongType )),
89
- specApply(func2, defn.DoubleType , List (defn.IntType , defn.LongType )),
90
- specApply(func2, defn.UnitType , List (defn.IntType , defn.DoubleType )),
91
- specApply(func2, defn.BooleanType , List (defn.IntType , defn.DoubleType )),
92
- specApply(func2, defn.IntType , List (defn.IntType , defn.DoubleType )),
93
- specApply(func2, defn.FloatType , List (defn.IntType , defn.DoubleType )),
94
- specApply(func2, defn.LongType , List (defn.IntType , defn.DoubleType )),
95
- specApply(func2, defn.DoubleType , List (defn.IntType , defn.DoubleType )),
96
- specApply(func2, defn.UnitType , List (defn.LongType , defn.IntType )),
97
- specApply(func2, defn.BooleanType , List (defn.LongType , defn.IntType )),
98
- specApply(func2, defn.IntType , List (defn.LongType , defn.IntType )),
99
- specApply(func2, defn.FloatType , List (defn.LongType , defn.IntType )),
100
- specApply(func2, defn.LongType , List (defn.LongType , defn.IntType )),
101
- specApply(func2, defn.DoubleType , List (defn.LongType , defn.IntType )),
102
- specApply(func2, defn.UnitType , List (defn.LongType , defn.LongType )),
103
- specApply(func2, defn.BooleanType , List (defn.LongType , defn.LongType )),
104
- specApply(func2, defn.IntType , List (defn.LongType , defn.LongType )),
105
- specApply(func2, defn.FloatType , List (defn.LongType , defn.LongType )),
106
- specApply(func2, defn.LongType , List (defn.LongType , defn.LongType )),
107
- specApply(func2, defn.DoubleType , List (defn.LongType , defn.LongType )),
108
- specApply(func2, defn.UnitType , List (defn.LongType , defn.DoubleType )),
109
- specApply(func2, defn.BooleanType , List (defn.LongType , defn.DoubleType )),
110
- specApply(func2, defn.IntType , List (defn.LongType , defn.DoubleType )),
111
- specApply(func2, defn.FloatType , List (defn.LongType , defn.DoubleType )),
112
- specApply(func2, defn.LongType , List (defn.LongType , defn.DoubleType )),
113
- specApply(func2, defn.DoubleType , List (defn.LongType , defn.DoubleType )),
114
- specApply(func2, defn.UnitType , List (defn.DoubleType , defn.IntType )),
115
- specApply(func2, defn.BooleanType , List (defn.DoubleType , defn.IntType )),
116
- specApply(func2, defn.IntType , List (defn.DoubleType , defn.IntType )),
117
- specApply(func2, defn.FloatType , List (defn.DoubleType , defn.IntType )),
118
- specApply(func2, defn.LongType , List (defn.DoubleType , defn.IntType )),
119
- specApply(func2, defn.DoubleType , List (defn.DoubleType , defn.IntType )),
120
- specApply(func2, defn.UnitType , List (defn.DoubleType , defn.LongType )),
121
- specApply(func2, defn.BooleanType , List (defn.DoubleType , defn.LongType )),
122
- specApply(func2, defn.IntType , List (defn.DoubleType , defn.LongType )),
123
- specApply(func2, defn.FloatType , List (defn.DoubleType , defn.LongType )),
124
- specApply(func2, defn.LongType , List (defn.DoubleType , defn.LongType )),
125
- specApply(func2, defn.DoubleType , List (defn.DoubleType , defn.LongType )),
126
- specApply(func2, defn.UnitType , List (defn.DoubleType , defn.DoubleType )),
127
- specApply(func2, defn.BooleanType , List (defn.DoubleType , defn.DoubleType )),
128
- specApply(func2, defn.IntType , List (defn.DoubleType , defn.DoubleType )),
129
- specApply(func2, defn.FloatType , List (defn.DoubleType , defn.DoubleType )),
130
- specApply(func2, defn.LongType , List (defn.DoubleType , defn.DoubleType )),
131
- specApply(func2, defn.DoubleType , List (defn.DoubleType , defn.DoubleType ))
132
- )
48
+ func2Applys = for {
49
+ r <- List (UnitType , BooleanType , IntType , FloatType , LongType , DoubleType )
50
+ t1 <- List (IntType , LongType , DoubleType )
51
+ t2 <- List (IntType , LongType , DoubleType )
52
+ } yield specApply(func2, List (t1, t2), r)
133
53
}
134
54
135
55
/** Add symbols for specialized methods to FunctionN */
@@ -164,20 +84,13 @@ class SpecializedApplyMethods extends MiniPhaseTransform with InfoTransformer {
164
84
else Nil
165
85
166
86
if (additionalSymbols eq Nil ) tree
167
- else {
168
- val newBody : List [Tree ] = tree.body ++ additionalSymbols.map { applySym =>
169
- polyDefDef(applySym.asTerm, tparams => vparamss => {
170
- val prefix = This (owner.asClass).select(nme.apply).appliedToTypes(vparamss.head.map(_.tpe))
171
- val argTypess = prefix.tpe.widen.paramTypess
172
-
173
- val argss = Collections .map2(vparamss, argTypess) { (vparams, argTypes) =>
174
- Collections .map2(vparams, argTypes) { (vparam, argType) => vparam.ensureConforms(argType) }
175
- }
176
- prefix.appliedToArgss(argss).ensureConforms(applySym.info.finalResultType)
177
- })
178
- }
179
-
180
- cpy.Template (tree)(body = newBody)
181
- }
87
+ else cpy.Template (tree)(body = tree.body ++ additionalSymbols.map { apply =>
88
+ DefDef (apply.asTerm, { vparamss =>
89
+ This (owner.asClass)
90
+ .select(nme.apply)
91
+ .appliedToArgss(vparamss)
92
+ .ensureConforms(apply.info.finalResultType)
93
+ })
94
+ })
182
95
}
183
96
}
0 commit comments