Skip to content

Commit a33eece

Browse files
committed
Constructors: remove self validation.
Curiously enough, it only found bugs in old scheme It was deleting accessors, that used to be vals but became defs without anybody raising the `Method` flag.
1 parent 86e83af commit a33eece

File tree

1 file changed

+3
-55
lines changed

1 file changed

+3
-55
lines changed

src/dotty/tools/dotc/transform/Constructors.scala

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,15 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor
4141
// 3. It is accessed on an object other than `this`
4242
// 4. It is a mutable parameter accessor
4343
// 5. It is has a wildcard initializer `_`
44-
4544
private var retainedPrivateVals = mutable.Set[Symbol]()
4645
private var seenPrivateVals = mutable.Set[Symbol]()
4746
private var insideConstructor = false
4847

4948
private def markUsedPrivateSymbols(tree: RefTree)(implicit ctx: Context): Unit = {
5049

5150
val sym = tree.symbol
52-
def retain = {
53-
if (sym.toString.contains("initialValues"))
54-
println("hooooo")
51+
def retain =
5552
retainedPrivateVals.add(sym)
56-
}
5753

5854
if (mightBeDropped(sym) && sym.owner.isClass) {
5955
val owner = sym.owner.asClass
@@ -134,8 +130,7 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor
134130

135131
override def transformTemplate(tree: Template)(implicit ctx: Context, info: TransformerInfo): Tree = {
136132
val cls = ctx.owner.asClass
137-
if (cls.toString.contains("VarianceChecker"))
138-
println("hoho")
133+
139134
val constr @ DefDef(nme.CONSTRUCTOR, Nil, vparams :: Nil, _, EmptyTree) = tree.constr
140135

141136
// Produce aligned accessors and constructor parameters. We have to adjust
@@ -174,53 +169,8 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor
174169
}
175170
}
176171

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-
216172
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)
224174
}
225175

226176
val constrStats, clsStats = new mutable.ListBuffer[Tree]
@@ -303,8 +253,6 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor
303253
cls.copy(
304254
info = clsInfo.derivedClassInfo(
305255
decls = clsInfo.decls.filteredScope(!dropped.contains(_))))
306-
307-
// TODO: this happens to work only because Constructors is the last phase in group
308256
}
309257

310258
val (superCalls, followConstrStats) = constrStats.toList match {

0 commit comments

Comments
 (0)