Skip to content

Commit e4dc604

Browse files
committed
WIP
1 parent 13077f7 commit e4dc604

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import core.Mode
3636
import util.Property
3737
import reporting.*
3838
import scala.annotation.tailrec
39+
import core.Annotations.*
40+
import ast.Trees.*
3941

4042
class Erasure extends Phase with DenotTransformer {
4143

@@ -926,7 +928,18 @@ object Erasure {
926928
* with more than `MaxImplementedFunctionArity` parameters to use a single
927929
* parameter of type `[]Object`.
928930
*/
929-
override def typedDefDef(ddef: untpd.DefDef, sym: Symbol)(using Context): Tree =
931+
override def typedDefDef(ddef: untpd.DefDef, sym: Symbol)(using Context): Tree = trace(i"typedDefDef $sym,"+s" ${atPhase(ctx.phaseId-1)(sym.info)}") {// Possible Annotation target
932+
atPhase(ctx.phaseId-1)(sym.info) match
933+
case pt: PolyType =>
934+
def toTypeB(tp: Type): TypeB = tp match
935+
case tpr: TypeParamRef => TypeB.M(tpr.paramNum)
936+
case _ => TypeB.None
937+
pt.resType match
938+
case mt: MethodType =>
939+
sym.addAnnotation(ErasedInfo(pt.paramInfos.size, mt.paramInfos.map(toTypeB), toTypeB(mt.resType)))
940+
case other =>
941+
sym.addAnnotation(ErasedInfo(pt.paramInfos.size, Nil, toTypeB(other.widenExpr)))
942+
case _ => ()
930943
if sym.isEffectivelyErased || sym.name.is(BodyRetainerName) then
931944
erasedDef(sym)
932945
else
@@ -970,6 +983,7 @@ object Erasure {
970983
tpt = untpd.TypedSplice(TypeTree(restpe).withSpan(ddef.tpt.span)),
971984
rhs = rhs1)
972985
super.typedDefDef(ddef1, sym)
986+
}
973987
end typedDefDef
974988

975989
/** The outer parameter definition of a constructor if it needs one */
@@ -1109,3 +1123,17 @@ object Erasure {
11091123
private def takesBridges(sym: Symbol)(using Context): Boolean =
11101124
sym.isClass && !sym.isOneOf(Flags.Trait | Flags.Package)
11111125
}
1126+
1127+
enum TypeB:
1128+
case None
1129+
case M(x: Int)
1130+
// case class TypeB(tp: Type)
1131+
1132+
class ErasedInfo(paramCount: Int, paramType: List[TypeB], returnType: TypeB) extends Annotation {
1133+
override def tree(using Context) =
1134+
tpd.New(defn.SourceFileAnnot.typeRef,
1135+
List(tpd.Literal(Constant(toString))))
1136+
1137+
override def toString =
1138+
s"$paramCount, $paramType, $returnType"
1139+
}

0 commit comments

Comments
 (0)