Skip to content

Commit 9a9855a

Browse files
committed
Enforce that CapturedVars runs after LiftTry
Add reference to alternate implementation scheme
1 parent 639fa95 commit 9a9855a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
2323
/** the following two members override abstract members in Transform */
2424
val phaseName: String = "capturedVars"
2525

26+
override def runsAfterGroupsOf: Set[String] = Set(LiftTry.name)
27+
// lifting tries changes what variables are considered to be captured
28+
2629
private[this] var Captured: Store.Location[collection.Set[Symbol]] = _
2730
private def captured(implicit ctx: Context) = ctx.store(Captured)
2831

compiler/src/dotty/tools/dotc/transform/LiftTry.scala

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import util.Store
3030
class LiftTry extends MiniPhase with IdentityDenotTransformer { thisPhase =>
3131
import ast.tpd._
3232

33-
val phaseName: String = "liftTry"
33+
val phaseName: String = LiftTry.name
3434

3535
private var NeedLift: Store.Location[Boolean] = _
3636
private def needLift(implicit ctx: Context): Boolean = ctx.store(NeedLift)
@@ -48,7 +48,11 @@ class LiftTry extends MiniPhase with IdentityDenotTransformer { thisPhase =>
4848
if !tree.symbol.exists
4949
|| tree.symbol.isSelfSym
5050
|| tree.symbol.owner == ctx.owner.enclosingMethod
51-
&& !tree.symbol.is(Lazy) // lazy vals compile to defs, so there will be a new enclosing method
51+
&& !tree.symbol.is(Lazy)
52+
// The current implementation wraps initializers of lazy vals in
53+
// calls to an initialize method, which means that a `try` in the
54+
// initializer needs to be lifted. Note that the new scheme proposed
55+
// in #6979 would avoid this.
5256
then ctx
5357
else liftingCtx(true)
5458

@@ -74,3 +78,5 @@ class LiftTry extends MiniPhase with IdentityDenotTransformer { thisPhase =>
7478
}
7579
else tree
7680
}
81+
object LiftTry with
82+
val name = "liftTry"

0 commit comments

Comments
 (0)