Skip to content

Commit 2f65192

Browse files
committed
Switch to (using context) for other files in typer
1 parent f88921b commit 2f65192

File tree

3 files changed

+119
-119
lines changed

3 files changed

+119
-119
lines changed

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

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Erasure extends Phase with DenotTransformer {
4545
override def changesMembers: Boolean = true // the phase adds bridges
4646
override def changesParents: Boolean = true // the phase drops Any
4747

48-
def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation = ref match {
48+
def transform(ref: SingleDenotation)(using Context): SingleDenotation = ref match {
4949
case ref: SymDenotation =>
5050
def isCompacted(sym: Symbol) =
5151
sym.isAnonymousFunction && {
@@ -116,12 +116,12 @@ class Erasure extends Phase with DenotTransformer {
116116

117117
private val eraser = new Erasure.Typer(this)
118118

119-
def run(implicit ctx: Context): Unit = {
119+
def run(using Context): Unit = {
120120
val unit = ctx.compilationUnit
121121
unit.tpdTree = eraser.typedExpr(unit.tpdTree)(using ctx.fresh.setTyper(eraser).setPhase(this.next))
122122
}
123123

124-
override def checkPostCondition(tree: tpd.Tree)(implicit ctx: Context): Unit = {
124+
override def checkPostCondition(tree: tpd.Tree)(using Context): Unit = {
125125
assertErased(tree)
126126
tree match {
127127
case res: tpd.This =>
@@ -143,7 +143,7 @@ class Erasure extends Phase with DenotTransformer {
143143
* they need not be reloaded using member; this would likely fail as signatures
144144
* may change after erasure).
145145
*/
146-
def assertErased(tree: tpd.Tree)(implicit ctx: Context): Unit = {
146+
def assertErased(tree: tpd.Tree)(using Context): Unit = {
147147
assertErased(tree.typeOpt, tree)
148148
if (!defn.isPolymorphicAfterErasure(tree.symbol))
149149
assertErased(tree.typeOpt.widen, tree)
@@ -157,7 +157,7 @@ class Erasure extends Phase with DenotTransformer {
157157
}
158158
}
159159

160-
def assertErased(tp: Type, tree: tpd.Tree = tpd.EmptyTree)(implicit ctx: Context): Unit = {
160+
def assertErased(tp: Type, tree: tpd.Tree = tpd.EmptyTree)(using Context): Unit = {
161161
def isAllowed(cls: Symbol, sourceName: String) =
162162
tp.widen.typeSymbol == cls && ctx.compilationUnit.source.file.name == sourceName
163163
assert(isErasedType(tp) ||
@@ -207,15 +207,15 @@ object Erasure {
207207

208208
object Boxing:
209209

210-
def isUnbox(sym: Symbol)(implicit ctx: Context): Boolean =
210+
def isUnbox(sym: Symbol)(using Context): Boolean =
211211
sym.name == nme.unbox && sym.owner.linkedClass.isPrimitiveValueClass
212212

213-
def isBox(sym: Symbol)(implicit ctx: Context): Boolean =
213+
def isBox(sym: Symbol)(using Context): Boolean =
214214
sym.name == nme.box && sym.owner.linkedClass.isPrimitiveValueClass
215215

216-
def boxMethod(cls: ClassSymbol)(implicit ctx: Context): Symbol =
216+
def boxMethod(cls: ClassSymbol)(using Context): Symbol =
217217
cls.linkedClass.info.member(nme.box).symbol
218-
def unboxMethod(cls: ClassSymbol)(implicit ctx: Context): Symbol =
218+
def unboxMethod(cls: ClassSymbol)(using Context): Symbol =
219219
cls.linkedClass.info.member(nme.unbox).symbol
220220

221221
/** Isf this tree is an unbox operation which can be safely removed
@@ -225,18 +225,18 @@ object Erasure {
225225
* This is important for specialization: calls to the super constructor should not box/unbox specialized
226226
* fields (see TupleX). (ID)
227227
*/
228-
private def safelyRemovableUnboxArg(tree: Tree)(implicit ctx: Context): Tree = tree match {
228+
private def safelyRemovableUnboxArg(tree: Tree)(using Context): Tree = tree match {
229229
case Apply(fn, arg :: Nil)
230230
if isUnbox(fn.symbol) && defn.ScalaBoxedClasses().contains(arg.tpe.widen.typeSymbol) =>
231231
arg
232232
case _ =>
233233
EmptyTree
234234
}
235235

236-
def constant(tree: Tree, const: Tree)(implicit ctx: Context): Tree =
236+
def constant(tree: Tree, const: Tree)(using Context): Tree =
237237
(if (isPureExpr(tree)) const else Block(tree :: Nil, const)).withSpan(tree.span)
238238

239-
final def box(tree: Tree, target: => String = "")(implicit ctx: Context): Tree = trace(i"boxing ${tree.showSummary}: ${tree.tpe} into $target") {
239+
final def box(tree: Tree, target: => String = "")(using Context): Tree = trace(i"boxing ${tree.showSummary}: ${tree.tpe} into $target") {
240240
tree.tpe.widen match {
241241
case ErasedValueType(tycon, _) =>
242242
New(tycon, cast(tree, underlyingOfValueClass(tycon.symbol.asClass)) :: Nil) // todo: use adaptToType?
@@ -256,7 +256,7 @@ object Erasure {
256256
}
257257
}
258258

259-
def unbox(tree: Tree, pt: Type)(implicit ctx: Context): Tree = trace(i"unboxing ${tree.showSummary}: ${tree.tpe} as a $pt") {
259+
def unbox(tree: Tree, pt: Type)(using Context): Tree = trace(i"unboxing ${tree.showSummary}: ${tree.tpe} as a $pt") {
260260
pt match {
261261
case ErasedValueType(tycon, underlying) =>
262262
def unboxedTree(t: Tree) =
@@ -299,7 +299,7 @@ object Erasure {
299299
* Casts from and to ErasedValueType are special, see the explanation
300300
* in ExtensionMethods#transform.
301301
*/
302-
def cast(tree: Tree, pt: Type)(implicit ctx: Context): Tree = trace(i"cast ${tree.tpe.widen} --> $pt", show = true) {
302+
def cast(tree: Tree, pt: Type)(using Context): Tree = trace(i"cast ${tree.tpe.widen} --> $pt", show = true) {
303303

304304
def wrap(tycon: TypeRef) =
305305
ref(u2evt(tycon.typeSymbol.asClass)).appliedTo(tree)
@@ -350,7 +350,7 @@ object Erasure {
350350
* e -> unbox(e, PT) if `PT` is a primitive type and `e` is not of primitive type
351351
* e -> cast(e, PT) otherwise
352352
*/
353-
def adaptToType(tree: Tree, pt: Type)(implicit ctx: Context): Tree = pt match
353+
def adaptToType(tree: Tree, pt: Type)(using Context): Tree = pt match
354354
case _: FunProto | AnyFunctionProto => tree
355355
case _ => tree.tpe.widen match
356356
case mt: MethodType if tree.isTerm =>
@@ -529,15 +529,15 @@ object Erasure {
529529
class Typer(erasurePhase: DenotTransformer) extends typer.ReTyper with NoChecking {
530530
import Boxing._
531531

532-
def isErased(tree: Tree)(implicit ctx: Context): Boolean = tree match {
532+
def isErased(tree: Tree)(using Context): Boolean = tree match {
533533
case TypeApply(Select(qual, _), _) if tree.symbol == defn.Any_typeCast =>
534534
isErased(qual)
535535
case _ => tree.symbol.isEffectivelyErased
536536
}
537537

538538
/** Check that Java statics and packages can only be used in selections.
539539
*/
540-
private def checkValue(tree: Tree, proto: Type)(implicit ctx: Context): tree.type =
540+
private def checkValue(tree: Tree, proto: Type)(using Context): tree.type =
541541
if (!proto.isInstanceOf[SelectionProto] && !proto.isInstanceOf[ApplyingProto]) then
542542
checkValue(tree)
543543
tree
@@ -549,7 +549,7 @@ object Erasure {
549549
then
550550
ctx.error(reporting.messages.JavaSymbolIsNotAValue(sym), tree.sourcePos)
551551

552-
private def checkNotErased(tree: Tree)(implicit ctx: Context): tree.type = {
552+
private def checkNotErased(tree: Tree)(using Context): tree.type = {
553553
if (!ctx.mode.is(Mode.Type)) {
554554
if (isErased(tree))
555555
ctx.error(em"${tree.symbol} is declared as erased, but is in fact used", tree.sourcePos)
@@ -566,17 +566,17 @@ object Erasure {
566566
tree
567567
}
568568

569-
def erasedDef(sym: Symbol)(implicit ctx: Context): Thicket = {
569+
def erasedDef(sym: Symbol)(using Context): Thicket = {
570570
if (sym.owner.isClass) sym.dropAfter(erasurePhase)
571571
tpd.EmptyTree
572572
}
573573

574-
def erasedType(tree: untpd.Tree)(implicit ctx: Context): Type = {
574+
def erasedType(tree: untpd.Tree)(using Context): Type = {
575575
val tp = tree.typeOpt
576576
if (tree.isTerm) erasedRef(tp) else valueErasure(tp)
577577
}
578578

579-
override def promote(tree: untpd.Tree)(implicit ctx: Context): tree.ThisTree[Type] = {
579+
override def promote(tree: untpd.Tree)(using Context): tree.ThisTree[Type] = {
580580
assert(tree.hasType)
581581
val erasedTp = erasedType(tree)
582582
ctx.log(s"promoting ${tree.show}: ${erasedTp.showWithUnderlying()}")
@@ -587,11 +587,11 @@ object Erasure {
587587
* This is not the case for [[DefDef#tpt]], [[ValDef#tpt]] and [[Typed#tpt]], they
588588
* are handled separately by [[typedDefDef]], [[typedValDef]] and [[typedTyped]].
589589
*/
590-
override def typedTypeTree(tree: untpd.TypeTree, pt: Type)(implicit ctx: Context): TypeTree =
590+
override def typedTypeTree(tree: untpd.TypeTree, pt: Type)(using Context): TypeTree =
591591
tree.withType(erasure(tree.tpe))
592592

593593
/** This override is only needed to semi-erase type ascriptions */
594-
override def typedTyped(tree: untpd.Typed, pt: Type)(implicit ctx: Context): Tree = {
594+
override def typedTyped(tree: untpd.Typed, pt: Type)(using Context): Tree = {
595595
val Typed(expr, tpt) = tree
596596
val tpt1 = tpt match {
597597
case Block(_, tpt) => tpt // erase type aliases (statements) from type block
@@ -602,15 +602,15 @@ object Erasure {
602602
assignType(untpd.cpy.Typed(tree)(expr1, tpt2), tpt2)
603603
}
604604

605-
override def typedLiteral(tree: untpd.Literal)(implicit ctx: Context): Tree =
605+
override def typedLiteral(tree: untpd.Literal)(using Context): Tree =
606606
if (tree.typeOpt.isRef(defn.UnitClass))
607607
tree.withType(tree.typeOpt)
608608
else if (tree.const.tag == Constants.ClazzTag)
609609
Literal(Constant(erasure(tree.const.typeValue)))
610610
else
611611
super.typedLiteral(tree)
612612

613-
override def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): Tree =
613+
override def typedIdent(tree: untpd.Ident, pt: Type)(using Context): Tree =
614614
checkValue(checkNotErased(super.typedIdent(tree, pt)), pt)
615615

616616
/** Type check select nodes, applying the following rewritings exhaustively
@@ -633,7 +633,7 @@ object Erasure {
633633
* e.clone -> e.clone' where clone' is Object's clone method
634634
* e.m -> e.[]m if `m` is an array operation other than `clone`.
635635
*/
636-
override def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = {
636+
override def typedSelect(tree: untpd.Select, pt: Type)(using Context): Tree = {
637637
if tree.name == nme.apply && integrateSelect(tree) then
638638
return typed(tree.qualifier, pt)
639639

@@ -717,14 +717,14 @@ object Erasure {
717717
checkValue(checkNotErased(recur(qual1)), pt)
718718
}
719719

720-
override def typedThis(tree: untpd.This)(implicit ctx: Context): Tree =
720+
override def typedThis(tree: untpd.This)(using Context): Tree =
721721
if (tree.symbol == ctx.owner.lexicallyEnclosingClass || tree.symbol.isStaticOwner) promote(tree)
722722
else {
723723
ctx.log(i"computing outer path from ${ctx.owner.ownersIterator.toList}%, % to ${tree.symbol}, encl class = ${ctx.owner.enclosingClass}")
724724
outer.path(toCls = tree.symbol)
725725
}
726726

727-
override def typedTypeApply(tree: untpd.TypeApply, pt: Type)(implicit ctx: Context): Tree = {
727+
override def typedTypeApply(tree: untpd.TypeApply, pt: Type)(using Context): Tree = {
728728
val ntree = interceptTypeApply(tree.asInstanceOf[TypeApply])(ctx.withPhase(ctx.erasurePhase)).withSpan(tree.span)
729729

730730
ntree match {
@@ -743,7 +743,7 @@ object Erasure {
743743
/** Besides normal typing, this method does uncurrying and collects parameters
744744
* to anonymous functions of arity > 22.
745745
*/
746-
override def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree =
746+
override def typedApply(tree: untpd.Apply, pt: Type)(using Context): Tree =
747747
val Apply(fun, args) = tree
748748
if fun.symbol == defn.cbnArg then
749749
typedUnadapted(args.head, pt)
@@ -794,31 +794,31 @@ object Erasure {
794794
// The following four methods take as the proto-type the erasure of the pre-existing type,
795795
// if the original proto-type is not a value type.
796796
// This makes all branches be adapted to the correct type.
797-
override def typedSeqLiteral(tree: untpd.SeqLiteral, pt: Type)(implicit ctx: Context): SeqLiteral =
797+
override def typedSeqLiteral(tree: untpd.SeqLiteral, pt: Type)(using Context): SeqLiteral =
798798
super.typedSeqLiteral(tree, erasure(tree.typeOpt))
799799
// proto type of typed seq literal is original type;
800800

801-
override def typedIf(tree: untpd.If, pt: Type)(implicit ctx: Context): Tree =
801+
override def typedIf(tree: untpd.If, pt: Type)(using Context): Tree =
802802
super.typedIf(tree, adaptProto(tree, pt))
803803

804-
override def typedMatch(tree: untpd.Match, pt: Type)(implicit ctx: Context): Tree =
804+
override def typedMatch(tree: untpd.Match, pt: Type)(using Context): Tree =
805805
super.typedMatch(tree, adaptProto(tree, pt))
806806

807-
override def typedTry(tree: untpd.Try, pt: Type)(implicit ctx: Context): Try =
807+
override def typedTry(tree: untpd.Try, pt: Type)(using Context): Try =
808808
super.typedTry(tree, adaptProto(tree, pt))
809809

810-
private def adaptProto(tree: untpd.Tree, pt: Type)(implicit ctx: Context) =
810+
private def adaptProto(tree: untpd.Tree, pt: Type)(using Context) =
811811
if (pt.isValueType) pt else
812812
if (tree.typeOpt.derivesFrom(ctx.definitions.UnitClass))
813813
tree.typeOpt
814814
else valueErasure(tree.typeOpt)
815815

816-
override def typedInlined(tree: untpd.Inlined, pt: Type)(implicit ctx: Context): Tree =
816+
override def typedInlined(tree: untpd.Inlined, pt: Type)(using Context): Tree =
817817
super.typedInlined(tree, pt) match {
818818
case tree: Inlined => Inliner.dropInlined(tree)
819819
}
820820

821-
override def typedValDef(vdef: untpd.ValDef, sym: Symbol)(implicit ctx: Context): Tree =
821+
override def typedValDef(vdef: untpd.ValDef, sym: Symbol)(using Context): Tree =
822822
if (sym.isEffectivelyErased) erasedDef(sym)
823823
else
824824
super.typedValDef(untpd.cpy.ValDef(vdef)(
@@ -828,7 +828,7 @@ object Erasure {
828828
* with more than `MaxImplementedFunctionArity` parameters to use a single
829829
* parameter of type `[]Object`.
830830
*/
831-
override def typedDefDef(ddef: untpd.DefDef, sym: Symbol)(implicit ctx: Context): Tree =
831+
override def typedDefDef(ddef: untpd.DefDef, sym: Symbol)(using Context): Tree =
832832
if sym.isEffectivelyErased || sym.name.is(BodyRetainerName) then
833833
erasedDef(sym)
834834
else
@@ -935,20 +935,20 @@ object Erasure {
935935
case stat => stat
936936
}
937937

938-
override def typedClosure(tree: untpd.Closure, pt: Type)(implicit ctx: Context): Tree = {
938+
override def typedClosure(tree: untpd.Closure, pt: Type)(using Context): Tree = {
939939
val xxl = defn.isXXLFunctionClass(tree.typeOpt.typeSymbol)
940940
var implClosure = super.typedClosure(tree, pt).asInstanceOf[Closure]
941941
if (xxl) implClosure = cpy.Closure(implClosure)(tpt = TypeTree(defn.FunctionXXLClass.typeRef))
942942
adaptClosure(implClosure)
943943
}
944944

945-
override def typedTypeDef(tdef: untpd.TypeDef, sym: Symbol)(implicit ctx: Context): Tree =
945+
override def typedTypeDef(tdef: untpd.TypeDef, sym: Symbol)(using Context): Tree =
946946
EmptyTree
947947

948-
override def typedAnnotated(tree: untpd.Annotated, pt: Type)(implicit ctx: Context): Tree =
948+
override def typedAnnotated(tree: untpd.Annotated, pt: Type)(using Context): Tree =
949949
typed(tree.arg, pt)
950950

951-
override def typedStats(stats: List[untpd.Tree], exprOwner: Symbol)(implicit ctx: Context): (List[Tree], Context) = {
951+
override def typedStats(stats: List[untpd.Tree], exprOwner: Symbol)(using Context): (List[Tree], Context) = {
952952
val stats0 = addRetainedInlineBodies(stats)(using preErasureCtx)
953953
val stats1 =
954954
if (takesBridges(ctx.owner)) new Bridges(ctx.owner.asClass, erasurePhase).add(stats0)
@@ -957,7 +957,7 @@ object Erasure {
957957
(stats2.filter(!_.isEmpty), finalCtx)
958958
}
959959

960-
override def adapt(tree: Tree, pt: Type, locked: TypeVars)(implicit ctx: Context): Tree =
960+
override def adapt(tree: Tree, pt: Type, locked: TypeVars)(using Context): Tree =
961961
trace(i"adapting ${tree.showSummary}: ${tree.tpe} to $pt", show = true) {
962962
if ctx.phase != ctx.erasurePhase && ctx.phase != ctx.erasurePhase.next then
963963
// this can happen when reading annotations loaded during erasure,
@@ -968,9 +968,9 @@ object Erasure {
968968
else adaptToType(tree, pt)
969969
}
970970

971-
override def simplify(tree: Tree, pt: Type, locked: TypeVars)(implicit ctx: Context): tree.type = tree
971+
override def simplify(tree: Tree, pt: Type, locked: TypeVars)(using Context): tree.type = tree
972972
}
973973

974-
private def takesBridges(sym: Symbol)(implicit ctx: Context): Boolean =
974+
private def takesBridges(sym: Symbol)(using Context): Boolean =
975975
sym.isClass && !sym.isOneOf(Flags.Trait | Flags.Package)
976976
}

0 commit comments

Comments
 (0)