Skip to content

Commit aa64078

Browse files
authored
Merge pull request #9333 from dotty-staging/change-using
Change implicit to using
2 parents e6bb414 + 159486a commit aa64078

File tree

323 files changed

+3976
-5983
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

323 files changed

+3976
-5983
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

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import dotty.tools.dotc.core.Symbols._
1919
import dotty.tools.dotc.transform.Erasure
2020
import dotty.tools.dotc.transform.SymUtils._
2121
import dotty.tools.dotc.util.Spans._
22+
import dotty.tools.dotc.core.Contexts.{inContext, atPhase}
23+
import dotty.tools.dotc.core.Phases._
2224

2325
/*
2426
*
@@ -30,7 +32,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
3032
// import global._
3133
// import definitions._
3234
import tpd._
33-
import int._
35+
import int.{_, given _}
3436
import DottyBackendInterface.symExtensions
3537
import bTypes._
3638
import coreBTypes._
@@ -1460,7 +1462,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
14601462
// TODO specialization
14611463
val constrainedType = new MethodBType(lambdaParamTypes.map(p => toTypeKind(p)), toTypeKind(lambdaTarget.info.resultType)).toASMType
14621464

1463-
val abstractMethod = ctx.atPhase(ctx.erasurePhase) {
1465+
val abstractMethod = atPhase(erasurePhase) {
14641466
val samMethods = toDenot(functionalInterface).info.possibleSamMethods.toList
14651467
samMethods match {
14661468
case x :: Nil => x.symbol

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import dotty.tools.dotc.ast.tpd
1313
import dotty.tools.dotc.ast.Trees
1414
import dotty.tools.dotc.core.Annotations._
1515
import dotty.tools.dotc.core.Constants._
16-
import dotty.tools.dotc.core.Contexts.Context
16+
import dotty.tools.dotc.core.Contexts.{Context, atPhase}
17+
import dotty.tools.dotc.core.Phases._
1718
import dotty.tools.dotc.core.Decorators._
1819
import dotty.tools.dotc.core.Flags._
1920
import dotty.tools.dotc.core.Names.Name
@@ -45,7 +46,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
4546
import bTypes._
4647
import tpd._
4748
import coreBTypes._
48-
import int._
49+
import int.{_, given _}
4950
import DottyBackendInterface._
5051

5152
def ScalaATTRName: String = "Scala"
@@ -360,7 +361,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
360361
val narg = normalizeArgument(arg)
361362
// Transformation phases are not run on annotation trees, so we need to run
362363
// `constToLiteral` at this point.
363-
val t = constToLiteral(narg)(ctx.withPhase(ctx.erasurePhase))
364+
val t = atPhase(erasurePhase)(constToLiteral(narg))
364365
t match {
365366
case Literal(const @ Constant(_)) =>
366367
const.tag match {
@@ -464,7 +465,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
464465
} // end of trait BCAnnotGen
465466

466467
trait BCJGenSigGen {
467-
import int._
468+
import int.{_, given _}
468469

469470
def getCurrentCUnit(): CompilationUnit
470471

@@ -478,7 +479,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
478479
* @see https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.4
479480
*/
480481
def getGenericSignature(sym: Symbol, owner: Symbol): String = {
481-
ctx.atPhase(ctx.erasurePhase) {
482+
atPhase(erasurePhase) {
482483
val memberTpe =
483484
if (sym.is(Method)) sym.denot.info
484485
else owner.denot.thisType.memberInfo(sym)
@@ -844,7 +845,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
844845
}
845846
}
846847

847-
private def getGenericSignatureHelper(sym: Symbol, owner: Symbol, memberTpe: Type)(implicit ctx: Context): Option[String] = {
848+
private def getGenericSignatureHelper(sym: Symbol, owner: Symbol, memberTpe: Type)(using Context): Option[String] = {
848849
if (needsGenericSignature(sym)) {
849850
val erasedTypeSym = TypeErasure.fullErasure(sym.denot.info).typeSymbol
850851
if (erasedTypeSym.isPrimitiveValueClass) {
@@ -864,7 +865,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
864865
}
865866
}
866867

867-
private def verifySignature(sym: Symbol, sig: String)(implicit ctx: Context): Unit = {
868+
private def verifySignature(sym: Symbol, sig: String)(using Context): Unit = {
868869
import scala.tools.asm.util.CheckClassAdapter
869870
def wrap(body: => Unit): Unit = {
870871
try body
@@ -913,7 +914,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
913914
// But for now, just like we did in mixin, we just avoid writing a wrong generic signature
914915
// (one that doesn't erase to the actual signature). See run/t3452b for a test case.
915916

916-
val memberTpe = ctx.atPhase(ctx.erasurePhase) { moduleClass.denot.thisType.memberInfo(sym) }
917+
val memberTpe = atPhase(erasurePhase) { moduleClass.denot.thisType.memberInfo(sym) }
917918
val erasedMemberType = TypeErasure.erasure(memberTpe)
918919
if (erasedMemberType =:= sym.denot.info)
919920
getGenericSignatureHelper(sym, moduleClass, memberTpe).orNull

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

+11-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import scala.collection.mutable
88
import scala.collection.generic.Clearable
99

1010
import dotty.tools.dotc.core.Flags._
11+
import dotty.tools.dotc.core.Contexts.{inContext, atPhase}
12+
import dotty.tools.dotc.core.Phases._
1113
import dotty.tools.dotc.core.Symbols._
1214
import dotty.tools.dotc.core.Phases.Phase
1315
import dotty.tools.dotc.transform.SymUtils._
@@ -26,7 +28,7 @@ import dotty.tools.dotc.util.WeakHashSet
2628
* not have access to the compiler instance.
2729
*/
2830
class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
29-
import int._
31+
import int.{_, given _}
3032
import DottyBackendInterface.{symExtensions, _}
3133

3234
lazy val TransientAttr = requiredClass[scala.transient]
@@ -202,16 +204,16 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
202204
/** For currently compiled classes: All locally defined classes including local classes.
203205
* The empty list for classes that are not currently compiled.
204206
*/
205-
private def getNestedClasses(sym: Symbol): List[Symbol] = definedClasses(sym, ctx.flattenPhase)
207+
private def getNestedClasses(sym: Symbol): List[Symbol] = definedClasses(sym, flattenPhase)
206208

207209
/** For currently compiled classes: All classes that are declared as members of this class
208210
* (but not inherited ones). The empty list for classes that are not currently compiled.
209211
*/
210-
private def getMemberClasses(sym: Symbol): List[Symbol] = definedClasses(sym, ctx.lambdaLiftPhase)
212+
private def getMemberClasses(sym: Symbol): List[Symbol] = definedClasses(sym, lambdaLiftPhase)
211213

212214
private def definedClasses(sym: Symbol, phase: Phase) =
213215
if (sym.isDefinedInCurrentRun)
214-
ctx.atPhase(phase) {
216+
atPhase(phase) {
215217
toDenot(sym).info.decls.filter(_.isClass)
216218
}
217219
else Nil
@@ -228,10 +230,11 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
228230
// After lambdalift (which is where we are), the rawowoner field contains the enclosing class.
229231
val enclosingClassSym = {
230232
if (innerClassSym.isClass) {
231-
val ct = ctx.withPhase(ctx.flattenPhase.prev)
232-
toDenot(innerClassSym)(ct).owner.enclosingClass(ct)
233+
atPhase(flattenPhase.prev) {
234+
toDenot(innerClassSym).owner.enclosingClass
235+
}
233236
}
234-
else innerClassSym.enclosingClass(ctx.withPhase(ctx.flattenPhase.prev))
237+
else atPhase(flattenPhase.prev)(innerClassSym.enclosingClass)
235238
} //todo is handled specially for JavaDefined symbols in scalac
236239

237240
val enclosingClass: ClassBType = classBTypeFromSymbol(enclosingClassSym)
@@ -255,7 +258,7 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
255258
if (innerClassSym.isAnonymousClass || innerClassSym.isAnonymousFunction) None
256259
else {
257260
val original = innerClassSym.initial
258-
Some(innerClassSym.name(ctx.withPhase(original.validFor.phaseId)).mangledString) // moduleSuffix for module classes
261+
Some(atPhase(original.validFor.phaseId)(innerClassSym.name).mangledString) // moduleSuffix for module classes
259262
}
260263
}
261264

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/CollectSuperCalls.scala

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package dotty.tools.backend.jvm
22

33
import dotty.tools.dotc.ast.tpd
4-
import dotty.tools.dotc.core.Contexts.Context
4+
import dotty.tools.dotc.core.Contexts.{Context, ctx}
5+
import dotty.tools.dotc.core.Phases._
56
import dotty.tools.dotc.core.Symbols._
67
import dotty.tools.dotc.core.Flags.Trait
78
import dotty.tools.dotc.transform.MegaPhase.MiniPhase
@@ -21,7 +22,7 @@ class CollectSuperCalls extends MiniPhase {
2122

2223
def phaseName: String = "collectSuperCalls"
2324

24-
override def transformSelect(tree: Select)(implicit ctx: Context): Tree = {
25+
override def transformSelect(tree: Select)(using Context): Tree = {
2526
tree.qualifier match {
2627
case sup: Super =>
2728
if (tree.symbol.owner.is(Trait))
@@ -31,8 +32,8 @@ class CollectSuperCalls extends MiniPhase {
3132
tree
3233
}
3334

34-
private def registerSuperCall(sym: ClassSymbol, calls: ClassSymbol)(implicit ctx: Context) = {
35-
ctx.genBCodePhase match {
35+
private def registerSuperCall(sym: ClassSymbol, calls: ClassSymbol)(using Context) = {
36+
genBCodePhase match {
3637
case genBCodePhase: GenBCode =>
3738
genBCodePhase.registerSuperCall(sym, calls)
3839
case _ =>

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

+10-8
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)
@@ -137,8 +137,9 @@ object DottyBackendInterface {
137137
// for example by specialization
138138
val original = toDenot(sym).initial
139139
val validity = original.validFor
140-
val shiftedContext = ctx.withPhase(validity.phaseId)
141-
toDenot(sym)(shiftedContext).isStatic(shiftedContext)
140+
atPhase(validity.phaseId) {
141+
toDenot(sym).isStatic
142+
}
142143
}
143144

144145

@@ -148,8 +149,9 @@ object DottyBackendInterface {
148149
// it is very tricky in presence of classes(and annonymous classes) defined inside supper calls.
149150
if (sym.exists) {
150151
val validity = toDenot(sym).initial.validFor
151-
val shiftedContext = ctx.withPhase(validity.phaseId)
152-
toDenot(sym)(shiftedContext).lexicallyEnclosingClass(shiftedContext)
152+
atPhase(validity.phaseId) {
153+
toDenot(sym).lexicallyEnclosingClass
154+
}
153155
} else NoSymbol
154156

155157
/**
@@ -158,7 +160,7 @@ object DottyBackendInterface {
158160
*/
159161
def isTopLevelModuleClass(using Context): Boolean =
160162
sym.is(ModuleClass) &&
161-
ctx.atPhase(ctx.flattenPhase) {
163+
atPhase(flattenPhase) {
162164
toDenot(sym).owner.is(PackageClass)
163165
}
164166

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

+13-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import java.util.Optional
1515
import dotty.tools.dotc.core._
1616
import dotty.tools.dotc.sbt.ExtractDependencies
1717
import Contexts._
18+
import Phases._
1819
import Symbols._
1920
import Decorators._
2021

@@ -40,18 +41,21 @@ class GenBCode extends Phase {
4041

4142
private var myOutput: AbstractFile = _
4243

43-
private def outputDir(implicit ctx: Context): AbstractFile = {
44+
private def outputDir(using Context): AbstractFile = {
4445
if (myOutput eq null)
4546
myOutput = ctx.settings.outputDir.value
4647
myOutput
4748
}
4849

49-
def run(implicit ctx: Context): Unit = {
50-
new GenBCodePipeline(new DottyBackendInterface(
51-
outputDir, superCallsMap.toMap)(ctx))(ctx).run(ctx.compilationUnit.tpdTree)
52-
}
50+
def run(using Context): Unit =
51+
new GenBCodePipeline(
52+
new DottyBackendInterface(
53+
outputDir, superCallsMap.toMap
54+
)
55+
).run(ctx.compilationUnit.tpdTree)
56+
5357

54-
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
58+
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] = {
5559
try super.runOn(units)
5660
finally myOutput match {
5761
case jar: JarArchive =>
@@ -69,7 +73,7 @@ object GenBCode {
6973
val name: String = "genBCode"
7074
}
7175

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

7579
private var tree: Tree = _
@@ -163,7 +167,7 @@ class GenBCodePipeline(val int: DottyBackendInterface)(implicit ctx: Context) ex
163167
if (classSymbol.effectiveName.toString < dupClassSym.effectiveName.toString) (classSymbol, dupClassSym)
164168
else (dupClassSym, classSymbol)
165169
val same = classSymbol.effectiveName.toString == dupClassSym.effectiveName.toString
166-
ctx.atPhase(ctx.typerPhase) {
170+
atPhase(typerPhase) {
167171
if (same)
168172
summon[Context].warning( // FIXME: This should really be an error, but then FromTasty tests fail
169173
s"${cl1.show} and ${cl2.showLocated} produce classes that overwrite one another", cl1.sourcePos)
@@ -268,7 +272,7 @@ class GenBCodePipeline(val int: DottyBackendInterface)(implicit ctx: Context) ex
268272

269273
// ----------- compiler and sbt's callbacks
270274

271-
val (fullClassName, isLocal) = ctx.atPhase(ctx.sbtExtractDependenciesPhase) {
275+
val (fullClassName, isLocal) = atPhase(sbtExtractDependenciesPhase) {
272276
(ExtractDependencies.classNameAsString(claszSymbol), claszSymbol.isLocal)
273277
}
274278

compiler/src/dotty/tools/backend/sjs/GenSJSIR.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import Phases._
88
class GenSJSIR extends Phase {
99
def phaseName: String = "genSJSIR"
1010

11-
override def isRunnable(implicit ctx: Context): Boolean =
11+
override def isRunnable(using Context): Boolean =
1212
super.isRunnable && ctx.settings.scalajs.value
1313

14-
def run(implicit ctx: Context): Unit =
14+
def run(using Context): Unit =
1515
new JSCodeGen().run()
1616
}

0 commit comments

Comments
 (0)