Skip to content

Commit dfd1fbe

Browse files
committed
Rename ctx method in Context
1 parent 2f34f69 commit dfd1fbe

File tree

7 files changed

+52
-52
lines changed

7 files changed

+52
-52
lines changed

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/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
*

compiler/src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ object Reporter {
6666
}
6767
}
6868

69-
trait Reporting { this: Context =>
69+
trait Reporting { thisCtx: Context =>
7070

7171
/** For sending messages that are printed only if -verbose is set */
7272
def inform(msg: => String, pos: SourcePosition = NoSourcePosition): Unit =
73-
if (this.settings.verbose.value) this.echo(msg, pos)
73+
if (thisCtx.settings.verbose.value) thisCtx.echo(msg, pos)
7474

7575
def echo(msg: => String, pos: SourcePosition = NoSourcePosition): Unit =
7676
reporter.report(new Info(msg, pos))
7777

7878
def reportWarning(warning: Warning): Unit =
79-
if (!this.settings.silentWarnings.value)
80-
if (this.settings.XfatalWarnings.value)
79+
if (!thisCtx.settings.silentWarnings.value)
80+
if (thisCtx.settings.XfatalWarnings.value)
8181
warning match {
8282
case warning: ConditionalWarning if !warning.enablingOption.value =>
8383
reporter.report(warning) // conditional warnings that are not enabled are not fatal
@@ -123,23 +123,23 @@ trait Reporting { this: Context =>
123123
reportWarning(new Warning(msg, addInlineds(pos)))
124124

125125
def strictWarning(msg: Message, pos: SourcePosition = NoSourcePosition): Unit =
126-
if (this.settings.strict.value) error(msg, pos)
126+
if (thisCtx.settings.strict.value) error(msg, pos)
127127
else warning(msg.append("\n(This would be an error under strict mode)"), pos)
128128

129129
def error(msg: Message, pos: SourcePosition = NoSourcePosition, sticky: Boolean = false): Unit = {
130130
val fullPos = addInlineds(pos)
131131
reporter.report(if (sticky) new StickyError(msg, fullPos) else new Error(msg, fullPos))
132-
if ctx.settings.YdebugError.value then Thread.dumpStack()
132+
if thisCtx.settings.YdebugError.value then Thread.dumpStack()
133133
}
134134

135135
def error(ex: TypeError, pos: SourcePosition): Unit = {
136136
error(ex.toMessage, pos, sticky = true)
137-
if (ctx.settings.YdebugTypeError.value)
137+
if (thisCtx.settings.YdebugTypeError.value)
138138
ex.printStackTrace()
139139
}
140140

141141
def errorOrMigrationWarning(msg: Message, pos: SourcePosition = NoSourcePosition): Unit =
142-
if (ctx.scala2CompatMode) migrationWarning(msg, pos) else error(msg, pos)
142+
if (thisCtx.scala2CompatMode) migrationWarning(msg, pos) else error(msg, pos)
143143

144144
def restrictionError(msg: Message, pos: SourcePosition = NoSourcePosition): Unit =
145145
error(msg.mapMsg("Implementation restriction: " + _), pos)
@@ -152,11 +152,11 @@ trait Reporting { this: Context =>
152152
* "contains" here.
153153
*/
154154
def log(msg: => String, pos: SourcePosition = NoSourcePosition): Unit =
155-
if (this.settings.Ylog.value.containsPhase(phase))
156-
echo(s"[log ${ctx.phasesStack.reverse.mkString(" -> ")}] $msg", pos)
155+
if (thisCtx.settings.Ylog.value.containsPhase(phase))
156+
echo(s"[log ${thisCtx.phasesStack.reverse.mkString(" -> ")}] $msg", pos)
157157

158158
def debuglog(msg: => String): Unit =
159-
if (ctx.debug) log(msg)
159+
if (thisCtx.debug) log(msg)
160160

161161
def informTime(msg: => String, start: Long): Unit = {
162162
def elapsed = s" in ${currentTimeMillis - start}ms"
@@ -172,7 +172,7 @@ trait Reporting { this: Context =>
172172
}
173173

174174
def debugwarn(msg: => String, pos: SourcePosition = NoSourcePosition): Unit =
175-
if (this.settings.Ydebug.value) warning(msg, pos)
175+
if (thisCtx.settings.Ydebug.value) warning(msg, pos)
176176

177177
private def addInlineds(pos: SourcePosition)(implicit ctx: Context) = {
178178
def recur(pos: SourcePosition, inlineds: List[Trees.Tree[?]]): SourcePosition = inlineds match {

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import transform.SymUtils._
2424
import reporting.messages._
2525

2626
trait NamerContextOps {
27-
this: Context =>
27+
thisCtx: Context =>
2828

2929
import NamerContextOps._
3030

31-
def typer: Typer = ctx.typeAssigner match {
31+
def typer: Typer = this.typeAssigner match {
3232
case typer: Typer => typer
3333
case _ => new Typer
3434
}
@@ -39,9 +39,9 @@ trait NamerContextOps {
3939
* finger prints.
4040
*/
4141
def enter(sym: Symbol): Symbol = {
42-
ctx.owner match {
42+
thisContext.owner match {
4343
case cls: ClassSymbol => cls.enter(sym)
44-
case _ => this.scope.openForMutations.enter(sym)
44+
case _ => thisCtx.scope.openForMutations.enter(sym)
4545
}
4646
sym
4747
}
@@ -105,7 +105,7 @@ trait NamerContextOps {
105105

106106
/** A new context for the interior of a class */
107107
def inClassContext(selfInfo: TypeOrSymbol): Context = {
108-
val localCtx: Context = ctx.fresh.setNewScope
108+
val localCtx: Context = thisCtx.fresh.setNewScope
109109
selfInfo match {
110110
case sym: Symbol if sym.exists && sym.name != nme.WILDCARD => localCtx.scope.openForMutations.enter(sym)
111111
case _ =>
@@ -114,8 +114,8 @@ trait NamerContextOps {
114114
}
115115

116116
def packageContext(tree: untpd.PackageDef, pkg: Symbol): Context =
117-
if (pkg.is(Package)) ctx.fresh.setOwner(pkg.moduleClass).setTree(tree)
118-
else ctx
117+
if (pkg.is(Package)) thisCtx.fresh.setOwner(pkg.moduleClass).setTree(tree)
118+
else thisCtx
119119

120120
/** The given type, unless `sym` is a constructor, in which case the
121121
* type of the constructed instance is returned

0 commit comments

Comments
 (0)