summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/cmd
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-04-30 07:44:42 -0700
committerPaul Phillips <paulp@improving.org>2012-04-30 09:40:41 -0700
commitcf18d879d3f43d5a0c15c5c0af72f88c25605a08 (patch)
tree2112180d54c913b387791899905fb3d8ede376d0 /src/compiler/scala/tools/cmd
parent94c63f5da548996535cad43142758c9405118828 (diff)
downloadscala-cf18d879d3f43d5a0c15c5c0af72f88c25605a08.tar.gz
scala-cf18d879d3f43d5a0c15c5c0af72f88c25605a08.tar.bz2
scala-cf18d879d3f43d5a0c15c5c0af72f88c25605a08.zip
Optimization of Predef implicits.
All those wildcards in a default-scoped implicit are expensive, they each lead to a typevar on every search. Restructured the Tuple2/Tuple3 Zipped classes, they're better this way anyway. This also gets all that Tuple[23] code out of genprod.
Diffstat (limited to 'src/compiler/scala/tools/cmd')
-rw-r--r--src/compiler/scala/tools/cmd/gen/AnyVals.scala45
1 files changed, 28 insertions, 17 deletions
diff --git a/src/compiler/scala/tools/cmd/gen/AnyVals.scala b/src/compiler/scala/tools/cmd/gen/AnyVals.scala
index e8230b8ca4..83cd9c2578 100644
--- a/src/compiler/scala/tools/cmd/gen/AnyVals.scala
+++ b/src/compiler/scala/tools/cmd/gen/AnyVals.scala
@@ -15,18 +15,27 @@ trait AnyValReps {
case class Op(val op : String, val doc : String)
- private def companionCoercions(tos: String*) = {
+ private def companionCoercions(tos: AnyValRep*) = {
tos.toList map (to =>
- """implicit def %s2%s(x: %s): %s = x.to%s""".format(javaEquiv, to, name, to.capitalize, to.capitalize)
+ """implicit def @javaequiv@2%s(x: @name@): %s = x.to%s""".format(to.javaEquiv, to.name, to.name)
)
}
- def implicitCoercions: List[String] = javaEquiv match {
- case "byte" => companionCoercions("short", "int", "long", "float", "double")
- case "short" | "char" => companionCoercions("int", "long", "float", "double")
- case "int" => companionCoercions("long", "float", "double")
- case "long" => companionCoercions("float", "double")
- case "float" => companionCoercions("double")
- case _ => Nil
+ def coercionCommentExtra = ""
+ def coercionComment = """
+ /** Language mandated coercions from @name@ to "wider" types.%s
+ */""".format(coercionCommentExtra)
+
+ def implicitCoercions: List[String] = {
+ val coercions = this match {
+ case B => companionCoercions(S, I, L, F, D)
+ case S | C => companionCoercions(I, L, F, D)
+ case I => companionCoercions(L, F, D)
+ case L => companionCoercions(F, D)
+ case F => companionCoercions(D)
+ case _ => Nil
+ }
+ if (coercions.isEmpty) Nil
+ else coercionComment :: coercions
}
def isCardinal: Boolean = isIntegerType(this)
@@ -174,7 +183,7 @@ trait AnyValReps {
}
def objectLines = {
val comp = if (isCardinal) cardinalCompanion else floatingCompanion
- ((comp + allCompanions).trim.lines map interpolate).toList ++ implicitCoercions
+ (comp + allCompanions + "\n" + nonUnitCompanions).trim.lines.toList ++ implicitCoercions map interpolate
}
/** Makes a set of binary operations based on the given set of ops, args, and resultFn.
@@ -238,8 +247,9 @@ trait AnyValReps {
def classDoc = interpolate(classDocTemplate)
def objectDoc = ""
def mkImports = ""
- def mkClass = assemble("final class", "private", "AnyVal", classLines) + "\n"
- def mkObject = assemble("object", "", "AnyValCompanion", objectLines) + "\n"
+
+ def mkClass = assemble("final class " + name + " private extends AnyVal", classLines)
+ def mkObject = assemble("object " + name + " extends AnyValCompanion", objectLines)
def make() = List[String](
headerTemplate,
mkImports,
@@ -249,11 +259,10 @@ trait AnyValReps {
mkObject
) mkString ""
- def assemble(what: String, ctor: String, parent: String, lines: List[String]): String = {
- val decl = "%s %s %s extends %s ".format(what, name, ctor, parent)
- val body = if (lines.isEmpty) "{ }\n\n" else lines map indent mkString ("{\n", "\n", "\n}\n")
+ def assemble(decl: String, lines: List[String]): String = {
+ val body = if (lines.isEmpty) " { }\n\n" else lines map indent mkString (" {\n", "\n", "\n}\n")
- decl + body
+ decl + body + "\n"
}
override def toString = name
}
@@ -310,6 +319,8 @@ def unbox(x: java.lang.Object): @name@ = @unboxImpl@
override def toString = "object scala.@name@"
"""
+ def nonUnitCompanions = "" // todo
+
def cardinalCompanion = """
/** The smallest value representable as a @name@.
*/
@@ -446,7 +457,7 @@ def ^(x: Boolean): Boolean = sys.error("stub")
override def getClass(): Class[Boolean] = sys.error("stub")
""".trim.lines.toList
- def objectLines = interpolate(allCompanions).lines.toList
+ def objectLines = interpolate(allCompanions + "\n" + nonUnitCompanions).lines.toList
}
object U extends AnyValRep("Unit", None, "void") {
override def classDoc = """