Skip to content

Commit 88129fc

Browse files
authored
Merge pull request #8654 from dotty-staging/rename-ctx
Rename ctx values
2 parents 07912a2 + df2ff53 commit 88129fc

25 files changed

+152
-153
lines changed

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ object GenBCode {
6969
val name: String = "genBCode"
7070
}
7171

72-
class GenBCodePipeline(val int: DottyBackendInterface)(implicit val ctx: Context) extends BCodeSyncAndTry {
72+
class GenBCodePipeline(val int: DottyBackendInterface)(implicit ctx: Context) extends BCodeSyncAndTry {
7373

7474
private var tree: Tree = _
7575

compiler/src/dotty/tools/backend/jvm/scalaPrimitives.scala

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/* NSC -- new Scala compiler
2-
* Copyright 2005-2012 LAMP/EPFL
3-
* @author Martin Odersky
4-
*/
5-
61
package dotty.tools
72
package backend.jvm
83

@@ -35,7 +30,7 @@ import scala.collection.immutable
3530
*
3631
* Inspired from the `scalac` compiler.
3732
*/
38-
class DottyPrimitives(ctx: Context) {
33+
class DottyPrimitives(ictx: Context) {
3934
import dotty.tools.backend.ScalaPrimitivesOps._
4035

4136
@threadUnsafe private lazy val primitives: immutable.Map[Symbol, Int] = init
@@ -124,7 +119,7 @@ class DottyPrimitives(ctx: Context) {
124119
/** Initialize the primitive map */
125120
private def init: immutable.Map[Symbol, Int] = {
126121

127-
implicit val ctx = this.ctx
122+
given Context = ictx
128123

129124
import Symbols.defn
130125
val primitives = Symbols.newMutableSymbolMap[Int]
@@ -401,14 +396,14 @@ class DottyPrimitives(ctx: Context) {
401396
primitives.toMap
402397
}
403398

404-
def isPrimitive(fun: Tree): Boolean = {
405-
(primitives contains fun.symbol(ctx)) ||
406-
(fun.symbol(ctx) == NoSymbol // the only trees that do not have a symbol assigned are array.{update,select,length,clone}}
407-
&& (fun match {
408-
case Select(_, StdNames.nme.clone_) => false // but array.clone is NOT a primitive op.
409-
case _ => true
410-
}))
411-
}
412-
399+
def isPrimitive(fun: Tree): Boolean =
400+
given Context = ictx
401+
primitives.contains(fun.symbol)
402+
|| (fun.symbol == NoSymbol // the only trees that do not have a symbol assigned are array.{update,select,length,clone}}
403+
&& {
404+
fun match
405+
case Select(_, StdNames.nme.clone_) => false // but array.clone is NOT a primitive op.
406+
case _ => true
407+
})
413408
}
414409

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ class Driver {
6464
protected def sourcesRequired: Boolean = true
6565

6666
def setup(args: Array[String], rootCtx: Context): (List[String], Context) = {
67-
val ctx = rootCtx.fresh
68-
val summary = CompilerCommand.distill(args)(ctx)
69-
ctx.setSettings(summary.sstate)
70-
MacroClassLoader.init(ctx)
71-
Positioned.updateDebugPos(ctx)
67+
val ictx = rootCtx.fresh
68+
val summary = CompilerCommand.distill(args)(ictx)
69+
ictx.setSettings(summary.sstate)
70+
MacroClassLoader.init(ictx)
71+
Positioned.updateDebugPos(ictx)
7272

73-
if (!ctx.settings.YdropComments.value(ctx) || ctx.mode.is(Mode.ReadComments))
74-
ctx.setProperty(ContextDoc, new ContextDocstrings)
73+
if (!ictx.settings.YdropComments.value(ictx) || ictx.mode.is(Mode.ReadComments))
74+
ictx.setProperty(ContextDoc, new ContextDocstrings)
7575

76-
val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)(ctx)
77-
fromTastySetup(fileNames, ctx)
76+
val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)(ictx)
77+
fromTastySetup(fileNames, ictx)
7878
}
7979

8080
/** Setup extra classpath and figure out class names for tasty file inputs */

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
6969
private var myCtx = rootContext(ictx)
7070

7171
/** The context created for this run */
72-
def runContext: Context = myCtx
73-
74-
protected implicit def ctx: Context = myCtx
75-
assert(ctx.runId <= Periods.MaxPossibleRunId)
72+
given runContext[Dummy_so_its_a_def] as Context = myCtx
73+
assert(runContext.runId <= Periods.MaxPossibleRunId)
7674

7775
private var myUnits: List[CompilationUnit] = _
7876
private var myUnitsCached: List[CompilationUnit] = _
@@ -108,12 +106,12 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
108106
private var finalizeActions = mutable.ListBuffer[() => Unit]()
109107

110108
def compile(fileNames: List[String]): Unit = try {
111-
val sources = fileNames.map(ctx.getSource(_))
109+
val sources = fileNames.map(runContext.getSource(_))
112110
compileSources(sources)
113111
}
114112
catch {
115113
case NonFatal(ex) =>
116-
ctx.echo(i"exception occurred while compiling $units%, %")
114+
runContext.echo(i"exception occurred while compiling $units%, %")
117115
throw ex
118116
}
119117

@@ -266,7 +264,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
266264
/** Print summary; return # of errors encountered */
267265
def printSummary(): Unit = {
268266
printMaxConstraint()
269-
val r = ctx.reporter
267+
val r = runContext.reporter
270268
r.printSummary
271269
}
272270

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ object desugar {
112112
val originalOwner = sym.owner
113113
def apply(tp: Type) = tp match {
114114
case tp: NamedType if tp.symbol.exists && (tp.symbol.owner eq originalOwner) =>
115-
val defctx = this.ctx.outersIterator.dropWhile(_.scope eq this.ctx.scope).next()
115+
val defctx = mapCtx.outersIterator.dropWhile(_.scope eq mapCtx.scope).next()
116116
var local = defctx.denotNamed(tp.name).suchThat(_.isParamOrAccessor).symbol
117117
if (local.exists) (defctx.owner.thisType select local).dealiasKeepAnnots
118118
else {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ object Contexts {
8484
with Plugins
8585
with Cloneable { thiscontext =>
8686

87-
implicit def ctx: Context = this
87+
implicit def thisContext: Context = this
8888

8989
/** All outer contexts, ending in `base.initialCtx` and then `NoContext` */
9090
def outersIterator: Iterator[Context] = new Iterator[Context] {
@@ -284,10 +284,10 @@ object Contexts {
284284
withPhase(phase.id)
285285

286286
final def withPhaseNoLater(phase: Phase): Context =
287-
if (phase.exists && ctx.phase.id > phase.id) withPhase(phase) else ctx
287+
if (phase.exists && this.phase.id > phase.id) withPhase(phase) else this
288288

289289
final def withPhaseNoEarlier(phase: Phase): Context =
290-
if (phase.exists && ctx.phase.id < phase.id) withPhase(phase) else ctx
290+
if (phase.exists && this.phase.id < phase.id) withPhase(phase) else this
291291

292292
// `creationTrace`-related code. To enable, uncomment the code below and the
293293
// call to `setCreationTrace()` in this file.
@@ -399,15 +399,15 @@ object Contexts {
399399
def exprContext(stat: Tree[? >: Untyped], exprOwner: Symbol): Context =
400400
if (exprOwner == this.owner) this
401401
else if (untpd.isSuperConstrCall(stat) && this.owner.isClass) superCallContext
402-
else ctx.fresh.setOwner(exprOwner)
402+
else fresh.setOwner(exprOwner)
403403

404404
/** A new context that summarizes an import statement */
405405
def importContext(imp: Import[?], sym: Symbol): FreshContext = {
406406
val impNameOpt = imp.expr match {
407407
case ref: RefTree[?] => Some(ref.name.asTermName)
408408
case _ => None
409409
}
410-
ctx.fresh.setImportInfo(ImportInfo(sym, imp.selectors, impNameOpt))
410+
fresh.setImportInfo(ImportInfo(sym, imp.selectors, impNameOpt))
411411
}
412412

413413
/** Does current phase use an erased types interpretation? */

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ object Definitions {
3737
class Definitions {
3838
import Definitions._
3939

40-
private implicit var ctx: Context = _
40+
private var initCtx: Context = _
41+
private given ctx[Dummy_so_its_a_def] as Context = initCtx
4142

4243
private def newSymbol[N <: Name](owner: Symbol, name: N, flags: FlagSet, info: Type) =
4344
ctx.newSymbol(owner, name, flags | Permanent, info)
@@ -1427,7 +1428,7 @@ class Definitions {
14271428
private var isInitialized = false
14281429

14291430
def init()(implicit ctx: Context): Unit = {
1430-
this.ctx = ctx
1431+
this.initCtx = ctx
14311432
if (!isInitialized) {
14321433
// Enter all symbols from the scalaShadowing package in the scala package
14331434
for (m <- ScalaShadowingPackage.info.decls)

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Contexts._
77
* run ids represent compiler runs
88
* phase ids represent compiler phases
99
*/
10-
abstract class Periods { self: Context =>
10+
abstract class Periods { thisCtx: Context =>
1111
import Periods._
1212

1313
/** The current phase identifier */
@@ -18,11 +18,11 @@ abstract class Periods { self: Context =>
1818

1919
/** Execute `op` at given period */
2020
def atPeriod[T](pd: Period)(op: Context => T): T =
21-
op(ctx.fresh.setPeriod(pd))
21+
op(thisCtx.fresh.setPeriod(pd))
2222

2323
/** Execute `op` at given phase id */
2424
def atPhase[T](pid: PhaseId)(op: Context ?=> T): T =
25-
op(using ctx.withPhase(pid))
25+
op(using thisCtx.withPhase(pid))
2626

2727
/** The period containing the current period where denotations do not change.
2828
* We compute this by taking as first phase the first phase less or equal to
@@ -31,19 +31,19 @@ abstract class Periods { self: Context =>
3131
*/
3232
def stablePeriod: Period = {
3333
var first = phaseId
34-
val nxTrans = ctx.base.nextDenotTransformerId(first)
35-
while (first - 1 > NoPhaseId && (ctx.base.nextDenotTransformerId(first - 1) == nxTrans))
34+
val nxTrans = thisCtx.base.nextDenotTransformerId(first)
35+
while (first - 1 > NoPhaseId && (thisCtx.base.nextDenotTransformerId(first - 1) == nxTrans))
3636
first -= 1
3737
Period(runId, first, nxTrans)
3838
}
3939

4040
/** Are all base types in the current period guaranteed to be the same as in period `p`? */
4141
def hasSameBaseTypesAs(p: Period): Boolean = {
42-
val period = this.period
42+
val period = thisCtx.period
4343
period == p ||
4444
period.runId == p.runId &&
45-
this.phases(period.phaseId).sameBaseTypesStartId ==
46-
this.phases(p.phaseId).sameBaseTypesStartId
45+
thisCtx.phases(period.phaseId).sameBaseTypesStartId ==
46+
thisCtx.phases(p.phaseId).sameBaseTypesStartId
4747
}
4848
}
4949

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import transform.TypeUtils._
2727

2828
import scala.annotation.internal.sharable
2929

30-
trait SymDenotations { this: Context =>
30+
trait SymDenotations { thisCtx: Context =>
3131
import SymDenotations._
3232

3333
/** Factory method for SymDenotion creation. All creations
@@ -53,9 +53,9 @@ trait SymDenotations { this: Context =>
5353
if (denot.isOneOf(ValidForeverFlags) || denot.isRefinementClass || denot.isImport) true
5454
else {
5555
val initial = denot.initial
56-
val firstPhaseId = initial.validFor.firstPhaseId.max(ctx.typerPhase.id)
57-
if ((initial ne denot) || ctx.phaseId != firstPhaseId)
58-
ctx.withPhase(firstPhaseId).stillValidInOwner(initial)
56+
val firstPhaseId = initial.validFor.firstPhaseId.max(thisCtx.typerPhase.id)
57+
if ((initial ne denot) || thisCtx.phaseId != firstPhaseId)
58+
thisCtx.withPhase(firstPhaseId).stillValidInOwner(initial)
5959
else
6060
stillValidInOwner(denot)
6161
}
@@ -78,15 +78,15 @@ trait SymDenotations { this: Context =>
7878
def traceInvalid(denot: Denotation): Boolean = {
7979
def show(d: Denotation) = s"$d#${d.symbol.id}"
8080
def explain(msg: String) = {
81-
println(s"${show(denot)} is invalid at ${this.period} because $msg")
81+
println(s"${show(denot)} is invalid at ${thisCtx.period} because $msg")
8282
false
8383
}
8484
denot match {
8585
case denot: SymDenotation =>
8686
def explainSym(msg: String) = explain(s"$msg\ndefined = ${denot.definedPeriodsString}")
8787
if (denot.isOneOf(ValidForeverFlags) || denot.isRefinementClass) true
8888
else {
89-
implicit val ctx = this
89+
implicit val ctx = thisCtx
9090
val initial = denot.initial
9191
if ((initial ne denot) || ctx.phaseId != initial.validFor.firstPhaseId)
9292
ctx.withPhase(initial.validFor.firstPhaseId).traceInvalid(initial)
@@ -116,7 +116,7 @@ trait SymDenotations { this: Context =>
116116
/** Possibly accept stale symbol with warning if in IDE */
117117
def acceptStale(denot: SingleDenotation): Boolean =
118118
staleOK && {
119-
ctx.debugwarn(denot.staleSymbolMsg)
119+
thisCtx.debugwarn(denot.staleSymbolMsg)
120120
true
121121
}
122122
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import scala.annotation.internal.sharable
3333
import config.Printers.typr
3434

3535
/** Creation methods for symbols */
36-
trait Symbols { this: Context =>
36+
trait Symbols { thisCtx: Context =>
3737

3838
// ---- Factory methods for symbol creation ----------------------
3939
//
@@ -131,7 +131,7 @@ trait Symbols { this: Context =>
131131
}
132132

133133
def newRefinedClassSymbol(coord: Coord = NoCoord): ClassSymbol =
134-
newCompleteClassSymbol(ctx.owner, tpnme.REFINE_CLASS, NonMember, parents = Nil, coord = coord)
134+
newCompleteClassSymbol(thisCtx.owner, tpnme.REFINE_CLASS, NonMember, parents = Nil, coord = coord)
135135

136136
/** Create a module symbol with associated module class
137137
* from its non-info fields and a function producing the info
@@ -268,7 +268,7 @@ trait Symbols { this: Context =>
268268

269269
/** Create a symbol representing a selftype declaration for class `cls`. */
270270
def newSelfSym(cls: ClassSymbol, name: TermName = nme.WILDCARD, selfInfo: Type = NoType): TermSymbol =
271-
ctx.newSymbol(cls, name, SelfSymFlags, selfInfo orElse cls.classInfo.selfType, coord = cls.coord)
271+
newSymbol(cls, name, SelfSymFlags, selfInfo orElse cls.classInfo.selfType, coord = cls.coord)
272272

273273
/** Create new type parameters with given owner, names, and flags.
274274
* @param boundsFn A function that, given type refs to the newly created

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import typer.IfBottom
2222

2323
import scala.annotation.internal.sharable
2424

25-
trait TypeOps { this: Context => // TODO: Make standalone object.
25+
trait TypeOps { thisCtx: Context => // TODO: Make standalone object.
2626

2727
/** The type `tp` as seen from prefix `pre` and owner `cls`. See the spec
2828
* for what this means.
@@ -134,7 +134,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
134134
}
135135
case tp: TypeParamRef =>
136136
if (tp.paramName.is(DepParamName)) {
137-
val bounds = ctx.typeComparer.bounds(tp)
137+
val bounds = thisCtx.typeComparer.bounds(tp)
138138
if (bounds.lo.isRef(defn.NothingClass)) bounds.hi else bounds.lo
139139
}
140140
else {
@@ -145,9 +145,9 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
145145
tp
146146
case tp: AliasingBounds =>
147147
tp.derivedAlias(simplify(tp.alias, theMap))
148-
case AndType(l, r) if !ctx.mode.is(Mode.Type) =>
148+
case AndType(l, r) if !thisCtx.mode.is(Mode.Type) =>
149149
simplify(l, theMap) & simplify(r, theMap)
150-
case OrType(l, r) if !ctx.mode.is(Mode.Type) =>
150+
case OrType(l, r) if !thisCtx.mode.is(Mode.Type) =>
151151
simplify(l, theMap) | simplify(r, theMap)
152152
case _: AppliedType | _: MatchType =>
153153
val normed = tp.tryNormalize
@@ -192,7 +192,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
192192
val accu1 = if (accu exists (_ derivesFrom c)) accu else c :: accu
193193
if (cs == c.baseClasses) accu1 else dominators(rest, accu1)
194194
case Nil => // this case can happen because after erasure we do not have a top class anymore
195-
assert(ctx.erasedTypes || ctx.reporter.errorsReported)
195+
assert(thisCtx.erasedTypes || thisCtx.reporter.errorsReported)
196196
defn.ObjectClass :: Nil
197197
}
198198

@@ -216,7 +216,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
216216
case AppliedType(tycon2, args2) =>
217217
tp1.derivedAppliedType(
218218
mergeRefinedOrApplied(tycon1, tycon2),
219-
ctx.typeComparer.lubArgs(args1, args2, tycon1.typeParams))
219+
thisCtx.typeComparer.lubArgs(args1, args2, tycon1.typeParams))
220220
case _ => fallback
221221
}
222222
case tp1 @ TypeRef(pre1, _) =>
@@ -492,15 +492,15 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
492492
def featureEnabled(feature: TermName, owner: Symbol = NoSymbol): Boolean = {
493493
def hasImport = {
494494
val owner1 = if (!owner.exists) defn.LanguageModule.moduleClass else owner
495-
ctx.importInfo != null &&
496-
ctx.importInfo.featureImported(feature, owner1)(ctx.withPhase(ctx.typerPhase))
495+
thisCtx.importInfo != null &&
496+
thisCtx.importInfo.featureImported(feature, owner1)(thisCtx.withPhase(thisCtx.typerPhase))
497497
}
498498
val hasOption = {
499499
def toPrefix(sym: Symbol): String =
500500
if (!sym.exists) ""
501501
else toPrefix(sym.owner) + sym.name + "."
502502
val featureName = toPrefix(owner) + feature
503-
ctx.base.settings.language.value contains featureName
503+
thisCtx.base.settings.language.value contains featureName
504504
}
505505
hasOption || hasImport
506506
}
@@ -527,7 +527,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
527527
* This test is used when we are too early in the pipeline to consider imports.
528528
*/
529529
def scala2CompatSetting: Boolean =
530-
ctx.settings.language.value.contains(nme.Scala2Compat.toString)
530+
thisCtx.settings.language.value.contains(nme.Scala2Compat.toString)
531531

532532
/** Refine child based on parent
533533
*

0 commit comments

Comments
 (0)