Skip to content

Commit a5b2382

Browse files
committed
Use Store in MiniPhases
Convert phases that created new TreeTransforms before to use the new Store concept instead of Properties.
1 parent ece7c45 commit a5b2382

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ import core.NameOps._
1515
import core.NameKinds.TempResultName
1616
import ast.Trees._
1717
import SymUtils._
18-
import util.Property
18+
import util.Store
1919
import collection.{ mutable, immutable }
2020
import collection.mutable.{ LinkedHashMap, LinkedHashSet, TreeSet }
2121

22-
object CapturedVars {
23-
val Captured = new Property.Key[collection.Set[Symbol]]
24-
def captured(implicit ctx: Context) = ctx.property(Captured).getOrElse(Set.empty)
25-
}
26-
2722
/** This phase translates variables that are captured in closures to
2823
* heap-allocated refs.
2924
*/
3025
class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =>
31-
import CapturedVars._
3226
import ast.tpd._
3327

3428
/** the following two members override abstract members in Transform */
3529
val phaseName: String = "capturedVars"
3630

31+
private var Captured: Store.Location[collection.Set[Symbol]] = _
32+
private def captured(implicit ctx: Context) = ctx.store(Captured)
33+
34+
override def initContext(ctx: FreshContext) =
35+
Captured = ctx.addLocation(Set.empty)
36+
3737
private class RefInfo(implicit ctx: Context) {
3838
/** The classes for which a Ref type exists. */
3939
val refClassKeys: collection.Set[Symbol] =
@@ -79,7 +79,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
7979
override def prepareForUnit(tree: Tree)(implicit ctx: Context) = {
8080
val captured = (new CollectCaptured)
8181
.runOver(ctx.compilationUnit.tpdTree)(ctx.withPhase(thisPhase))
82-
ctx.fresh.setProperty(Captured, captured)
82+
ctx.fresh.updateStore(Captured, captured)
8383
}
8484

8585
/** The {Volatile|}{Int|Double|...|Object}Ref class corresponding to the class `cls`,

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,27 @@ package transform
44
import core._
55
import DenotTransformers.SymTransformer
66
import Phases.Phase
7-
import Contexts.Context
7+
import Contexts.{Context, FreshContext}
88
import Flags._
99
import SymDenotations.SymDenotation
1010
import collection.mutable
1111
import SuperPhase.MiniPhase
12-
import util.Property
13-
14-
object Flatten {
15-
import ast.tpd._
16-
val LiftedDefs = new Property.Key[mutable.ListBuffer[Tree]]
17-
def liftedDefs(implicit ctx: Context) = ctx.property(LiftedDefs).get
18-
}
12+
import util.Store
1913

2014
/** Lift nested classes to toplevel */
2115
class Flatten extends MiniPhase with SymTransformer {
2216
import ast.tpd._
23-
import Flatten._
2417

2518
override def phaseName = "flatten"
2619

2720
override def changesMembers = true // the phase removes inner classes
2821

22+
private var LiftedDefs: Store.Location[mutable.ListBuffer[Tree]] = _
23+
private def liftedDefs(implicit ctx: Context) = ctx.store(LiftedDefs)
24+
25+
override def initContext(ctx: FreshContext) =
26+
LiftedDefs = ctx.addLocation[mutable.ListBuffer[Tree]](null)
27+
2928
def transformSym(ref: SymDenotation)(implicit ctx: Context) = {
3029
if (ref.isClass && !ref.is(Package) && !ref.owner.is(Package)) {
3130
ref.copySymDenotation(
@@ -36,7 +35,7 @@ class Flatten extends MiniPhase with SymTransformer {
3635
}
3736

3837
override def prepareForPackageDef(tree: PackageDef)(implicit ctx: Context) =
39-
ctx.fresh.setProperty(LiftedDefs, new mutable.ListBuffer[Tree])
38+
ctx.fresh.updateStore(LiftedDefs, new mutable.ListBuffer[Tree])
4039

4140
private def liftIfNested(tree: Tree)(implicit ctx: Context) =
4241
if (ctx.owner is Package) tree

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import core.Phases._
1616
import ast.Trees._
1717
import SymUtils._
1818
import ExplicitOuter.outer
19-
import util.Property
19+
import util.Store
2020
import util.Positions._
2121
import collection.{ mutable, immutable }
2222
import collection.mutable.{ HashMap, HashSet, LinkedHashMap, LinkedHashSet, TreeSet }
@@ -450,9 +450,6 @@ object LambdaLift {
450450

451451
def needsLifting(sym: Symbol) = liftedOwner contains sym
452452
}
453-
454-
val Lifter = new Property.Key[Lifter]
455-
def lifter(implicit ctx: Context) = ctx.property(Lifter).get
456453
}
457454

458455
/** This phase performs the necessary rewritings to eliminate classes and methods
@@ -500,8 +497,14 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisPhase =>
500497
// lambda lift for super calls right. Witness the implementation restrictions to
501498
// this effect in scalac.
502499

500+
private var Lifter: Store.Location[Lifter] = _
501+
private def lifter(implicit ctx: Context) = ctx.store(Lifter)
502+
503+
override def initContext(ctx: FreshContext) =
504+
Lifter = ctx.addLocation[Lifter](null)
505+
503506
override def prepareForUnit(tree: Tree)(implicit ctx: Context) =
504-
ctx.fresh.setProperty(Lifter, new Lifter(thisPhase))
507+
ctx.fresh.updateStore(Lifter, new Lifter(thisPhase))
505508

506509
override def transformIdent(tree: Ident)(implicit ctx: Context) = {
507510
val sym = tree.symbol

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ import core.Flags._
1010
import core.Decorators._
1111
import core.NameKinds.LiftedTreeName
1212
import NonLocalReturns._
13-
import util.Property
14-
15-
object LiftTry {
16-
val NeedLift = new Property.Key[Boolean]
17-
def needLift(implicit ctx: Context) = ctx.property(NeedLift).getOrElse(false)
18-
def liftingCtx(p: Boolean)(implicit ctx: Context) = ctx.withProperty(NeedLift, Some(p))
19-
}
13+
import util.Store
2014

2115
/** Lifts try's that might be executed on non-empty expression stacks
2216
* to their own methods. I.e.
@@ -29,11 +23,19 @@ object LiftTry {
2923
*/
3024
class LiftTry extends MiniPhase with IdentityDenotTransformer { thisPhase =>
3125
import ast.tpd._
32-
import LiftTry._
3326

3427
/** the following two members override abstract members in Transform */
3528
val phaseName: String = "liftTry"
3629

30+
private var NeedLift: Store.Location[Boolean] = _
31+
private def needLift(implicit ctx: Context): Boolean = ctx.store(NeedLift)
32+
33+
override def initContext(ctx: FreshContext) =
34+
NeedLift = ctx.addLocation(false)
35+
36+
private def liftingCtx(p: Boolean)(implicit ctx: Context) =
37+
if (needLift == p) ctx else ctx.fresh.updateStore(NeedLift, p)
38+
3739
override def prepareForApply(tree: Apply)(implicit ctx: Context) =
3840
if (tree.fun.symbol.is(Label)) ctx
3941
else liftingCtx(true)

0 commit comments

Comments
 (0)