Skip to content

Commit a33c99d

Browse files
Remove Context to ContextBase implicit conversion
1 parent 29fa55e commit a33c99d

10 files changed

+61
-44
lines changed

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

Lines changed: 7 additions & 7 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))
@@ -147,23 +147,23 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
147147
}
148148

149149
protected def compileUnits()(implicit ctx: Context) = Stats.maybeMonitored {
150-
ctx.checkSingleThreaded()
150+
ctx.base.checkSingleThreaded()
151151
compiling = true
152152

153153
// If testing pickler, make sure to stop after pickling phase:
154154
val stopAfter =
155155
if (ctx.settings.YtestPickler.value) List("pickler")
156156
else ctx.settings.YstopAfter.value
157157

158-
val phases = ctx.squashPhases(ctx.phasePlan,
158+
val phases = ctx.base.squashPhases(ctx.base.phasePlan,
159159
ctx.settings.Yskip.value, ctx.settings.YstopBefore.value, stopAfter, ctx.settings.Ycheck.value)
160-
ctx.usePhases(phases)
160+
ctx.base.usePhases(phases)
161161

162162
def runPhases(implicit ctx: Context) = {
163163
var lastPrintedTree: PrintedTree = NoPrintedTree
164164
val profiler = ctx.profiler
165165

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

228228
ctx.echo(s"result of $unit after $squashedPhase:")
@@ -268,4 +268,4 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
268268
myUnits = null
269269
myUnitsCached = null
270270
}
271-
}
271+
}

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

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

429454
/** A condensed context provides only a small memory footprint over
@@ -516,7 +541,7 @@ object Contexts {
516541
/** A class defining the initial context with given context base
517542
* and set of possible settings.
518543
*/
519-
private class InitialContext(val base: ContextBase, settings: SettingGroup) extends FreshContext {
544+
private class InitialContext(val base: ContextBase, settingsGroup: SettingGroup) extends FreshContext {
520545
outer = NoContext
521546
period = InitialPeriod
522547
mode = Mode.None
@@ -525,7 +550,7 @@ object Contexts {
525550
tree = untpd.EmptyTree
526551
typeAssigner = TypeAssigner
527552
moreProperties = Map.empty
528-
store = initialStore.updated(settingsStateLoc, settings.defaultState)
553+
store = initialStore.updated(settingsStateLoc, settingsGroup.defaultState)
529554
typeComparer = new TypeComparer(this)
530555
searchHistory = new SearchHistory(0, Map())
531556
gadt = EmptyGADTMap
@@ -683,14 +708,6 @@ object Contexts {
683708
else assert(thread == Thread.currentThread(), "illegal multithreaded access to ContextBase")
684709
}
685710

686-
object Context {
687-
688-
/** implicit conversion that injects all ContextBase members into a context */
689-
implicit def toBase(ctx: Context): ContextBase = ctx.base
690-
691-
// @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
692-
}
693-
694711
class GADTMap(initBounds: SimpleIdentityMap[Symbol, TypeBounds]) extends util.DotClass {
695712
private[this] var myBounds = initBounds
696713
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
@@ -869,12 +869,12 @@ object Denotations {
869869
} else {
870870
//println(s"might need new denot for $cur, valid for ${cur.validFor} at $currentPeriod")
871871
// not found, cur points to highest existing variant
872-
val nextTransformerId = ctx.nextDenotTransformerId(cur.validFor.lastPhaseId)
872+
val nextTransformerId = ctx.base.nextDenotTransformerId(cur.validFor.lastPhaseId)
873873
if (currentPeriod.lastPhaseId <= nextTransformerId)
874874
cur.validFor = Period(currentPeriod.runId, cur.validFor.firstPhaseId, nextTransformerId)
875875
else {
876876
var startPid = nextTransformerId + 1
877-
val transformer = ctx.denotTransformers(nextTransformerId)
877+
val transformer = ctx.base.denotTransformers(nextTransformerId)
878878
//println(s"transforming $this with $transformer")
879879
try {
880880
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
@@ -587,14 +587,14 @@ object Types {
587587
val jointInfo =
588588
if (rinfo.isAlias) rinfo
589589
else if (pdenot.info.isAlias) pdenot.info
590-
else if (ctx.pendingMemberSearches.contains(name)) pdenot.info safe_& rinfo
590+
else if (ctx.base.pendingMemberSearches.contains(name)) pdenot.info safe_& rinfo
591591
else pdenot.info recoverable_& rinfo
592592
pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, jointInfo)
593593
} else {
594594
pdenot & (
595595
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId)),
596596
pre,
597-
safeIntersection = ctx.pendingMemberSearches.contains(name))
597+
safeIntersection = ctx.base.pendingMemberSearches.contains(name))
598598
}
599599
}
600600

@@ -639,17 +639,17 @@ object Types {
639639
case d => d
640640
}
641641
def goAnd(l: Type, r: Type) = {
642-
go(l) & (go(r), pre, safeIntersection = ctx.pendingMemberSearches.contains(name))
642+
go(l) & (go(r), pre, safeIntersection = ctx.base.pendingMemberSearches.contains(name))
643643
}
644644

645-
val recCount = ctx.findMemberCount
645+
val recCount = ctx.base.findMemberCount
646646
if (recCount >= Config.LogPendingFindMemberThreshold) {
647647
if (ctx.property(TypeOps.findMemberLimit).isDefined &&
648-
ctx.findMemberCount > Config.PendingFindMemberLimit)
648+
ctx.base.findMemberCount > Config.PendingFindMemberLimit)
649649
return NoDenotation
650-
ctx.pendingMemberSearches = name :: ctx.pendingMemberSearches
650+
ctx.base.pendingMemberSearches = name :: ctx.base.pendingMemberSearches
651651
}
652-
ctx.findMemberCount = recCount + 1
652+
ctx.base.findMemberCount = recCount + 1
653653
//assert(ctx.findMemberCount < 20)
654654
try go(this)
655655
catch {
@@ -659,8 +659,8 @@ object Types {
659659
}
660660
finally {
661661
if (recCount >= Config.LogPendingFindMemberThreshold)
662-
ctx.pendingMemberSearches = ctx.pendingMemberSearches.tail
663-
ctx.findMemberCount = recCount
662+
ctx.base.pendingMemberSearches = ctx.base.pendingMemberSearches.tail
663+
ctx.base.findMemberCount = recCount
664664
}
665665
}
666666

@@ -1904,8 +1904,8 @@ object Types {
19041904
* not loop before the error is detected.
19051905
*/
19061906
final def controlled[T](op: => T)(implicit ctx: Context): T = try {
1907-
ctx.underlyingRecursions += 1
1908-
if (ctx.underlyingRecursions < Config.LogPendingUnderlyingThreshold)
1907+
ctx.base.underlyingRecursions += 1
1908+
if (ctx.base.underlyingRecursions < Config.LogPendingUnderlyingThreshold)
19091909
op
19101910
else if (ctx.pendingUnderlying contains this)
19111911
throw CyclicReference(symbol)
@@ -1917,7 +1917,7 @@ object Types {
19171917
ctx.pendingUnderlying -= this
19181918
}
19191919
} finally {
1920-
ctx.underlyingRecursions -= 1
1920+
ctx.base.underlyingRecursions -= 1
19211921
}
19221922

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

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/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
"...".toText
3636
}
@@ -523,7 +523,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
523523

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase =>
4949
addCompanionPhases.exists(_.isCompanionNeeded(cls))
5050

5151
override def prepareForUnit(tree: Tree)(implicit ctx: Context) = {
52-
addCompanionPhases = ctx.phasePlan.flatMap(_ collect { case p: NeedsCompanions => p })
52+
addCompanionPhases = ctx.base.phasePlan.flatMap(_ collect { case p: NeedsCompanions => p })
5353
ctx
5454
}
5555

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

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

104104
def run(implicit ctx: Context): Unit = {
105-
check(ctx.allPhases, ctx)
105+
check(ctx.base.allPhases, ctx)
106106
}
107107

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

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

125125
assertSelectWrapsNew(ctx.compilationUnit.tpdTree)(ctx)

0 commit comments

Comments
 (0)