Skip to content

Commit e8320fa

Browse files
committed
WIP
1 parent 8eca7de commit e8320fa

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import ast.{tpd, untpd}
1919
import reporting.*
2020
import dotty.tools.dotc.transform.MegaPhase.MiniPhase
2121
import dotty.tools.dotc.util.Property
22+
import dotty.tools.dotc.cc.pathOwner
2223

2324
class ErasurePreservation extends MiniPhase with InfoTransformer {
2425

@@ -40,9 +41,21 @@ class ErasurePreservation extends MiniPhase with InfoTransformer {
4041
}
4142

4243

43-
def toTypeB(tp: Type)(using Context): TypeB = tp match
44+
def toTypeB(tp: Type)(using Context): TypeB = trace(i"toTypeB ${tp}"){ tp match
4445
case tpr: TypeParamRef => TypeB.M(tpr.paramNum)
46+
case tr: TypeRef if tr.symbol.isTypeParam =>
47+
val owner = tr.symbol.owner
48+
if owner.isClass then
49+
val ind = owner.typeParams.indexOf(tr.symbol)
50+
if ind != -1 then TypeB.K(ind) else TypeB.None
51+
else
52+
???
53+
// val ind = owner.paramSymss.headOption match
54+
// case None => assert(false, i"Got unexpected type ${tp}")
55+
// case Some(value) => value.indexWhere(tr.isRef(_))
56+
// if ind != -1 then TypeB.M(ind) else TypeB.None
4557
case _ => TypeB.None
58+
}
4659

4760
def toReturnTypeB(tp: Type)(using Context): TypeB = tp match
4861
case tr: TypeRef =>
@@ -55,16 +68,27 @@ class ErasurePreservation extends MiniPhase with InfoTransformer {
5568
case _ => TypeB.None
5669

5770

58-
override def transformInfo(tp: Type, sym: Symbol)(using Context): Type =
71+
override def transformInfo(tp: Type, sym: Symbol)(using Context): Type = trace(i"transformInfo ${tp}, ${sym}") {
5972
tp match
6073
case pt: PolyType =>
6174
pt.resType match
6275
case mt: MethodType =>
6376
sym.addAnnotation(ErasedInfo(pt.paramInfos.size, mt.paramInfos.map(toTypeB), toTypeB(mt.resType)))
6477
case other =>
6578
sym.addAnnotation(ErasedInfo(pt.paramInfos.size, Nil, toTypeB(other.widenExpr)))
66-
case _ => ()
79+
case mt: MethodType =>
80+
val params = mt.paramInfos.map(toTypeB)
81+
val ret = toTypeB(mt.resType)
82+
if (params.exists(_ != TypeB.None) || ret != TypeB.None) then
83+
sym.addAnnotation(ErasedInfo(0, params, ret))
84+
case et: ExprType =>
85+
val ret = toTypeB(et.widenExpr)
86+
if (ret != TypeB.None) then
87+
sym.addAnnotation(ErasedInfo(0, Nil, ret))
88+
()
89+
case other =>
6790
tp
91+
}
6892

6993
override def transformApply(tree: tpd.Apply)(using Context): tpd.Tree =
7094
tree.putAttachment(InvokeReturnType, toReturnTypeB(tree.tpe))
@@ -75,6 +99,10 @@ class ErasurePreservation extends MiniPhase with InfoTransformer {
7599
tree.fun.putAttachment(InstructionTypeArguments, args) // Pattern match args based on their types
76100
tree
77101

102+
// override def transformTypeDef(tree: tpd.TypeDef)(using Context): tpd.Tree =
103+
// println(s"$tree")
104+
// tree
105+
78106
}
79107

80108
object ErasurePreservation {
@@ -91,6 +119,7 @@ enum TypeA:
91119
enum TypeB:
92120
case None
93121
case M(x: Int)
122+
case K(x: Int)
94123
// case class TypeB(tp: Type)
95124

96125
object InstructionTypeArguments extends Property.StickyKey[List[TypeA]]

0 commit comments

Comments
 (0)