@@ -41,19 +41,15 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor
41
41
// 3. It is accessed on an object other than `this`
42
42
// 4. It is a mutable parameter accessor
43
43
// 5. It is has a wildcard initializer `_`
44
-
45
44
private var retainedPrivateVals = mutable.Set [Symbol ]()
46
45
private var seenPrivateVals = mutable.Set [Symbol ]()
47
46
private var insideConstructor = false
48
47
49
48
private def markUsedPrivateSymbols (tree : RefTree )(implicit ctx : Context ): Unit = {
50
49
51
50
val sym = tree.symbol
52
- def retain = {
53
- if (sym.toString.contains(" initialValues" ))
54
- println(" hooooo" )
51
+ def retain =
55
52
retainedPrivateVals.add(sym)
56
- }
57
53
58
54
if (mightBeDropped(sym) && sym.owner.isClass) {
59
55
val owner = sym.owner.asClass
@@ -134,8 +130,7 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor
134
130
135
131
override def transformTemplate (tree : Template )(implicit ctx : Context , info : TransformerInfo ): Tree = {
136
132
val cls = ctx.owner.asClass
137
- if (cls.toString.contains(" VarianceChecker" ))
138
- println(" hoho" )
133
+
139
134
val constr @ DefDef (nme.CONSTRUCTOR , Nil , vparams :: Nil , _, EmptyTree ) = tree.constr
140
135
141
136
// Produce aligned accessors and constructor parameters. We have to adjust
@@ -174,53 +169,8 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor
174
169
}
175
170
}
176
171
177
- // Collect all private parameter accessors and value definitions that need
178
- // to be retained. There are several reasons why a parameter accessor or
179
- // definition might need to be retained:
180
- // 1. It is accessed after the constructor has finished
181
- // 2. It is accessed before it is defined
182
- // 3. It is accessed on an object other than `this`
183
- // 4. It is a mutable parameter accessor
184
- // 5. It is has a wildcard initializer `_`
185
- object usage extends TreeTraverser {
186
- private var inConstr : Boolean = true
187
- private val seen = mutable.Set [Symbol ](accessors : _* )
188
- val retained = mutable.Set [Symbol ]()
189
- def dropped : collection.Set [Symbol ] = seen -- retained
190
- override def traverse (tree : Tree )(implicit ctx : Context ) = {
191
- val sym = tree.symbol
192
- tree match {
193
- case Ident (_) | Select (This (_), _) if inConstr && seen(tree.symbol) =>
194
- // could refer to definition in constructors, so no retention necessary
195
- case tree : RefTree =>
196
- if (mightBeDropped(sym)) retained += sym
197
- case _ =>
198
- }
199
- if (! noDirectRefsFrom(tree)) traverseChildren(tree)
200
- }
201
- def collect (stats : List [Tree ]): Unit = stats foreach {
202
- case stat : ValDef if ! stat.symbol.is(Lazy ) =>
203
- traverse(stat)
204
- if (mightBeDropped(stat.symbol))
205
- (if (isWildcardStarArg(stat.rhs)) retained else seen) += stat.symbol
206
- case stat : DefTree =>
207
- inConstr = false
208
- traverse(stat)
209
- inConstr = true
210
- case stat =>
211
- traverse(stat)
212
- }
213
- }
214
- usage.collect(tree.body)
215
-
216
172
def isRetained (acc : Symbol ) = {
217
- ! mightBeDropped(acc) || {
218
- val a = usage.retained(acc)
219
- val b = retainedPrivateVals(acc)
220
- if (a != b)
221
- println(" fail" )
222
- b
223
- }
173
+ ! mightBeDropped(acc) || retainedPrivateVals(acc)
224
174
}
225
175
226
176
val constrStats, clsStats = new mutable.ListBuffer [Tree ]
@@ -303,8 +253,6 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor
303
253
cls.copy(
304
254
info = clsInfo.derivedClassInfo(
305
255
decls = clsInfo.decls.filteredScope(! dropped.contains(_))))
306
-
307
- // TODO: this happens to work only because Constructors is the last phase in group
308
256
}
309
257
310
258
val (superCalls, followConstrStats) = constrStats.toList match {
0 commit comments