Skip to content

Commit 46dd4a8

Browse files
committed
Make CaptguredVars use prepareForUnit instead of init.
Required some refactoring. Instead of transformSym we now transform ValDefs as we prepare for them. The previous scheme could not control directly whetrher transformSym or collectCaptured would run first. Turns out that init ran before collectCaptured but prepareForUnit did not, leading to test failures in pos/capturedvars.
1 parent e65f8da commit 46dd4a8

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import SymUtils._
1717
import collection.{ mutable, immutable }
1818
import collection.mutable.{ LinkedHashMap, LinkedHashSet, TreeSet }
1919

20-
class CapturedVars extends MiniPhaseTransform with SymTransformer { thisTransform =>
20+
class CapturedVars extends MiniPhaseTransform with IdentityDenotTransformer { thisTransform =>
2121
import ast.tpd._
2222

2323
/** the following two members override abstract members in Transform */
@@ -44,16 +44,10 @@ class CapturedVars extends MiniPhaseTransform with SymTransformer { thisTransfor
4444
}
4545
}
4646

47-
override def init(implicit ctx: Context, info: TransformerInfo): Unit =
47+
override def prepareForUnit(tree: Tree)(implicit ctx: Context) = {
4848
(new CollectCaptured)(ctx.withPhase(thisTransform)).runOver(ctx.compilationUnit.tpdTree)
49-
50-
override def transformSym(sd: SymDenotation)(implicit ctx: Context): SymDenotation =
51-
if (captured(sd.symbol)) {
52-
val newd = sd.copySymDenotation(
53-
info = refCls(sd.info.classSymbol, sd.hasAnnotation(defn.VolatileAnnot)).typeRef)
54-
newd.removeAnnotation(defn.VolatileAnnot)
55-
newd
56-
} else sd
49+
this
50+
}
5751

5852
/** The {Volatile|}{Int|Double|...|Object}Ref class corresponding to the class `cls`,
5953
* depending on whether the reference should be @volatile
@@ -68,6 +62,17 @@ class CapturedVars extends MiniPhaseTransform with SymTransformer { thisTransfor
6862
refCls(oldInfo.classSymbol, vble.isVolatile).typeRef
6963
}
7064

65+
override def prepareForValDef(vdef: ValDef)(implicit ctx: Context) = {
66+
val sym = vdef.symbol
67+
if (captured contains sym) {
68+
val newd = sym.denot(ctx.withPhase(thisTransform)).copySymDenotation(
69+
info = refCls(sym.info.classSymbol, sym.hasAnnotation(defn.VolatileAnnot)).typeRef)
70+
newd.removeAnnotation(defn.VolatileAnnot)
71+
newd.installAfter(thisTransform)
72+
}
73+
this
74+
}
75+
7176
override def transformValDef(vdef: ValDef)(implicit ctx: Context, info: TransformerInfo): Tree = {
7277
val vble = vdef.symbol
7378
if (captured contains vble) {

0 commit comments

Comments
 (0)