Skip to content

Commit 9e0f3fc

Browse files
committed
Add debug flag and adjust list access
1 parent 2566ec1 commit 9e0f3fc

File tree

2 files changed

+39
-32
lines changed

2 files changed

+39
-32
lines changed

compiler/src/dotty/tools/backend/jvm/MethodNode1.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public MethodNode1() {
6666
}
6767

6868
public void genOffsetMap(){
69-
if (!offsetMap.isEmpty()) {
69+
if (!offsetMap.isEmpty() && DEBUG) {
7070
System.out.println("already non empty");
7171
return;
7272
}
@@ -349,7 +349,7 @@ public void genOffsetMap(){
349349
}
350350

351351
public void printOffsetMap() {
352-
if (invokeReturnTypeBs.isEmpty() || instructionTypeArgTypeAs.isEmpty()) {
352+
if (invokeReturnTypeBs.isEmpty() || instructionTypeArgTypeAs.isEmpty() || !DEBUG) {
353353
return;
354354
}
355355
System.out.println("for method " + name + " offsetMap:");
@@ -362,7 +362,7 @@ public void printOffsetMap() {
362362
}
363363

364364
public void printInvokeReturnTypeBs(){
365-
if (invokeReturnTypeBs.isEmpty()) {
365+
if (invokeReturnTypeBs.isEmpty() &&!DEBUG) {
366366
return;
367367
}
368368
System.out.println("for method " + name + " invokeReturnTypeBs:");
@@ -374,7 +374,7 @@ public void printInvokeReturnTypeBs(){
374374
}
375375

376376
public void printInstructionTypeArgTypeAs(){
377-
if (instructionTypeArgTypeAs.isEmpty()) {
377+
if (instructionTypeArgTypeAs.isEmpty() || !DEBUG) {
378378
return;
379379
}
380380
System.out.println("for method " + name + " instructionTypeArgTypeAs:");
@@ -408,7 +408,7 @@ public void setAttribtues(){
408408
}
409409
if (typeBHintList.size() != 0){
410410
this.invokeReturnTypeAttribute = new InvokeReturnType(typeBHintList.size(), typeBHintList);
411-
System.out.println("invokeReturnTypeAttribute: " + invokeReturnTypeAttribute);
411+
if (DEBUG) System.out.println("invokeReturnTypeAttribute: " + invokeReturnTypeAttribute);
412412
visitAttribute(invokeReturnTypeAttribute);
413413
}
414414
List<TypeHints.TypeAHint> typeAHintList = new ArrayList<>();
@@ -425,7 +425,7 @@ public void setAttribtues(){
425425
}
426426
if (typeAHintList.size() != 0){
427427
this.instructionTypeArgumentsAttribute = new InstructionTypeArguments(typeAHintList);
428-
System.out.println("instructionTypeArgumentsAttribute: " + instructionTypeArgumentsAttribute);
428+
if (DEBUG) System.out.println("instructionTypeArgumentsAttribute: " + instructionTypeArgumentsAttribute);
429429
visitAttribute(instructionTypeArgumentsAttribute);
430430
}
431431

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

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@ class ErasurePreservation extends MiniPhase {
4242
if tr.isRef(defn.BooleanClass) then TypeA.Boolean else
4343
if tr.symbol.isTypeParam then
4444
def search(tr: TypeRef, depth: Int, outers: List[List[Symbol]]): TypeA =
45-
outers.head.indexOf(tr.symbol) match
46-
case -1 =>
47-
search(tr, depth+1, outers.tail)
48-
case ind =>
49-
if depth != 0 then
50-
TypeA.K(depth-1, ind)
51-
else
52-
TypeA.M(ind)
45+
outers.headOption match
46+
case Some(value) => value.indexOf(tr.symbol) match
47+
case -1 =>
48+
search(tr, depth+1, outers.tail)
49+
case ind =>
50+
if depth != 0 then
51+
TypeA.K(depth-1, ind)
52+
else
53+
TypeA.M(ind)
54+
case None =>
55+
TypeA.Ref
5356
search(tr, 0, outers)
5457
else TypeA.Ref
5558
case _ =>
@@ -70,17 +73,19 @@ class ErasurePreservation extends MiniPhase {
7073
TypeB.M(outers.head.indexWhere(sym => sym.name == tpr.paramName))
7174
case tr: TypeRef if tr.symbol.isTypeParam =>
7275
def search(tr: TypeRef, depth: Int, outers: List[List[Symbol]]): TypeB =
73-
outers.head.indexOf(tr.symbol) match
74-
case -1 =>
75-
search(tr, depth+1, outers.tail)
76-
case ind =>
77-
if depth != 0 then
78-
if isConstructor then
79-
TypeB.K(depth, ind)
76+
outers.headOption match
77+
case Some(value) => value.indexOf(tr.symbol) match
78+
case -1 =>
79+
search(tr, depth+1, outers.tail)
80+
case ind =>
81+
if depth != 0 then
82+
if isConstructor then
83+
TypeB.K(depth, ind)
84+
else
85+
TypeB.K(depth-1, ind)
8086
else
81-
TypeB.K(depth-1, ind)
82-
else
83-
TypeB.M(ind)
87+
TypeB.M(ind)
88+
case None => TypeB.None
8489
search(tr, 0, outers)
8590
case at: AppliedType if at.tycon.isRef(defn.ArrayClass) =>
8691
TypeB.Array(toTypeB(at.args.head, outers))
@@ -90,14 +95,16 @@ class ErasurePreservation extends MiniPhase {
9095
def toReturnTypeB(tp: Type, outers: List[List[Symbol]])(using Context): TypeB = tp match
9196
case tr: TypeRef if tr.symbol.isTypeParam =>
9297
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)
98+
outers.headOption match
99+
case Some(value) => value.indexOf(tr.symbol) match
100+
case -1 =>
101+
search(tr, depth+1, outers.tail)
102+
case ind =>
103+
if depth != 0 then
104+
TypeB.K(depth-1, ind)
105+
else
106+
TypeB.M(ind)
107+
case None => TypeB.None
101108
search(tr, 0, outers)
102109
case at: AppliedType if at.tycon.isRef(defn.ArrayClass) =>
103110
TypeB.Array(toTypeB(at.args.head, outers))

0 commit comments

Comments
 (0)