Skip to content

Commit c16ed30

Browse files
Remove Context to ContextBase implicit conversion
1 parent 669d5df commit c16ed30

File tree

11 files changed

+70
-52
lines changed

11 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
@@ -43,7 +43,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
4343
*/
4444
protected[this] def rootContext(implicit ctx: Context): Context = {
4545
ctx.initialize()(ctx)
46-
ctx.setPhasePlan(comp.phases)
46+
ctx.base.setPhasePlan(comp.phases)
4747
val rootScope = new MutableScope
4848
val bootstrap = ctx.fresh
4949
.setPeriod(Period(comp.nextRunId, FirstPhaseId))
@@ -148,7 +148,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
148148

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

153153
compiling = true
154154

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

160-
val pluginPlan = ctx.addPluginPhases(ctx.phasePlan)
161-
val phases = ctx.squashPhases(pluginPlan,
160+
val pluginPlan = ctx.addPluginPhases(ctx.base.phasePlan)
161+
val phases = ctx.base.squashPhases(pluginPlan,
162162
ctx.settings.Yskip.value, ctx.settings.YstopBefore.value, stopAfter, ctx.settings.Ycheck.value)
163-
ctx.usePhases(phases)
163+
ctx.base.usePhases(phases)
164164

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

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

231231
ctx.echo(s"result of $unit after $squashedPhase:")
@@ -271,4 +271,4 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
271271
myUnits = null
272272
myUnitsCached = null
273273
}
274-
}
274+
}

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

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

431457
/** A condensed context provides only a small memory footprint over
@@ -518,7 +544,7 @@ object Contexts {
518544
/** A class defining the initial context with given context base
519545
* and set of possible settings.
520546
*/
521-
private class InitialContext(val base: ContextBase, settings: SettingGroup) extends FreshContext {
547+
private class InitialContext(val base: ContextBase, settingsGroup: SettingGroup) extends FreshContext {
522548
outer = NoContext
523549
period = InitialPeriod
524550
mode = Mode.None
@@ -527,7 +553,7 @@ object Contexts {
527553
tree = untpd.EmptyTree
528554
typeAssigner = TypeAssigner
529555
moreProperties = Map.empty
530-
store = initialStore.updated(settingsStateLoc, settings.defaultState)
556+
store = initialStore.updated(settingsStateLoc, settingsGroup.defaultState)
531557
typeComparer = new TypeComparer(this)
532558
searchHistory = new SearchHistory(0, Map())
533559
gadt = EmptyGADTMap
@@ -685,14 +711,6 @@ object Contexts {
685711
else assert(thread == Thread.currentThread(), "illegal multithreaded access to ContextBase")
686712
}
687713

688-
object Context {
689-
690-
/** implicit conversion that injects all ContextBase members into a context */
691-
implicit def toBase(ctx: Context): ContextBase = ctx.base
692-
693-
// @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
694-
}
695-
696714
class GADTMap(initBounds: SimpleIdentityMap[Symbol, TypeBounds]) extends util.DotClass {
697715
private[this] var myBounds = initBounds
698716
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
@@ -189,12 +189,12 @@ class Definitions {
189189
}
190190

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

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

200200
/** 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 transformer 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
@@ -880,12 +880,12 @@ object Denotations {
880880
} else {
881881
//println(s"might need new denot for $cur, valid for ${cur.validFor} at $currentPeriod")
882882
// not found, cur points to highest existing variant
883-
val nextTransformerId = ctx.nextDenotTransformerId(cur.validFor.lastPhaseId)
883+
val nextTransformerId = ctx.base.nextDenotTransformerId(cur.validFor.lastPhaseId)
884884
if (currentPeriod.lastPhaseId <= nextTransformerId)
885885
cur.validFor = Period(currentPeriod.runId, cur.validFor.firstPhaseId, nextTransformerId)
886886
else {
887887
var startPid = nextTransformerId + 1
888-
val transformer = ctx.denotTransformers(nextTransformerId)
888+
val transformer = ctx.base.denotTransformers(nextTransformerId)
889889
//println(s"transforming $this with $transformer")
890890
try {
891891
next = transformer.transform(cur)(ctx.withPhase(transformer))

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -597,14 +597,14 @@ object Types {
597597
val jointInfo =
598598
if (rinfo.isAlias) rinfo
599599
else if (pdenot.info.isAlias) pdenot.info
600-
else if (ctx.pendingMemberSearches.contains(name)) pdenot.info safe_& rinfo
600+
else if (ctx.base.pendingMemberSearches.contains(name)) pdenot.info safe_& rinfo
601601
else pdenot.info recoverable_& rinfo
602602
pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, jointInfo)
603603
} else {
604604
pdenot & (
605605
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId)),
606606
pre,
607-
safeIntersection = ctx.pendingMemberSearches.contains(name))
607+
safeIntersection = ctx.base.pendingMemberSearches.contains(name))
608608
}
609609
}
610610

@@ -646,17 +646,17 @@ object Types {
646646
}
647647

648648
def goAnd(l: Type, r: Type) = {
649-
go(l) & (go(r), pre, safeIntersection = ctx.pendingMemberSearches.contains(name))
649+
go(l) & (go(r), pre, safeIntersection = ctx.base.pendingMemberSearches.contains(name))
650650
}
651651

652-
val recCount = ctx.findMemberCount
652+
val recCount = ctx.base.findMemberCount
653653
if (recCount >= Config.LogPendingFindMemberThreshold) {
654654
if (ctx.property(TypeOps.findMemberLimit).isDefined &&
655-
ctx.findMemberCount > Config.PendingFindMemberLimit)
655+
ctx.base.findMemberCount > Config.PendingFindMemberLimit)
656656
return NoDenotation
657-
ctx.pendingMemberSearches = name :: ctx.pendingMemberSearches
657+
ctx.base.pendingMemberSearches = name :: ctx.base.pendingMemberSearches
658658
}
659-
ctx.findMemberCount = recCount + 1
659+
ctx.base.findMemberCount = recCount + 1
660660
//assert(ctx.findMemberCount < 20)
661661
try go(this)
662662
catch {
@@ -666,8 +666,8 @@ object Types {
666666
}
667667
finally {
668668
if (recCount >= Config.LogPendingFindMemberThreshold)
669-
ctx.pendingMemberSearches = ctx.pendingMemberSearches.tail
670-
ctx.findMemberCount = recCount
669+
ctx.base.pendingMemberSearches = ctx.base.pendingMemberSearches.tail
670+
ctx.base.findMemberCount = recCount
671671
}
672672
}
673673

@@ -1907,8 +1907,8 @@ object Types {
19071907
* not loop before the error is detected.
19081908
*/
19091909
final def controlled[T](op: => T)(implicit ctx: Context): T = try {
1910-
ctx.underlyingRecursions += 1
1911-
if (ctx.underlyingRecursions < Config.LogPendingUnderlyingThreshold)
1910+
ctx.base.underlyingRecursions += 1
1911+
if (ctx.base.underlyingRecursions < Config.LogPendingUnderlyingThreshold)
19121912
op
19131913
else if (ctx.pendingUnderlying contains this)
19141914
throw CyclicReference(symbol)
@@ -1920,7 +1920,7 @@ object Types {
19201920
ctx.pendingUnderlying -= this
19211921
}
19221922
} finally {
1923-
ctx.underlyingRecursions -= 1
1923+
ctx.base.underlyingRecursions -= 1
19241924
}
19251925

19261926
/** The argument corresponding to class type parameter `tparam` as seen from
@@ -3734,7 +3734,7 @@ object Types {
37343734
def apply(msg: => Message)(implicit ctx: Context): ErrorType = {
37353735
val et = new ErrorType {
37363736
def msg(implicit ctx: Context): Message =
3737-
ctx.errorTypeMsg.get(this) match {
3737+
ctx.base.errorTypeMsg.get(this) match {
37383738
case Some(msgFun) => msgFun()
37393739
case None => "error message from previous run no longer available"
37403740
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class ReadTastyTreesFromClasses extends FrontEnd {
6161
// Note that if both the class and the object are present, then loading the class will also load
6262
// the object, this is why we use orElse here, otherwise we could load the object twice and
6363
// create ambiguities!
64-
ctx.staticRef(className) match {
64+
ctx.base.staticRef(className) match {
6565
case clsd: ClassDenotation =>
6666
clsd.infoOrCompleter match {
6767
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
}
@@ -520,7 +520,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
520520

521521
def summarized[T](depth: Int)(op: => T): T = {
522522
val saved = maxSummarized
523-
maxSummarized = ctx.toTextRecursions + depth
523+
maxSummarized = ctx.base.toTextRecursions + depth
524524
try op
525525
finally maxSummarized = depth
526526
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class TreeChecker extends Phase with SymTransformer {
9797
def phaseName: String = "Ycheck"
9898

9999
def run(implicit ctx: Context): Unit = {
100-
check(ctx.allPhases, ctx)
100+
check(ctx.base.allPhases, ctx)
101101
}
102102

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

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

120120
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)