Skip to content

Commit 0f52ece

Browse files
committed
Rename ctx values
We would like to distinguish between `ctx` referring to an enclosing parameter and `ctx` referring to a field. This is so that we can at some point drop `ctx` as a parameter name and just use (using Context). The `ctx` would then go to an imported def in `Contexts`. But any other use of `ctx` does does not follow strict nesting discipline can then change meaning, so we should get these out of the way first.
1 parent a0690e1 commit 0f52ece

File tree

4 files changed

+27
-30
lines changed

4 files changed

+27
-30
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/core/Definitions.scala

Lines changed: 6 additions & 4 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 [Dummy_to_ensure_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)
@@ -1273,8 +1274,9 @@ class Definitions {
12731274
* types `As`, the result type `B` and a whether the type is an erased context function.
12741275
*/
12751276
object ContextFunctionType:
1276-
def unapply(tp: Type)(using ctx: Context): Option[(List[Type], Type, Boolean)] =
1277-
if ctx.erasedTypes then unapply(tp)(using ctx.withPhase(ctx.erasurePhase))
1277+
def unapply(tp: Type)(using Context): Option[(List[Type], Type, Boolean)] =
1278+
if ctx.erasedTypes then
1279+
unapply(tp)(using ctx.withPhase(ctx.erasurePhase))
12781280
else
12791281
val tp1 = tp.dealias
12801282
if isContextFunctionClass(tp1.typeSymbol) then
@@ -1427,7 +1429,7 @@ class Definitions {
14271429
private var isInitialized = false
14281430

14291431
def init()(implicit ctx: Context): Unit = {
1430-
this.ctx = ctx
1432+
this.initCtx = ctx
14311433
if (!isInitialized) {
14321434
// Enter all symbols from the scalaShadowing package in the scala package
14331435
for (m <- ScalaShadowingPackage.info.decls)

0 commit comments

Comments
 (0)