summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2014-01-17 20:29:33 -0800
committerAdriaan Moors <adriaan.moors@typesafe.com>2014-01-17 20:30:15 -0800
commit22ab72f3021b46435bef3437ff1d2ea3a7cc30c7 (patch)
treeeb072eefcd20d72944a0e445f5b0376df2c7e2af
parent7c0fd124a636bb0dcca236d5aaf7e799c40d6104 (diff)
parent97b9b2c06a5f562b749eb34834096118f21ca843 (diff)
downloadscala-22ab72f3021b46435bef3437ff1d2ea3a7cc30c7.tar.gz
scala-22ab72f3021b46435bef3437ff1d2ea3a7cc30c7.tar.bz2
scala-22ab72f3021b46435bef3437ff1d2ea3a7cc30c7.zip
Merge commit '97b9b2c06a' from 2.10.x into master
Check files updated: test/files/presentation/t8085*.check Conflicts: build.xml src/compiler/scala/tools/nsc/ast/parser/Parsers.scala src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala
-rw-r--r--src/asm/scala/tools/asm/MethodWriter.java7
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala6
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Scanners.scala5
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala5
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/Members.scala4
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala6
-rw-r--r--src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala6
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala7
-rw-r--r--test/files/neg/t6426.check7
-rw-r--r--test/files/neg/t6426.scala5
-rw-r--r--test/files/pos/t8062.flags1
-rw-r--r--test/files/pos/t8062/A_1.scala5
-rw-r--r--test/files/pos/t8062/B_2.scala3
-rw-r--r--test/files/presentation/t8085.check3
-rw-r--r--test/files/presentation/t8085.flags1
-rw-r--r--test/files/presentation/t8085/Test.scala27
-rw-r--r--test/files/presentation/t8085/src/nodescala/Foo.scala3
-rw-r--r--test/files/presentation/t8085/src/nodescala/NodeScalaSuite.scala10
-rw-r--r--test/files/presentation/t8085/src/nodescala/package.scala7
-rw-r--r--test/files/presentation/t8085b.check3
-rw-r--r--test/files/presentation/t8085b.flags1
-rw-r--r--test/files/presentation/t8085b/Test.scala27
-rw-r--r--test/files/presentation/t8085b/src/p1/nodescala/Foo.scala4
-rw-r--r--test/files/presentation/t8085b/src/p1/nodescala/NodeScalaSuite.scala11
-rw-r--r--test/files/presentation/t8085b/src/p1/nodescala/package.scala9
-rw-r--r--test/files/run/large_code.check3
-rw-r--r--test/files/run/large_code.scala24
27 files changed, 172 insertions, 28 deletions
diff --git a/src/asm/scala/tools/asm/MethodWriter.java b/src/asm/scala/tools/asm/MethodWriter.java
index f5fbd1e74f..87acab17c9 100644
--- a/src/asm/scala/tools/asm/MethodWriter.java
+++ b/src/asm/scala/tools/asm/MethodWriter.java
@@ -1869,7 +1869,12 @@ class MethodWriter extends MethodVisitor {
int size = 8;
if (code.length > 0) {
if (code.length > 65536) {
- throw new RuntimeException("Method code too large!");
+ String nameString = "";
+ int i = 0;
+ // find item that corresponds to the index of our name
+ while (i < cw.items.length && (cw.items[i] == null || cw.items[i].index != name)) i++;
+ if (cw.items[i] != null) nameString = cw.items[i].strVal1 +"'s ";
+ throw new RuntimeException("Method "+ nameString +"code too large!");
}
cw.newUTF8("Code");
size += 18 + code.length + 8 * handlerCount;
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 38a6170637..0728fff74f 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -1030,7 +1030,11 @@ self =>
/** Assumed (provisionally) to be TermNames. */
def ident(skipIt: Boolean): Name = (
- if (isIdent) rawIdent().encode
+ if (isIdent) {
+ val name = in.name.encode
+ in.nextToken()
+ name
+ }
else syntaxErrorOrIncompleteAnd(expectedMsg(IDENTIFIER), skipIt)(nme.ERROR)
)
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
index 32c15b04aa..8011abc1ed 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
@@ -607,10 +607,7 @@ trait Scanners extends ScannersCommon {
if (ch == '`') {
nextChar()
finishNamed(BACKQUOTED_IDENT)
- if (name.length == 0)
- syntaxError("empty quoted identifier")
- else if (name == nme.WILDCARD)
- syntaxError("wildcard invalid as backquoted identifier")
+ if (name.length == 0) syntaxError("empty quoted identifier")
}
else syntaxError("unclosed quoted identifier")
}
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index d44e7a9312..1332d01dbd 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -793,10 +793,7 @@ abstract class GenICode extends SubComponent {
case _ =>
}
ctx1.bb.emit(cm, tree.pos)
-
- if (sym == ctx1.method.symbol) {
- ctx1.method.recursive = true
- }
+ ctx1.method.updateRecursive(sym)
generatedType =
if (sym.isClassConstructor) UNIT
else toTypeKind(sym.info.resultType)
diff --git a/src/compiler/scala/tools/nsc/backend/icode/Members.scala b/src/compiler/scala/tools/nsc/backend/icode/Members.scala
index 4d1d59cd12..267fa15312 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/Members.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/Members.scala
@@ -195,6 +195,10 @@ trait Members {
this
}
+ final def updateRecursive(called: Symbol): Unit = {
+ recursive ||= (called == symbol)
+ }
+
def addLocal(l: Local): Local = findOrElse(locals)(_ == l) { locals ::= l ; l }
def addParam(p: Local): Unit =
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
index 7e1a82a155..eb40e1dbde 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
@@ -469,9 +469,9 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
}
bytecodeWriter.writeClass(label, jclassName, arr, outF)
} catch {
- case e: java.lang.RuntimeException if(e.getMessage() == "Class file too large!") =>
- // TODO check where ASM throws the equivalent of CodeSizeTooBigException
- log("Skipped class "+jclassName+" because it exceeds JVM limits (it's too big or has methods that are too long).")
+ case e: java.lang.RuntimeException if e != null && (e.getMessage contains "too large!") =>
+ reporter.error(sym.pos,
+ s"Could not write class $jclassName because it exceeds JVM code size limits. ${e.getMessage}")
}
}
diff --git a/src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala b/src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala
index 4b9e056df3..c2d0f5ccec 100644
--- a/src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala
+++ b/src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala
@@ -64,8 +64,10 @@ abstract class BrowsingLoaders extends GlobalSymbolLoaders {
addPackagePrefix(pre)
packagePrefix += ("." + name)
case Ident(name) =>
- if (packagePrefix.length != 0) packagePrefix += "."
- packagePrefix += name
+ if (name != nme.EMPTY_PACKAGE_NAME) { // mirrors logic in Namers, see createPackageSymbol
+ if (packagePrefix.length != 0) packagePrefix += "."
+ packagePrefix += name
+ }
case _ =>
throw new MalformedInput(pkg.pos.point, "illegal tree node in package prefix: "+pkg)
}
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala
index f704d8ac89..6ca2205881 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala
@@ -575,23 +575,28 @@ abstract class ICodeReader extends ClassfileParser {
case JVM.invokevirtual =>
val m = pool.getMemberSymbol(u2, static = false); size += 2
code.emit(CALL_METHOD(m, Dynamic))
+ method.updateRecursive(m)
case JVM.invokeinterface =>
val m = pool.getMemberSymbol(u2, static = false); size += 4
in.skip(2)
code.emit(CALL_METHOD(m, Dynamic))
+ // invokeinterface can't be recursive
case JVM.invokespecial =>
val m = pool.getMemberSymbol(u2, static = false); size += 2
val style = if (m.name == nme.CONSTRUCTOR || m.isPrivate) Static(onInstance = true)
else SuperCall(m.owner.name)
code.emit(CALL_METHOD(m, style))
+ method.updateRecursive(m)
case JVM.invokestatic =>
val m = pool.getMemberSymbol(u2, static = true); size += 2
if (isBox(m))
code.emit(BOX(toTypeKind(m.info.paramTypes.head)))
else if (isUnbox(m))
code.emit(UNBOX(toTypeKind(m.info.resultType)))
- else
+ else {
code.emit(CALL_METHOD(m, Static(onInstance = false)))
+ method.updateRecursive(m)
+ }
case JVM.invokedynamic =>
// TODO, this is just a place holder. A real implementation must parse the class constant entry
debuglog("Found JVM invokedynamic instructionm, inserting place holder ICode INVOKE_DYNAMIC.")
diff --git a/test/files/neg/t6426.check b/test/files/neg/t6426.check
deleted file mode 100644
index 149f74c4de..0000000000
--- a/test/files/neg/t6426.check
+++ /dev/null
@@ -1,7 +0,0 @@
-t6426.scala:4: error: wildcard invalid as backquoted identifier
- println(`_`.Buffer(0))
- ^
-t6426.scala:5: error: ')' expected but '}' found.
-}
-^
-two errors found
diff --git a/test/files/neg/t6426.scala b/test/files/neg/t6426.scala
deleted file mode 100644
index a27d18eb58..0000000000
--- a/test/files/neg/t6426.scala
+++ /dev/null
@@ -1,5 +0,0 @@
-class A {
- import collection.{mutable => _, _}
-
- println(`_`.Buffer(0))
-}
diff --git a/test/files/pos/t8062.flags b/test/files/pos/t8062.flags
new file mode 100644
index 0000000000..49d036a887
--- /dev/null
+++ b/test/files/pos/t8062.flags
@@ -0,0 +1 @@
+-optimize
diff --git a/test/files/pos/t8062/A_1.scala b/test/files/pos/t8062/A_1.scala
new file mode 100644
index 0000000000..ca0411dae8
--- /dev/null
+++ b/test/files/pos/t8062/A_1.scala
@@ -0,0 +1,5 @@
+package warmup
+
+object Warmup {
+ def filter[A](p: Any => Boolean): Any = filter[Any](p)
+}
diff --git a/test/files/pos/t8062/B_2.scala b/test/files/pos/t8062/B_2.scala
new file mode 100644
index 0000000000..f0a6761488
--- /dev/null
+++ b/test/files/pos/t8062/B_2.scala
@@ -0,0 +1,3 @@
+object Test {
+ warmup.Warmup.filter[Any](x => false)
+}
diff --git a/test/files/presentation/t8085.check b/test/files/presentation/t8085.check
new file mode 100644
index 0000000000..921ca7528b
--- /dev/null
+++ b/test/files/presentation/t8085.check
@@ -0,0 +1,3 @@
+reload: NodeScalaSuite.scala
+open package module: package object nodescala
+Test OK
diff --git a/test/files/presentation/t8085.flags b/test/files/presentation/t8085.flags
new file mode 100644
index 0000000000..ec35b223d8
--- /dev/null
+++ b/test/files/presentation/t8085.flags
@@ -0,0 +1 @@
+-sourcepath src
diff --git a/test/files/presentation/t8085/Test.scala b/test/files/presentation/t8085/Test.scala
new file mode 100644
index 0000000000..e46b7ab8c8
--- /dev/null
+++ b/test/files/presentation/t8085/Test.scala
@@ -0,0 +1,27 @@
+import scala.tools.nsc.interactive.tests.InteractiveTest
+import scala.reflect.internal.util.SourceFile
+import scala.tools.nsc.interactive.Response
+
+object Test extends InteractiveTest {
+
+ override def execute(): Unit = {
+ val src = loadSourceAndWaitUntilTypechecked("NodeScalaSuite.scala")
+ checkErrors(src)
+ }
+
+ private def loadSourceAndWaitUntilTypechecked(sourceName: String): SourceFile = {
+ val sourceFile = sourceFiles.find(_.file.name == sourceName).head
+ askReload(List(sourceFile)).get
+ askLoadedTyped(sourceFile).get
+ sourceFile
+ }
+
+ private def checkErrors(source: SourceFile): Unit = compiler.getUnitOf(source) match {
+ case Some(unit) =>
+ val problems = unit.problems.toList
+ if(problems.isEmpty) reporter.println("Test OK")
+ else problems.foreach(problem => reporter.println(problem.msg))
+
+ case None => reporter.println("No compilation unit found for " + source.file.name)
+ }
+}
diff --git a/test/files/presentation/t8085/src/nodescala/Foo.scala b/test/files/presentation/t8085/src/nodescala/Foo.scala
new file mode 100644
index 0000000000..19efdb65dd
--- /dev/null
+++ b/test/files/presentation/t8085/src/nodescala/Foo.scala
@@ -0,0 +1,3 @@
+package nodescala
+
+class Foo
diff --git a/test/files/presentation/t8085/src/nodescala/NodeScalaSuite.scala b/test/files/presentation/t8085/src/nodescala/NodeScalaSuite.scala
new file mode 100644
index 0000000000..45e43c7afb
--- /dev/null
+++ b/test/files/presentation/t8085/src/nodescala/NodeScalaSuite.scala
@@ -0,0 +1,10 @@
+package nodescala
+
+class NodeScalaSuite {
+ "".rich
+
+ // This is here only to prove that the presentation compiler is instantiated with the
+ // correct `sourcepath` value (if it wasn't, you would see a `not found: type Foo` in
+ // the test's output
+ println(new Foo())
+}
diff --git a/test/files/presentation/t8085/src/nodescala/package.scala b/test/files/presentation/t8085/src/nodescala/package.scala
new file mode 100644
index 0000000000..26fb9f08e4
--- /dev/null
+++ b/test/files/presentation/t8085/src/nodescala/package.scala
@@ -0,0 +1,7 @@
+import scala.Some // <-- if you move the import *inside* the package object, then it all works fine!!
+
+package object nodescala {
+ implicit class StringOps(val f: String) {
+ def rich = 0
+ }
+}
diff --git a/test/files/presentation/t8085b.check b/test/files/presentation/t8085b.check
new file mode 100644
index 0000000000..921ca7528b
--- /dev/null
+++ b/test/files/presentation/t8085b.check
@@ -0,0 +1,3 @@
+reload: NodeScalaSuite.scala
+open package module: package object nodescala
+Test OK
diff --git a/test/files/presentation/t8085b.flags b/test/files/presentation/t8085b.flags
new file mode 100644
index 0000000000..ec35b223d8
--- /dev/null
+++ b/test/files/presentation/t8085b.flags
@@ -0,0 +1 @@
+-sourcepath src
diff --git a/test/files/presentation/t8085b/Test.scala b/test/files/presentation/t8085b/Test.scala
new file mode 100644
index 0000000000..e46b7ab8c8
--- /dev/null
+++ b/test/files/presentation/t8085b/Test.scala
@@ -0,0 +1,27 @@
+import scala.tools.nsc.interactive.tests.InteractiveTest
+import scala.reflect.internal.util.SourceFile
+import scala.tools.nsc.interactive.Response
+
+object Test extends InteractiveTest {
+
+ override def execute(): Unit = {
+ val src = loadSourceAndWaitUntilTypechecked("NodeScalaSuite.scala")
+ checkErrors(src)
+ }
+
+ private def loadSourceAndWaitUntilTypechecked(sourceName: String): SourceFile = {
+ val sourceFile = sourceFiles.find(_.file.name == sourceName).head
+ askReload(List(sourceFile)).get
+ askLoadedTyped(sourceFile).get
+ sourceFile
+ }
+
+ private def checkErrors(source: SourceFile): Unit = compiler.getUnitOf(source) match {
+ case Some(unit) =>
+ val problems = unit.problems.toList
+ if(problems.isEmpty) reporter.println("Test OK")
+ else problems.foreach(problem => reporter.println(problem.msg))
+
+ case None => reporter.println("No compilation unit found for " + source.file.name)
+ }
+}
diff --git a/test/files/presentation/t8085b/src/p1/nodescala/Foo.scala b/test/files/presentation/t8085b/src/p1/nodescala/Foo.scala
new file mode 100644
index 0000000000..8ed1ada6b6
--- /dev/null
+++ b/test/files/presentation/t8085b/src/p1/nodescala/Foo.scala
@@ -0,0 +1,4 @@
+package p1
+package nodescala
+
+class Foo
diff --git a/test/files/presentation/t8085b/src/p1/nodescala/NodeScalaSuite.scala b/test/files/presentation/t8085b/src/p1/nodescala/NodeScalaSuite.scala
new file mode 100644
index 0000000000..f6da67bdc7
--- /dev/null
+++ b/test/files/presentation/t8085b/src/p1/nodescala/NodeScalaSuite.scala
@@ -0,0 +1,11 @@
+package p1
+package nodescala
+
+class NodeScalaSuite {
+ "".rich
+
+ // This is here only to prove that the presentation compiler is instantiated with the
+ // correct `sourcepath` value (if it wasn't, you would see a `not found: type Foo` in
+ // the test's output
+ println(new Foo())
+}
diff --git a/test/files/presentation/t8085b/src/p1/nodescala/package.scala b/test/files/presentation/t8085b/src/p1/nodescala/package.scala
new file mode 100644
index 0000000000..cc383f1bab
--- /dev/null
+++ b/test/files/presentation/t8085b/src/p1/nodescala/package.scala
@@ -0,0 +1,9 @@
+import scala.Some // <-- if you move the import *inside* the package object, then it all works fine!!
+
+package p1 {
+ package object nodescala {
+ implicit class StringOps(val f: String) {
+ def rich = 0
+ }
+ }
+}
diff --git a/test/files/run/large_code.check b/test/files/run/large_code.check
new file mode 100644
index 0000000000..6ad50967bc
--- /dev/null
+++ b/test/files/run/large_code.check
@@ -0,0 +1,3 @@
+newSource1.scala:1: error: Could not write class BigEnoughToFail because it exceeds JVM code size limits. Method tooLong's code too large!
+class BigEnoughToFail {
+ ^
diff --git a/test/files/run/large_code.scala b/test/files/run/large_code.scala
new file mode 100644
index 0000000000..f9d7f8c95b
--- /dev/null
+++ b/test/files/run/large_code.scala
@@ -0,0 +1,24 @@
+import scala.tools.partest._
+import java.io.{Console => _, _}
+
+// a cold run of partest takes about 15s for this test on my laptop
+object Test extends DirectTest {
+ override def extraSettings: String = "-usejavacp -d " + testOutput.path
+
+ // test that we hit the code size limit and error out gracefully
+ // 5958 is the magic number (2^16/11 -- each `a(1,2,3,4,5,6)` is 11 bytes of bytecode)
+ override def code
+ = s"""
+ |class BigEnoughToFail {
+ | def a(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int): Unit = {}
+ | def tooLong: Unit = {
+ | ${(1 to 5958) map (_ => "a(1,2,3,4,5,6)") mkString(";")}
+ | }
+ |}""".stripMargin.trim
+
+ override def show(): Unit = {
+ Console.withErr(System.out) {
+ compile()
+ }
+ }
+}