@@ -65,7 +65,7 @@ class ErasurePreservation extends MiniPhase {
6565 case _ => ???
6666
6767
68- def toTypeB (tp : Type , outers : List [List [Symbol ]])(using Context ): TypeB = trace.force (i " toTypeB ${tp}, ${outers}" ){ tp match
68+ def toTypeB (tp : Type , outers : List [List [Symbol ]], isConstructor : Boolean = false )(using Context ): TypeB = trace(i " toTypeB ${tp}, ${outers}" ){ tp match
6969 case tpr : TypeParamRef =>
7070 TypeB .M (outers.head.indexWhere(sym => sym.name == tpr.paramName))
7171 case tr : TypeRef if tr.symbol.isTypeParam =>
@@ -75,24 +75,40 @@ class ErasurePreservation extends MiniPhase {
7575 search(tr, depth+ 1 , outers.tail)
7676 case ind =>
7777 if depth != 0 then
78- TypeB .K (depth- 1 , ind)
78+ if isConstructor then
79+ TypeB .K (depth, ind)
80+ else
81+ TypeB .K (depth- 1 , ind)
7982 else
8083 TypeB .M (ind)
8184 search(tr, 0 , outers)
85+ case at : AppliedType if at.tycon.isRef(defn.ArrayClass ) =>
86+ TypeB .Array (toTypeB(at.args.head, outers))
8287 case _ => TypeB .None
8388 }
8489
85- def toReturnTypeB (tp : Type , sourceSym : Symbol )(using Context ): TypeB = tp match
90+ def toReturnTypeB (tp : Type , outers : List [ List [ Symbol ]] )(using Context ): TypeB = tp match
8691 case tr : TypeRef if tr.symbol.isTypeParam =>
87- ???
92+ def search (tr : TypeRef , depth : Int , outers : List [List [Symbol ]]): TypeB =
93+ outers.head.indexOf(tr.symbol) match
94+ case - 1 =>
95+ search(tr, depth+ 1 , outers.tail)
96+ case ind =>
97+ if depth != 0 then
98+ TypeB .K (depth- 1 , ind)
99+ else
100+ TypeB .M (ind)
101+ search(tr, 0 , outers)
102+ case at : AppliedType if at.tycon.isRef(defn.ArrayClass ) =>
103+ TypeB .Array (toTypeB(at.args.head, outers))
88104 case _ => TypeB .None
89105
90106
91107 /**
92108 * Return all outer type parameters that originate from a method
93109 * until we reach a class
94110 */
95- def getOuterParamss (sym : Symbol , isConstructor : Boolean )(using Context ): List [List [Symbol ]] = trace.force (i " getOuterParamss ${sym}" ) {
111+ def getOuterParamss (sym : Symbol , isConstructor : Boolean )(using Context ): List [List [Symbol ]] = trace(i " getOuterParamss ${sym}" ) {
96112 if ! sym.exists then List (List ())
97113 else if sym.isClass && isConstructor then
98114 // println(sym.typeParams)
@@ -114,18 +130,18 @@ class ErasurePreservation extends MiniPhase {
114130 params : List [Type ],
115131 resType : Type ,
116132 tyParams : List [Symbol ],
117- isConstructor : Boolean )(using Context ): Tuple3 [Int , List [TypeB ], TypeB ] = trace.force (i " methodToInfos ${params}, ${resType}" )
133+ isConstructor : Boolean )(using Context ): Tuple3 [Int , List [TypeB ], TypeB ] = trace(i " methodToInfos ${params}, ${resType}" )
118134 {
119135 var outers = getOuterParamss(ctx.owner, isConstructor)
120136 if (! isConstructor)
121137 outers = outers.head ++ tyParams :: outers.tail
122- val paramsTypeB : List [TypeB ] = params.map(tp => toTypeB(tp, outers))
123- val ret : TypeB = toTypeB(resType, outers)
138+ val paramsTypeB : List [TypeB ] = params.map(tp => toTypeB(tp, outers, isConstructor ))
139+ val ret : TypeB = toTypeB(resType, outers, isConstructor )
124140 (outers.head.length, paramsTypeB, ret)
125141 }
126142
127143
128- override def transformDefDef (tree : tpd.DefDef )(using Context ): tpd.Tree = trace.force (i " transformDefDef $tree, ${tree.tpe}, ${tree.tpe.widen}" ){
144+ override def transformDefDef (tree : tpd.DefDef )(using Context ): tpd.Tree = trace(i " transformDefDef $tree, ${tree.tpe}, ${tree.tpe.widen}" ){
129145 val tup : Tuple3 [Int , List [TypeB ], TypeB ] = tree.tpe.widen match
130146 case pt : PolyType => pt.resType match
131147 case mt : MethodType =>
@@ -134,18 +150,21 @@ class ErasurePreservation extends MiniPhase {
134150 methodToInfos(Nil , other.widenExpr, tree.symbol.paramSymss.head, tree.symbol.isConstructor)
135151 case mt : MethodType =>
136152 methodToInfos(mt.paramInfos, mt.resType, Nil , false )
137- // case tr: TypeRef => Some((0, Nil, toTypeB(tr, ctx.owner)))
138- case et : ExprType =>
139- ???
153+ // case tr: TypeRef =>
154+ // methodToInfos(Nil, tr, Nil, false)
155+ // case et: ExprType =>
156+ // ???
140157 case other =>
141- ???
158+ ( 0 , Nil , TypeB . None )
142159 val (paramCount, paramRefs, retType) = tup
143- tree.putAttachment(MethodParameterReturnType , (paramCount, paramRefs, retType))
160+ if (paramCount != 0 || paramRefs.length > 0 || retType != TypeB .None ) then
161+ tree.putAttachment(MethodParameterReturnType , (paramCount, paramRefs, retType))
144162 tree
145163 }
146164
147165 override def transformApply (tree : tpd.Apply )(using Context ): tpd.Tree = trace(i " transfromApply ${tree}" ) {
148- tree.putAttachment(InvokeReturnType , toReturnTypeB(tree.tpe, ctx.owner))
166+ val outers = getOuterParamss(ctx.owner, false )
167+ tree.putAttachment(InvokeReturnType , toReturnTypeB(tree.tpe, outers))
149168 tree
150169 }
151170
@@ -184,6 +203,7 @@ enum TypeB:
184203 case K (
185204 outer : Int ,
186205 paramNum : Int )
206+ case Array (tp : TypeB )
187207// case class TypeB(tp: Type)
188208
189209object InstructionTypeArguments extends Property .StickyKey [List [TypeA ]]
0 commit comments