Skip to content

Commit 798e57e

Browse files
Remove Context to ContextBase implicit conversion
1 parent 10c58d4 commit 798e57e

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
@@ -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
@@ -682,14 +708,6 @@ object Contexts {
682708
else assert(thread == Thread.currentThread(), "illegal multithreaded access to ContextBase")
683709
}
684710

685-
object Context {
686-
687-
/** implicit conversion that injects all ContextBase members into a context */
688-
implicit def toBase(ctx: Context): ContextBase = ctx.base
689-
690-
// @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
691-
}
692-
693711
class GADTMap(initBounds: SimpleIdentityMap[Symbol, TypeBounds]) extends util.DotClass {
694712
private[this] var myBounds = initBounds
695713
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 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
@@ -896,12 +896,12 @@ object Denotations {
896896
} else {
897897
//println(s"might need new denot for $cur, valid for ${cur.validFor} at $currentPeriod")
898898
// not found, cur points to highest existing variant
899-
val nextTransformerId = ctx.nextDenotTransformerId(cur.validFor.lastPhaseId)
899+
val nextTransformerId = ctx.base.nextDenotTransformerId(cur.validFor.lastPhaseId)
900900
if (currentPeriod.lastPhaseId <= nextTransformerId)
901901
cur.validFor = Period(currentPeriod.runId, cur.validFor.firstPhaseId, nextTransformerId)
902902
else {
903903
var startPid = nextTransformerId + 1
904-
val transformer = ctx.denotTransformers(nextTransformerId)
904+
val transformer = ctx.base.denotTransformers(nextTransformerId)
905905
//println(s"transforming $this with $transformer")
906906
try {
907907
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
@@ -619,14 +619,14 @@ object Types {
619619
val jointInfo =
620620
if (rinfo.isAlias) rinfo
621621
else if (pinfo.isAlias) pinfo
622-
else if (ctx.pendingMemberSearches.contains(name)) pinfo safe_& rinfo
622+
else if (ctx.base.pendingMemberSearches.contains(name)) pinfo safe_& rinfo
623623
else pinfo recoverable_& rinfo
624624
pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, jointInfo)
625625
} else {
626626
pdenot & (
627627
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId)),
628628
pre,
629-
safeIntersection = ctx.pendingMemberSearches.contains(name))
629+
safeIntersection = ctx.base.pendingMemberSearches.contains(name))
630630
}
631631
}
632632

@@ -668,13 +668,13 @@ object Types {
668668
}
669669

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

674-
val recCount = ctx.findMemberCount
674+
val recCount = ctx.base.findMemberCount
675675
if (recCount >= Config.LogPendingFindMemberThreshold)
676-
ctx.pendingMemberSearches = name :: ctx.pendingMemberSearches
677-
ctx.findMemberCount = recCount + 1
676+
ctx.base.pendingMemberSearches = name :: ctx.base.pendingMemberSearches
677+
ctx.base.findMemberCount = recCount + 1
678678
try go(this)
679679
catch {
680680
case ex: Throwable =>
@@ -691,8 +691,8 @@ object Types {
691691
}
692692
finally {
693693
if (recCount >= Config.LogPendingFindMemberThreshold)
694-
ctx.pendingMemberSearches = ctx.pendingMemberSearches.tail
695-
ctx.findMemberCount = recCount
694+
ctx.base.pendingMemberSearches = ctx.base.pendingMemberSearches.tail
695+
ctx.base.findMemberCount = recCount
696696
}
697697
}
698698

@@ -1928,8 +1928,8 @@ object Types {
19281928
* not loop before the error is detected.
19291929
*/
19301930
final def controlled[T](op: => T)(implicit ctx: Context): T = try {
1931-
ctx.underlyingRecursions += 1
1932-
if (ctx.underlyingRecursions < Config.LogPendingUnderlyingThreshold)
1931+
ctx.base.underlyingRecursions += 1
1932+
if (ctx.base.underlyingRecursions < Config.LogPendingUnderlyingThreshold)
19331933
op
19341934
else if (ctx.pendingUnderlying contains this)
19351935
throw CyclicReference(symbol)
@@ -1941,7 +1941,7 @@ object Types {
19411941
ctx.pendingUnderlying -= this
19421942
}
19431943
} finally {
1944-
ctx.underlyingRecursions -= 1
1944+
ctx.base.underlyingRecursions -= 1
19451945
}
19461946

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

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)