Skip to content

Change implicit to using #9333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 41 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d8cd2bb
Convert to using clauses
odersky Jul 9, 2020
717bce7
Convert Symbols to using clauses
odersky Jul 8, 2020
7330e7f
Convert Denotations to using clauses
odersky Jul 8, 2020
86ae3ca
Remove implicit definitions of `ctx` that are not parameters
odersky Jul 9, 2020
1d8cb7c
Change Printers to givens
odersky Jul 9, 2020
9d52399
Change Printers to givens
odersky Jul 9, 2020
d1f2a11
Remove implicit definitions of `ctx` that are not parameters (2)
odersky Jul 9, 2020
017a578
Convert to givens in TypeComparer
odersky Jul 9, 2020
f16fec0
Convert core classes (1)
odersky Jul 9, 2020
0c0d896
Convert core classes (2)
odersky Jul 9, 2020
114e0d2
Convert core classes (3)
odersky Jul 9, 2020
23b19e8
Convert core classes (4)
odersky Jul 9, 2020
50144f4
Convert core classes (5)
odersky Jul 9, 2020
adc75a0
Convert core classes (6)
odersky Jul 9, 2020
a66f8f3
Convert tasty and unpickler classes
odersky Jul 9, 2020
f76b9b6
Convert ast classes
odersky Jul 9, 2020
b935477
Convert config classes
odersky Jul 9, 2020
2ab9a58
Convert parser classes
odersky Jul 9, 2020
e71a167
Convert interactive classes
odersky Jul 9, 2020
f5c30a9
Convert reporting classes
odersky Jul 9, 2020
1ae90ec
Convert transform classes (1)
odersky Jul 9, 2020
7366f5c
Convert transform classes (2)
odersky Jul 9, 2020
1798e29
Convert transform classes (3)
odersky Jul 9, 2020
ce9aa2d
Convert transform classes (4)
odersky Jul 9, 2020
edb4869
Convert other dotc classes (1)
odersky Jul 9, 2020
68e1fea
Convert other dotc classes (2)
odersky Jul 9, 2020
4dc0b9b
Fixes
odersky Jul 10, 2020
d84abfe
Convert tools classes
odersky Jul 9, 2020
682ef6a
Convert repl classes
odersky Jul 10, 2020
6e54aed
Convert test classes (1)
odersky Jul 10, 2020
f71a4b3
Convert test classes (2)
odersky Jul 10, 2020
b76d2e4
Make Contexts.ctx an inline function
odersky Jul 10, 2020
a9c405f
Omit redundant (using ctx)
odersky Jul 10, 2020
f3e03fc
Move atPhase and friends to Contexts
odersky Jul 10, 2020
0ece69a
Use atPhase instead of inContext where possible
odersky Jul 10, 2020
da6829b
Rename Context#phases -> Phases.curPhases
odersky Jul 10, 2020
cd9f05d
Move individual phases to Phases
odersky Jul 10, 2020
165b7d8
Use atPhase instead of passing ctx.withPhase
odersky Jul 10, 2020
5442a4f
Use atPhase for ContextFunctionResults
odersky Jul 10, 2020
1236d8c
Convert remaining instance to atPhase
odersky Jul 10, 2020
159486a
Move plugins to ContextBase
odersky Jul 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/BCodeAsmCommon.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import dotty.tools.dotc.core.Symbols._
* the compiler cake (Global).
*/
final class BCodeAsmCommon[I <: DottyBackendInterface](val interface: I) {
import interface._
import interface.{_, given _}
import DottyBackendInterface.symExtensions

/**
Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.transform.Erasure
import dotty.tools.dotc.transform.SymUtils._
import dotty.tools.dotc.util.Spans._
import dotty.tools.dotc.core.Contexts.{inContext, atPhase}
import dotty.tools.dotc.core.Phases._

/*
*
Expand All @@ -30,7 +32,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
// import global._
// import definitions._
import tpd._
import int._
import int.{_, given _}
import DottyBackendInterface.symExtensions
import bTypes._
import coreBTypes._
Expand Down Expand Up @@ -1460,7 +1462,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
// TODO specialization
val constrainedType = new MethodBType(lambdaParamTypes.map(p => toTypeKind(p)), toTypeKind(lambdaTarget.info.resultType)).toASMType

val abstractMethod = ctx.atPhase(ctx.erasurePhase) {
val abstractMethod = atPhase(erasurePhase) {
val samMethods = toDenot(functionalInterface).info.possibleSamMethods.toList
samMethods match {
case x :: Nil => x.symbol
Expand Down
17 changes: 9 additions & 8 deletions compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.ast.Trees
import dotty.tools.dotc.core.Annotations._
import dotty.tools.dotc.core.Constants._
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Contexts.{Context, atPhase}
import dotty.tools.dotc.core.Phases._
import dotty.tools.dotc.core.Decorators._
import dotty.tools.dotc.core.Flags._
import dotty.tools.dotc.core.Names.Name
Expand Down Expand Up @@ -45,7 +46,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
import bTypes._
import tpd._
import coreBTypes._
import int._
import int.{_, given _}
import DottyBackendInterface._

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

trait BCJGenSigGen {
import int._
import int.{_, given _}

def getCurrentCUnit(): CompilationUnit

Expand All @@ -478,7 +479,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
* @see https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.4
*/
def getGenericSignature(sym: Symbol, owner: Symbol): String = {
ctx.atPhase(ctx.erasurePhase) {
atPhase(erasurePhase) {
val memberTpe =
if (sym.is(Method)) sym.denot.info
else owner.denot.thisType.memberInfo(sym)
Expand Down Expand Up @@ -844,7 +845,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
}
}

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

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

val memberTpe = ctx.atPhase(ctx.erasurePhase) { moduleClass.denot.thisType.memberInfo(sym) }
val memberTpe = atPhase(erasurePhase) { moduleClass.denot.thisType.memberInfo(sym) }
val erasedMemberType = TypeErasure.erasure(memberTpe)
if (erasedMemberType =:= sym.denot.info)
getGenericSignatureHelper(sym, moduleClass, memberTpe).orNull
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/BCodeIdiomatic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ trait BCodeIdiomatic {
val int: DottyBackendInterface
final lazy val bTypes = new BTypesFromSymbols[int.type](int)

import int._
import int.{_, given _}
import bTypes._
import coreBTypes._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import dotty.tools.dotc.util.Spans._
*
*/
trait BCodeSkelBuilder extends BCodeHelpers {
import int._
import int.{_, given _}
import DottyBackendInterface.{symExtensions, _}
import tpd._
import bTypes._
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/BCodeSyncAndTry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import dotty.tools.dotc.ast.tpd.TreeOps
*
*/
trait BCodeSyncAndTry extends BCodeBodyBuilder {
import int._
import int.{_, given _}
import tpd._
import bTypes._
import coreBTypes._
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/BTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import scala.tools.asm
abstract class BTypes {

val int: DottyBackendInterface
import int._
import int.{_, given _}
/**
* A map from internal names to ClassBTypes. Every ClassBType is added to this map on its
* construction.
Expand Down
19 changes: 11 additions & 8 deletions compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import scala.collection.mutable
import scala.collection.generic.Clearable

import dotty.tools.dotc.core.Flags._
import dotty.tools.dotc.core.Contexts.{inContext, atPhase}
import dotty.tools.dotc.core.Phases._
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.core.Phases.Phase
import dotty.tools.dotc.transform.SymUtils._
Expand All @@ -26,7 +28,7 @@ import dotty.tools.dotc.util.WeakHashSet
* not have access to the compiler instance.
*/
class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
import int._
import int.{_, given _}
import DottyBackendInterface.{symExtensions, _}

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

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

private def definedClasses(sym: Symbol, phase: Phase) =
if (sym.isDefinedInCurrentRun)
ctx.atPhase(phase) {
atPhase(phase) {
toDenot(sym).info.decls.filter(_.isClass)
}
else Nil
Expand All @@ -228,10 +230,11 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
// After lambdalift (which is where we are), the rawowoner field contains the enclosing class.
val enclosingClassSym = {
if (innerClassSym.isClass) {
val ct = ctx.withPhase(ctx.flattenPhase.prev)
toDenot(innerClassSym)(ct).owner.enclosingClass(ct)
atPhase(flattenPhase.prev) {
toDenot(innerClassSym).owner.enclosingClass
}
}
else innerClassSym.enclosingClass(ctx.withPhase(ctx.flattenPhase.prev))
else atPhase(flattenPhase.prev)(innerClassSym.enclosingClass)
} //todo is handled specially for JavaDefined symbols in scalac

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

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/BytecodeWriters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FileConflictException(msg: String, val file: AbstractFile) extends IOExcep
*/
trait BytecodeWriters {
val int: DottyBackendInterface
import int._
import int.{_, given _}

/**
* @param clsName cls.getName
Expand Down
9 changes: 5 additions & 4 deletions compiler/src/dotty/tools/backend/jvm/CollectSuperCalls.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package dotty.tools.backend.jvm

import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Contexts.{Context, ctx}
import dotty.tools.dotc.core.Phases._
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.core.Flags.Trait
import dotty.tools.dotc.transform.MegaPhase.MiniPhase
Expand All @@ -21,7 +22,7 @@ class CollectSuperCalls extends MiniPhase {

def phaseName: String = "collectSuperCalls"

override def transformSelect(tree: Select)(implicit ctx: Context): Tree = {
override def transformSelect(tree: Select)(using Context): Tree = {
tree.qualifier match {
case sup: Super =>
if (tree.symbol.owner.is(Trait))
Expand All @@ -31,8 +32,8 @@ class CollectSuperCalls extends MiniPhase {
tree
}

private def registerSuperCall(sym: ClassSymbol, calls: ClassSymbol)(implicit ctx: Context) = {
ctx.genBCodePhase match {
private def registerSuperCall(sym: ClassSymbol, calls: ClassSymbol)(using Context) = {
genBCodePhase match {
case genBCodePhase: GenBCode =>
genBCodePhase.registerSuperCall(sym, calls)
case _ =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/CoreBTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import dotty.tools.dotc.transform.Erasure
*/
class CoreBTypes[BTFS <: BTypesFromSymbols[_ <: DottyBackendInterface]](val bTypes: BTFS) {
import bTypes._
import int._
import int.{_, given _}
import DottyBackendInterface._

//import global._
Expand Down
18 changes: 10 additions & 8 deletions compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Names.TermName
import Annotations.Annotation
import Names.Name

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

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

Expand Down Expand Up @@ -107,10 +107,10 @@ object DottyBackendInterface {
else clazz.getName
}

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

def requiredModule[T](implicit evidence: ClassTag[T], ctx: Context): Symbol = {
def requiredModule[T](using evidence: ClassTag[T], ctx: Context): Symbol = {
val moduleName = erasureString(evidence.runtimeClass)
val className = if (moduleName.endsWith("$")) moduleName.dropRight(1) else moduleName
ctx.requiredModule(className)
Expand All @@ -137,8 +137,9 @@ object DottyBackendInterface {
// for example by specialization
val original = toDenot(sym).initial
val validity = original.validFor
val shiftedContext = ctx.withPhase(validity.phaseId)
toDenot(sym)(shiftedContext).isStatic(shiftedContext)
atPhase(validity.phaseId) {
toDenot(sym).isStatic
}
}


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

/**
Expand All @@ -158,7 +160,7 @@ object DottyBackendInterface {
*/
def isTopLevelModuleClass(using Context): Boolean =
sym.is(ModuleClass) &&
ctx.atPhase(ctx.flattenPhase) {
atPhase(flattenPhase) {
toDenot(sym).owner.is(PackageClass)
}

Expand Down
22 changes: 13 additions & 9 deletions compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import java.util.Optional
import dotty.tools.dotc.core._
import dotty.tools.dotc.sbt.ExtractDependencies
import Contexts._
import Phases._
import Symbols._
import Decorators._

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

private var myOutput: AbstractFile = _

private def outputDir(implicit ctx: Context): AbstractFile = {
private def outputDir(using Context): AbstractFile = {
if (myOutput eq null)
myOutput = ctx.settings.outputDir.value
myOutput
}

def run(implicit ctx: Context): Unit = {
new GenBCodePipeline(new DottyBackendInterface(
outputDir, superCallsMap.toMap)(ctx))(ctx).run(ctx.compilationUnit.tpdTree)
}
def run(using Context): Unit =
new GenBCodePipeline(
new DottyBackendInterface(
outputDir, superCallsMap.toMap
)
).run(ctx.compilationUnit.tpdTree)


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

class GenBCodePipeline(val int: DottyBackendInterface)(implicit ctx: Context) extends BCodeSyncAndTry {
class GenBCodePipeline(val int: DottyBackendInterface)(using ctx: Context) extends BCodeSyncAndTry {
import DottyBackendInterface.symExtensions

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

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

val (fullClassName, isLocal) = ctx.atPhase(ctx.sbtExtractDependenciesPhase) {
val (fullClassName, isLocal) = atPhase(sbtExtractDependenciesPhase) {
(ExtractDependencies.classNameAsString(claszSymbol), claszSymbol.isLocal)
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/backend/sjs/GenSJSIR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import Phases._
class GenSJSIR extends Phase {
def phaseName: String = "genSJSIR"

override def isRunnable(implicit ctx: Context): Boolean =
override def isRunnable(using Context): Boolean =
super.isRunnable && ctx.settings.scalajs.value

def run(implicit ctx: Context): Unit =
def run(using Context): Unit =
new JSCodeGen().run()
}
Loading