Skip to content

Commit ce9aa2d

Browse files
committed
Convert transform classes (4)
1 parent 1798e29 commit ce9aa2d

23 files changed

+138
-138
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class TailRec extends MiniPhase {
114114

115115
override def runsAfter: Set[String] = Set(Erasure.name) // tailrec assumes erased types
116116

117-
override def transformDefDef(tree: DefDef)(implicit ctx: Context): Tree = {
117+
override def transformDefDef(tree: DefDef)(using Context): Tree = {
118118
val method = tree.symbol
119119
val mandatory = method.hasAnnotation(defn.TailrecAnnot)
120120
def noTailTransform(failureReported: Boolean) = {
@@ -222,7 +222,7 @@ class TailRec extends MiniPhase {
222222

223223
/** The `tailLabelN` label symbol, used to encode a `continue` from the infinite `while` loop. */
224224
private var myContinueLabel: Symbol = _
225-
def continueLabel(implicit ctx: Context): Symbol = {
225+
def continueLabel(using Context): Symbol = {
226226
if (myContinueLabel == null)
227227
myContinueLabel = ctx.newSymbol(method, TailLabelName.fresh(), Label, defn.UnitType)
228228
myContinueLabel
@@ -235,7 +235,7 @@ class TailRec extends MiniPhase {
235235
/** The replacement `var`s for the params in `rewrittenParamSyms`. */
236236
var varsForRewrittenParamSyms: List[Symbol] = Nil
237237

238-
private def getVarForRewrittenThis()(implicit ctx: Context): Symbol =
238+
private def getVarForRewrittenThis()(using Context): Symbol =
239239
varForRewrittenThis match {
240240
case Some(sym) => sym
241241
case none =>
@@ -247,7 +247,7 @@ class TailRec extends MiniPhase {
247247
sym
248248
}
249249

250-
private def getVarForRewrittenParam(param: Symbol)(implicit ctx: Context): Symbol =
250+
private def getVarForRewrittenParam(param: Symbol)(using Context): Symbol =
251251
rewrittenParamSyms.indexOf(param) match {
252252
case -1 =>
253253
val sym = ctx.newSymbol(method, TailLocalName.fresh(param.name.toTermName), Synthetic | Mutable, param.info)
@@ -263,7 +263,7 @@ class TailRec extends MiniPhase {
263263
private var inTailPosition = true
264264

265265
/** Rewrite this tree to contain no tail recursive calls */
266-
def transform(tree: Tree, tailPosition: Boolean)(implicit ctx: Context): Tree =
266+
def transform(tree: Tree, tailPosition: Boolean)(using Context): Tree =
267267
if (inTailPosition == tailPosition) transform(tree)
268268
else {
269269
val saved = inTailPosition
@@ -272,7 +272,7 @@ class TailRec extends MiniPhase {
272272
finally inTailPosition = saved
273273
}
274274

275-
def yesTailTransform(tree: Tree)(implicit ctx: Context): Tree =
275+
def yesTailTransform(tree: Tree)(using Context): Tree =
276276
transform(tree, tailPosition = true)
277277

278278
/** If not in tail position a tree traversal may not be needed.
@@ -285,15 +285,15 @@ class TailRec extends MiniPhase {
285285
private def isTraversalNeeded =
286286
isMandatory || tailPositionLabeledSyms.nonEmpty
287287

288-
def noTailTransform(tree: Tree)(implicit ctx: Context): Tree =
288+
def noTailTransform(tree: Tree)(using Context): Tree =
289289
if (isTraversalNeeded) transform(tree, tailPosition = false)
290290
else tree
291291

292-
def noTailTransforms[Tr <: Tree](trees: List[Tr])(implicit ctx: Context): List[Tr] =
292+
def noTailTransforms[Tr <: Tree](trees: List[Tr])(using Context): List[Tr] =
293293
if (isTraversalNeeded) trees.mapConserve(noTailTransform).asInstanceOf[List[Tr]]
294294
else trees
295295

296-
override def transform(tree: Tree)(implicit ctx: Context): Tree = {
296+
override def transform(tree: Tree)(using Context): Tree = {
297297
/* Rewrite an Apply to be considered for tail call transformation. */
298298
def rewriteApply(tree: Apply): Tree = {
299299
val arguments = noTailTransforms(tree.args)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ abstract class TransformByNameApply extends MiniPhase { thisPhase: DenotTransfor
2222
import ast.tpd._
2323

2424
/** The info of the tree's symbol before it is potentially transformed in this phase */
25-
private def originalDenotation(tree: Tree)(implicit ctx: Context) =
25+
private def originalDenotation(tree: Tree)(using Context) =
2626
tree.symbol.denot(using ctx.withPhase(thisPhase))
2727

2828
/** If denotation had an ExprType before, it now gets a function type */
29-
protected def exprBecomesFunction(symd: SymDenotation)(implicit ctx: Context): Boolean =
29+
protected def exprBecomesFunction(symd: SymDenotation)(using Context): Boolean =
3030
symd.is(Param) || symd.is(ParamAccessor, butNot = Method)
3131

32-
protected def isByNameRef(tree: Tree)(implicit ctx: Context): Boolean = {
32+
protected def isByNameRef(tree: Tree)(using Context): Boolean = {
3333
val origDenot = originalDenotation(tree)
3434
origDenot.info.isInstanceOf[ExprType] && exprBecomesFunction(origDenot)
3535
}
3636

37-
def mkByNameClosure(arg: Tree, argType: Type)(implicit ctx: Context): Tree = unsupported(i"mkClosure($arg)")
37+
def mkByNameClosure(arg: Tree, argType: Type)(using Context): Tree = unsupported(i"mkClosure($arg)")
3838

39-
override def transformApply(tree: Apply)(implicit ctx: Context): Tree =
39+
override def transformApply(tree: Apply)(using Context): Tree =
4040
trace(s"transforming ${tree.show} at phase ${ctx.phase}", show = true) {
4141

4242
def transformArg(arg: Tree, formal: Type): Tree = formal.dealias match {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ class TransformWildcards extends MiniPhase with IdentityDenotTransformer {
1616

1717
override def phaseName: String = "transformWildcards"
1818

19-
override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit =
19+
override def checkPostCondition(tree: Tree)(using Context): Unit =
2020
tree match {
2121
case vDef: ValDef => assert(!tpd.isWildcardArg(vDef.rhs))
2222
case _ =>
2323
}
2424

25-
override def transformValDef(tree: ValDef)(implicit ctx: Context): Tree =
25+
override def transformValDef(tree: ValDef)(using Context): Tree =
2626
if (ctx.owner.isClass) tree
2727
else cpy.ValDef(tree)(rhs = tree.rhs.wildcardToDefault)
2828
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object TreeExtractors {
1111

1212
/** Match arg1.op(arg2) and extract (arg1, op.symbol, arg2) */
1313
object BinaryOp {
14-
def unapply(t: Tree)(implicit ctx: Context): Option[(Tree, Symbol, Tree)] = t match {
14+
def unapply(t: Tree)(using Context): Option[(Tree, Symbol, Tree)] = t match {
1515
case Apply(sel @ Select(arg1, _), List(arg2)) =>
1616
Some((arg1, sel.symbol, arg2))
1717
case _ =>
@@ -21,7 +21,7 @@ object TreeExtractors {
2121

2222
/** Match new C(args) and extract (C, args) */
2323
object NewWithArgs {
24-
def unapply(t: Tree)(implicit ctx: Context): Option[(Type, List[Tree])] = t match {
24+
def unapply(t: Tree)(using Context): Option[(Type, List[Tree])] = t match {
2525
case Apply(Select(New(_), nme.CONSTRUCTOR), args) =>
2626
Some((t.tpe, args))
2727
case _ =>
@@ -34,7 +34,7 @@ object TreeExtractors {
3434
* Match v.underlying() and extract v
3535
*/
3636
object ValueClassUnbox {
37-
def unapply(t: Tree)(implicit ctx: Context): Option[Tree] = t match {
37+
def unapply(t: Tree)(using Context): Option[Tree] = t match {
3838
case Apply(sel @ Select(ref, _), Nil) =>
3939
val sym = ref.tpe.widenDealias.typeSymbol
4040
if (isDerivedValueClass(sym) && (sel.symbol eq valueClassUnbox(sym.asClass)))

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,30 +53,30 @@ abstract class TreeMapWithStages(@constructorOnly ictx: Context) extends TreeMap
5353
protected def isInQuoteOrSplice: Boolean = inQuoteOrSplice
5454

5555
/** Enter staging level of symbol defined by `tree` */
56-
private def markSymbol(sym: Symbol)(implicit ctx: Context): Unit =
56+
private def markSymbol(sym: Symbol)(using Context): Unit =
5757
if level != 0 && !levelOfMap.contains(sym) then
5858
levelOfMap(sym) = level
5959
enteredSyms = sym :: enteredSyms
6060

6161
/** Enter staging level of symbol defined by `tree`, if applicable. */
62-
private def markDef(tree: Tree)(implicit ctx: Context): Unit = tree match {
62+
private def markDef(tree: Tree)(using Context): Unit = tree match {
6363
case tree: DefTree => markSymbol(tree.symbol)
6464
case _ =>
6565
}
6666

6767
/** Transform the quote `quote` which contains the quoted `body`. */
68-
protected def transformQuotation(body: Tree, quote: Tree)(implicit ctx: Context): Tree =
68+
protected def transformQuotation(body: Tree, quote: Tree)(using Context): Tree =
6969
quote match {
7070
case quote: Apply => cpy.Apply(quote)(quote.fun, body :: Nil)
7171
case quote: TypeApply => cpy.TypeApply(quote)(quote.fun, body :: Nil)
7272
}
7373

7474
/** Transform the splice `splice` which contains the spliced `body`. */
75-
protected def transformSplice(body: Tree, splice: Tree)(implicit ctx: Context): Tree
75+
protected def transformSplice(body: Tree, splice: Tree)(using Context): Tree
7676

77-
override def transform(tree: Tree)(implicit ctx: Context): Tree =
77+
override def transform(tree: Tree)(using Context): Tree =
7878
if (tree.source != ctx.source && tree.source.exists)
79-
transform(tree)(ctx.withSource(tree.source))
79+
transform(tree)(using ctx.withSource(tree.source))
8080
else reporting.trace(i"StagingTransformer.transform $tree at $level", staging, show = true) {
8181
def mapOverTree(lastEntered: List[Symbol]) =
8282
try super.transform(tree)
@@ -149,7 +149,7 @@ object TreeMapWithStages {
149149
private val LevelOfKey = new Property.Key[mutable.HashMap[Symbol, Int]]
150150

151151
/** Initial context for a StagingTransformer transformation. */
152-
def freshStagingContext(implicit ctx: Context): Context =
152+
def freshStagingContext(using Context): Context =
153153
ctx.fresh.setProperty(LevelOfKey, new mutable.HashMap[Symbol, Int])
154154

155155
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class TryCatchPatterns extends MiniPhase {
4646

4747
override def runsAfter: Set[String] = Set(ElimRepeated.name)
4848

49-
override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = tree match {
49+
override def checkPostCondition(tree: Tree)(using Context): Unit = tree match {
5050
case Try(_, cases, _) =>
5151
cases.foreach {
5252
case CaseDef(Typed(_, _), guard, _) => assert(guard.isEmpty, "Try case should not contain a guard.")
@@ -57,20 +57,20 @@ class TryCatchPatterns extends MiniPhase {
5757
case _ =>
5858
}
5959

60-
override def transformTry(tree: Try)(implicit ctx: Context): Tree = {
60+
override def transformTry(tree: Try)(using Context): Tree = {
6161
val (tryCases, patternMatchCases) = tree.cases.span(isCatchCase)
6262
val fallbackCase = mkFallbackPatterMatchCase(patternMatchCases, tree.span)
6363
cpy.Try(tree)(cases = tryCases ++ fallbackCase)
6464
}
6565

6666
/** Is this pattern node a catch-all or type-test pattern? */
67-
private def isCatchCase(cdef: CaseDef)(implicit ctx: Context): Boolean = cdef match {
67+
private def isCatchCase(cdef: CaseDef)(using Context): Boolean = cdef match {
6868
case CaseDef(Typed(Ident(nme.WILDCARD), tpt), EmptyTree, _) => isSimpleThrowable(tpt.tpe)
6969
case CaseDef(Bind(_, Typed(Ident(nme.WILDCARD), tpt)), EmptyTree, _) => isSimpleThrowable(tpt.tpe)
7070
case _ => isDefaultCase(cdef)
7171
}
7272

73-
private def isSimpleThrowable(tp: Type)(implicit ctx: Context): Boolean = tp.stripAnnots match {
73+
private def isSimpleThrowable(tp: Type)(using Context): Boolean = tp.stripAnnots match {
7474
case tp @ TypeRef(pre, _) =>
7575
(pre == NoPrefix || pre.widen.typeSymbol.isStatic) && // Does not require outer class check
7676
!tp.symbol.is(Flags.Trait) && // Traits not supported by JVM

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
2323

2424
def phaseName: String = "genericTuples"
2525

26-
override def transformApply(tree: tpd.Apply)(implicit ctx: Context): tpd.Tree =
26+
override def transformApply(tree: tpd.Apply)(using Context): tpd.Tree =
2727
if (!tree.symbol.exists || tree.symbol.owner != defn.RuntimeTupleModuleClass) tree
2828
else if (tree.symbol == defn.RuntimeTuple_cons) transformTupleCons(tree)
2929
else if (tree.symbol == defn.RuntimeTuple_tail) transformTupleTail(tree)
@@ -33,7 +33,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
3333
else if (tree.symbol == defn.RuntimeTuple_toArray) transformTupleToArray(tree)
3434
else tree
3535

36-
private def transformTupleCons(tree: tpd.Apply)(implicit ctx: Context): Tree = {
36+
private def transformTupleCons(tree: tpd.Apply)(using Context): Tree = {
3737
val head :: tail :: Nil = tree.args
3838
defn.tupleTypes(tree.tpe.widenTermRefExpr.dealias) match {
3939
case Some(tpes) =>
@@ -61,7 +61,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
6161
}
6262
}
6363

64-
private def transformTupleTail(tree: tpd.Apply)(implicit ctx: Context): Tree = {
64+
private def transformTupleTail(tree: tpd.Apply)(using Context): Tree = {
6565
val Apply(_, tup :: Nil) = tree
6666
defn.tupleTypes(tup.tpe.widenTermRefExpr.dealias, MaxTupleArity + 1) match {
6767
case Some(tpes) =>
@@ -98,13 +98,13 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
9898
}
9999
}
100100

101-
private def transformTupleSize(tree: tpd.Apply)(implicit ctx: Context): Tree =
101+
private def transformTupleSize(tree: tpd.Apply)(using Context): Tree =
102102
tree.tpe.tryNormalize match {
103103
case tp: ConstantType => Literal(tp.value)
104104
case _ => tree
105105
}
106106

107-
private def transformTupleConcat(tree: tpd.Apply)(implicit ctx: Context): Tree = {
107+
private def transformTupleConcat(tree: tpd.Apply)(using Context): Tree = {
108108
val Apply(_, self :: that :: Nil) = tree
109109
(defn.tupleTypes(self.tpe.widenTermRefExpr.dealias), defn.tupleTypes(that.tpe.widenTermRefExpr.dealias)) match {
110110
case (Some(tpes1), Some(tpes2)) =>
@@ -139,7 +139,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
139139
}
140140
}
141141

142-
private def transformTupleApply(tree: tpd.Apply)(implicit ctx: Context): Tree = {
142+
private def transformTupleApply(tree: tpd.Apply)(using Context): Tree = {
143143
val Apply(_, tup :: nTree :: Nil) = tree
144144
(defn.tupleTypes(tup.tpe.widenTermRefExpr.dealias), nTree.tpe) match {
145145
case (Some(tpes), nTpe: ConstantType) =>
@@ -166,7 +166,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
166166
}
167167
}
168168

169-
private def transformTupleToArray(tree: tpd.Apply)(implicit ctx: Context): Tree = {
169+
private def transformTupleToArray(tree: tpd.Apply)(using Context): Tree = {
170170
val Apply(_, tup :: Nil) = tree
171171
defn.tupleTypes(tup.tpe.widen, MaxTupleArity) match {
172172
case Some(tpes) =>
@@ -188,14 +188,14 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
188188
}
189189

190190
/** Create a TupleN (1 <= N < 23) from the elements */
191-
private def knownTupleFromElements(tpes: List[Type], elements: List[Tree])(implicit ctx: Context) = {
191+
private def knownTupleFromElements(tpes: List[Type], elements: List[Tree])(using Context) = {
192192
val size = elements.size
193193
assert(0 < size && size <= MaxTupleArity)
194194
val tupleModule = defn.TupleType(size).classSymbol.companionModule
195195
ref(tupleModule).select(nme.apply).appliedToTypes(tpes).appliedToArgs(elements)
196196
}
197197

198-
private def knownTupleFromIterator(size: Int, it: Tree)(implicit ctx: Context): Tree =
198+
private def knownTupleFromIterator(size: Int, it: Tree)(using Context): Tree =
199199
if (size == 0)
200200
// EmptyTuple for empty tuple
201201
ref(defn.EmptyTupleModule.termRef) // TODO should this code be here? Or assert(size > specializedSize)
@@ -214,7 +214,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
214214
// TupleXXL.fromIterator(it)
215215
ref(defn.TupleXXL_fromIterator).appliedTo(it)
216216

217-
private def tupleSelectors(tup: Tree, size: Int)(implicit ctx: Context): List[Tree] =
217+
private def tupleSelectors(tup: Tree, size: Int)(using Context): List[Tree] =
218218
(0 until size).map(i => tup.select(nme.selectorName(i))).toList
219219
}
220220

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object TypeTestsCasts {
5656
def checkable(X: Type, P: Type, span: Span)(using Context): Boolean = {
5757
def isAbstract(P: Type) = !P.dealias.typeSymbol.isClass
5858

59-
def replaceP(tp: Type)(implicit ctx: Context) = new TypeMap {
59+
def replaceP(tp: Type)(using Context) = new TypeMap {
6060
def apply(tp: Type) = tp match {
6161
case tref: TypeRef if tref.typeSymbol.isPatternBound =>
6262
WildcardType
@@ -66,7 +66,7 @@ object TypeTestsCasts {
6666
}
6767
}.apply(tp)
6868

69-
def replaceX(tp: Type)(implicit ctx: Context) = new TypeMap {
69+
def replaceX(tp: Type)(using Context) = new TypeMap {
7070
def apply(tp: Type) = tp match {
7171
case tref: TypeRef if tref.typeSymbol.isPatternBound =>
7272
if (variance == 1) tref.info.hiBound
@@ -77,7 +77,7 @@ object TypeTestsCasts {
7777
}.apply(tp)
7878

7979
/** Approximate type parameters depending on variance */
80-
def stripTypeParam(tp: Type)(implicit ctx: Context) = new ApproximatingTypeMap {
80+
def stripTypeParam(tp: Type)(using Context) = new ApproximatingTypeMap {
8181
def apply(tp: Type): Type = tp match {
8282
case _: MatchType =>
8383
tp // break cycles

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@ object TypeUtils {
1515
*/
1616
implicit class TypeUtilsOps(val self: Type) extends AnyVal {
1717

18-
def isErasedValueType(implicit ctx: Context): Boolean =
18+
def isErasedValueType(using Context): Boolean =
1919
self.isInstanceOf[ErasedValueType]
2020

21-
def isPrimitiveValueType(implicit ctx: Context): Boolean =
21+
def isPrimitiveValueType(using Context): Boolean =
2222
self.classSymbol.isPrimitiveValueClass
2323

24-
def ensureMethodic(implicit ctx: Context): Type = self match {
24+
def ensureMethodic(using Context): Type = self match {
2525
case self: MethodicType => self
2626
case _ => if (ctx.erasedTypes) MethodType(Nil, self) else ExprType(self)
2727
}
2828

29-
def widenToParents(implicit ctx: Context): Type = self.parents match {
29+
def widenToParents(using Context): Type = self.parents match {
3030
case Nil => self
3131
case ps => ps.reduceLeft(AndType(_, _))
3232
}
3333

3434
/** The arity of this tuple type, which can be made up of EmptyTuple, TupleX and `*:` pairs,
3535
* or -1 if this is not a tuple type.
3636
*/
37-
def tupleArity(implicit ctx: Context): Int = self match {
37+
def tupleArity(using Context): Int = self match {
3838
case AppliedType(tycon, _ :: tl :: Nil) if tycon.isRef(defn.PairClass) =>
3939
val arity = tl.tupleArity
4040
if (arity < 0) arity else arity + 1
@@ -47,7 +47,7 @@ object TypeUtils {
4747
}
4848

4949
/** The element types of this tuple type, which can be made up of EmptyTuple, TupleX and `*:` pairs */
50-
def tupleElementTypes(implicit ctx: Context): List[Type] = self match {
50+
def tupleElementTypes(using Context): List[Type] = self match {
5151
case AppliedType(tycon, hd :: tl :: Nil) if tycon.isRef(defn.PairClass) =>
5252
hd :: tl.tupleElementTypes
5353
case self: TermRef if self.symbol == defn.EmptyTupleModule =>
@@ -59,15 +59,15 @@ object TypeUtils {
5959
}
6060

6161
/** The `*:` equivalent of an instance of a Tuple class */
62-
def toNestedPairs(implicit ctx: Context): Type =
62+
def toNestedPairs(using Context): Type =
6363
TypeOps.nestedPairs(tupleElementTypes)
6464

65-
def refinedWith(name: Name, info: Type)(implicit ctx: Context) = RefinedType(self, name, info)
65+
def refinedWith(name: Name, info: Type)(using Context) = RefinedType(self, name, info)
6666

6767
/** The TermRef referring to the companion of the underlying class reference
6868
* of this type, while keeping the same prefix.
6969
*/
70-
def companionRef(implicit ctx: Context): TermRef = self match {
70+
def companionRef(using Context): TermRef = self match {
7171
case self @ TypeRef(prefix, _) if self.symbol.isClass =>
7272
prefix.select(self.symbol.companionModule).asInstanceOf[TermRef]
7373
case self: TypeProxy =>

0 commit comments

Comments
 (0)