From bf951ec134e8ee2fcfc28152b6d72ddb2c42b988 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Wed, 1 Jul 2015 13:53:37 +0200 Subject: Fix some tests, move others to pending/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move run/t8960 to pending It tests the serialVersionUID field on closure classes. The field doesn't exist for indyLambda closures. See https://issues.scala-lang.org/browse/SI-9373 Move some reify tests to pending They fail at runtime in GenBCode since scala is built with indyLambda enabled: java.lang.AssertionError: assertion failed: Bad superClass for trait JFunction1: class Any at scala.tools.nsc.Global.assert(Global.scala:261) at scala.tools.nsc.backend.jvm.BTypesFromSymbols.setClassInfo(BTypesFromSymbols.scala:228) Noted in https://issues.scala-lang.org/browse/SI-9374 force t6546 to GenASM - no closure elimination in GenBCode yet Noted in https://issues.scala-lang.org/browse/SI-9364. Fix or disable some tests that fail because of the old optimizer The old inliner fails more often when the library is built with indylambda. Noted in https://issues.scala-lang.org/browse/SI-9374. Example: List.foreach ➜ sandbox git:(jfun) ✗ qs -Ybackend:GenASM -optimize -Yinline-warnings Welcome to Scala version 2.12.0-20150630-220939-1cb032d806 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45). Type in expressions to have them evaluated. Type :help for more information. scala> List(1,2,3).foreach(x => x + 1) :11: warning: Could not inline required method foreach because bytecode unavailable. List(1,2,3).foreach(x => x + 1) ^ :11: warning: At the end of the day, could not inline @inline-marked method foreach List(1,2,3).foreach(x => x + 1) ^ Upate a number of tests for having indyLambda enabled The delambdafyLambdaClassNames tests was removed, there's nothing to tests with indyLambda. --- test/files/jvm/innerClassAttribute.check | 54 ------- test/files/jvm/innerClassAttribute/Classes_1.scala | 37 ++--- test/files/jvm/innerClassAttribute/Test.scala | 173 ++++----------------- test/files/jvm/javaReflection.check | 83 ---------- .../jvm/patmat_opt_ignore_underscore/test.scala | 3 + test/files/jvm/patmat_opt_no_nullcheck/test.scala | 3 + test/files/run/delambdafyLambdaClassNames.check | 1 - test/files/run/delambdafyLambdaClassNames.flags | 1 - .../files/run/delambdafyLambdaClassNames/A_1.scala | 5 - .../run/delambdafyLambdaClassNames/Test.scala | 4 - test/files/run/private-inline.check | 13 -- test/files/run/private-inline.flags | 1 - test/files/run/private-inline.scala | 52 ------- test/files/run/reify_csv.check | 10 -- test/files/run/reify_csv.scala | 36 ----- test/files/run/reify_for1.scala | 10 -- test/files/run/reify_fors_newpatmat.check | 5 - test/files/run/reify_fors_newpatmat.scala | 101 ------------ test/files/run/reify_fors_oldpatmat.check | 5 - test/files/run/reify_fors_oldpatmat.scala | 101 ------------ test/files/run/reify_newimpl_51.check | 3 - test/files/run/reify_newimpl_51.scala | 18 --- test/files/run/reify_newimpl_52.check | 3 - test/files/run/reify_newimpl_52.scala | 18 --- test/files/run/reify_properties.check | 2 - test/files/run/reify_properties.scala | 57 ------- test/files/run/reify_sort1.check | 2 - test/files/run/reify_sort1.scala | 21 --- test/files/run/repl-parens.scala | 7 + test/files/run/t3158.scala | 2 +- test/files/run/t5535.scala | 7 + test/files/run/t5789.scala | 7 + test/files/run/t6260-delambdafy.check | 2 +- test/files/run/t6260-delambdafy.flags | 1 - test/files/run/t6260c.check | 6 +- test/files/run/t6434.scala | 7 + test/files/run/t6546.flags | 2 +- test/files/run/t7008-scala-defined/Test_3.scala | 3 + test/files/run/t7747-repl.scala | 7 + test/files/run/t8960.scala | 72 --------- test/files/run/t9097.scala | 2 +- test/pending/run/private-inline.check | 13 ++ test/pending/run/private-inline.flags | 1 + test/pending/run/private-inline.scala | 52 +++++++ test/pending/run/reify_csv.check | 10 ++ test/pending/run/reify_csv.scala | 36 +++++ test/pending/run/reify_for1.scala | 10 ++ test/pending/run/reify_fors_newpatmat.check | 5 + test/pending/run/reify_fors_newpatmat.scala | 101 ++++++++++++ test/pending/run/reify_fors_oldpatmat.check | 5 + test/pending/run/reify_fors_oldpatmat.scala | 101 ++++++++++++ test/pending/run/reify_newimpl_51.check | 3 + test/pending/run/reify_newimpl_51.scala | 18 +++ test/pending/run/reify_newimpl_52.check | 3 + test/pending/run/reify_newimpl_52.scala | 18 +++ test/pending/run/reify_properties.check | 2 + test/pending/run/reify_properties.scala | 57 +++++++ test/pending/run/reify_sort1.check | 2 + test/pending/run/reify_sort1.scala | 21 +++ test/pending/run/t8960.scala | 72 +++++++++ 60 files changed, 624 insertions(+), 853 deletions(-) delete mode 100644 test/files/jvm/innerClassAttribute.check delete mode 100644 test/files/run/delambdafyLambdaClassNames.check delete mode 100644 test/files/run/delambdafyLambdaClassNames.flags delete mode 100644 test/files/run/delambdafyLambdaClassNames/A_1.scala delete mode 100644 test/files/run/delambdafyLambdaClassNames/Test.scala delete mode 100644 test/files/run/private-inline.check delete mode 100644 test/files/run/private-inline.flags delete mode 100644 test/files/run/private-inline.scala delete mode 100644 test/files/run/reify_csv.check delete mode 100644 test/files/run/reify_csv.scala delete mode 100644 test/files/run/reify_for1.scala delete mode 100644 test/files/run/reify_fors_newpatmat.check delete mode 100644 test/files/run/reify_fors_newpatmat.scala delete mode 100644 test/files/run/reify_fors_oldpatmat.check delete mode 100644 test/files/run/reify_fors_oldpatmat.scala delete mode 100644 test/files/run/reify_newimpl_51.check delete mode 100644 test/files/run/reify_newimpl_51.scala delete mode 100644 test/files/run/reify_newimpl_52.check delete mode 100644 test/files/run/reify_newimpl_52.scala delete mode 100644 test/files/run/reify_properties.check delete mode 100644 test/files/run/reify_properties.scala delete mode 100644 test/files/run/reify_sort1.check delete mode 100644 test/files/run/reify_sort1.scala delete mode 100644 test/files/run/t6260-delambdafy.flags delete mode 100644 test/files/run/t8960.scala create mode 100644 test/pending/run/private-inline.check create mode 100644 test/pending/run/private-inline.flags create mode 100644 test/pending/run/private-inline.scala create mode 100644 test/pending/run/reify_csv.check create mode 100644 test/pending/run/reify_csv.scala create mode 100644 test/pending/run/reify_for1.scala create mode 100644 test/pending/run/reify_fors_newpatmat.check create mode 100644 test/pending/run/reify_fors_newpatmat.scala create mode 100644 test/pending/run/reify_fors_oldpatmat.check create mode 100644 test/pending/run/reify_fors_oldpatmat.scala create mode 100644 test/pending/run/reify_newimpl_51.check create mode 100644 test/pending/run/reify_newimpl_51.scala create mode 100644 test/pending/run/reify_newimpl_52.check create mode 100644 test/pending/run/reify_newimpl_52.scala create mode 100644 test/pending/run/reify_properties.check create mode 100644 test/pending/run/reify_properties.scala create mode 100644 test/pending/run/reify_sort1.check create mode 100644 test/pending/run/reify_sort1.scala create mode 100644 test/pending/run/t8960.scala (limited to 'test') diff --git a/test/files/jvm/innerClassAttribute.check b/test/files/jvm/innerClassAttribute.check deleted file mode 100644 index 7c697f9053..0000000000 --- a/test/files/jvm/innerClassAttribute.check +++ /dev/null @@ -1,54 +0,0 @@ -#partest -Ydelambdafy:inline --- A4 -- -A4$$anonfun$f$1 / null / null / 17 -A4$$anonfun$f$1 / null / null / 17 -A4 / f / (Lscala/collection/immutable/List;)Lscala/collection/immutable/List; --- A19 -- -A19$$anonfun$1 / null / null / 17 -A19$$anonfun$2 / null / null / 17 -A19$$anonfun$3 / null / null / 17 -A19$$anonfun$1 / null / null / 17 -A19$$anonfun$2 / null / null / 17 -A19$$anonfun$3 / null / null / 17 -A19 / null / null -A19 / null / null -A19 / null / null --- A20 -- -A20$$anonfun$4 / null / null / 17 -fun1: attribute for itself and the two child closures `() => ()` and `() => () => 1` -A20$$anonfun$4 / null / null / 17 -A20$$anonfun$4$$anonfun$apply$1 / null / null / 17 -A20$$anonfun$4$$anonfun$apply$2 / null / null / 17 -fun2 () => (): itself and the outer closure -A20$$anonfun$4 / null / null / 17 -A20$$anonfun$4$$anonfun$apply$1 / null / null / 17 -fun3 () => () => (): itself, the outer closure and its child closure -A20$$anonfun$4 / null / null / 17 -A20$$anonfun$4$$anonfun$apply$2 / null / null / 17 -A20$$anonfun$4$$anonfun$apply$2$$anonfun$apply$3 / null / null / 17 -fun4: () => 1: itself and the two outer closures -A20$$anonfun$4 / null / null / 17 -A20$$anonfun$4$$anonfun$apply$2 / null / null / 17 -A20$$anonfun$4$$anonfun$apply$2$$anonfun$apply$3 / null / null / 17 -enclosing: nested closures have outer class defined, but no outer method -A20 / null / null -A20$$anonfun$4 / null / null -A20$$anonfun$4 / null / null -A20$$anonfun$4$$anonfun$apply$2 / null / null -#partest !-Ydelambdafy:inline --- A4 -- -null / null / null --- A19 -- -null / null / null -null / null / null -null / null / null --- A20 -- -fun1: attribute for itself and the two child closures `() => ()` and `() => () => 1` -fun2 () => (): itself and the outer closure -fun3 () => () => (): itself, the outer closure and its child closure -fun4: () => 1: itself and the two outer closures -enclosing: nested closures have outer class defined, but no outer method -null / null / null -null / null / null -null / null / null -null / null / null diff --git a/test/files/jvm/innerClassAttribute/Classes_1.scala b/test/files/jvm/innerClassAttribute/Classes_1.scala index 62c7d94d90..2b690bdd7b 100644 --- a/test/files/jvm/innerClassAttribute/Classes_1.scala +++ b/test/files/jvm/innerClassAttribute/Classes_1.scala @@ -187,41 +187,30 @@ trait A24 extends A24Base { } class SI_9105 { - // the EnclosingMethod attributes depend on the delambdafy strategy (inline vs method) - - // outerClass-inline enclMeth-inline outerClass-method enclMeth-method + // outerClass enclMeth val fun = (s: String) => { - class A // closure null (*) SI_9105 null - def m: Object = { class B; new B } // closure m$1 SI_9105 m$1 - val f: Object = { class C; new C } // closure null (*) SI_9105 null + class A // SI_9105 null + def m: Object = { class B; new B } // SI_9105 m$1 + val f: Object = { class C; new C } // SI_9105 null } def met = (s: String) => { - class D // closure null (*) SI_9105 met - def m: Object = { class E; new E } // closure m$1 SI_9105 m$1 - val f: Object = { class F; new F } // closure null (*) SI_9105 met + class D // SI_9105 met + def m: Object = { class E; new E } // SI_9105 m$1 + val f: Object = { class F; new F } // SI_9105 met } - // (*) the originalOwner chain of A (similar for D) is: SI_9105.fun.$anonfun-value.A - // we can get to the anonfun-class (created by uncurry), but not to the apply method. - // - // for C and F, the originalOwner chain is fun.$anonfun-value.f.C. at later phases, the rawowner of f is - // an apply$sp method of the closure class. we could use that as enclosing method, but it would be unsystematic - // (A / D don't have an encl meth either), and also strange to use the $sp, which is a compilation artifact. - // So using `null` looks more like the situation in the source code: C / F are nested classes of the anon-fun, and - // there's no method in between. - def byName(op: => Any) = 0 val bnV = byName { - class G // closure null (*) SI_9105 null - def m: Object = { class H; new H } // closure m$1 SI_9105 m$1 - val f: Object = { class I; new I } // closure null (*) SI_9105 null + class G // SI_9105 null + def m: Object = { class H; new H } // SI_9105 m$1 + val f: Object = { class I; new I } // SI_9105 null "" } def bnM = byName { - class J // closure null (*) SI_9105 bnM - def m: Object = { class K; new K } // closure m$1 SI_9105 m$1 - val f: Object = { class L; new L } // closure null (*) SI_9105 bnM + class J // SI_9105 bnM + def m: Object = { class K; new K } // SI_9105 m$1 + val f: Object = { class L; new L } // SI_9105 bnM "" } } diff --git a/test/files/jvm/innerClassAttribute/Test.scala b/test/files/jvm/innerClassAttribute/Test.scala index 376b3c895b..ca50beae7f 100644 --- a/test/files/jvm/innerClassAttribute/Test.scala +++ b/test/files/jvm/innerClassAttribute/Test.scala @@ -78,9 +78,9 @@ object Test extends BytecodeTest { println(s"${e.outerClass} / ${e.name} / ${e.descriptor}") } - def lambdaClass(anonfunName: String, lambdaName: String): String = { - if (classpath.findClass(anonfunName).isDefined) anonfunName else lambdaName - } + + val methodHandlesLookup = assertMember(_: InnerClassNode, "java/lang/invoke/MethodHandles", "Lookup", flags = publicStatic | Flags.ACC_FINAL) + def testA1() = { val List(b1) = innerClassNodes("A1") @@ -109,11 +109,7 @@ object Test extends BytecodeTest { } def testA4() = { - println("-- A4 --") - printInnerClassNodes("A4") - val fun = lambdaClass("A4$$anonfun$f$1", "A4$lambda$$f$1") - printInnerClassNodes(fun) - printEnclosingMethod(fun) + testInner("A4", methodHandlesLookup) } def testA5() = { @@ -247,47 +243,11 @@ object Test extends BytecodeTest { } def testA19() = { - println("-- A19 --") - - printInnerClassNodes("A19") - - val fun1 = lambdaClass("A19$$anonfun$1", "A19$lambda$1") - val fun2 = lambdaClass("A19$$anonfun$2", "A19$lambda$2") - val fun3 = lambdaClass("A19$$anonfun$3", "A19$lambda$3") - - printInnerClassNodes(fun1) - printInnerClassNodes(fun2) - printInnerClassNodes(fun3) - - printEnclosingMethod(fun1) - printEnclosingMethod(fun2) - printEnclosingMethod(fun3) + testInner("A19", methodHandlesLookup) } def testA20() = { - println("-- A20 --") - - printInnerClassNodes("A20") - - val fun1 = lambdaClass("A20$$anonfun$4", "A20$lambda$1") - val fun2 = lambdaClass("A20$$anonfun$4$$anonfun$apply$1", "A20$lambda$$$nestedInAnonfun$5$1") - val fun3 = lambdaClass("A20$$anonfun$4$$anonfun$apply$2", "A20$lambda$$$nestedInAnonfun$5$2") - val fun4 = lambdaClass("A20$$anonfun$4$$anonfun$apply$2$$anonfun$apply$3", "A20$lambda$$$nestedInAnonfun$7$1") - - println("fun1: attribute for itself and the two child closures `() => ()` and `() => () => 1`") - printInnerClassNodes(fun1) - println("fun2 () => (): itself and the outer closure") - printInnerClassNodes(fun2) - println("fun3 () => () => (): itself, the outer closure and its child closure") - printInnerClassNodes(fun3) - println("fun4: () => 1: itself and the two outer closures") - printInnerClassNodes(fun4) - - println("enclosing: nested closures have outer class defined, but no outer method") - printEnclosingMethod(fun1) - printEnclosingMethod(fun2) - printEnclosingMethod(fun3) - printEnclosingMethod(fun4) + testInner("A20", methodHandlesLookup) } def testA21() = { @@ -337,70 +297,30 @@ object Test extends BytecodeTest { } def testSI_9105() { - val isDelambdafyMethod = classpath.findClass("SI_9105$lambda$1").isDefined - if (isDelambdafyMethod) { - assertEnclosingMethod ("SI_9105$A$3" , "SI_9105", null , null) - assertEnclosingMethod ("SI_9105$B$5" , "SI_9105", "m$1", "()Ljava/lang/Object;") - assertEnclosingMethod ("SI_9105$C$1" , "SI_9105", null , null) - assertEnclosingMethod ("SI_9105$D$1" , "SI_9105", "met", "()Lscala/Function1;") - assertEnclosingMethod ("SI_9105$E$1" , "SI_9105", "m$3", "()Ljava/lang/Object;") - assertEnclosingMethod ("SI_9105$F$1" , "SI_9105", "met", "()Lscala/Function1;") - assertNoEnclosingMethod("SI_9105$lambda$$met$1") - assertNoEnclosingMethod("SI_9105$lambda$1") - assertNoEnclosingMethod("SI_9105") - - assertLocal(innerClassNodes("SI_9105$A$3").head, "SI_9105$A$3", "A$3") - assertLocal(innerClassNodes("SI_9105$B$5").head, "SI_9105$B$5", "B$5") - assertLocal(innerClassNodes("SI_9105$C$1").head, "SI_9105$C$1", "C$1") - assertLocal(innerClassNodes("SI_9105$D$1").head, "SI_9105$D$1", "D$1") - assertLocal(innerClassNodes("SI_9105$E$1").head, "SI_9105$E$1", "E$1") - assertLocal(innerClassNodes("SI_9105$F$1").head, "SI_9105$F$1", "F$1") - - // by-name - assertEnclosingMethod("SI_9105$G$1", "SI_9105", null , null) - assertEnclosingMethod("SI_9105$H$1", "SI_9105", "m$2", "()Ljava/lang/Object;") - assertEnclosingMethod("SI_9105$I$1", "SI_9105", null , null) - assertEnclosingMethod("SI_9105$J$1", "SI_9105", "bnM", "()I") - assertEnclosingMethod("SI_9105$K$2", "SI_9105", "m$4", "()Ljava/lang/Object;") - assertEnclosingMethod("SI_9105$L$1", "SI_9105", "bnM", "()I") - - assert(innerClassNodes("SI_9105$lambda$$met$1").isEmpty) - assert(innerClassNodes("SI_9105$lambda$1").isEmpty) - assert(innerClassNodes("SI_9105").length == 12) // the 12 local classes - } else { - // comment in innerClassAttribute/Classes_1.scala explains the difference between A / C and D / F. - assertEnclosingMethod ("SI_9105$$anonfun$5$A$3" , "SI_9105$$anonfun$5" , null , null) - assertEnclosingMethod ("SI_9105$$anonfun$5$B$5" , "SI_9105$$anonfun$5" , "m$1" , "()Ljava/lang/Object;") - assertEnclosingMethod ("SI_9105$$anonfun$5$C$1" , "SI_9105$$anonfun$5" , null , null) - assertEnclosingMethod ("SI_9105$$anonfun$met$1$D$1", "SI_9105$$anonfun$met$1", null , null) - assertEnclosingMethod ("SI_9105$$anonfun$met$1$E$1", "SI_9105$$anonfun$met$1", "m$3" , "()Ljava/lang/Object;") - assertEnclosingMethod ("SI_9105$$anonfun$met$1$F$1", "SI_9105$$anonfun$met$1", null , null) - assertEnclosingMethod ("SI_9105$$anonfun$5" , "SI_9105" , null , null) - assertEnclosingMethod ("SI_9105$$anonfun$met$1" , "SI_9105" , "met" , "()Lscala/Function1;") - assertNoEnclosingMethod("SI_9105") - - assertLocal(ownInnerClassNode("SI_9105$$anonfun$5$A$3"), "SI_9105$$anonfun$5$A$3" , "A$3") - assertLocal(ownInnerClassNode("SI_9105$$anonfun$5$B$5"), "SI_9105$$anonfun$5$B$5" , "B$5") - assertLocal(ownInnerClassNode("SI_9105$$anonfun$5$C$1"), "SI_9105$$anonfun$5$C$1" , "C$1") - assertLocal(ownInnerClassNode("SI_9105$$anonfun$met$1$D$1"), "SI_9105$$anonfun$met$1$D$1", "D$1") - assertLocal(ownInnerClassNode("SI_9105$$anonfun$met$1$E$1"), "SI_9105$$anonfun$met$1$E$1", "E$1") - assertLocal(ownInnerClassNode("SI_9105$$anonfun$met$1$F$1"), "SI_9105$$anonfun$met$1$F$1", "F$1") - - // by-name - assertEnclosingMethod("SI_9105$$anonfun$6$G$1", "SI_9105$$anonfun$6", null, null) - assertEnclosingMethod("SI_9105$$anonfun$6$H$1", "SI_9105$$anonfun$6", "m$2", "()Ljava/lang/Object;") - assertEnclosingMethod("SI_9105$$anonfun$6$I$1", "SI_9105$$anonfun$6", null, null) - assertEnclosingMethod("SI_9105$$anonfun$bnM$1$J$1", "SI_9105$$anonfun$bnM$1", null, null) - assertEnclosingMethod("SI_9105$$anonfun$bnM$1$K$2", "SI_9105$$anonfun$bnM$1", "m$4", "()Ljava/lang/Object;") - assertEnclosingMethod("SI_9105$$anonfun$bnM$1$L$1", "SI_9105$$anonfun$bnM$1", null, null) - - assertAnonymous(ownInnerClassNode("SI_9105$$anonfun$5"), "SI_9105$$anonfun$5") - assertAnonymous(ownInnerClassNode("SI_9105$$anonfun$met$1"), "SI_9105$$anonfun$met$1") - - assert(innerClassNodes("SI_9105$$anonfun$5").length == 4) // itself and three of the local classes - assert(innerClassNodes("SI_9105$$anonfun$met$1").length == 4) // itself and three of the local classes - assert(innerClassNodes("SI_9105").length == 4) // the four anon funs - } + assertEnclosingMethod ("SI_9105$A$3" , "SI_9105", null , null) + assertEnclosingMethod ("SI_9105$B$5" , "SI_9105", "m$1", "()Ljava/lang/Object;") + assertEnclosingMethod ("SI_9105$C$1" , "SI_9105", null , null) + assertEnclosingMethod ("SI_9105$D$1" , "SI_9105", "met", "()Lscala/Function1;") + assertEnclosingMethod ("SI_9105$E$1" , "SI_9105", "m$3", "()Ljava/lang/Object;") + assertEnclosingMethod ("SI_9105$F$1" , "SI_9105", "met", "()Lscala/Function1;") + assertNoEnclosingMethod("SI_9105") + + assertLocal(innerClassNodes("SI_9105$A$3").head, "SI_9105$A$3", "A$3") + assertLocal(innerClassNodes("SI_9105$B$5").head, "SI_9105$B$5", "B$5") + assertLocal(innerClassNodes("SI_9105$C$1").head, "SI_9105$C$1", "C$1") + assertLocal(innerClassNodes("SI_9105$D$1").head, "SI_9105$D$1", "D$1") + assertLocal(innerClassNodes("SI_9105$E$1").head, "SI_9105$E$1", "E$1") + assertLocal(innerClassNodes("SI_9105$F$1").head, "SI_9105$F$1", "F$1") + + // by-name + assertEnclosingMethod("SI_9105$G$1", "SI_9105", null , null) + assertEnclosingMethod("SI_9105$H$1", "SI_9105", "m$2", "()Ljava/lang/Object;") + assertEnclosingMethod("SI_9105$I$1", "SI_9105", null , null) + assertEnclosingMethod("SI_9105$J$1", "SI_9105", "bnM", "()I") + assertEnclosingMethod("SI_9105$K$2", "SI_9105", "m$4", "()Ljava/lang/Object;") + assertEnclosingMethod("SI_9105$L$1", "SI_9105", "bnM", "()I") + + assert(innerClassNodes("SI_9105").length == 13) // the 12 local classes, plus MethodHandles$Lookup } def testSI_9124() { @@ -530,37 +450,8 @@ object Test extends BytecodeTest { testInner("NestedInValueClass$A$B", am, b) testInner("NestedInValueClass$A$C$2", am, c) - val isDelambdafyMethod = classpath.findClass("NestedInValueClass$A$lambda$$f$extension$1").isDefined - if (isDelambdafyMethod) { - List( - "NestedInValueClass$A$lambda$$g$2$1", - "NestedInValueClass$A$lambda$$f$extension$1", - "NestedInValueClass$A$lambda$$$nestedInAnonfun$13$1", - "NestedInValueClass$A$lambda$$NestedInValueClass$A$$$nestedInAnonfun$15$1").foreach(assertNoEnclosingMethod) - testInner("NestedInValueClass$A", a, am) - testInner("NestedInValueClass$A$", a, am, b, c) - testInner("NestedInValueClass$A$lambda$$g$2$1", am) - testInner("NestedInValueClass$A$lambda$$f$extension$1", am) - testInner("NestedInValueClass$A$lambda$$$nestedInAnonfun$13$1", am) - testInner("NestedInValueClass$A$lambda$$NestedInValueClass$A$$$nestedInAnonfun$15$1", am) - } else { - assertEnclosingMethod("NestedInValueClass$A$$anonfun$g$2$1" , "NestedInValueClass$A" , null, null) - assertEnclosingMethod("NestedInValueClass$A$$anonfun$g$2$1$$anonfun$apply$4" , "NestedInValueClass$A$$anonfun$g$2$1" , null, null) - assertEnclosingMethod("NestedInValueClass$A$$anonfun$f$extension$1" , "NestedInValueClass$A" , "f", "()Lscala/collection/immutable/List;") - assertEnclosingMethod("NestedInValueClass$A$$anonfun$f$extension$1$$anonfun$apply$5", "NestedInValueClass$A$$anonfun$f$extension$1", null, null) - - val gfun = assertAnonymous(_: I, "NestedInValueClass$A$$anonfun$g$2$1") - val ffun = assertAnonymous(_: I, "NestedInValueClass$A$$anonfun$f$extension$1") - val gfunfun = assertAnonymous(_: I, "NestedInValueClass$A$$anonfun$g$2$1$$anonfun$apply$4") - val ffunfun = assertAnonymous(_: I, "NestedInValueClass$A$$anonfun$f$extension$1$$anonfun$apply$5") - - testInner("NestedInValueClass$A", a, am, ffun, gfun) - testInner("NestedInValueClass$A$", a, am, ffun, gfun, b, c) - testInner("NestedInValueClass$A$$anonfun$g$2$1", a, am, gfun, gfunfun) - testInner("NestedInValueClass$A$$anonfun$g$2$1$$anonfun$apply$4", am, gfun, gfunfun) - testInner("NestedInValueClass$A$$anonfun$f$extension$1", a, am, ffun, ffunfun) - testInner("NestedInValueClass$A$$anonfun$f$extension$1$$anonfun$apply$5", am, ffun, ffunfun) - } + testInner("NestedInValueClass$A", a, am) + testInner("NestedInValueClass$A$", a, am, b, c, methodHandlesLookup) } def show(): Unit = { diff --git a/test/files/jvm/javaReflection.check b/test/files/jvm/javaReflection.check index 83518c7990..5f7aafe77c 100644 --- a/test/files/jvm/javaReflection.check +++ b/test/files/jvm/javaReflection.check @@ -1,86 +1,3 @@ -#partest -Ydelambdafy:inline -A$$anonfun$$lessinit$greater$1 / null (canon) / $anonfun$$lessinit$greater$1 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / class A (cls) / public A(int) (constr) / null (meth) -- properties : true (local) / false (member) -A$$anonfun$$lessinit$greater$1$$anonfun$apply$1 / null (canon) / $anonfun$apply$1 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / class A$$anonfun$$lessinit$greater$1 (cls) / null (constr) / null (meth) -- properties : true (local) / false (member) -A$$anonfun$2 / null (canon) / $anonfun$2 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / class A (cls) / null (constr) / null (meth) -- properties : true (local) / false (member) -A$$anonfun$3 / null (canon) / $anonfun$3 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / class A (cls) / null (constr) / null (meth) -- properties : true (local) / false (member) -A$$anonfun$4 / null (canon) / $anonfun$4 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / class A (cls) / null (constr) / null (meth) -- properties : true (local) / false (member) -A$$anonfun$f$1 / null (canon) / $anonfun$f$1 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / class A (cls) / null (constr) / public java.lang.Object A.f() (meth) -- properties : true (local) / false (member) -A$$anonfun$f$2 / null (canon) / $anonfun$f$2 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / class A (cls) / null (constr) / public java.lang.Object A.f() (meth) -- properties : true (local) / false (member) -A$D$$anonfun$1 / null (canon) / anonfun$1 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / class A$D$ (cls) / null (constr) / null (meth) -- properties : true (local) / false (member) -AO$$anonfun$5 / null (canon) / anonfun$5 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / class AO$ (cls) / null (constr) / null (meth) -- properties : true (local) / false (member) -AT$$anonfun$6 / null (canon) / $anonfun$6 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / interface AT (cls) / null (constr) / null (meth) -- properties : true (local) / false (member) -#partest !-Ydelambdafy:inline -A$D$lambda$1 / A$D$lambda$1 (canon) / A$D$lambda$1 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / null (cls) / null (constr) / null (meth) -- properties : false (local) / false (member) -A$lambda$$$lessinit$greater$1 / A$lambda$$$lessinit$greater$1 (canon) / A$lambda$$$lessinit$greater$1 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / null (cls) / null (constr) / null (meth) -- properties : false (local) / false (member) -A$lambda$$$nestedInAnonfun$7$1 / A$lambda$$$nestedInAnonfun$7$1 (canon) / A$lambda$$$nestedInAnonfun$7$1 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / null (cls) / null (constr) / null (meth) -- properties : false (local) / false (member) -A$lambda$$f$1 / A$lambda$$f$1 (canon) / A$lambda$$f$1 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / null (cls) / null (constr) / null (meth) -- properties : false (local) / false (member) -A$lambda$$f$2 / A$lambda$$f$2 (canon) / A$lambda$$f$2 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / null (cls) / null (constr) / null (meth) -- properties : false (local) / false (member) -A$lambda$1 / A$lambda$1 (canon) / A$lambda$1 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / null (cls) / null (constr) / null (meth) -- properties : false (local) / false (member) -A$lambda$2 / A$lambda$2 (canon) / A$lambda$2 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / null (cls) / null (constr) / null (meth) -- properties : false (local) / false (member) -A$lambda$3 / A$lambda$3 (canon) / A$lambda$3 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / null (cls) / null (constr) / null (meth) -- properties : false (local) / false (member) -AO$lambda$1 / AO$lambda$1 (canon) / AO$lambda$1 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / null (cls) / null (constr) / null (meth) -- properties : false (local) / false (member) -AT$class$lambda$1 / AT$class$lambda$1 (canon) / AT$class$lambda$1 (simple) -- declared cls: List() -- enclosing : null (declaring cls) / null (cls) / null (constr) / null (meth) -- properties : false (local) / false (member) -#partest A / A (canon) / A (simple) - declared cls: List(class A$B, interface A$C, class A$D$) - enclosing : null (declaring cls) / null (cls) / null (constr) / null (meth) diff --git a/test/files/jvm/patmat_opt_ignore_underscore/test.scala b/test/files/jvm/patmat_opt_ignore_underscore/test.scala index 6179101a7e..d6630e80a0 100644 --- a/test/files/jvm/patmat_opt_ignore_underscore/test.scala +++ b/test/files/jvm/patmat_opt_ignore_underscore/test.scala @@ -1,3 +1,6 @@ +/* + * filter: inliner warning; re-run with + */ import scala.tools.partest.BytecodeTest import scala.tools.nsc.util.JavaClassPath diff --git a/test/files/jvm/patmat_opt_no_nullcheck/test.scala b/test/files/jvm/patmat_opt_no_nullcheck/test.scala index 2927e763d5..d02c929e01 100644 --- a/test/files/jvm/patmat_opt_no_nullcheck/test.scala +++ b/test/files/jvm/patmat_opt_no_nullcheck/test.scala @@ -1,3 +1,6 @@ +/* + * filter: inliner warning; re-run with + */ import scala.tools.partest.BytecodeTest object Test extends BytecodeTest { diff --git a/test/files/run/delambdafyLambdaClassNames.check b/test/files/run/delambdafyLambdaClassNames.check deleted file mode 100644 index d425d15dd0..0000000000 --- a/test/files/run/delambdafyLambdaClassNames.check +++ /dev/null @@ -1 +0,0 @@ -A$$nestedInAnon$1$lambda$$run$1 diff --git a/test/files/run/delambdafyLambdaClassNames.flags b/test/files/run/delambdafyLambdaClassNames.flags deleted file mode 100644 index b10233d322..0000000000 --- a/test/files/run/delambdafyLambdaClassNames.flags +++ /dev/null @@ -1 +0,0 @@ --Ybackend:GenBCode -Ydelambdafy:method \ No newline at end of file diff --git a/test/files/run/delambdafyLambdaClassNames/A_1.scala b/test/files/run/delambdafyLambdaClassNames/A_1.scala deleted file mode 100644 index 10489414b7..0000000000 --- a/test/files/run/delambdafyLambdaClassNames/A_1.scala +++ /dev/null @@ -1,5 +0,0 @@ -class A { - def f = new Runnable { - def run(): Unit = List(1,2).foreach(println) - } -} diff --git a/test/files/run/delambdafyLambdaClassNames/Test.scala b/test/files/run/delambdafyLambdaClassNames/Test.scala deleted file mode 100644 index 49a397d1d2..0000000000 --- a/test/files/run/delambdafyLambdaClassNames/Test.scala +++ /dev/null @@ -1,4 +0,0 @@ -object Test extends App { - val c = Class.forName("A$$nestedInAnon$1$lambda$$run$1") - println(c.getName) -} diff --git a/test/files/run/private-inline.check b/test/files/run/private-inline.check deleted file mode 100644 index e71aec2fcf..0000000000 --- a/test/files/run/private-inline.check +++ /dev/null @@ -1,13 +0,0 @@ -private-inline.scala:24: warning: Could not inline required method wrapper1 because callee contains exception handlers / finally clause, and is invoked with non-empty operand stack. - def f1b() = identity(wrapper1(5)) - ^ -private-inline.scala:24: warning: At the end of the day, could not inline @inline-marked method wrapper1 - def f1b() = identity(wrapper1(5)) - ^ -private-inline.scala:29: warning: Could not inline required method wrapper2 because callee contains exception handlers / finally clause, and is invoked with non-empty operand stack. - def f2b() = identity(wrapper2(5)) - ^ -private-inline.scala:29: warning: At the end of the day, could not inline @inline-marked method wrapper2 - def f2b() = identity(wrapper2(5)) - ^ -20 diff --git a/test/files/run/private-inline.flags b/test/files/run/private-inline.flags deleted file mode 100644 index c550fdce16..0000000000 --- a/test/files/run/private-inline.flags +++ /dev/null @@ -1 +0,0 @@ --optimise -Yinline-warnings -Ybackend:GenASM diff --git a/test/files/run/private-inline.scala b/test/files/run/private-inline.scala deleted file mode 100644 index 60fef9efca..0000000000 --- a/test/files/run/private-inline.scala +++ /dev/null @@ -1,52 +0,0 @@ - -final class A { - private var x1 = false - var x2 = false - - // manipulates private var - @inline private def wrapper1[T](body: => T): T = { - val saved = x1 - x1 = true - try body - finally x1 = saved - } - // manipulates public var - @inline private def wrapper2[T](body: => T): T = { - val saved = x2 - x2 = true - try body - finally x2 = saved - } - - // not inlined - def f1a() = wrapper1(5) - // inlined! - def f1b() = identity(wrapper1(5)) - - // not inlined - def f2a() = wrapper2(5) - // inlined! - def f2b() = identity(wrapper2(5)) -} - -object Test { - def methodClasses = List("f1a", "f2a") map ("A$$anonfun$" + _ + "$1") - - def main(args: Array[String]): Unit = { - val a = new A - import a._ - println(f1a() + f1b() + f2a() + f2b()) - - // Don't know how else to test this: all these should have been - // inlined, so all should fail. - methodClasses foreach { clazz => - - val foundClass = ( - try Class.forName(clazz) - catch { case _: Throwable => null } - ) - - assert(foundClass == null, foundClass) - } - } -} diff --git a/test/files/run/reify_csv.check b/test/files/run/reify_csv.check deleted file mode 100644 index b56f4bb50b..0000000000 --- a/test/files/run/reify_csv.check +++ /dev/null @@ -1,10 +0,0 @@ -List(phase name, id, description) -record(parser,1,parse source into ASTs, perform simple desugaring) -record(namer,2,resolve names, attach symbols to named trees) -record(packageobjects,3,load package objects) -record(typer,4,the meat and potatoes: type the trees) -record(superaccessors,5,add super accessors in traits and nested classes) -record(pickler,6,serialize symbol tables) -record(refchecks,7,reference/override checking, translate nested objects) -record(selectiveanf,8,) -record(liftcode,9,reify trees) diff --git a/test/files/run/reify_csv.scala b/test/files/run/reify_csv.scala deleted file mode 100644 index c35624469c..0000000000 --- a/test/files/run/reify_csv.scala +++ /dev/null @@ -1,36 +0,0 @@ -import scala.reflect.runtime.universe._ -import scala.tools.reflect.Eval - -object Test extends App { - val csv = """ - | phase name; id; description - | parser; 1; parse source into ASTs, perform simple desugaring - | namer; 2; resolve names, attach symbols to named trees - |packageobjects; 3; load package objects - | typer; 4; the meat and potatoes: type the trees - |superaccessors; 5; add super accessors in traits and nested classes - | pickler; 6; serialize symbol tables - | refchecks; 7; reference/override checking, translate nested objects - | selectiveanf; 8; - | liftcode; 9; reify trees""".stripMargin.split("\n").map{_.trim()}.drop(1).toList - - val fields = csv.head.split(";").map{_.trim()}.toList - println(fields) - - reify({ - object Csv { - case class record(`phase name`: String, id: String, description: String) - - object record { - def parse(lines: List[String]) = { - lines drop(1) map { line => line.split(";", -1).toList match { - case phase$whitespace$name :: id :: description :: _ => record(phase$whitespace$name.trim(), id.trim(), description.trim()) - case _ => throw new Exception("format error") - }} - } - } - } - - Csv.record.parse(csv) foreach println - }).eval -} diff --git a/test/files/run/reify_for1.scala b/test/files/run/reify_for1.scala deleted file mode 100644 index e1f5347572..0000000000 --- a/test/files/run/reify_for1.scala +++ /dev/null @@ -1,10 +0,0 @@ -import scala.reflect.runtime.universe._ -import scala.tools.reflect.Eval - -object Test extends App { - reify { - val sumOfSquares1 = (for (i <- 1 to 100; if (i % 3 == 0)) yield Math.pow(i, 2)).sum - val sumOfSquares2 = (1 to 100).filter(_ % 3 == 0).map(Math.pow(_, 2)).sum - assert(sumOfSquares1 == sumOfSquares2) - }.eval -} \ No newline at end of file diff --git a/test/files/run/reify_fors_newpatmat.check b/test/files/run/reify_fors_newpatmat.check deleted file mode 100644 index eefddedc20..0000000000 --- a/test/files/run/reify_fors_newpatmat.check +++ /dev/null @@ -1,5 +0,0 @@ -Persons over 20: John Richard -divisors(34) = List(1, 2, 17, 34) -findNums(15) = (4,1) (5,2) (6,1) (7,4) (8,3) (8,5) (9,2) (9,4) (10,1) (10,3) (10,7) (11,2) (11,6) (11,8) (12,1) (12,5) (12,7) (13,4) (13,6) (13,10) (14,3) (14,5) (14,9) -average(List(3.5, 5.0, 4.5)) = 4.333333333333333 -scalProd(List(3.5, 5.0, 4.5), List(2.0, 1.0, 3.0)) = 25.5 diff --git a/test/files/run/reify_fors_newpatmat.scala b/test/files/run/reify_fors_newpatmat.scala deleted file mode 100644 index 6bee9538a8..0000000000 --- a/test/files/run/reify_fors_newpatmat.scala +++ /dev/null @@ -1,101 +0,0 @@ -import scala.reflect.runtime.universe._ -import scala.tools.reflect.Eval - -object Test extends App { - reify { - object Persons { - /** A list of persons. To create a list, we use Predef.List - * which takes a variable number of arguments and constructs - * a list out of them. - */ - val persons = List( - new Person("Bob", 17), - new Person("John", 40), - new Person("Richard", 68) - ) - - /** A Person class. 'val' constructor parameters become - * public members of the class. - */ - class Person(val name: String, val age: Int) - - /** Return an iterator over persons that are older than 20. - */ - def olderThan20(xs: Seq[Person]): Iterator[String] = - olderThan20(xs.iterator) - - /** Return an iterator over persons older than 20, given - * an iterator over persons. - */ - def olderThan20(xs: Iterator[Person]): Iterator[String] = { - - // The first expression is called a 'generator' and makes - // 'p' take values from 'xs'. The second expression is - // called a 'filter' and it is a boolean expression which - // selects only persons older than 20. There can be more than - // one generator and filter. The 'yield' expression is evaluated - // for each 'p' which satisfies the filters and used to assemble - // the resulting iterator - for (p <- xs if p.age > 20) yield p.name - } - } - - /** Some functions over lists of numbers which demonstrate - * the use of for comprehensions. - */ - object Numeric { - - /** Return the divisors of n. */ - def divisors(n: Int): List[Int] = - for (i <- List.range(1, n+1) if n % i == 0) yield i - - /** Is 'n' a prime number? */ - def isPrime(n: Int) = divisors(n).length == 2 - - /** Return pairs of numbers whose sum is prime. */ - def findNums(n: Int): Iterable[(Int, Int)] = { - - // a for comprehension using two generators - for (i <- 1 until n; - j <- 1 until (i-1); - if isPrime(i + j)) yield (i, j) - } - - /** Return the sum of the elements of 'xs'. */ - def sum(xs: List[Double]): Double = - xs.foldLeft(0.0) { (x, y) => x + y } - - /** Return the sum of pairwise product of the two lists. */ - def scalProd(xs: List[Double], ys: List[Double]) = - sum(for((x, y) <- xs zip ys) yield x * y); - - /** Remove duplicate elements in 'xs'. */ - def removeDuplicates[A](xs: List[A]): List[A] = - if (xs.isEmpty) - xs - else - xs.head :: removeDuplicates(for (x <- xs.tail if x != xs.head) yield x) - } - - // import all members of object 'persons' in the current scope - import Persons._ - - print("Persons over 20:") - olderThan20(persons) foreach { x => print(" " + x) } - println - - import Numeric._ - - println("divisors(34) = " + divisors(34)) - - print("findNums(15) =") - findNums(15) foreach { x => print(" " + x) } - println - - val xs = List(3.5, 5.0, 4.5) - println("average(" + xs + ") = " + sum(xs) / xs.length) - - val ys = List(2.0, 1.0, 3.0) - println("scalProd(" + xs + ", " + ys +") = " + scalProd(xs, ys)) - }.eval -} \ No newline at end of file diff --git a/test/files/run/reify_fors_oldpatmat.check b/test/files/run/reify_fors_oldpatmat.check deleted file mode 100644 index eefddedc20..0000000000 --- a/test/files/run/reify_fors_oldpatmat.check +++ /dev/null @@ -1,5 +0,0 @@ -Persons over 20: John Richard -divisors(34) = List(1, 2, 17, 34) -findNums(15) = (4,1) (5,2) (6,1) (7,4) (8,3) (8,5) (9,2) (9,4) (10,1) (10,3) (10,7) (11,2) (11,6) (11,8) (12,1) (12,5) (12,7) (13,4) (13,6) (13,10) (14,3) (14,5) (14,9) -average(List(3.5, 5.0, 4.5)) = 4.333333333333333 -scalProd(List(3.5, 5.0, 4.5), List(2.0, 1.0, 3.0)) = 25.5 diff --git a/test/files/run/reify_fors_oldpatmat.scala b/test/files/run/reify_fors_oldpatmat.scala deleted file mode 100644 index 6bee9538a8..0000000000 --- a/test/files/run/reify_fors_oldpatmat.scala +++ /dev/null @@ -1,101 +0,0 @@ -import scala.reflect.runtime.universe._ -import scala.tools.reflect.Eval - -object Test extends App { - reify { - object Persons { - /** A list of persons. To create a list, we use Predef.List - * which takes a variable number of arguments and constructs - * a list out of them. - */ - val persons = List( - new Person("Bob", 17), - new Person("John", 40), - new Person("Richard", 68) - ) - - /** A Person class. 'val' constructor parameters become - * public members of the class. - */ - class Person(val name: String, val age: Int) - - /** Return an iterator over persons that are older than 20. - */ - def olderThan20(xs: Seq[Person]): Iterator[String] = - olderThan20(xs.iterator) - - /** Return an iterator over persons older than 20, given - * an iterator over persons. - */ - def olderThan20(xs: Iterator[Person]): Iterator[String] = { - - // The first expression is called a 'generator' and makes - // 'p' take values from 'xs'. The second expression is - // called a 'filter' and it is a boolean expression which - // selects only persons older than 20. There can be more than - // one generator and filter. The 'yield' expression is evaluated - // for each 'p' which satisfies the filters and used to assemble - // the resulting iterator - for (p <- xs if p.age > 20) yield p.name - } - } - - /** Some functions over lists of numbers which demonstrate - * the use of for comprehensions. - */ - object Numeric { - - /** Return the divisors of n. */ - def divisors(n: Int): List[Int] = - for (i <- List.range(1, n+1) if n % i == 0) yield i - - /** Is 'n' a prime number? */ - def isPrime(n: Int) = divisors(n).length == 2 - - /** Return pairs of numbers whose sum is prime. */ - def findNums(n: Int): Iterable[(Int, Int)] = { - - // a for comprehension using two generators - for (i <- 1 until n; - j <- 1 until (i-1); - if isPrime(i + j)) yield (i, j) - } - - /** Return the sum of the elements of 'xs'. */ - def sum(xs: List[Double]): Double = - xs.foldLeft(0.0) { (x, y) => x + y } - - /** Return the sum of pairwise product of the two lists. */ - def scalProd(xs: List[Double], ys: List[Double]) = - sum(for((x, y) <- xs zip ys) yield x * y); - - /** Remove duplicate elements in 'xs'. */ - def removeDuplicates[A](xs: List[A]): List[A] = - if (xs.isEmpty) - xs - else - xs.head :: removeDuplicates(for (x <- xs.tail if x != xs.head) yield x) - } - - // import all members of object 'persons' in the current scope - import Persons._ - - print("Persons over 20:") - olderThan20(persons) foreach { x => print(" " + x) } - println - - import Numeric._ - - println("divisors(34) = " + divisors(34)) - - print("findNums(15) =") - findNums(15) foreach { x => print(" " + x) } - println - - val xs = List(3.5, 5.0, 4.5) - println("average(" + xs + ") = " + sum(xs) / xs.length) - - val ys = List(2.0, 1.0, 3.0) - println("scalProd(" + xs + ", " + ys +") = " + scalProd(xs, ys)) - }.eval -} \ No newline at end of file diff --git a/test/files/run/reify_newimpl_51.check b/test/files/run/reify_newimpl_51.check deleted file mode 100644 index 9a4ddeacd3..0000000000 --- a/test/files/run/reify_newimpl_51.check +++ /dev/null @@ -1,3 +0,0 @@ -2 -1 -2 \ No newline at end of file diff --git a/test/files/run/reify_newimpl_51.scala b/test/files/run/reify_newimpl_51.scala deleted file mode 100644 index f823bf4033..0000000000 --- a/test/files/run/reify_newimpl_51.scala +++ /dev/null @@ -1,18 +0,0 @@ -import scala.reflect.runtime.universe._ -import scala.tools.reflect.Eval - -object Test extends App { - { - var counter = 0 - lazy val x = { counter += 1; counter } - lazy val y = { counter += 1; counter } - val code = reify { - def foo = y // ensures that y is the first freevar we find - val bar = reify { println(x * y) } - bar.eval - println(x) - println(y) - } - code.eval - } -} \ No newline at end of file diff --git a/test/files/run/reify_newimpl_52.check b/test/files/run/reify_newimpl_52.check deleted file mode 100644 index 9359a2b211..0000000000 --- a/test/files/run/reify_newimpl_52.check +++ /dev/null @@ -1,3 +0,0 @@ -2 -2 -1 \ No newline at end of file diff --git a/test/files/run/reify_newimpl_52.scala b/test/files/run/reify_newimpl_52.scala deleted file mode 100644 index f01199e830..0000000000 --- a/test/files/run/reify_newimpl_52.scala +++ /dev/null @@ -1,18 +0,0 @@ -import scala.reflect.runtime.universe._ -import scala.tools.reflect.Eval - -object Test extends App { - { - var counter = 0 - lazy val x = { counter += 1; counter } - lazy val y = { counter += 1; counter } - val code = reify { - def foo = y // ensures that y is the first freevar we find - val bar = reify { println(y * x) } - bar.eval - println(x) - println(y) - } - code.eval - } -} \ No newline at end of file diff --git a/test/files/run/reify_properties.check b/test/files/run/reify_properties.check deleted file mode 100644 index d769bea4b0..0000000000 --- a/test/files/run/reify_properties.check +++ /dev/null @@ -1,2 +0,0 @@ -user1: MR. ROBERT -user2: MR. BOB KUZ diff --git a/test/files/run/reify_properties.scala b/test/files/run/reify_properties.scala deleted file mode 100644 index 01a9b12a92..0000000000 --- a/test/files/run/reify_properties.scala +++ /dev/null @@ -1,57 +0,0 @@ -import scala.reflect.runtime.universe._ -import scala.tools.reflect.Eval - -object Test extends App { - reify { - /** A mutable property whose getter and setter may be customized. */ - case class Property[T](init: T) { - private var value: T = init - - /** The getter function, defaults to identity. */ - private var setter: T => T = identity[T] - - /** The setter function, defaults to identity. */ - private var getter: T => T = identity[T] - - /** Retrive the value held in this property. */ - def apply(): T = getter(value) - - /** Update the value held in this property, through the setter. */ - def update(newValue: T) = value = setter(newValue) - - /** Change the getter. */ - def get(newGetter: T => T) = { getter = newGetter; this } - - /** Change the setter */ - def set(newSetter: T => T) = { setter = newSetter; this } - } - - class User { - // Create a property with custom getter and setter - val firstname = Property("") - .get { v => v.toUpperCase() } - .set { v => "Mr. " + v } - val lastname = Property("") - - /** Scala provides syntactic sugar for calling 'apply'. Simply - * adding a list of arguments between parenthesis (in this case, - * an empty list) is translated to a call to 'apply' with those - * arguments. - */ - override def toString() = firstname() + " " + lastname() - } - - val user1 = new User - - // Syntactic sugar for 'update': an assignment is translated to a - // call to method 'update' - user1.firstname() = "Robert" - - val user2 = new User - user2.firstname() = "bob" - user2.lastname() = "KUZ" - - println("user1: " + user1) - println("user2: " + user2) - }.eval -} diff --git a/test/files/run/reify_sort1.check b/test/files/run/reify_sort1.check deleted file mode 100644 index 0d30805141..0000000000 --- a/test/files/run/reify_sort1.check +++ /dev/null @@ -1,2 +0,0 @@ -List(6, 2, 8, 5, 1) -List(1, 2, 5, 6, 8) diff --git a/test/files/run/reify_sort1.scala b/test/files/run/reify_sort1.scala deleted file mode 100644 index 6fb3cc5895..0000000000 --- a/test/files/run/reify_sort1.scala +++ /dev/null @@ -1,21 +0,0 @@ -import scala.reflect.runtime.universe._ -import scala.tools.reflect.Eval - -object Test extends App { - reify { - def sort(a: List[Int]): List[Int] = { - if (a.length < 2) - a - else { - val pivot = a(a.length / 2) - sort(a.filter(_ < pivot)) ::: - a.filter(_ == pivot) ::: - sort(a.filter(_ > pivot)) - } - } - - val xs = List(6, 2, 8, 5, 1) - println(xs) - println(sort(xs)) - }.eval -} \ No newline at end of file diff --git a/test/files/run/repl-parens.scala b/test/files/run/repl-parens.scala index e25933b1a2..43e642a806 100644 --- a/test/files/run/repl-parens.scala +++ b/test/files/run/repl-parens.scala @@ -26,4 +26,11 @@ foo(5)(10)(15)+foo(5)(10)(15) List(1) ++ List('a') """.trim + + // replace indylambda function names by + override def eval() = { + val lines = super.eval + val r = """\$\$Lambda.*""".r + lines.map(l => r.replaceAllIn(l, "")) + } } diff --git a/test/files/run/t3158.scala b/test/files/run/t3158.scala index c824b62e96..1e5ec186f5 100644 --- a/test/files/run/t3158.scala +++ b/test/files/run/t3158.scala @@ -1,6 +1,6 @@ object Test { def main(args: Array[String]) { - println(args.map(_ => foo _).deep) + println(args.map(_ => foo _).map(_ => "").deep) } def foo(xs: String*) { diff --git a/test/files/run/t5535.scala b/test/files/run/t5535.scala index 7bc12f3470..2833b9c94b 100644 --- a/test/files/run/t5535.scala +++ b/test/files/run/t5535.scala @@ -7,4 +7,11 @@ println(h()(5)) val f = h() _ println(f(10)) """ + + // replace indylambda function names by + override def eval() = { + val lines = super.eval + val r = """\$\$Lambda.*""".r + lines.map(l => r.replaceAllIn(l, "")) + } } diff --git a/test/files/run/t5789.scala b/test/files/run/t5789.scala index 461f6a4aae..2903dada48 100644 --- a/test/files/run/t5789.scala +++ b/test/files/run/t5789.scala @@ -10,5 +10,12 @@ object Test extends ReplTest { val n = 2 () => n """ + + // replace indylambda function names by + override def eval() = { + val lines = super.eval + val r = """\$\$Lambda.*""".r + lines.map(l => r.replaceAllIn(l, "")) + } } diff --git a/test/files/run/t6260-delambdafy.check b/test/files/run/t6260-delambdafy.check index b2a7bed988..2fea68afb1 100644 --- a/test/files/run/t6260-delambdafy.check +++ b/test/files/run/t6260-delambdafy.check @@ -1,4 +1,4 @@ f(C@2e) -Test$lambda$1$$apply apply +writeReplace diff --git a/test/files/run/t6260-delambdafy.flags b/test/files/run/t6260-delambdafy.flags deleted file mode 100644 index 48b438ddf8..0000000000 --- a/test/files/run/t6260-delambdafy.flags +++ /dev/null @@ -1 +0,0 @@ --Ydelambdafy:method diff --git a/test/files/run/t6260c.check b/test/files/run/t6260c.check index 1f17b1791b..388f6690d6 100644 --- a/test/files/run/t6260c.check +++ b/test/files/run/t6260c.check @@ -1,9 +1,5 @@ f(C@2e) -#partest -Ydelambdafy:inline -Test$$anonfun$$apply -#partest !-Ydelambdafy:inline -Test$lambda$1$$apply -#partest apply +writeReplace g(C@2e) diff --git a/test/files/run/t6434.scala b/test/files/run/t6434.scala index e4a4579613..6b6a783299 100644 --- a/test/files/run/t6434.scala +++ b/test/files/run/t6434.scala @@ -5,4 +5,11 @@ object Test extends ReplTest { """def f(x: => Int): Int = x f _ """ + + // replace indylambda function names by + override def eval() = { + val lines = super.eval + val r = """\$\$Lambda.*""".r + lines.map(l => r.replaceAllIn(l, "")) + } } diff --git a/test/files/run/t6546.flags b/test/files/run/t6546.flags index eb4d19bcb9..6015e7c61f 100644 --- a/test/files/run/t6546.flags +++ b/test/files/run/t6546.flags @@ -1 +1 @@ --optimise \ No newline at end of file +-Ybackend:GenASM -optimise \ No newline at end of file diff --git a/test/files/run/t7008-scala-defined/Test_3.scala b/test/files/run/t7008-scala-defined/Test_3.scala index ee7b9d9cde..26178142ab 100644 --- a/test/files/run/t7008-scala-defined/Test_3.scala +++ b/test/files/run/t7008-scala-defined/Test_3.scala @@ -1,3 +1,6 @@ +/* + * filter: inliner warning; re-run with + */ import scala.reflect.runtime.universe._ object Test extends App { diff --git a/test/files/run/t7747-repl.scala b/test/files/run/t7747-repl.scala index 141c2d9844..9b2d1c40be 100644 --- a/test/files/run/t7747-repl.scala +++ b/test/files/run/t7747-repl.scala @@ -8,6 +8,13 @@ object Test extends ReplTest { s } + // replace indylambda function names by + override def eval() = { + val lines = super.eval + val r = """\$Lambda.*""".r + lines.map(l => r.replaceAllIn(l, "")) + } + def code = """ |var x = 10 |var y = 11 diff --git a/test/files/run/t8960.scala b/test/files/run/t8960.scala deleted file mode 100644 index a58ac53d33..0000000000 --- a/test/files/run/t8960.scala +++ /dev/null @@ -1,72 +0,0 @@ -object Test extends App { - def test(o: AnyRef, sp: Boolean = false) = { - val isSpecialized = o.getClass.getSuperclass.getName contains "$sp" - val isDelambdafyMethod = o.getClass.getName contains "$lambda$" - assert( - // delambdafy:method doesn't currently emit specialized anonymous function classes - if (sp) (isSpecialized || isDelambdafyMethod) else !isSpecialized, - o.getClass.getName) - - val Some(f) = o.getClass.getDeclaredFields.find(_.getName == "serialVersionUID") - assert(f.getLong(null) == 0l) - } - - test(() => (), sp = true) - test(() => 1, sp = true) - test(() => "") - - test((x: Int) => x, sp = true) - test((x: Boolean) => x) - test((x: Int) => "") - - test((x1: Int, x2: Int) => 0d, sp = true) - test((x1: Int, x2: AnyRef) => 0d) - test((x1: Any, x2: Any) => x1) - - // scala> println((for (i <- 3 to 22) yield (for (j <- 1 to i) yield s"x$j: Int").mkString(" test((", ", ", ") => x1)")).mkString("\n")) - - test((x1: Int, x2: Int, x3: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int) => x1) - test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int) => x1) - - test({ - case x: Int => x - }: PartialFunction[Int, Int], sp = true) - - test({ - case x: Int => x - }: PartialFunction[Any, Any]) - - test({ - case x: Int => () - }: PartialFunction[Int, Unit], sp = true) - - test({ - case x: String => 1 - }: PartialFunction[String, Int]) - - test({ - case x: String => () - }: PartialFunction[String, Unit]) - - test({ - case x: String => x - }: PartialFunction[String, String]) -} diff --git a/test/files/run/t9097.scala b/test/files/run/t9097.scala index aa2b23bbac..2b5cf66a75 100644 --- a/test/files/run/t9097.scala +++ b/test/files/run/t9097.scala @@ -29,6 +29,6 @@ object Test extends StoreReporterDirectTest { assert(!storeReporter.hasErrors, message = filteredInfos map (_.msg) mkString "; ") val out = baos.toString("UTF-8") // was 2 before the fix, the two PackageDefs for a would both contain the ClassDef for the closure - assert(out.lines.count(_ contains "class hihi$1") == 1, out) + assert(out.lines.count(_ contains "def $anonfun$1(x$1: Int): String") == 1, out) } } diff --git a/test/pending/run/private-inline.check b/test/pending/run/private-inline.check new file mode 100644 index 0000000000..e71aec2fcf --- /dev/null +++ b/test/pending/run/private-inline.check @@ -0,0 +1,13 @@ +private-inline.scala:24: warning: Could not inline required method wrapper1 because callee contains exception handlers / finally clause, and is invoked with non-empty operand stack. + def f1b() = identity(wrapper1(5)) + ^ +private-inline.scala:24: warning: At the end of the day, could not inline @inline-marked method wrapper1 + def f1b() = identity(wrapper1(5)) + ^ +private-inline.scala:29: warning: Could not inline required method wrapper2 because callee contains exception handlers / finally clause, and is invoked with non-empty operand stack. + def f2b() = identity(wrapper2(5)) + ^ +private-inline.scala:29: warning: At the end of the day, could not inline @inline-marked method wrapper2 + def f2b() = identity(wrapper2(5)) + ^ +20 diff --git a/test/pending/run/private-inline.flags b/test/pending/run/private-inline.flags new file mode 100644 index 0000000000..c550fdce16 --- /dev/null +++ b/test/pending/run/private-inline.flags @@ -0,0 +1 @@ +-optimise -Yinline-warnings -Ybackend:GenASM diff --git a/test/pending/run/private-inline.scala b/test/pending/run/private-inline.scala new file mode 100644 index 0000000000..60fef9efca --- /dev/null +++ b/test/pending/run/private-inline.scala @@ -0,0 +1,52 @@ + +final class A { + private var x1 = false + var x2 = false + + // manipulates private var + @inline private def wrapper1[T](body: => T): T = { + val saved = x1 + x1 = true + try body + finally x1 = saved + } + // manipulates public var + @inline private def wrapper2[T](body: => T): T = { + val saved = x2 + x2 = true + try body + finally x2 = saved + } + + // not inlined + def f1a() = wrapper1(5) + // inlined! + def f1b() = identity(wrapper1(5)) + + // not inlined + def f2a() = wrapper2(5) + // inlined! + def f2b() = identity(wrapper2(5)) +} + +object Test { + def methodClasses = List("f1a", "f2a") map ("A$$anonfun$" + _ + "$1") + + def main(args: Array[String]): Unit = { + val a = new A + import a._ + println(f1a() + f1b() + f2a() + f2b()) + + // Don't know how else to test this: all these should have been + // inlined, so all should fail. + methodClasses foreach { clazz => + + val foundClass = ( + try Class.forName(clazz) + catch { case _: Throwable => null } + ) + + assert(foundClass == null, foundClass) + } + } +} diff --git a/test/pending/run/reify_csv.check b/test/pending/run/reify_csv.check new file mode 100644 index 0000000000..b56f4bb50b --- /dev/null +++ b/test/pending/run/reify_csv.check @@ -0,0 +1,10 @@ +List(phase name, id, description) +record(parser,1,parse source into ASTs, perform simple desugaring) +record(namer,2,resolve names, attach symbols to named trees) +record(packageobjects,3,load package objects) +record(typer,4,the meat and potatoes: type the trees) +record(superaccessors,5,add super accessors in traits and nested classes) +record(pickler,6,serialize symbol tables) +record(refchecks,7,reference/override checking, translate nested objects) +record(selectiveanf,8,) +record(liftcode,9,reify trees) diff --git a/test/pending/run/reify_csv.scala b/test/pending/run/reify_csv.scala new file mode 100644 index 0000000000..c35624469c --- /dev/null +++ b/test/pending/run/reify_csv.scala @@ -0,0 +1,36 @@ +import scala.reflect.runtime.universe._ +import scala.tools.reflect.Eval + +object Test extends App { + val csv = """ + | phase name; id; description + | parser; 1; parse source into ASTs, perform simple desugaring + | namer; 2; resolve names, attach symbols to named trees + |packageobjects; 3; load package objects + | typer; 4; the meat and potatoes: type the trees + |superaccessors; 5; add super accessors in traits and nested classes + | pickler; 6; serialize symbol tables + | refchecks; 7; reference/override checking, translate nested objects + | selectiveanf; 8; + | liftcode; 9; reify trees""".stripMargin.split("\n").map{_.trim()}.drop(1).toList + + val fields = csv.head.split(";").map{_.trim()}.toList + println(fields) + + reify({ + object Csv { + case class record(`phase name`: String, id: String, description: String) + + object record { + def parse(lines: List[String]) = { + lines drop(1) map { line => line.split(";", -1).toList match { + case phase$whitespace$name :: id :: description :: _ => record(phase$whitespace$name.trim(), id.trim(), description.trim()) + case _ => throw new Exception("format error") + }} + } + } + } + + Csv.record.parse(csv) foreach println + }).eval +} diff --git a/test/pending/run/reify_for1.scala b/test/pending/run/reify_for1.scala new file mode 100644 index 0000000000..e1f5347572 --- /dev/null +++ b/test/pending/run/reify_for1.scala @@ -0,0 +1,10 @@ +import scala.reflect.runtime.universe._ +import scala.tools.reflect.Eval + +object Test extends App { + reify { + val sumOfSquares1 = (for (i <- 1 to 100; if (i % 3 == 0)) yield Math.pow(i, 2)).sum + val sumOfSquares2 = (1 to 100).filter(_ % 3 == 0).map(Math.pow(_, 2)).sum + assert(sumOfSquares1 == sumOfSquares2) + }.eval +} \ No newline at end of file diff --git a/test/pending/run/reify_fors_newpatmat.check b/test/pending/run/reify_fors_newpatmat.check new file mode 100644 index 0000000000..eefddedc20 --- /dev/null +++ b/test/pending/run/reify_fors_newpatmat.check @@ -0,0 +1,5 @@ +Persons over 20: John Richard +divisors(34) = List(1, 2, 17, 34) +findNums(15) = (4,1) (5,2) (6,1) (7,4) (8,3) (8,5) (9,2) (9,4) (10,1) (10,3) (10,7) (11,2) (11,6) (11,8) (12,1) (12,5) (12,7) (13,4) (13,6) (13,10) (14,3) (14,5) (14,9) +average(List(3.5, 5.0, 4.5)) = 4.333333333333333 +scalProd(List(3.5, 5.0, 4.5), List(2.0, 1.0, 3.0)) = 25.5 diff --git a/test/pending/run/reify_fors_newpatmat.scala b/test/pending/run/reify_fors_newpatmat.scala new file mode 100644 index 0000000000..6bee9538a8 --- /dev/null +++ b/test/pending/run/reify_fors_newpatmat.scala @@ -0,0 +1,101 @@ +import scala.reflect.runtime.universe._ +import scala.tools.reflect.Eval + +object Test extends App { + reify { + object Persons { + /** A list of persons. To create a list, we use Predef.List + * which takes a variable number of arguments and constructs + * a list out of them. + */ + val persons = List( + new Person("Bob", 17), + new Person("John", 40), + new Person("Richard", 68) + ) + + /** A Person class. 'val' constructor parameters become + * public members of the class. + */ + class Person(val name: String, val age: Int) + + /** Return an iterator over persons that are older than 20. + */ + def olderThan20(xs: Seq[Person]): Iterator[String] = + olderThan20(xs.iterator) + + /** Return an iterator over persons older than 20, given + * an iterator over persons. + */ + def olderThan20(xs: Iterator[Person]): Iterator[String] = { + + // The first expression is called a 'generator' and makes + // 'p' take values from 'xs'. The second expression is + // called a 'filter' and it is a boolean expression which + // selects only persons older than 20. There can be more than + // one generator and filter. The 'yield' expression is evaluated + // for each 'p' which satisfies the filters and used to assemble + // the resulting iterator + for (p <- xs if p.age > 20) yield p.name + } + } + + /** Some functions over lists of numbers which demonstrate + * the use of for comprehensions. + */ + object Numeric { + + /** Return the divisors of n. */ + def divisors(n: Int): List[Int] = + for (i <- List.range(1, n+1) if n % i == 0) yield i + + /** Is 'n' a prime number? */ + def isPrime(n: Int) = divisors(n).length == 2 + + /** Return pairs of numbers whose sum is prime. */ + def findNums(n: Int): Iterable[(Int, Int)] = { + + // a for comprehension using two generators + for (i <- 1 until n; + j <- 1 until (i-1); + if isPrime(i + j)) yield (i, j) + } + + /** Return the sum of the elements of 'xs'. */ + def sum(xs: List[Double]): Double = + xs.foldLeft(0.0) { (x, y) => x + y } + + /** Return the sum of pairwise product of the two lists. */ + def scalProd(xs: List[Double], ys: List[Double]) = + sum(for((x, y) <- xs zip ys) yield x * y); + + /** Remove duplicate elements in 'xs'. */ + def removeDuplicates[A](xs: List[A]): List[A] = + if (xs.isEmpty) + xs + else + xs.head :: removeDuplicates(for (x <- xs.tail if x != xs.head) yield x) + } + + // import all members of object 'persons' in the current scope + import Persons._ + + print("Persons over 20:") + olderThan20(persons) foreach { x => print(" " + x) } + println + + import Numeric._ + + println("divisors(34) = " + divisors(34)) + + print("findNums(15) =") + findNums(15) foreach { x => print(" " + x) } + println + + val xs = List(3.5, 5.0, 4.5) + println("average(" + xs + ") = " + sum(xs) / xs.length) + + val ys = List(2.0, 1.0, 3.0) + println("scalProd(" + xs + ", " + ys +") = " + scalProd(xs, ys)) + }.eval +} \ No newline at end of file diff --git a/test/pending/run/reify_fors_oldpatmat.check b/test/pending/run/reify_fors_oldpatmat.check new file mode 100644 index 0000000000..eefddedc20 --- /dev/null +++ b/test/pending/run/reify_fors_oldpatmat.check @@ -0,0 +1,5 @@ +Persons over 20: John Richard +divisors(34) = List(1, 2, 17, 34) +findNums(15) = (4,1) (5,2) (6,1) (7,4) (8,3) (8,5) (9,2) (9,4) (10,1) (10,3) (10,7) (11,2) (11,6) (11,8) (12,1) (12,5) (12,7) (13,4) (13,6) (13,10) (14,3) (14,5) (14,9) +average(List(3.5, 5.0, 4.5)) = 4.333333333333333 +scalProd(List(3.5, 5.0, 4.5), List(2.0, 1.0, 3.0)) = 25.5 diff --git a/test/pending/run/reify_fors_oldpatmat.scala b/test/pending/run/reify_fors_oldpatmat.scala new file mode 100644 index 0000000000..6bee9538a8 --- /dev/null +++ b/test/pending/run/reify_fors_oldpatmat.scala @@ -0,0 +1,101 @@ +import scala.reflect.runtime.universe._ +import scala.tools.reflect.Eval + +object Test extends App { + reify { + object Persons { + /** A list of persons. To create a list, we use Predef.List + * which takes a variable number of arguments and constructs + * a list out of them. + */ + val persons = List( + new Person("Bob", 17), + new Person("John", 40), + new Person("Richard", 68) + ) + + /** A Person class. 'val' constructor parameters become + * public members of the class. + */ + class Person(val name: String, val age: Int) + + /** Return an iterator over persons that are older than 20. + */ + def olderThan20(xs: Seq[Person]): Iterator[String] = + olderThan20(xs.iterator) + + /** Return an iterator over persons older than 20, given + * an iterator over persons. + */ + def olderThan20(xs: Iterator[Person]): Iterator[String] = { + + // The first expression is called a 'generator' and makes + // 'p' take values from 'xs'. The second expression is + // called a 'filter' and it is a boolean expression which + // selects only persons older than 20. There can be more than + // one generator and filter. The 'yield' expression is evaluated + // for each 'p' which satisfies the filters and used to assemble + // the resulting iterator + for (p <- xs if p.age > 20) yield p.name + } + } + + /** Some functions over lists of numbers which demonstrate + * the use of for comprehensions. + */ + object Numeric { + + /** Return the divisors of n. */ + def divisors(n: Int): List[Int] = + for (i <- List.range(1, n+1) if n % i == 0) yield i + + /** Is 'n' a prime number? */ + def isPrime(n: Int) = divisors(n).length == 2 + + /** Return pairs of numbers whose sum is prime. */ + def findNums(n: Int): Iterable[(Int, Int)] = { + + // a for comprehension using two generators + for (i <- 1 until n; + j <- 1 until (i-1); + if isPrime(i + j)) yield (i, j) + } + + /** Return the sum of the elements of 'xs'. */ + def sum(xs: List[Double]): Double = + xs.foldLeft(0.0) { (x, y) => x + y } + + /** Return the sum of pairwise product of the two lists. */ + def scalProd(xs: List[Double], ys: List[Double]) = + sum(for((x, y) <- xs zip ys) yield x * y); + + /** Remove duplicate elements in 'xs'. */ + def removeDuplicates[A](xs: List[A]): List[A] = + if (xs.isEmpty) + xs + else + xs.head :: removeDuplicates(for (x <- xs.tail if x != xs.head) yield x) + } + + // import all members of object 'persons' in the current scope + import Persons._ + + print("Persons over 20:") + olderThan20(persons) foreach { x => print(" " + x) } + println + + import Numeric._ + + println("divisors(34) = " + divisors(34)) + + print("findNums(15) =") + findNums(15) foreach { x => print(" " + x) } + println + + val xs = List(3.5, 5.0, 4.5) + println("average(" + xs + ") = " + sum(xs) / xs.length) + + val ys = List(2.0, 1.0, 3.0) + println("scalProd(" + xs + ", " + ys +") = " + scalProd(xs, ys)) + }.eval +} \ No newline at end of file diff --git a/test/pending/run/reify_newimpl_51.check b/test/pending/run/reify_newimpl_51.check new file mode 100644 index 0000000000..9a4ddeacd3 --- /dev/null +++ b/test/pending/run/reify_newimpl_51.check @@ -0,0 +1,3 @@ +2 +1 +2 \ No newline at end of file diff --git a/test/pending/run/reify_newimpl_51.scala b/test/pending/run/reify_newimpl_51.scala new file mode 100644 index 0000000000..f823bf4033 --- /dev/null +++ b/test/pending/run/reify_newimpl_51.scala @@ -0,0 +1,18 @@ +import scala.reflect.runtime.universe._ +import scala.tools.reflect.Eval + +object Test extends App { + { + var counter = 0 + lazy val x = { counter += 1; counter } + lazy val y = { counter += 1; counter } + val code = reify { + def foo = y // ensures that y is the first freevar we find + val bar = reify { println(x * y) } + bar.eval + println(x) + println(y) + } + code.eval + } +} \ No newline at end of file diff --git a/test/pending/run/reify_newimpl_52.check b/test/pending/run/reify_newimpl_52.check new file mode 100644 index 0000000000..9359a2b211 --- /dev/null +++ b/test/pending/run/reify_newimpl_52.check @@ -0,0 +1,3 @@ +2 +2 +1 \ No newline at end of file diff --git a/test/pending/run/reify_newimpl_52.scala b/test/pending/run/reify_newimpl_52.scala new file mode 100644 index 0000000000..f01199e830 --- /dev/null +++ b/test/pending/run/reify_newimpl_52.scala @@ -0,0 +1,18 @@ +import scala.reflect.runtime.universe._ +import scala.tools.reflect.Eval + +object Test extends App { + { + var counter = 0 + lazy val x = { counter += 1; counter } + lazy val y = { counter += 1; counter } + val code = reify { + def foo = y // ensures that y is the first freevar we find + val bar = reify { println(y * x) } + bar.eval + println(x) + println(y) + } + code.eval + } +} \ No newline at end of file diff --git a/test/pending/run/reify_properties.check b/test/pending/run/reify_properties.check new file mode 100644 index 0000000000..d769bea4b0 --- /dev/null +++ b/test/pending/run/reify_properties.check @@ -0,0 +1,2 @@ +user1: MR. ROBERT +user2: MR. BOB KUZ diff --git a/test/pending/run/reify_properties.scala b/test/pending/run/reify_properties.scala new file mode 100644 index 0000000000..01a9b12a92 --- /dev/null +++ b/test/pending/run/reify_properties.scala @@ -0,0 +1,57 @@ +import scala.reflect.runtime.universe._ +import scala.tools.reflect.Eval + +object Test extends App { + reify { + /** A mutable property whose getter and setter may be customized. */ + case class Property[T](init: T) { + private var value: T = init + + /** The getter function, defaults to identity. */ + private var setter: T => T = identity[T] + + /** The setter function, defaults to identity. */ + private var getter: T => T = identity[T] + + /** Retrive the value held in this property. */ + def apply(): T = getter(value) + + /** Update the value held in this property, through the setter. */ + def update(newValue: T) = value = setter(newValue) + + /** Change the getter. */ + def get(newGetter: T => T) = { getter = newGetter; this } + + /** Change the setter */ + def set(newSetter: T => T) = { setter = newSetter; this } + } + + class User { + // Create a property with custom getter and setter + val firstname = Property("") + .get { v => v.toUpperCase() } + .set { v => "Mr. " + v } + val lastname = Property("") + + /** Scala provides syntactic sugar for calling 'apply'. Simply + * adding a list of arguments between parenthesis (in this case, + * an empty list) is translated to a call to 'apply' with those + * arguments. + */ + override def toString() = firstname() + " " + lastname() + } + + val user1 = new User + + // Syntactic sugar for 'update': an assignment is translated to a + // call to method 'update' + user1.firstname() = "Robert" + + val user2 = new User + user2.firstname() = "bob" + user2.lastname() = "KUZ" + + println("user1: " + user1) + println("user2: " + user2) + }.eval +} diff --git a/test/pending/run/reify_sort1.check b/test/pending/run/reify_sort1.check new file mode 100644 index 0000000000..0d30805141 --- /dev/null +++ b/test/pending/run/reify_sort1.check @@ -0,0 +1,2 @@ +List(6, 2, 8, 5, 1) +List(1, 2, 5, 6, 8) diff --git a/test/pending/run/reify_sort1.scala b/test/pending/run/reify_sort1.scala new file mode 100644 index 0000000000..6fb3cc5895 --- /dev/null +++ b/test/pending/run/reify_sort1.scala @@ -0,0 +1,21 @@ +import scala.reflect.runtime.universe._ +import scala.tools.reflect.Eval + +object Test extends App { + reify { + def sort(a: List[Int]): List[Int] = { + if (a.length < 2) + a + else { + val pivot = a(a.length / 2) + sort(a.filter(_ < pivot)) ::: + a.filter(_ == pivot) ::: + sort(a.filter(_ > pivot)) + } + } + + val xs = List(6, 2, 8, 5, 1) + println(xs) + println(sort(xs)) + }.eval +} \ No newline at end of file diff --git a/test/pending/run/t8960.scala b/test/pending/run/t8960.scala new file mode 100644 index 0000000000..a58ac53d33 --- /dev/null +++ b/test/pending/run/t8960.scala @@ -0,0 +1,72 @@ +object Test extends App { + def test(o: AnyRef, sp: Boolean = false) = { + val isSpecialized = o.getClass.getSuperclass.getName contains "$sp" + val isDelambdafyMethod = o.getClass.getName contains "$lambda$" + assert( + // delambdafy:method doesn't currently emit specialized anonymous function classes + if (sp) (isSpecialized || isDelambdafyMethod) else !isSpecialized, + o.getClass.getName) + + val Some(f) = o.getClass.getDeclaredFields.find(_.getName == "serialVersionUID") + assert(f.getLong(null) == 0l) + } + + test(() => (), sp = true) + test(() => 1, sp = true) + test(() => "") + + test((x: Int) => x, sp = true) + test((x: Boolean) => x) + test((x: Int) => "") + + test((x1: Int, x2: Int) => 0d, sp = true) + test((x1: Int, x2: AnyRef) => 0d) + test((x1: Any, x2: Any) => x1) + + // scala> println((for (i <- 3 to 22) yield (for (j <- 1 to i) yield s"x$j: Int").mkString(" test((", ", ", ") => x1)")).mkString("\n")) + + test((x1: Int, x2: Int, x3: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int) => x1) + test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int) => x1) + + test({ + case x: Int => x + }: PartialFunction[Int, Int], sp = true) + + test({ + case x: Int => x + }: PartialFunction[Any, Any]) + + test({ + case x: Int => () + }: PartialFunction[Int, Unit], sp = true) + + test({ + case x: String => 1 + }: PartialFunction[String, Int]) + + test({ + case x: String => () + }: PartialFunction[String, Unit]) + + test({ + case x: String => x + }: PartialFunction[String, String]) +} -- cgit v1.2.3