Skip to content

Commit a356142

Browse files
committed
Remove implicit definitions of ctx that are not parameters
1 parent 7330e7f commit a356142

35 files changed

+119
-224
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import dotty.tools.dotc.core.Symbols._
1010
* the compiler cake (Global).
1111
*/
1212
final class BCodeAsmCommon[I <: DottyBackendInterface](val interface: I) {
13-
import interface._
13+
import interface.{_, given _}
1414
import DottyBackendInterface.symExtensions
1515

1616
/**

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
3030
// import global._
3131
// import definitions._
3232
import tpd._
33-
import int._
33+
import int.{_, given _}
3434
import DottyBackendInterface.symExtensions
3535
import bTypes._
3636
import coreBTypes._

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
4545
import bTypes._
4646
import tpd._
4747
import coreBTypes._
48-
import int._
48+
import int.{_, given _}
4949
import DottyBackendInterface._
5050

5151
def ScalaATTRName: String = "Scala"
@@ -360,7 +360,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
360360
val narg = normalizeArgument(arg)
361361
// Transformation phases are not run on annotation trees, so we need to run
362362
// `constToLiteral` at this point.
363-
val t = constToLiteral(narg)(ctx.withPhase(ctx.erasurePhase))
363+
val t = constToLiteral(narg)(using ctx.withPhase(ctx.erasurePhase))
364364
t match {
365365
case Literal(const @ Constant(_)) =>
366366
const.tag match {
@@ -464,7 +464,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
464464
} // end of trait BCAnnotGen
465465

466466
trait BCJGenSigGen {
467-
import int._
467+
import int.{_, given _}
468468

469469
def getCurrentCUnit(): CompilationUnit
470470

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ trait BCodeIdiomatic {
1919
val int: DottyBackendInterface
2020
final lazy val bTypes = new BTypesFromSymbols[int.type](int)
2121

22-
import int._
22+
import int.{_, given _}
2323
import bTypes._
2424
import coreBTypes._
2525

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import dotty.tools.dotc.util.Spans._
2626
*
2727
*/
2828
trait BCodeSkelBuilder extends BCodeHelpers {
29-
import int._
29+
import int.{_, given _}
3030
import DottyBackendInterface.{symExtensions, _}
3131
import tpd._
3232
import bTypes._

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import dotty.tools.dotc.ast.tpd.TreeOps
1818
*
1919
*/
2020
trait BCodeSyncAndTry extends BCodeBodyBuilder {
21-
import int._
21+
import int.{_, given _}
2222
import tpd._
2323
import bTypes._
2424
import coreBTypes._

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import scala.tools.asm
1515
abstract class BTypes {
1616

1717
val int: DottyBackendInterface
18-
import int._
18+
import int.{_, given _}
1919
/**
2020
* A map from internal names to ClassBTypes. Every ClassBType is added to this map on its
2121
* construction.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import dotty.tools.dotc.util.WeakHashSet
2727
* not have access to the compiler instance.
2828
*/
2929
class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
30-
import int._
30+
import int.{_, given _}
3131
import DottyBackendInterface.{symExtensions, _}
3232

3333
lazy val TransientAttr = requiredClass[scala.transient]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class FileConflictException(msg: String, val file: AbstractFile) extends IOExcep
1616
*/
1717
trait BytecodeWriters {
1818
val int: DottyBackendInterface
19-
import int._
19+
import int.{_, given _}
2020

2121
/**
2222
* @param clsName cls.getName

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import dotty.tools.dotc.transform.Erasure
3333
*/
3434
class CoreBTypes[BTFS <: BTypesFromSymbols[_ <: DottyBackendInterface]](val bTypes: BTFS) {
3535
import bTypes._
36-
import int._
36+
import int.{_, given _}
3737
import DottyBackendInterface._
3838

3939
//import global._

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import Names.TermName
3434
import Annotations.Annotation
3535
import Names.Name
3636

37-
class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap: Map[Symbol, Set[ClassSymbol]])(implicit val ctx: Context) {
37+
class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap: Map[Symbol, Set[ClassSymbol]])(using val ctx: Context) {
3838

3939
private val desugared = new java.util.IdentityHashMap[Type, tpd.Select]
4040

@@ -107,10 +107,10 @@ object DottyBackendInterface {
107107
else clazz.getName
108108
}
109109

110-
def requiredClass[T](implicit evidence: ClassTag[T], ctx: Context): Symbol =
110+
def requiredClass[T](using evidence: ClassTag[T], ctx: Context): Symbol =
111111
ctx.requiredClass(erasureString(evidence.runtimeClass))
112112

113-
def requiredModule[T](implicit evidence: ClassTag[T], ctx: Context): Symbol = {
113+
def requiredModule[T](using evidence: ClassTag[T], ctx: Context): Symbol = {
114114
val moduleName = erasureString(evidence.runtimeClass)
115115
val className = if (moduleName.endsWith("$")) moduleName.dropRight(1) else moduleName
116116
ctx.requiredModule(className)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class GenBCode extends Phase {
4848

4949
def run(implicit ctx: Context): Unit = {
5050
new GenBCodePipeline(new DottyBackendInterface(
51-
outputDir, superCallsMap.toMap)(ctx))(ctx).run(ctx.compilationUnit.tpdTree)
51+
outputDir, superCallsMap.toMap)(using ctx))(using ctx).run(ctx.compilationUnit.tpdTree)
5252
}
5353

5454
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
@@ -69,7 +69,7 @@ object GenBCode {
6969
val name: String = "genBCode"
7070
}
7171

72-
class GenBCodePipeline(val int: DottyBackendInterface)(implicit ctx: Context) extends BCodeSyncAndTry {
72+
class GenBCodePipeline(val int: DottyBackendInterface)(using ctx: Context) extends BCodeSyncAndTry {
7373
import DottyBackendInterface.symExtensions
7474

7575
private var tree: Tree = _

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ class Driver {
155155
*/
156156
final def process(args: Array[String], reporter: Reporter = null,
157157
callback: interfaces.CompilerCallback = null): Reporter = {
158-
val ctx = initCtx.fresh
158+
val compileCtx = initCtx.fresh
159159
if (reporter != null)
160-
ctx.setReporter(reporter)
160+
compileCtx.setReporter(reporter)
161161
if (callback != null)
162-
ctx.setCompilerCallback(callback)
163-
process(args, ctx)
162+
compileCtx.setCompilerCallback(callback)
163+
process(args, compileCtx)
164164
}
165165

166166
/** Entry point to the compiler with no optional arguments.
@@ -190,8 +190,8 @@ class Driver {
190190
* if compilation succeeded.
191191
*/
192192
def process(args: Array[String], rootCtx: Context): Reporter = {
193-
val (fileNames, ctx) = setup(args, rootCtx)
194-
doCompile(newCompiler(ctx), fileNames)(ctx)
193+
val (fileNames, compileCtx) = setup(args, rootCtx)
194+
doCompile(newCompiler(compileCtx), fileNames)(compileCtx)
195195
}
196196

197197
def main(args: Array[String]): Unit = {

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

-105
This file was deleted.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
847847
traverser.traverse(tree)
848848
tree
849849
}
850-
else changeOwnerAfter(from, to, trans)(ctx.withPhase(trans.next))
850+
else changeOwnerAfter(from, to, trans)(using ctx.withPhase(trans.next))
851851

852852
/** A select node with the given selector name and a computed type */
853853
def select(name: Name)(implicit ctx: Context): Select =

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotc
33
package core
44

55
import SymDenotations.{ SymDenotation, ClassDenotation, NoDenotation, LazyType }
6-
import Contexts.{Context, Ctx, ctx, ContextBase}
6+
import Contexts.{Context, ctx, ContextBase}
77
import Names._
88
import NameKinds._
99
import StdNames._
@@ -797,7 +797,7 @@ object Denotations {
797797
val transformer = ctx.base.denotTransformers(nextTransformerId)
798798
//println(s"transforming $this with $transformer")
799799
try
800-
next = transformer.transform(cur)(ctx.withPhase(transformer))
800+
next = transformer.transform(cur)(using ctx.withPhase(transformer))
801801
catch {
802802
case ex: CyclicReference =>
803803
println(s"error while transforming $this") // DEBUG

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -4919,7 +4919,8 @@ object Types {
49194919
def mapOver(tp: Type): Type = {
49204920
record(s"mapOver ${getClass}")
49214921
record("mapOver total")
4922-
implicit val ctx = this.mapCtx
4922+
val ctx = this.mapCtx // optimization for performance
4923+
given Context = ctx
49234924
tp match {
49244925
case tp: NamedType =>
49254926
if stopBecauseStaticOrLocal(tp) then tp

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ class ClassfileParser(
939939
val outerName = entry.outerName.stripModuleClassSuffix
940940
val innerName = entry.originalName
941941
val owner = classNameToSymbol(outerName)
942-
val result = getMember(owner, innerName.toTypeName)(ctx.withPhase(ctx.typerPhase))
942+
val result = getMember(owner, innerName.toTypeName)(using ctx.withPhase(ctx.typerPhase))
943943
assert(result ne NoSymbol,
944944
i"""failure to resolve inner class:
945945
|externalName = ${entry.externalName},

compiler/src/dotty/tools/dotc/decompiler/IDEDecompilerDriver.scala

+9-9
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ class IDEDecompilerDriver(val settings: List[String]) extends dotc.Driver {
2929

3030
val run = decompiler.newRun(myInitCtx.fresh.setReporter(reporter))
3131

32-
implicit val ctx = run.runContext
32+
inContext(run.runContext) {
33+
run.compile(List(className))
34+
run.printSummary()
35+
val unit = ctx.run.units.head
3336

34-
run.compile(List(className))
35-
run.printSummary()
36-
val unit = ctx.run.units.head
37+
val decompiled = ReflectionImpl.showTree(unit.tpdTree)
38+
val tree = new TastyHTMLPrinter(unit.pickled.head._2).printContents()
3739

38-
val decompiled = ReflectionImpl.showTree(unit.tpdTree)
39-
val tree = new TastyHTMLPrinter(unit.pickled.head._2).printContents()
40-
41-
reporter.removeBufferedMessages.foreach(message => System.err.println(message))
42-
(tree, decompiled)
40+
reporter.removeBufferedMessages.foreach(message => System.err.println(message))
41+
(tree, decompiled)
42+
}
4343
}
4444
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
7676

7777
override def prepareForUnit(tree: Tree)(implicit ctx: Context): Context = {
7878
val captured = (new CollectCaptured)
79-
.runOver(ctx.compilationUnit.tpdTree)(ctx.withPhase(thisPhase))
79+
.runOver(ctx.compilationUnit.tpdTree)(using ctx.withPhase(thisPhase))
8080
ctx.fresh.updateStore(Captured, captured)
8181
}
8282

@@ -91,7 +91,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
9191
}
9292

9393
override def prepareForValDef(vdef: ValDef)(implicit ctx: Context): Context = {
94-
val sym = vdef.symbol(ctx.withPhase(thisPhase))
94+
val sym = vdef.symbol(using ctx.withPhase(thisPhase))
9595
if (captured contains sym) {
9696
val newd = sym.denot(using ctx.withPhase(thisPhase)).copySymDenotation(
9797
info = refClass(sym.info.classSymbol, sym.hasAnnotation(defn.VolatileAnnot)).typeRef,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class ElimErasedValueType extends MiniPhase with InfoTransformer { thisPhase =>
7878
* this phase, yet do not have matching types before erasure.
7979
*/
8080
private def checkNoClashes(root: Symbol)(implicit ctx: Context) = {
81-
val opc = new OverridingPairs.Cursor(root)(ctx.withPhase(thisPhase)) {
81+
val opc = new OverridingPairs.Cursor(root)(using ctx.withPhase(thisPhase)) {
8282
override def exclude(sym: Symbol) =
8383
!sym.is(Method) || sym.is(Bridge) || super.exclude(sym)
8484
override def matches(sym1: Symbol, sym2: Symbol) =

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ object ExplicitOuter {
347347
*/
348348
class OuterOps(val ictx: Context) extends AnyVal {
349349
/** The context of all operations of this class */
350-
private implicit def ctx: Context = ictx
350+
given Context = ictx
351351

352352
/** If `cls` has an outer parameter add one to the method type `tp`. */
353353
def addParam(cls: ClassSymbol, tp: Type): Type =

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase =>
129129
}
130130

131131
override def transformStats(trees: List[Tree])(implicit ctx: Context): List[Tree] =
132-
ast.Trees.flatten(reorderAndComplete(trees)(ctx.withPhase(thisPhase.next)))
132+
ast.Trees.flatten(reorderAndComplete(trees)(using ctx.withPhase(thisPhase.next)))
133133

134134
private object collectBinders extends TreeAccumulator[List[Ident]] {
135135
def apply(annots: List[Ident], t: Tree)(implicit ctx: Context): List[Ident] = t match {

0 commit comments

Comments
 (0)