From 19ab7ab10fabe7113f45063ffd2b6cc6abcc3329 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 6 Sep 2016 13:20:39 +0200 Subject: Make inline annotation @scala.inline. Drop @dotty.annotation.inline. This will inline all @inline marked methods in Scala for which a body is known (i.e. that are either compiled in the same run or have Tasty trees available). Option -Yno-inline suppresses inlining. This is needed for the moment because some @inline methods access private members or members that are otherwise inaccessible at the call-site. Also fixes some problems in Inliner - make sure type arguments to inline calls re fully defined - don't forget recursive calls in typeMap - don't forget positions in treeMap - drop dead code dealing with outer. --- test/dotc/tests.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index 9f95a30c1..a12e77918 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -156,7 +156,7 @@ class tests extends CompilerTest { .filter(_.nonEmpty) .toList - @Test def compileStdLib = compileList("compileStdLib", stdlibFiles, "-migration" :: scala2mode) + @Test def compileStdLib = compileList("compileStdLib", stdlibFiles, "-migration" :: "-Yno-inline" :: scala2mode) @Test def compileMixed = compileLine( """tests/pos/B.scala |./scala-scala/src/library/scala/collection/immutable/Seq.scala @@ -274,7 +274,7 @@ class tests extends CompilerTest { "ClassOf.scala", "CollectEntryPoints.scala", "Constructors.scala", "CrossCastAnd.scala", "CtxLazy.scala", "ElimByName.scala", "ElimErasedValueType.scala", "ElimRepeated.scala", "ElimStaticThis.scala", "Erasure.scala", "ExpandPrivate.scala", "ExpandSAMs.scala", - "ExplicitOuter.scala", "ExplicitSelf.scala", "ExtensionMethods.scala", "FirstTransform.scala", + "ExplicitOuter.scala", "ExtensionMethods.scala", "FirstTransform.scala", "Flatten.scala", "FullParameterization.scala", "FunctionalInterfaces.scala", "GetClass.scala", "Getters.scala", "InterceptedMethods.scala", "LambdaLift.scala", "LiftTry.scala", "LinkScala2ImplClasses.scala", "MacroTransform.scala", "Memoize.scala", "Mixin.scala", "MixinOps.scala", "NonLocalReturns.scala", -- cgit v1.2.3 From 215b97c22bd85fb807896fc03ffaab22c0748414 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Wed, 5 Oct 2016 18:00:38 +0200 Subject: DottyBytecodeTest: fix diffInstructions output --- test/test/DottyBytecodeTest.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/test/DottyBytecodeTest.scala b/test/test/DottyBytecodeTest.scala index f2218d4b6..dbf86bf8e 100644 --- a/test/test/DottyBytecodeTest.scala +++ b/test/test/DottyBytecodeTest.scala @@ -105,7 +105,7 @@ trait DottyBytecodeTest extends DottyTest { val a = isaPadded(line-1) val b = isbPadded(line-1) - sb append (s"""$line${" " * (lineWidth-line.toString.length)} ${if (a==b) "==" else "<>"} $a${" " * (width-a.length)} | $b""") + sb append (s"""$line${" " * (lineWidth-line.toString.length)} ${if (a==b) "==" else "<>"} $a${" " * (width-a.length)} | $b\n""") } } sb.toString -- cgit v1.2.3 From e0a14e7939eda6a7f4914831975b2ac8877696f2 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Wed, 5 Oct 2016 18:01:29 +0200 Subject: Add InlineBytecodeTests to check that inline really works --- test/test/InlineBytecodeTests.scala | 32 ++++++++++++++++++++++++++++++++ tests/pos/inlineUnit.scala | 7 ------- 2 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 test/test/InlineBytecodeTests.scala delete mode 100644 tests/pos/inlineUnit.scala (limited to 'test') diff --git a/test/test/InlineBytecodeTests.scala b/test/test/InlineBytecodeTests.scala new file mode 100644 index 000000000..f7dc35305 --- /dev/null +++ b/test/test/InlineBytecodeTests.scala @@ -0,0 +1,32 @@ +package test + +import org.junit.Assert._ +import org.junit.Test + +class InlineBytecodeTests extends DottyBytecodeTest { + import ASMConverters._ + @Test def inlineUnit = { + val source = """ + |class Foo { + | inline def foo: Int = 1 + | + | def meth1: Unit = foo + | def meth2: Unit = 1 + |} + """.stripMargin + + checkBCode(source) { dir => + val clsIn = dir.lookupName("Foo.class", directory = false).input + val clsNode = loadClassNode(clsIn) + val meth1 = getMethod(clsNode, "meth1") + val meth2 = getMethod(clsNode, "meth2") + + val instructions1 = instructionsFromMethod(meth1) + val instructions2 = instructionsFromMethod(meth2) + + assert(instructions1 == instructions2, + "`foo` was not properly inlined in `meth1`\n" + + diffInstructions(instructions1, instructions2)) + } + } +} diff --git a/tests/pos/inlineUnit.scala b/tests/pos/inlineUnit.scala deleted file mode 100644 index e4f135db7..000000000 --- a/tests/pos/inlineUnit.scala +++ /dev/null @@ -1,7 +0,0 @@ -object Test { - inline def foo: Int = 1 - - def test: Unit = { - foo - } -} -- cgit v1.2.3