From c0fc53a72df59976963b4ee3a5da1da5582ea202 Mon Sep 17 00:00:00 2001 From: Aggelos Biboudis Date: Thu, 30 Aug 2018 15:32:52 +0200 Subject: [PATCH 1/2] Fix #4522: add a regression test --- .../backend/jvm/InlineBytecodeTests.scala | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala b/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala index e9d99dcd7f20..e1056d385f4a 100644 --- a/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala +++ b/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala @@ -281,4 +281,51 @@ class InlineBytecodeTests extends DottyBytecodeTest { } } + + // Testing that a is not boxed + @Test def i4522 = { + val source = """class Foo { + | def fun: Int = { + | var a = 10 + | rewrite def f(arg: => Unit) = { + | a += 1 + | arg + | } + | + | f { + | return a + | } + | a + | } + |} + """.stripMargin + + checkBCode(source) { dir => + val clsIn = dir.lookupName("Foo.class", directory = false).input + val clsNode = loadClassNode(clsIn) + + val fun = getMethod(clsNode, "fun") + val instructions = instructionsFromMethod(fun) + val expected = + List( + IntOp(BIPUSH, 10) + , VarOp(ISTORE, 1) + , VarOp(ILOAD, 1) + , Op(ICONST_1) + , Op(IADD) + , VarOp(ISTORE, 1) + , VarOp(ILOAD, 1) + , Op(IRETURN) + , Label(8) + , FrameEntry(0, List(), List("java/lang/Throwable")) + , Op(ATHROW) + , Label(11) + , FrameEntry(4, List(), List("java/lang/Throwable")) + , Op(ATHROW) + ) + assert(instructions == expected, + "`f` was not properly inlined in `fun`\n" + diffInstructions(instructions, expected)) + + } + } } From 7f9b5d2c7560084dc09208b8024183de089a9622 Mon Sep 17 00:00:00 2001 From: Aggelos Biboudis Date: Fri, 31 Aug 2018 11:49:25 +0200 Subject: [PATCH 2/2] Simplify test --- .../backend/jvm/InlineBytecodeTests.scala | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala b/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala index e1056d385f4a..350735d3f1f5 100644 --- a/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala +++ b/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala @@ -285,26 +285,24 @@ class InlineBytecodeTests extends DottyBytecodeTest { // Testing that a is not boxed @Test def i4522 = { val source = """class Foo { - | def fun: Int = { - | var a = 10 - | rewrite def f(arg: => Unit) = { - | a += 1 - | arg - | } - | - | f { - | return a - | } - | a - | } - |} + | def test: Int = { + | var a = 10 + | + | rewrite def f() = { + | a += 1 + | } + | + | f() + | a + | } + |} """.stripMargin checkBCode(source) { dir => val clsIn = dir.lookupName("Foo.class", directory = false).input val clsNode = loadClassNode(clsIn) - val fun = getMethod(clsNode, "fun") + val fun = getMethod(clsNode, "test") val instructions = instructionsFromMethod(fun) val expected = List( @@ -316,12 +314,6 @@ class InlineBytecodeTests extends DottyBytecodeTest { , VarOp(ISTORE, 1) , VarOp(ILOAD, 1) , Op(IRETURN) - , Label(8) - , FrameEntry(0, List(), List("java/lang/Throwable")) - , Op(ATHROW) - , Label(11) - , FrameEntry(4, List(), List("java/lang/Throwable")) - , Op(ATHROW) ) assert(instructions == expected, "`f` was not properly inlined in `fun`\n" + diffInstructions(instructions, expected))