Permalink
Browse files

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.
  • Loading branch information...
paulp committed Jun 4, 2012
1 parent a43e070 commit 241c7606d0bf5f3209b9d549fb751dbbc5b8e514
@@ -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)
@@ -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
@@ -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,
@@ -26,7 +26,5 @@ package scala
* The ''floating point types'' are [[scala.Float]] and [[scala.Double]].
*/
abstract class AnyVal extends Any with NotNull {
- // disabled for now to make the standard build go through.
- // Once we have a new strap we can uncomment this and delete the AnyVal_getClass entry in Definitions.
- def getClass(): Class[_ <: AnyVal] = ???
+ def getClass(): Class[_ <: AnyVal] = null
}
@@ -10,14 +10,16 @@
package scala
+import language.implicitConversions
+
/** `Boolean` (equivalent to Java's `boolean` primitive type) is a
* subtype of [[scala.AnyVal]]. Instances of `Boolean` are not
* represented by an object in the underlying runtime system.
*
* There is an implicit conversion from [[scala.Boolean]] => [[scala.runtime.RichBoolean]]
* which provides useful non-primitive operations.
*/
-final class Boolean private extends AnyVal {
+final abstract class Boolean private extends AnyVal {
/**
* Negates a Boolean expression.
*
@@ -26,7 +28,7 @@ final class Boolean private extends AnyVal {
*
* @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.
@@ -35,7 +37,7 @@ final class Boolean private extends AnyVal {
* - `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.
@@ -44,7 +46,7 @@ final class Boolean private extends AnyVal {
* - `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.
@@ -58,7 +60,7 @@ final class Boolean private extends AnyVal {
* 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.
@@ -70,11 +72,11 @@ final class Boolean private extends AnyVal {
* 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.
@@ -86,7 +88,7 @@ final class Boolean private extends AnyVal {
*
* @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.
@@ -96,7 +98,7 @@ final class Boolean private extends AnyVal {
*
* @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.
@@ -105,12 +107,12 @@ final class Boolean private extends AnyVal {
* - `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
}
-object Boolean extends AnyValCompanion {
+object Boolean extends AnyValCompanion {
/** Transform a value type into a boxed reference type.
*
@@ -132,5 +134,6 @@ object Boolean extends AnyValCompanion {
/** The String representation of the scala.Boolean companion object.
*/
override def toString = "object scala.Boolean"
+
}
Oops, something went wrong.

0 comments on commit 241c760

Please sign in to comment.