@@ -45,7 +45,7 @@ class Erasure extends Phase with DenotTransformer {
45
45
override def changesMembers : Boolean = true // the phase adds bridges
46
46
override def changesParents : Boolean = true // the phase drops Any
47
47
48
- def transform (ref : SingleDenotation )(implicit ctx : Context ): SingleDenotation = ref match {
48
+ def transform (ref : SingleDenotation )(using Context ): SingleDenotation = ref match {
49
49
case ref : SymDenotation =>
50
50
def isCompacted (sym : Symbol ) =
51
51
sym.isAnonymousFunction && {
@@ -116,12 +116,12 @@ class Erasure extends Phase with DenotTransformer {
116
116
117
117
private val eraser = new Erasure .Typer (this )
118
118
119
- def run (implicit ctx : Context ): Unit = {
119
+ def run (using Context ): Unit = {
120
120
val unit = ctx.compilationUnit
121
121
unit.tpdTree = eraser.typedExpr(unit.tpdTree)(using ctx.fresh.setTyper(eraser).setPhase(this .next))
122
122
}
123
123
124
- override def checkPostCondition (tree : tpd.Tree )(implicit ctx : Context ): Unit = {
124
+ override def checkPostCondition (tree : tpd.Tree )(using Context ): Unit = {
125
125
assertErased(tree)
126
126
tree match {
127
127
case res : tpd.This =>
@@ -143,7 +143,7 @@ class Erasure extends Phase with DenotTransformer {
143
143
* they need not be reloaded using member; this would likely fail as signatures
144
144
* may change after erasure).
145
145
*/
146
- def assertErased (tree : tpd.Tree )(implicit ctx : Context ): Unit = {
146
+ def assertErased (tree : tpd.Tree )(using Context ): Unit = {
147
147
assertErased(tree.typeOpt, tree)
148
148
if (! defn.isPolymorphicAfterErasure(tree.symbol))
149
149
assertErased(tree.typeOpt.widen, tree)
@@ -157,7 +157,7 @@ class Erasure extends Phase with DenotTransformer {
157
157
}
158
158
}
159
159
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 = {
161
161
def isAllowed (cls : Symbol , sourceName : String ) =
162
162
tp.widen.typeSymbol == cls && ctx.compilationUnit.source.file.name == sourceName
163
163
assert(isErasedType(tp) ||
@@ -207,15 +207,15 @@ object Erasure {
207
207
208
208
object Boxing :
209
209
210
- def isUnbox (sym : Symbol )(implicit ctx : Context ): Boolean =
210
+ def isUnbox (sym : Symbol )(using Context ): Boolean =
211
211
sym.name == nme.unbox && sym.owner.linkedClass.isPrimitiveValueClass
212
212
213
- def isBox (sym : Symbol )(implicit ctx : Context ): Boolean =
213
+ def isBox (sym : Symbol )(using Context ): Boolean =
214
214
sym.name == nme.box && sym.owner.linkedClass.isPrimitiveValueClass
215
215
216
- def boxMethod (cls : ClassSymbol )(implicit ctx : Context ): Symbol =
216
+ def boxMethod (cls : ClassSymbol )(using Context ): Symbol =
217
217
cls.linkedClass.info.member(nme.box).symbol
218
- def unboxMethod (cls : ClassSymbol )(implicit ctx : Context ): Symbol =
218
+ def unboxMethod (cls : ClassSymbol )(using Context ): Symbol =
219
219
cls.linkedClass.info.member(nme.unbox).symbol
220
220
221
221
/** Isf this tree is an unbox operation which can be safely removed
@@ -225,18 +225,18 @@ object Erasure {
225
225
* This is important for specialization: calls to the super constructor should not box/unbox specialized
226
226
* fields (see TupleX). (ID)
227
227
*/
228
- private def safelyRemovableUnboxArg (tree : Tree )(implicit ctx : Context ): Tree = tree match {
228
+ private def safelyRemovableUnboxArg (tree : Tree )(using Context ): Tree = tree match {
229
229
case Apply (fn, arg :: Nil )
230
230
if isUnbox(fn.symbol) && defn.ScalaBoxedClasses ().contains(arg.tpe.widen.typeSymbol) =>
231
231
arg
232
232
case _ =>
233
233
EmptyTree
234
234
}
235
235
236
- def constant (tree : Tree , const : Tree )(implicit ctx : Context ): Tree =
236
+ def constant (tree : Tree , const : Tree )(using Context ): Tree =
237
237
(if (isPureExpr(tree)) const else Block (tree :: Nil , const)).withSpan(tree.span)
238
238
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" ) {
240
240
tree.tpe.widen match {
241
241
case ErasedValueType (tycon, _) =>
242
242
New (tycon, cast(tree, underlyingOfValueClass(tycon.symbol.asClass)) :: Nil ) // todo: use adaptToType?
@@ -256,7 +256,7 @@ object Erasure {
256
256
}
257
257
}
258
258
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" ) {
260
260
pt match {
261
261
case ErasedValueType (tycon, underlying) =>
262
262
def unboxedTree (t : Tree ) =
@@ -299,7 +299,7 @@ object Erasure {
299
299
* Casts from and to ErasedValueType are special, see the explanation
300
300
* in ExtensionMethods#transform.
301
301
*/
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 ) {
303
303
304
304
def wrap (tycon : TypeRef ) =
305
305
ref(u2evt(tycon.typeSymbol.asClass)).appliedTo(tree)
@@ -350,7 +350,7 @@ object Erasure {
350
350
* e -> unbox(e, PT) if `PT` is a primitive type and `e` is not of primitive type
351
351
* e -> cast(e, PT) otherwise
352
352
*/
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
354
354
case _ : FunProto | AnyFunctionProto => tree
355
355
case _ => tree.tpe.widen match
356
356
case mt : MethodType if tree.isTerm =>
@@ -529,15 +529,15 @@ object Erasure {
529
529
class Typer (erasurePhase : DenotTransformer ) extends typer.ReTyper with NoChecking {
530
530
import Boxing ._
531
531
532
- def isErased (tree : Tree )(implicit ctx : Context ): Boolean = tree match {
532
+ def isErased (tree : Tree )(using Context ): Boolean = tree match {
533
533
case TypeApply (Select (qual, _), _) if tree.symbol == defn.Any_typeCast =>
534
534
isErased(qual)
535
535
case _ => tree.symbol.isEffectivelyErased
536
536
}
537
537
538
538
/** Check that Java statics and packages can only be used in selections.
539
539
*/
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 =
541
541
if (! proto.isInstanceOf [SelectionProto ] && ! proto.isInstanceOf [ApplyingProto ]) then
542
542
checkValue(tree)
543
543
tree
@@ -549,7 +549,7 @@ object Erasure {
549
549
then
550
550
ctx.error(reporting.messages.JavaSymbolIsNotAValue (sym), tree.sourcePos)
551
551
552
- private def checkNotErased (tree : Tree )(implicit ctx : Context ): tree.type = {
552
+ private def checkNotErased (tree : Tree )(using Context ): tree.type = {
553
553
if (! ctx.mode.is(Mode .Type )) {
554
554
if (isErased(tree))
555
555
ctx.error(em " ${tree.symbol} is declared as erased, but is in fact used " , tree.sourcePos)
@@ -566,17 +566,17 @@ object Erasure {
566
566
tree
567
567
}
568
568
569
- def erasedDef (sym : Symbol )(implicit ctx : Context ): Thicket = {
569
+ def erasedDef (sym : Symbol )(using Context ): Thicket = {
570
570
if (sym.owner.isClass) sym.dropAfter(erasurePhase)
571
571
tpd.EmptyTree
572
572
}
573
573
574
- def erasedType (tree : untpd.Tree )(implicit ctx : Context ): Type = {
574
+ def erasedType (tree : untpd.Tree )(using Context ): Type = {
575
575
val tp = tree.typeOpt
576
576
if (tree.isTerm) erasedRef(tp) else valueErasure(tp)
577
577
}
578
578
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 ] = {
580
580
assert(tree.hasType)
581
581
val erasedTp = erasedType(tree)
582
582
ctx.log(s " promoting ${tree.show}: ${erasedTp.showWithUnderlying()}" )
@@ -587,11 +587,11 @@ object Erasure {
587
587
* This is not the case for [[DefDef#tpt ]], [[ValDef#tpt ]] and [[Typed#tpt ]], they
588
588
* are handled separately by [[typedDefDef ]], [[typedValDef ]] and [[typedTyped ]].
589
589
*/
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 =
591
591
tree.withType(erasure(tree.tpe))
592
592
593
593
/** 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 = {
595
595
val Typed (expr, tpt) = tree
596
596
val tpt1 = tpt match {
597
597
case Block (_, tpt) => tpt // erase type aliases (statements) from type block
@@ -602,15 +602,15 @@ object Erasure {
602
602
assignType(untpd.cpy.Typed (tree)(expr1, tpt2), tpt2)
603
603
}
604
604
605
- override def typedLiteral (tree : untpd.Literal )(implicit ctx : Context ): Tree =
605
+ override def typedLiteral (tree : untpd.Literal )(using Context ): Tree =
606
606
if (tree.typeOpt.isRef(defn.UnitClass ))
607
607
tree.withType(tree.typeOpt)
608
608
else if (tree.const.tag == Constants .ClazzTag )
609
609
Literal (Constant (erasure(tree.const.typeValue)))
610
610
else
611
611
super .typedLiteral(tree)
612
612
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 =
614
614
checkValue(checkNotErased(super .typedIdent(tree, pt)), pt)
615
615
616
616
/** Type check select nodes, applying the following rewritings exhaustively
@@ -633,7 +633,7 @@ object Erasure {
633
633
* e.clone -> e.clone' where clone' is Object's clone method
634
634
* e.m -> e.[]m if `m` is an array operation other than `clone`.
635
635
*/
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 = {
637
637
if tree.name == nme.apply && integrateSelect(tree) then
638
638
return typed(tree.qualifier, pt)
639
639
@@ -717,14 +717,14 @@ object Erasure {
717
717
checkValue(checkNotErased(recur(qual1)), pt)
718
718
}
719
719
720
- override def typedThis (tree : untpd.This )(implicit ctx : Context ): Tree =
720
+ override def typedThis (tree : untpd.This )(using Context ): Tree =
721
721
if (tree.symbol == ctx.owner.lexicallyEnclosingClass || tree.symbol.isStaticOwner) promote(tree)
722
722
else {
723
723
ctx.log(i " computing outer path from ${ctx.owner.ownersIterator.toList}%, % to ${tree.symbol}, encl class = ${ctx.owner.enclosingClass}" )
724
724
outer.path(toCls = tree.symbol)
725
725
}
726
726
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 = {
728
728
val ntree = interceptTypeApply(tree.asInstanceOf [TypeApply ])(ctx.withPhase(ctx.erasurePhase)).withSpan(tree.span)
729
729
730
730
ntree match {
@@ -743,7 +743,7 @@ object Erasure {
743
743
/** Besides normal typing, this method does uncurrying and collects parameters
744
744
* to anonymous functions of arity > 22.
745
745
*/
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 =
747
747
val Apply (fun, args) = tree
748
748
if fun.symbol == defn.cbnArg then
749
749
typedUnadapted(args.head, pt)
@@ -794,31 +794,31 @@ object Erasure {
794
794
// The following four methods take as the proto-type the erasure of the pre-existing type,
795
795
// if the original proto-type is not a value type.
796
796
// 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 =
798
798
super .typedSeqLiteral(tree, erasure(tree.typeOpt))
799
799
// proto type of typed seq literal is original type;
800
800
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 =
802
802
super .typedIf(tree, adaptProto(tree, pt))
803
803
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 =
805
805
super .typedMatch(tree, adaptProto(tree, pt))
806
806
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 =
808
808
super .typedTry(tree, adaptProto(tree, pt))
809
809
810
- private def adaptProto (tree : untpd.Tree , pt : Type )(implicit ctx : Context ) =
810
+ private def adaptProto (tree : untpd.Tree , pt : Type )(using Context ) =
811
811
if (pt.isValueType) pt else
812
812
if (tree.typeOpt.derivesFrom(ctx.definitions.UnitClass ))
813
813
tree.typeOpt
814
814
else valueErasure(tree.typeOpt)
815
815
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 =
817
817
super .typedInlined(tree, pt) match {
818
818
case tree : Inlined => Inliner .dropInlined(tree)
819
819
}
820
820
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 =
822
822
if (sym.isEffectivelyErased) erasedDef(sym)
823
823
else
824
824
super .typedValDef(untpd.cpy.ValDef (vdef)(
@@ -828,7 +828,7 @@ object Erasure {
828
828
* with more than `MaxImplementedFunctionArity` parameters to use a single
829
829
* parameter of type `[]Object`.
830
830
*/
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 =
832
832
if sym.isEffectivelyErased || sym.name.is(BodyRetainerName ) then
833
833
erasedDef(sym)
834
834
else
@@ -935,20 +935,20 @@ object Erasure {
935
935
case stat => stat
936
936
}
937
937
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 = {
939
939
val xxl = defn.isXXLFunctionClass(tree.typeOpt.typeSymbol)
940
940
var implClosure = super .typedClosure(tree, pt).asInstanceOf [Closure ]
941
941
if (xxl) implClosure = cpy.Closure (implClosure)(tpt = TypeTree (defn.FunctionXXLClass .typeRef))
942
942
adaptClosure(implClosure)
943
943
}
944
944
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 =
946
946
EmptyTree
947
947
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 =
949
949
typed(tree.arg, pt)
950
950
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 ) = {
952
952
val stats0 = addRetainedInlineBodies(stats)(using preErasureCtx)
953
953
val stats1 =
954
954
if (takesBridges(ctx.owner)) new Bridges (ctx.owner.asClass, erasurePhase).add(stats0)
@@ -957,7 +957,7 @@ object Erasure {
957
957
(stats2.filter(! _.isEmpty), finalCtx)
958
958
}
959
959
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 =
961
961
trace(i " adapting ${tree.showSummary}: ${tree.tpe} to $pt" , show = true ) {
962
962
if ctx.phase != ctx.erasurePhase && ctx.phase != ctx.erasurePhase.next then
963
963
// this can happen when reading annotations loaded during erasure,
@@ -968,9 +968,9 @@ object Erasure {
968
968
else adaptToType(tree, pt)
969
969
}
970
970
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
972
972
}
973
973
974
- private def takesBridges (sym : Symbol )(implicit ctx : Context ): Boolean =
974
+ private def takesBridges (sym : Symbol )(using Context ): Boolean =
975
975
sym.isClass && ! sym.isOneOf(Flags .Trait | Flags .Package )
976
976
}
0 commit comments