Skip to content

Commit 1ae90ec

Browse files
committed
Convert transform classes (1)
1 parent f5c30a9 commit 1ae90ec

37 files changed

+200
-200
lines changed

compiler/src/dotty/tools/dotc/rewrites/Rewrites.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ object Rewrites {
6363
/** If -rewrite is set, record a patch that replaces the range
6464
* given by `span` in `source` by `replacement`
6565
*/
66-
def patch(source: SourceFile, span: Span, replacement: String)(implicit ctx: Context): Unit =
66+
def patch(source: SourceFile, span: Span, replacement: String)(using Context): Unit =
6767
if (ctx.reporter != Reporter.NoReporter) // NoReporter is used for syntax highlighting
6868
for (rewrites <- ctx.settings.rewrite.value)
6969
rewrites.patched
7070
.getOrElseUpdate(source, new Patches(source))
7171
.addPatch(span, replacement)
7272

7373
/** Patch position in `ctx.compilationUnit.source`. */
74-
def patch(span: Span, replacement: String)(implicit ctx: Context): Unit =
74+
def patch(span: Span, replacement: String)(using Context): Unit =
7575
patch(ctx.compilationUnit.source, span, replacement)
7676

7777
/** Does `span` overlap with a patch region of `source`? */
@@ -82,7 +82,7 @@ object Rewrites {
8282

8383
/** If -rewrite is set, apply all patches and overwrite patched source files.
8484
*/
85-
def writeBack()(implicit ctx: Context): Unit =
85+
def writeBack()(using Context): Unit =
8686
for (rewrites <- ctx.settings.rewrite.value; source <- rewrites.patched.keys) {
8787
ctx.echo(s"[patched file ${source.file.path}]")
8888
rewrites.patched(source).writeBack()

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ abstract class AccessProxies {
2828
/** Given the name of an accessor, is the receiver of the call to accessed obtained
2929
* as a parameterer?
3030
*/
31-
protected def passReceiverAsArg(accessorName: Name)(implicit ctx: Context): Boolean = false
31+
protected def passReceiverAsArg(accessorName: Name)(using Context): Boolean = false
3232

3333
/** The accessor definitions that need to be added to class `cls`
3434
* As a side-effect, this method removes entries from the `accessedBy` map.
3535
* So a second call of the same method will yield the empty list.
3636
*/
37-
private def accessorDefs(cls: Symbol)(implicit ctx: Context): Iterator[DefDef] =
37+
private def accessorDefs(cls: Symbol)(using Context): Iterator[DefDef] =
3838
for (accessor <- cls.info.decls.iterator; accessed <- accessedBy.remove(accessor)) yield
3939
polyDefDef(accessor.asTerm, tps => argss => {
4040
def numTypeParams = accessed.info match {
@@ -57,7 +57,7 @@ abstract class AccessProxies {
5757
})
5858

5959
/** Add all needed accessors to the `body` of class `cls` */
60-
def addAccessorDefs(cls: Symbol, body: List[Tree])(implicit ctx: Context): List[Tree] = {
60+
def addAccessorDefs(cls: Symbol, body: List[Tree])(using Context): List[Tree] = {
6161
val accDefs = accessorDefs(cls)
6262
transforms.println(i"add accessors for $cls: $accDefs%, %")
6363
if (accDefs.isEmpty) body else body ++ accDefs
@@ -67,22 +67,22 @@ abstract class AccessProxies {
6767
import ast.tpd._
6868

6969
def accessorNameKind: ClassifiedNameKind
70-
def needsAccessor(sym: Symbol)(implicit ctx: Context): Boolean
70+
def needsAccessor(sym: Symbol)(using Context): Boolean
7171

72-
def ifNoHost(reference: RefTree)(implicit ctx: Context): Tree = {
72+
def ifNoHost(reference: RefTree)(using Context): Tree = {
7373
assert(false, "no host found for $reference with ${reference.symbol.showLocated} from ${ctx.owner}")
7474
reference
7575
}
7676

7777
/** A fresh accessor symbol */
78-
private def newAccessorSymbol(owner: Symbol, name: TermName, info: Type, span: Span)(implicit ctx: Context): TermSymbol = {
78+
private def newAccessorSymbol(owner: Symbol, name: TermName, info: Type, span: Span)(using Context): TermSymbol = {
7979
val sym = ctx.newSymbol(owner, name, Synthetic | Method, info, coord = span).entered
8080
if (sym.allOverriddenSymbols.exists(!_.is(Deferred))) sym.setFlag(Override)
8181
sym
8282
}
8383

8484
/** An accessor symbol, create a fresh one unless one exists already */
85-
protected def accessorSymbol(owner: Symbol, accessorName: TermName, accessorInfo: Type, accessed: Symbol)(implicit ctx: Context): Symbol = {
85+
protected def accessorSymbol(owner: Symbol, accessorName: TermName, accessorInfo: Type, accessed: Symbol)(using Context): Symbol = {
8686
def refersToAccessed(sym: Symbol) = accessedBy.get(sym).contains(accessed)
8787
owner.info.decl(accessorName).suchThat(refersToAccessed).symbol.orElse {
8888
val acc = newAccessorSymbol(owner, accessorName, accessorInfo, accessed.span)
@@ -92,15 +92,15 @@ abstract class AccessProxies {
9292
}
9393

9494
/** Rewire reference to refer to `accessor` symbol */
95-
private def rewire(reference: RefTree, accessor: Symbol)(implicit ctx: Context): Tree = {
95+
private def rewire(reference: RefTree, accessor: Symbol)(using Context): Tree = {
9696
reference match {
9797
case Select(qual, _) if qual.tpe.derivesFrom(accessor.owner) => qual.select(accessor)
9898
case _ => ref(accessor)
9999
}
100100
}.withSpan(reference.span)
101101

102102
/** Given a reference to a getter accessor, the corresponding setter reference */
103-
def useSetter(getterRef: Tree)(implicit ctx: Context): Tree = getterRef match {
103+
def useSetter(getterRef: Tree)(using Context): Tree = getterRef match {
104104
case getterRef: RefTree =>
105105
val getter = getterRef.symbol.asTerm
106106
val accessed = accessedBy(getter)
@@ -126,7 +126,7 @@ abstract class AccessProxies {
126126
* @param reference The original reference to the non-public symbol
127127
* @param onLHS The reference is on the left-hand side of an assignment
128128
*/
129-
def useAccessor(reference: RefTree)(implicit ctx: Context): Tree = {
129+
def useAccessor(reference: RefTree)(using Context): Tree = {
130130
val accessed = reference.symbol.asTerm
131131
var accessorClass = hostForAccessorOf(accessed: Symbol)
132132
if (accessorClass.exists) {
@@ -142,7 +142,7 @@ abstract class AccessProxies {
142142
}
143143

144144
/** Replace tree with a reference to an accessor if needed */
145-
def accessorIfNeeded(tree: Tree)(implicit ctx: Context): Tree = tree match {
145+
def accessorIfNeeded(tree: Tree)(using Context): Tree = tree match {
146146
case tree: RefTree if needsAccessor(tree.symbol) =>
147147
if (tree.symbol.isConstructor) {
148148
ctx.error("Implementation restriction: cannot use private constructors in inlineable methods", tree.sourcePos)
@@ -158,7 +158,7 @@ object AccessProxies {
158158
/** Where an accessor for the `accessed` symbol should be placed.
159159
* This is the closest enclosing class that has `accessed` as a member.
160160
*/
161-
def hostForAccessorOf(accessed: Symbol)(implicit ctx: Context): Symbol = {
161+
def hostForAccessorOf(accessed: Symbol)(using Context): Symbol = {
162162
def recur(cls: Symbol): Symbol =
163163
if (!cls.exists) NoSymbol
164164
else if cls.derivesFrom(accessed.owner)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ArrayApply extends MiniPhase {
2222

2323
override def phaseName: String = "arrayApply"
2424

25-
override def transformApply(tree: tpd.Apply)(implicit ctx: Context): tpd.Tree =
25+
override def transformApply(tree: tpd.Apply)(using Context): tpd.Tree =
2626
if (tree.symbol.name == nme.apply && tree.symbol.owner == defn.ArrayModule.moduleClass) // Is `Array.apply`
2727
tree.args match {
2828
case StripAscription(Apply(wrapRefArrayMeth, (seqLit: tpd.JavaSeqLiteral) :: Nil)) :: ct :: Nil
@@ -44,7 +44,7 @@ class ArrayApply extends MiniPhase {
4444
* - `ClassTag.apply(java.lang.XYZ.Type)` for boxed primitives `XYZ``
4545
* - `ClassTag.XYZ` for primitive types
4646
*/
47-
private def elideClassTag(ct: Tree)(implicit ctx: Context): Boolean = ct match {
47+
private def elideClassTag(ct: Tree)(using Context): Boolean = ct match {
4848
case Apply(_, rc :: Nil) if ct.symbol == defn.ClassTagModule_apply =>
4949
rc match {
5050
case _: Literal => true // ClassTag.apply(classOf[XYZ])
@@ -60,7 +60,7 @@ class ArrayApply extends MiniPhase {
6060
}
6161

6262
object StripAscription {
63-
def unapply(tree: Tree)(implicit ctx: Context): Some[Tree] = tree match {
63+
def unapply(tree: Tree)(using Context): Some[Tree] = tree match {
6464
case Typed(expr, _) => unapply(expr)
6565
case _ => Some(tree)
6666
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ArrayConstructors extends MiniPhase {
2424

2525
override def phaseName: String = "arrayConstructors"
2626

27-
override def transformApply(tree: tpd.Apply)(implicit ctx: Context): tpd.Tree = {
27+
override def transformApply(tree: tpd.Apply)(using Context): tpd.Tree = {
2828
def expand(elemType: Type, dims: List[Tree]) =
2929
tpd.newArray(elemType, tree.tpe, tree.span, JavaSeqLiteral(dims, TypeTree(defn.IntClass.typeRef)))
3030

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class AugmentScala2Traits extends MiniPhase with IdentityDenotTransformer { this
3636

3737
override def phaseName: String = AugmentScala2Traits.name
3838

39-
override def transformTemplate(impl: Template)(implicit ctx: Context): Template = {
39+
override def transformTemplate(impl: Template)(using Context): Template = {
4040
val cls = impl.symbol.owner.asClass
4141
for (mixin <- cls.mixins) {
4242
val erasedMixin = TypeErasure.normalizeClass(mixin)
@@ -46,7 +46,7 @@ class AugmentScala2Traits extends MiniPhase with IdentityDenotTransformer { this
4646
impl
4747
}
4848

49-
private def augmentScala2Trait(mixin: ClassSymbol)(implicit ctx: Context): Unit = {
49+
private def augmentScala2Trait(mixin: ClassSymbol)(using Context): Unit = {
5050
def traitSetter(getter: TermSymbol) =
5151
getter.copy(
5252
name = getter.ensureNotPrivate.name

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import util.Spans.Span
1111
import util.SourcePosition
1212

1313
/** A helper class for generating bridge methods in class `root`. */
14-
class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Context) {
14+
class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(using Context) {
1515
import ast.tpd._
1616

1717
assert(ctx.phase == ctx.erasurePhase.next)
1818
private val preErasureCtx = ctx.withPhase(ctx.erasurePhase)
1919
private lazy val elimErasedCtx = ctx.withPhase(ctx.elimErasedValueTypePhase.next)
2020

21-
private class BridgesCursor(implicit ctx: Context) extends OverridingPairs.Cursor(root) {
21+
private class BridgesCursor(using Context) extends OverridingPairs.Cursor(root) {
2222

2323
/** Only use the superclass of `root` as a parent class. This means
2424
* overriding pairs that have a common implementation in a trait parent
@@ -57,9 +57,9 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont
5757
def bridgeExists =
5858
bridgesScope.lookupAll(member.name).exists(bridge =>
5959
bridgeTarget(bridge) == member && bridge.signature == other.signature)
60-
def info(sym: Symbol)(implicit ctx: Context) = sym.info
60+
def info(sym: Symbol)(using Context) = sym.info
6161
def desc(sym: Symbol)= {
62-
val infoStr = info(sym)(preErasureCtx) match {
62+
val infoStr = info(sym)(using preErasureCtx) match {
6363
case ExprType(info) => i": $info"
6464
case info => info.show
6565
}
@@ -69,7 +69,7 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont
6969
if (!member.info.matches(other.info))
7070
ctx.error(em"""bridge generated for member ${desc(member)}
7171
|which overrides ${desc(other)}
72-
|clashes with definition of the member itself; both have erased type ${info(member)(elimErasedCtx)}."""",
72+
|clashes with definition of the member itself; both have erased type ${info(member)(using elimErasedCtx)}."""",
7373
bridgePosFor(member))
7474
}
7575
else if (!bridgeExists)
@@ -112,7 +112,7 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont
112112
* time deferred methods in `stats` that are replaced by a bridge with the same signature.
113113
*/
114114
def add(stats: List[untpd.Tree]): List[untpd.Tree] =
115-
val opc = new BridgesCursor()(preErasureCtx)
115+
val opc = new BridgesCursor()(using preErasureCtx)
116116
val ectx = ctx.withPhase(thisPhase)
117117
while opc.hasNext do
118118
if !opc.overriding.is(Deferred) then

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ByNameClosures extends TransformByNameApply with IdentityDenotTransformer
2525

2626
override def phaseName: String = ByNameClosures.name
2727

28-
override def mkByNameClosure(arg: Tree, argType: Type)(implicit ctx: Context): Tree = {
28+
override def mkByNameClosure(arg: Tree, argType: Type)(using Context): Tree = {
2929
val meth = ctx.newSymbol(
3030
ctx.owner, nme.ANON_FUN, Synthetic | Method, MethodType(Nil, Nil, argType))
3131
Closure(meth, _ => arg.changeOwnerAfter(ctx.owner, meth, thisPhase)).withSpan(arg.span)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CacheAliasImplicits extends MiniPhase with IdentityDenotTransformer { this
4646

4747
override def phaseName: String = CacheAliasImplicits.name
4848

49-
override def transformDefDef(tree: DefDef)(implicit ctx: Context): Tree = {
49+
override def transformDefDef(tree: DefDef)(using Context): Tree = {
5050
val sym = tree.symbol
5151
val isCached = !sym.is(Inline) && {
5252
sym.info match {

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
2727
// lifting tries changes what variables are considered to be captured
2828

2929
private[this] var Captured: Store.Location[collection.Set[Symbol]] = _
30-
private def captured(implicit ctx: Context) = ctx.store(Captured)
30+
private def captured(using Context) = ctx.store(Captured)
3131

3232
override def initContext(ctx: FreshContext): Unit =
3333
Captured = ctx.addLocation(Set.empty)
3434

35-
private class RefInfo(implicit ctx: Context) {
35+
private class RefInfo(using Context) {
3636
/** The classes for which a Ref type exists. */
3737
val refClassKeys: collection.Set[Symbol] =
3838
defn.ScalaNumericValueClasses() `union` Set(defn.BooleanClass, defn.ObjectClass)
@@ -48,14 +48,14 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
4848
}
4949

5050
private var myRefInfo: RefInfo = null
51-
private def refInfo(implicit ctx: Context) = {
51+
private def refInfo(using Context) = {
5252
if (myRefInfo == null) myRefInfo = new RefInfo()
5353
myRefInfo
5454
}
5555

5656
private class CollectCaptured extends TreeTraverser {
5757
private val captured = mutable.HashSet[Symbol]()
58-
def traverse(tree: Tree)(implicit ctx: Context) = tree match {
58+
def traverse(tree: Tree)(using Context) = tree match {
5959
case id: Ident =>
6060
val sym = id.symbol
6161
if (sym.is(Mutable, butNot = Method) && sym.owner.isTerm) {
@@ -68,13 +68,13 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
6868
case _ =>
6969
traverseChildren(tree)
7070
}
71-
def runOver(tree: Tree)(implicit ctx: Context): collection.Set[Symbol] = {
71+
def runOver(tree: Tree)(using Context): collection.Set[Symbol] = {
7272
traverse(tree)
7373
captured
7474
}
7575
}
7676

77-
override def prepareForUnit(tree: Tree)(implicit ctx: Context): Context = {
77+
override def prepareForUnit(tree: Tree)(using Context): Context = {
7878
val captured = (new CollectCaptured)
7979
.runOver(ctx.compilationUnit.tpdTree)(using ctx.withPhase(thisPhase))
8080
ctx.fresh.updateStore(Captured, captured)
@@ -83,14 +83,14 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
8383
/** The {Volatile|}{Int|Double|...|Object}Ref class corresponding to the class `cls`,
8484
* depending on whether the reference should be @volatile
8585
*/
86-
def refClass(cls: Symbol, isVolatile: Boolean)(implicit ctx: Context): Symbol = {
86+
def refClass(cls: Symbol, isVolatile: Boolean)(using Context): Symbol = {
8787
val refMap = if (isVolatile) refInfo.volatileRefClass else refInfo.refClass
8888
if (cls.isClass)
8989
refMap.getOrElse(cls, refMap(defn.ObjectClass))
9090
else refMap(defn.ObjectClass)
9191
}
9292

93-
override def prepareForValDef(vdef: ValDef)(implicit ctx: Context): Context = {
93+
override def prepareForValDef(vdef: ValDef)(using Context): Context = {
9494
val sym = vdef.symbol(using ctx.withPhase(thisPhase))
9595
if (captured contains sym) {
9696
val newd = sym.denot(using ctx.withPhase(thisPhase)).copySymDenotation(
@@ -102,7 +102,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
102102
ctx
103103
}
104104

105-
override def transformValDef(vdef: ValDef)(implicit ctx: Context): Tree = {
105+
override def transformValDef(vdef: ValDef)(using Context): Tree = {
106106
val vble = vdef.symbol
107107
if (captured.contains(vble)) {
108108
def boxMethod(name: TermName): Tree =
@@ -114,7 +114,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
114114
else vdef
115115
}
116116

117-
override def transformIdent(id: Ident)(implicit ctx: Context): Tree = {
117+
override def transformIdent(id: Ident)(using Context): Tree = {
118118
val vble = id.symbol
119119
if (captured.contains(vble))
120120
id.select(nme.elem).ensureConforms(vble.denot(using ctx.withPhase(thisPhase)).info)
@@ -137,7 +137,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
137137
* Also: If the ref type lhs is followed by a cast (can be an artifact of nested translation),
138138
* drop the cast.
139139
*/
140-
override def transformAssign(tree: Assign)(implicit ctx: Context): Tree = {
140+
override def transformAssign(tree: Assign)(using Context): Tree = {
141141
def recur(lhs: Tree): Tree = lhs match {
142142
case TypeApply(Select(qual, nme.asInstanceOf_), _) =>
143143
val Select(_, nme.elem) = qual

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class CheckReentrant extends MiniPhase {
4444
private val scalaJSIRPackageClass = new CtxLazy(
4545
summon[Context].getPackageClassIfDefined("org.scalajs.ir"))
4646

47-
def isIgnored(sym: Symbol)(implicit ctx: Context): Boolean =
47+
def isIgnored(sym: Symbol)(using Context): Boolean =
4848
sym.hasAnnotation(sharableAnnot()) ||
4949
sym.hasAnnotation(unsharedAnnot()) ||
5050
sym.topLevelClass.owner == scalaJSIRPackageClass() ||
@@ -54,14 +54,14 @@ class CheckReentrant extends MiniPhase {
5454
// enum values are initialized eagerly before use
5555
// in the long run, we should make them vals
5656

57-
def scanning(sym: Symbol)(op: => Unit)(implicit ctx: Context): Unit = {
57+
def scanning(sym: Symbol)(op: => Unit)(using Context): Unit = {
5858
ctx.log(i"${" " * indent}scanning $sym")
5959
indent += 1
6060
try op
6161
finally indent -= 1
6262
}
6363

64-
def addVars(cls: ClassSymbol)(implicit ctx: Context): Unit =
64+
def addVars(cls: ClassSymbol)(using Context): Unit =
6565
if (!seen.contains(cls) && !isIgnored(cls)) {
6666
seen += cls
6767
scanning(cls) {
@@ -82,7 +82,7 @@ class CheckReentrant extends MiniPhase {
8282
}
8383
}
8484

85-
override def transformTemplate(tree: Template)(implicit ctx: Context): Tree = {
85+
override def transformTemplate(tree: Template)(using Context): Tree = {
8686
if (ctx.settings.YcheckReentrant.value && tree.symbol.owner.isStaticOwner)
8787
addVars(tree.symbol.owner.asClass)
8888
tree

0 commit comments

Comments
 (0)