summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-06-04 12:05:57 -0700
committerPaul Phillips <paulp@improving.org>2012-06-06 14:23:45 -0700
commit241c7606d0bf5f3209b9d549fb751dbbc5b8e514 (patch)
tree1a9ce60b92f37cf6ca58f69a7fdcaecd90e532bb /src/compiler
parenta43e070e232ce35ef14fce34458ee3ea6e823078 (diff)
downloadscala-241c7606d0bf5f3209b9d549fb751dbbc5b8e514.tar.gz
scala-241c7606d0bf5f3209b9d549fb751dbbc5b8e514.tar.bz2
scala-241c7606d0bf5f3209b9d549fb751dbbc5b8e514.zip
Generate abstract methods in scala.Byte and friends.
Rather than stub implementations. This saves over 50K of bytecode. I also added the necessary imports to silence the feature warnings.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/reflect/internal/Definitions.scala2
-rw-r--r--src/compiler/scala/tools/cmd/gen/AnyVals.scala33
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala6
3 files changed, 22 insertions, 19 deletions
diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala
index 0cdef9e79a..96819eab91 100644
--- a/src/compiler/scala/reflect/internal/Definitions.scala
+++ b/src/compiler/scala/reflect/internal/Definitions.scala
@@ -293,8 +293,6 @@ trait Definitions extends reflect.api.StandardDefinitions {
anyval
}).asInstanceOf[ClassSymbol]
- lazy val AnyVal_getClass = enterNewMethod(AnyValClass, nme.getClass_, Nil, getClassReturnType(AnyValClass.tpe))
-
// bottom types
lazy val RuntimeNothingClass = getClass(fulltpnme.RuntimeNothing)
lazy val RuntimeNullClass = getClass(fulltpnme.RuntimeNull)
diff --git a/src/compiler/scala/tools/cmd/gen/AnyVals.scala b/src/compiler/scala/tools/cmd/gen/AnyVals.scala
index 83cd9c2578..9d0795b2f6 100644
--- a/src/compiler/scala/tools/cmd/gen/AnyVals.scala
+++ b/src/compiler/scala/tools/cmd/gen/AnyVals.scala
@@ -177,7 +177,7 @@ trait AnyValReps {
case (res, lines) =>
val xs = lines map {
case "" => ""
- case s => interpolate(s) + " = " + stub
+ case s => interpolate(s)
}
res ++ xs
}
@@ -205,7 +205,7 @@ trait AnyValReps {
def classLines: List[String]
def objectLines: List[String]
def commonClassLines = List(
- "override def getClass(): Class[@name@]"
+ "override def getClass(): Class[@name@] = null"
)
def lcname = name.toLowerCase
@@ -248,7 +248,7 @@ trait AnyValReps {
def objectDoc = ""
def mkImports = ""
- def mkClass = assemble("final class " + name + " private extends AnyVal", classLines)
+ def mkClass = assemble("final abstract class " + name + " private extends AnyVal", classLines)
def mkObject = assemble("object " + name + " extends AnyValCompanion", objectLines)
def make() = List[String](
headerTemplate,
@@ -281,6 +281,8 @@ trait AnyValTemplates {
%s
package scala
+import language.implicitConversions
+
""".trim.format(timestampString) + "\n\n")
def classDocTemplate = ("""
@@ -294,7 +296,6 @@ package scala
""".trim + "\n")
def timestampString = "// DO NOT EDIT, CHANGES WILL BE LOST.\n"
- def stub = """sys.error("stub")"""
def allCompanions = """
/** Transform a value type into a boxed reference type.
@@ -373,7 +374,7 @@ class AnyVals extends AnyValReps with AnyValTemplates {
*
* @return the negated expression
*/
-def unary_! : Boolean = sys.error("stub")
+def unary_! : Boolean
/**
* Compares two Boolean expressions and returns `true` if they evaluate to the same value.
@@ -382,7 +383,7 @@ def unary_! : Boolean = sys.error("stub")
* - `a` and `b` are `true` or
* - `a` and `b` are `false`.
*/
-def ==(x: Boolean): Boolean = sys.error("stub")
+def ==(x: Boolean): Boolean
/**
* Compares two Boolean expressions and returns `true` if they evaluate to a different value.
@@ -391,7 +392,7 @@ def ==(x: Boolean): Boolean = sys.error("stub")
* - `a` is `true` and `b` is `false` or
* - `a` is `false` and `b` is `true`.
*/
-def !=(x: Boolean): Boolean = sys.error("stub")
+def !=(x: Boolean): Boolean
/**
* Compares two Boolean expressions and returns `true` if one or both of them evaluate to true.
@@ -405,7 +406,7 @@ def !=(x: Boolean): Boolean = sys.error("stub")
* behaves as if it was declared as `def ||(x: => Boolean): Boolean`.
* If `a` evaluates to `true`, `true` is returned without evaluating `b`.
*/
-def ||(x: Boolean): Boolean = sys.error("stub")
+def ||(x: Boolean): Boolean
/**
* Compares two Boolean expressions and returns `true` if both of them evaluate to true.
@@ -417,11 +418,11 @@ def ||(x: Boolean): Boolean = sys.error("stub")
* behaves as if it was declared as `def &&(x: => Boolean): Boolean`.
* If `a` evaluates to `false`, `false` is returned without evaluating `b`.
*/
-def &&(x: Boolean): Boolean = sys.error("stub")
+def &&(x: Boolean): Boolean
// Compiler won't build with these seemingly more accurate signatures
-// def ||(x: => Boolean): Boolean = sys.error("stub")
-// def &&(x: => Boolean): Boolean = sys.error("stub")
+// def ||(x: => Boolean): Boolean
+// def &&(x: => Boolean): Boolean
/**
* Compares two Boolean expressions and returns `true` if one or both of them evaluate to true.
@@ -433,7 +434,7 @@ def &&(x: Boolean): Boolean = sys.error("stub")
*
* @note This method evaluates both `a` and `b`, even if the result is already determined after evaluating `a`.
*/
-def |(x: Boolean): Boolean = sys.error("stub")
+def |(x: Boolean): Boolean
/**
* Compares two Boolean expressions and returns `true` if both of them evaluate to true.
@@ -443,7 +444,7 @@ def |(x: Boolean): Boolean = sys.error("stub")
*
* @note This method evaluates both `a` and `b`, even if the result is already determined after evaluating `a`.
*/
-def &(x: Boolean): Boolean = sys.error("stub")
+def &(x: Boolean): Boolean
/**
* Compares two Boolean expressions and returns `true` if they evaluate to a different value.
@@ -452,9 +453,9 @@ def &(x: Boolean): Boolean = sys.error("stub")
* - `a` is `true` and `b` is `false` or
* - `a` is `false` and `b` is `true`.
*/
-def ^(x: Boolean): Boolean = sys.error("stub")
+def ^(x: Boolean): Boolean
-override def getClass(): Class[Boolean] = sys.error("stub")
+override def getClass(): Class[Boolean] = null
""".trim.lines.toList
def objectLines = interpolate(allCompanions + "\n" + nonUnitCompanions).lines.toList
@@ -468,7 +469,7 @@ override def getClass(): Class[Boolean] = sys.error("stub")
*/
"""
def classLines = List(
- """override def getClass(): Class[Unit] = sys.error("stub")"""
+ """override def getClass(): Class[Unit] = null"""
)
def objectLines = interpolate(allCompanions).lines.toList
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
index c29630d04b..73bcd08f4b 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
@@ -1961,11 +1961,15 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
&& !sym.isMutable // lazy vals and vars both
)
+ // Primitives are "abstract final" to prohibit instantiation
+ // without having to provide any implementations, but that is an
+ // illegal combination of modifiers at the bytecode level so
+ // suppress final if abstract if present.
mkFlags(
if (privateFlag) ACC_PRIVATE else ACC_PUBLIC,
if (sym.isDeferred || sym.hasAbstractFlag) ACC_ABSTRACT else 0,
if (sym.isInterface) ACC_INTERFACE else 0,
- if (finalFlag) ACC_FINAL else 0,
+ if (finalFlag && !sym.hasAbstractFlag) ACC_FINAL else 0,
if (sym.isStaticMember) ACC_STATIC else 0,
if (sym.isBridge) ACC_BRIDGE | ACC_SYNTHETIC else 0,
if (sym.isClass && !sym.isInterface) ACC_SUPER else 0,