Skip to content

Commit c9189c2

Browse files
Remove Context to ContextBase implicit conversion
1 parent e156dc3 commit c9189c2

File tree

12 files changed

+70
-52
lines changed

12 files changed

+70
-52
lines changed

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
4444
*/
4545
protected[this] def rootContext(implicit ctx: Context): Context = {
4646
ctx.initialize()(ctx)
47-
ctx.setPhasePlan(comp.phases)
47+
ctx.base.setPhasePlan(comp.phases)
4848
val rootScope = new MutableScope
4949
val bootstrap = ctx.fresh
5050
.setPeriod(Period(comp.nextRunId, FirstPhaseId))
@@ -149,7 +149,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
149149

150150
protected def compileUnits()(implicit ctx: Context) = Stats.maybeMonitored {
151151
if (!ctx.mode.is(Mode.Interactive)) // IDEs might have multi-threaded access, accesses are synchronized
152-
ctx.checkSingleThreaded()
152+
ctx.base.checkSingleThreaded()
153153

154154
compiling = true
155155

@@ -158,16 +158,16 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
158158
if (ctx.settings.YtestPickler.value) List("pickler")
159159
else ctx.settings.YstopAfter.value
160160

161-
val pluginPlan = ctx.addPluginPhases(ctx.phasePlan)
162-
val phases = ctx.squashPhases(pluginPlan,
161+
val pluginPlan = ctx.addPluginPhases(ctx.base.phasePlan)
162+
val phases = ctx.base.squashPhases(pluginPlan,
163163
ctx.settings.Yskip.value, ctx.settings.YstopBefore.value, stopAfter, ctx.settings.Ycheck.value)
164-
ctx.usePhases(phases)
164+
ctx.base.usePhases(phases)
165165

166166
def runPhases(implicit ctx: Context) = {
167167
var lastPrintedTree: PrintedTree = NoPrintedTree
168168
val profiler = ctx.profiler
169169

170-
for (phase <- ctx.allPhases)
170+
for (phase <- ctx.base.allPhases)
171171
if (phase.isRunnable)
172172
Stats.trackTime(s"$phase ms ") {
173173
val start = System.currentTimeMillis
@@ -228,7 +228,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
228228
private def printTree(last: PrintedTree)(implicit ctx: Context): PrintedTree = {
229229
val unit = ctx.compilationUnit
230230
val prevPhase = ctx.phase.prev // can be a mini-phase
231-
val squashedPhase = ctx.squashed(prevPhase)
231+
val squashedPhase = ctx.base.squashed(prevPhase)
232232
val treeString = unit.tpdTree.show(ctx.withProperty(XprintMode, Some(())))
233233

234234
ctx.echo(s"result of $unit after $squashedPhase:")
@@ -274,4 +274,4 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
274274
myUnits = null
275275
myUnitsCached = null
276276
}
277-
}
277+
}

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,32 @@ object Contexts {
428428
"Context(\n" +
429429
(outersIterator map ( ctx => s" owner = ${ctx.owner}, scope = ${ctx.scope}, import = ${iinfo(ctx)}") mkString "\n")
430430
}
431+
432+
def typerPhase = base.typerPhase
433+
def sbtExtractDependenciesPhase = base.sbtExtractDependenciesPhase
434+
def picklerPhase = base.picklerPhase
435+
def refchecksPhase = base.refchecksPhase
436+
def patmatPhase = base.patmatPhase
437+
def elimRepeatedPhase = base.elimRepeatedPhase
438+
def extensionMethodsPhase = base.extensionMethodsPhase
439+
def explicitOuterPhase = base.explicitOuterPhase
440+
def gettersPhase = base.gettersPhase
441+
def erasurePhase = base.erasurePhase
442+
def elimErasedValueTypePhase = base.elimErasedValueTypePhase
443+
def lambdaLiftPhase = base.lambdaLiftPhase
444+
def flattenPhase = base.flattenPhase
445+
def genBCodePhase = base.genBCodePhase
446+
def phases = base.phases
447+
448+
def settings = base.settings
449+
def definitions = base.definitions
450+
def platform = base.platform
451+
def pendingUnderlying = base.pendingUnderlying
452+
def uniqueNamedTypes = base.uniqueNamedTypes
453+
def uniques = base.uniques
454+
def nextId = base.nextId
455+
456+
def initialize()(implicit ctx: Context) = base.initialize()(ctx)
431457
}
432458

433459
/** A condensed context provides only a small memory footprint over
@@ -520,7 +546,7 @@ object Contexts {
520546
/** A class defining the initial context with given context base
521547
* and set of possible settings.
522548
*/
523-
private class InitialContext(val base: ContextBase, settings: SettingGroup) extends FreshContext {
549+
private class InitialContext(val base: ContextBase, settingsGroup: SettingGroup) extends FreshContext {
524550
outer = NoContext
525551
period = InitialPeriod
526552
mode = Mode.None
@@ -529,7 +555,7 @@ object Contexts {
529555
tree = untpd.EmptyTree
530556
typeAssigner = TypeAssigner
531557
moreProperties = Map.empty
532-
store = initialStore.updated(settingsStateLoc, settings.defaultState)
558+
store = initialStore.updated(settingsStateLoc, settingsGroup.defaultState)
533559
typeComparer = new TypeComparer(this)
534560
searchHistory = new SearchHistory(0, Map())
535561
gadt = EmptyGADTMap
@@ -684,14 +710,6 @@ object Contexts {
684710
else assert(thread == Thread.currentThread(), "illegal multithreaded access to ContextBase")
685711
}
686712

687-
object Context {
688-
689-
/** implicit conversion that injects all ContextBase members into a context */
690-
implicit def toBase(ctx: Context): ContextBase = ctx.base
691-
692-
// @sharable val theBase = new ContextBase // !!! DEBUG, so that we can use a minimal context for reporting even in code that normally cannot access a context
693-
}
694-
695713
class GADTMap(initBounds: SimpleIdentityMap[Symbol, TypeBounds]) extends util.DotClass {
696714
private[this] var myBounds = initBounds
697715
def setBounds(sym: Symbol, b: TypeBounds): Unit =

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ class Definitions {
188188
}
189189

190190
lazy val RootClass: ClassSymbol = ctx.newPackageSymbol(
191-
NoSymbol, nme.ROOT, (root, rootcls) => ctx.rootLoader(root)).moduleClass.asClass
191+
NoSymbol, nme.ROOT, (root, rootcls) => ctx.base.rootLoader(root)).moduleClass.asClass
192192
lazy val RootPackage: TermSymbol = ctx.newSymbol(
193193
NoSymbol, nme.ROOTPKG, PackageCreationFlags, TypeRef(NoPrefix, RootClass))
194194

195195
lazy val EmptyPackageVal = ctx.newPackageSymbol(
196-
RootClass, nme.EMPTY_PACKAGE, (emptypkg, emptycls) => ctx.rootLoader(emptypkg)).entered
196+
RootClass, nme.EMPTY_PACKAGE, (emptypkg, emptycls) => ctx.base.rootLoader(emptypkg)).entered
197197
lazy val EmptyPackageClass = EmptyPackageVal.moduleClass.asClass
198198

199199
/** A package in which we can place all methods that are interpreted specially by the compiler */

compiler/src/dotty/tools/dotc/core/DenotTransformers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object DenotTransformers {
2222
trait DenotTransformer extends Phase {
2323

2424
/** The last phase during which the transformed denotations are valid */
25-
def lastPhaseId(implicit ctx: Context) = ctx.nextDenotTransformerId(id + 1)
25+
def lastPhaseId(implicit ctx: Context) = ctx.base.nextDenotTransformerId(id + 1)
2626

2727
/** The validity period of the transformed denotations in the given context */
2828
def validFor(implicit ctx: Context): Period =

compiler/src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,12 +899,12 @@ object Denotations {
899899
} else {
900900
//println(s"might need new denot for $cur, valid for ${cur.validFor} at $currentPeriod")
901901
// not found, cur points to highest existing variant
902-
val nextTransformerId = ctx.nextDenotTransformerId(cur.validFor.lastPhaseId)
902+
val nextTransformerId = ctx.base.nextDenotTransformerId(cur.validFor.lastPhaseId)
903903
if (currentPeriod.lastPhaseId <= nextTransformerId)
904904
cur.validFor = Period(currentPeriod.runId, cur.validFor.firstPhaseId, nextTransformerId)
905905
else {
906906
var startPid = nextTransformerId + 1
907-
val transformer = ctx.denotTransformers(nextTransformerId)
907+
val transformer = ctx.base.denotTransformers(nextTransformerId)
908908
//println(s"transforming $this with $transformer")
909909
try {
910910
next = transformer.transform(cur)(ctx.withPhase(transformer))

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -621,14 +621,14 @@ object Types {
621621
val jointInfo =
622622
if (rinfo.isAlias) rinfo
623623
else if (pinfo.isAlias) pinfo
624-
else if (ctx.pendingMemberSearches.contains(name)) pinfo safe_& rinfo
624+
else if (ctx.base.pendingMemberSearches.contains(name)) pinfo safe_& rinfo
625625
else pinfo recoverable_& rinfo
626626
pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, jointInfo)
627627
} else {
628628
pdenot & (
629629
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId)),
630630
pre,
631-
safeIntersection = ctx.pendingMemberSearches.contains(name))
631+
safeIntersection = ctx.base.pendingMemberSearches.contains(name))
632632
}
633633
}
634634

@@ -670,13 +670,13 @@ object Types {
670670
}
671671

672672
def goAnd(l: Type, r: Type) = {
673-
go(l) & (go(r), pre, safeIntersection = ctx.pendingMemberSearches.contains(name))
673+
go(l) & (go(r), pre, safeIntersection = ctx.base.pendingMemberSearches.contains(name))
674674
}
675675

676-
val recCount = ctx.findMemberCount
676+
val recCount = ctx.base.findMemberCount
677677
if (recCount >= Config.LogPendingFindMemberThreshold)
678-
ctx.pendingMemberSearches = name :: ctx.pendingMemberSearches
679-
ctx.findMemberCount = recCount + 1
678+
ctx.base.pendingMemberSearches = name :: ctx.base.pendingMemberSearches
679+
ctx.base.findMemberCount = recCount + 1
680680
try go(this)
681681
catch {
682682
case ex: Throwable =>
@@ -693,8 +693,8 @@ object Types {
693693
}
694694
finally {
695695
if (recCount >= Config.LogPendingFindMemberThreshold)
696-
ctx.pendingMemberSearches = ctx.pendingMemberSearches.tail
697-
ctx.findMemberCount = recCount
696+
ctx.base.pendingMemberSearches = ctx.base.pendingMemberSearches.tail
697+
ctx.base.findMemberCount = recCount
698698
}
699699
}
700700

@@ -1930,8 +1930,8 @@ object Types {
19301930
* not loop before the error is detected.
19311931
*/
19321932
final def controlled[T](op: => T)(implicit ctx: Context): T = try {
1933-
ctx.underlyingRecursions += 1
1934-
if (ctx.underlyingRecursions < Config.LogPendingUnderlyingThreshold)
1933+
ctx.base.underlyingRecursions += 1
1934+
if (ctx.base.underlyingRecursions < Config.LogPendingUnderlyingThreshold)
19351935
op
19361936
else if (ctx.pendingUnderlying contains this)
19371937
throw CyclicReference(symbol)
@@ -1943,7 +1943,7 @@ object Types {
19431943
ctx.pendingUnderlying -= this
19441944
}
19451945
} finally {
1946-
ctx.underlyingRecursions -= 1
1946+
ctx.base.underlyingRecursions -= 1
19471947
}
19481948

19491949
/** The argument corresponding to class type parameter `tparam` as seen from
@@ -3788,7 +3788,7 @@ object Types {
37883788
def apply(msg: => Message)(implicit ctx: Context): ErrorType = {
37893789
val et = new ErrorType {
37903790
def msg(implicit ctx: Context): Message =
3791-
ctx.errorTypeMsg.get(this) match {
3791+
ctx.base.errorTypeMsg.get(this) match {
37923792
case Some(msgFun) => msgFun()
37933793
case None => "error message from previous run no longer available"
37943794
}

compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ReadTastyTreesFromClasses extends FrontEnd {
6060
// Note that if both the class and the object are present, then loading the class will also load
6161
// the object, this is why we use orElse here, otherwise we could load the object twice and
6262
// create ambiguities!
63-
ctx.staticRef(className) match {
63+
ctx.base.staticRef(className) match {
6464
case clsd: ClassDenotation =>
6565
clsd.infoOrCompleter match {
6666
case info: ClassfileLoader =>

compiler/src/dotty/tools/dotc/plugins/Plugins.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ trait Plugins {
8080
}
8181
}
8282

83-
val plugs = pick(roughPluginsList, ctx.phasePlan.flatten.map(_.phaseName).toSet)
83+
val plugs = pick(roughPluginsList, ctx.base.phasePlan.flatten.map(_.phaseName).toSet)
8484

8585
// Verify required plugins are present.
8686
for (req <- ctx.settings.require.value ; if !(plugs exists (_.name == req)))

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ class PlainPrinter(_ctx: Context) extends Printer {
2222
protected def maxToTextRecursions = 100
2323

2424
protected final def controlled(op: => Text): Text =
25-
if (ctx.toTextRecursions < maxToTextRecursions && ctx.toTextRecursions < maxSummarized)
25+
if (ctx.base.toTextRecursions < maxToTextRecursions && ctx.base.toTextRecursions < maxSummarized)
2626
try {
27-
ctx.toTextRecursions += 1
27+
ctx.base.toTextRecursions += 1
2828
op
2929
} finally {
30-
ctx.toTextRecursions -= 1
30+
ctx.base.toTextRecursions -= 1
3131
}
3232
else {
33-
if (ctx.toTextRecursions >= maxToTextRecursions)
33+
if (ctx.base.toTextRecursions >= maxToTextRecursions)
3434
recursionLimitExceeded()
3535
"..."
3636
}
@@ -522,7 +522,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
522522

523523
def summarized[T](depth: Int)(op: => T): T = {
524524
val saved = maxSummarized
525-
maxSummarized = ctx.toTextRecursions + depth
525+
maxSummarized = ctx.base.toTextRecursions + depth
526526
try op
527527
finally maxSummarized = depth
528528
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
6464

6565
override def prepareForUnit(tree: Tree)(implicit ctx: Context) = {
6666
if (lazyValNullables == null)
67-
lazyValNullables = ctx.collectNullableFieldsPhase.asInstanceOf[CollectNullableFields].lazyValNullables
67+
lazyValNullables = ctx.base.collectNullableFieldsPhase.asInstanceOf[CollectNullableFields].lazyValNullables
6868
ctx
6969
}
7070

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class TreeChecker extends Phase with SymTransformer {
101101
if (ctx.settings.YtestPickler.value && ctx.phase.prev.isInstanceOf[Pickler])
102102
ctx.echo("Skipping Ycheck after pickling with -Ytest-pickler, the returned tree contains stale symbols")
103103
else
104-
check(ctx.allPhases, ctx)
104+
check(ctx.base.allPhases, ctx)
105105
}
106106

107107
private def previousPhases(phases: List[Phase])(implicit ctx: Context): List[Phase] = phases match {
@@ -118,7 +118,7 @@ class TreeChecker extends Phase with SymTransformer {
118118

119119
def check(phasesToRun: Seq[Phase], ctx: Context) = {
120120
val prevPhase = ctx.phase.prev // can be a mini-phase
121-
val squahsedPhase = ctx.squashed(prevPhase)
121+
val squahsedPhase = ctx.base.squashed(prevPhase)
122122
ctx.echo(s"checking ${ctx.compilationUnit} after phase ${squahsedPhase}")
123123

124124
assertSelectWrapsNew(ctx.compilationUnit.tpdTree)(ctx)

compiler/test/dotty/tools/dotc/transform/TreeTransformerTest.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TreeTransformerTest extends DottyTest {
1616
implicit val ctx = context
1717
class EmptyTransform extends MiniPhase {
1818
override def phaseName: String = "empty"
19-
init(ctx, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
19+
init(ctx.base, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
2020
}
2121
val transformer = new MegaPhase(Array(new EmptyTransform))
2222
val transformed = transformer.transformUnit(tree)
@@ -34,7 +34,7 @@ class TreeTransformerTest extends DottyTest {
3434

3535
override def transformLiteral(tree: tpd.Literal)(implicit ctx: Context): tpd.Tree = tpd.Literal(Constant(2))
3636
override def phaseName: String = "canReplaceConstant"
37-
init(ctx, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
37+
init(ctx.base, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
3838
}
3939
val transformer = new MegaPhase(Array(new ConstantTransform))
4040
val transformed = transformer.transformUnit(tree)
@@ -60,7 +60,7 @@ class TreeTransformerTest extends DottyTest {
6060
tpd.cpy.ValDef(tree)(rhs = tpd.Literal(Constant(2)))
6161
}
6262

63-
init(ctx, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
63+
init(ctx.base, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
6464
}
6565
val transformer = new MegaPhase(Array(new Transformation))
6666
val tr = transformer.transformUnit(tree).toString
@@ -91,7 +91,7 @@ class TreeTransformerTest extends DottyTest {
9191
tpd.cpy.ValDef(tree)(rhs = tpd.Literal(Constant(2)))
9292
}
9393

94-
init(ctx, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
94+
init(ctx.base, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
9595
}
9696
class Transformation2 extends MiniPhase {
9797
override def phaseName: String = "transformationOrder2"
@@ -102,7 +102,7 @@ class TreeTransformerTest extends DottyTest {
102102
tpd.cpy.ValDef(tree)(rhs = tpd.Literal(Constant(3)))
103103
}
104104

105-
init(ctx, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
105+
init(ctx.base, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
106106
}
107107
val transformer = new MegaPhase(Array(new Transformation1, new Transformation2))
108108
val tr = transformer.transformUnit(tree).toString
@@ -135,7 +135,7 @@ class TreeTransformerTest extends DottyTest {
135135
tpd.cpy.ValDef(tree)(rhs = transformFollowing(tpd.Literal(Constant(2))))
136136
}
137137

138-
init(ctx, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
138+
init(ctx.base, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
139139
}
140140
var transformed2 = 0
141141
class Transformation2 extends MiniPhase {
@@ -166,7 +166,7 @@ class TreeTransformerTest extends DottyTest {
166166
transformFollowing(tpd.cpy.ValDef(tree)(rhs = tpd.Literal(Constant(3))))
167167
}
168168

169-
init(ctx, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
169+
init(ctx.base, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
170170
}
171171
val transformer = new MegaPhase(Array(new Transformation1, new Transformation2))
172172
val tr = transformer.transformUnit(tree).toString

0 commit comments

Comments
 (0)