summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-12-24 23:13:58 -0800
committerPaul Phillips <paulp@improving.org>2011-12-25 00:53:00 -0800
commita31e4f8a75f9162ab2f0c8d3bec42675b29fefb5 (patch)
tree2d7dc5d7cb35b3ea5d667cdc15edcaaab2a73f06 /src/compiler
parent8834d3c191e37dfa31ae11605596ce2b641ea083 (diff)
downloadscala-a31e4f8a75f9162ab2f0c8d3bec42675b29fefb5.tar.gz
scala-a31e4f8a75f9162ab2f0c8d3bec42675b29fefb5.tar.bz2
scala-a31e4f8a75f9162ab2f0c8d3bec42675b29fefb5.zip
Optimizing at the Name/String boundary.
Working on reducing the now significant amount of both garbage and retained but duplicated Strings taking place as Names become Strings and vice versa. Long way to go.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/reflect/internal/Definitions.scala4
-rw-r--r--src/compiler/scala/reflect/internal/NameManglers.scala22
-rw-r--r--src/compiler/scala/reflect/internal/Names.scala15
-rw-r--r--src/compiler/scala/reflect/internal/Symbols.scala63
-rw-r--r--src/compiler/scala/reflect/internal/Types.scala4
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/opt/Inliners.scala5
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/IMain.scala36
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Power.scala21
-rw-r--r--src/compiler/scala/tools/nsc/transform/Constructors.scala16
-rw-r--r--src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala13
11 files changed, 114 insertions, 87 deletions
diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala
index 6ee9347aab..15f89e1382 100644
--- a/src/compiler/scala/reflect/internal/Definitions.scala
+++ b/src/compiler/scala/reflect/internal/Definitions.scala
@@ -692,10 +692,14 @@ trait Definitions extends reflect.api.StandardDefinitions {
result
}
+ def getClassIfDefined(fullname: String): Symbol =
+ getClassIfDefined(newTypeName(fullname))
def getClassIfDefined(fullname: Name): Symbol =
try getClass(fullname.toTypeName)
catch { case _: MissingRequirementError => NoSymbol }
+ def getModuleIfDefined(fullname: String): Symbol =
+ getModuleIfDefined(newTermName(fullname))
def getModuleIfDefined(fullname: Name): Symbol =
try getModule(fullname.toTermName)
catch { case _: MissingRequirementError => NoSymbol }
diff --git a/src/compiler/scala/reflect/internal/NameManglers.scala b/src/compiler/scala/reflect/internal/NameManglers.scala
index 01a93c0ada..d4aa6339ff 100644
--- a/src/compiler/scala/reflect/internal/NameManglers.scala
+++ b/src/compiler/scala/reflect/internal/NameManglers.scala
@@ -22,7 +22,10 @@ trait NameManglers {
val MODULE_SUFFIX_STRING = NameTransformer.MODULE_SUFFIX_STRING
val NAME_JOIN_STRING = NameTransformer.NAME_JOIN_STRING
-
+
+ val MODULE_SUFFIX_NAME: TermName = MODULE_SUFFIX_STRING
+ val NAME_JOIN_NAME: TermName = NAME_JOIN_STRING
+
def flattenedName(segments: Name*): NameType = compactedString(segments mkString NAME_JOIN_STRING)
/**
@@ -74,8 +77,11 @@ trait NameManglers {
val PROTECTED_SET_PREFIX = PROTECTED_PREFIX + "set"
val SETTER_SUFFIX = encode("_=")
val SINGLETON_SUFFIX = ".type"
+ val SPECIALIZED_SUFFIX_STRING = "$sp"
val SUPER_PREFIX_STRING = "super$"
val TRAIT_SETTER_SEPARATOR_STRING = "$_setter_$"
+
+ val SPECIALIZED_SUFFIX_NAME: TermName = SPECIALIZED_SUFFIX_STRING
def isConstructorName(name: Name) = name == CONSTRUCTOR || name == MIXIN_CONSTRUCTOR
def isExceptionResultName(name: Name) = name startsWith EXCEPTION_RESULT_PREFIX
@@ -88,7 +94,7 @@ trait NameManglers {
def isSetterName(name: Name) = name endsWith SETTER_SUFFIX
def isTraitSetterName(name: Name) = isSetterName(name) && (name containsName TRAIT_SETTER_SEPARATOR_STRING)
def isSingletonName(name: Name) = name endsWith SINGLETON_SUFFIX
- def isModuleName(name: Name) = name endsWith MODULE_SUFFIX_STRING
+ def isModuleName(name: Name) = name endsWith MODULE_SUFFIX_NAME
def isOpAssignmentName(name: Name) = name match {
case raw.NE | raw.LE | raw.GE | EMPTY => false
@@ -112,6 +118,12 @@ trait NameManglers {
name.subName(i, name.length)
} else name
}
+
+ def unspecializedName(name: Name): Name = (
+ if (name endsWith SPECIALIZED_SUFFIX_NAME)
+ name.subName(0, name.lastIndexOf('m') - 1)
+ else name
+ )
/** Return the original name and the types on which this name
* is specialized. For example,
@@ -123,8 +135,8 @@ trait NameManglers {
* and another one belonging to the enclosing class, on Double.
*/
def splitSpecializedName(name: Name): (Name, String, String) =
- if (name.endsWith("$sp")) {
- val name1 = name stripEnd "$sp"
+ if (name endsWith SPECIALIZED_SUFFIX_NAME) {
+ val name1 = name stripEnd SPECIALIZED_SUFFIX_NAME
val idxC = name1 lastIndexOf 'c'
val idxM = name1 lastIndexOf 'm'
@@ -138,6 +150,8 @@ trait NameManglers {
def getterToLocal(name: TermName): TermName = name.toTermName append LOCAL_SUFFIX_STRING
def getterToSetter(name: TermName): TermName = name.toTermName append SETTER_SUFFIX
def localToGetter(name: TermName): TermName = name stripEnd LOCAL_SUFFIX_STRING toTermName
+
+ def dropLocalSuffix(name: Name): Name = if (name endsWith ' ') name dropRight 1 else name
def setterToGetter(name: TermName): TermName = {
val p = name.pos(TRAIT_SETTER_SEPARATOR_STRING)
diff --git a/src/compiler/scala/reflect/internal/Names.scala b/src/compiler/scala/reflect/internal/Names.scala
index a6fd2adb34..11be9c80d1 100644
--- a/src/compiler/scala/reflect/internal/Names.scala
+++ b/src/compiler/scala/reflect/internal/Names.scala
@@ -306,6 +306,16 @@ trait Names extends api.Names {
while (start <= last && !startsWith(subname, start)) start += 1
start <= last
}
+ final def containsChar(ch: Char): Boolean = {
+ var i = index
+ val max = index + len
+ while (i < max) {
+ if (chrs(i) == ch)
+ return true
+ i += 1
+ }
+ false
+ }
/** Some thoroughly self-explanatory convenience functions. They
* assume that what they're being asked to do is known to be valid.
@@ -320,6 +330,8 @@ trait Names extends api.Names {
final def stripStart(prefix: String): Name = subName(prefix.length, len)
final def stripEnd(suffix: Name): Name = subName(0, len - suffix.length)
final def stripEnd(suffix: String): Name = subName(0, len - suffix.length)
+
+ def dropRight(n: Int) = subName(0, len - n)
def lastIndexOf(ch: Char) = toChars lastIndexOf ch
@@ -349,6 +361,7 @@ trait Names extends api.Names {
else newTermName(res)
}
+ def append(ch: Char): Name
def append(suffix: String): Name
def append(suffix: Name): Name
@@ -377,6 +390,7 @@ trait Names extends api.Names {
n = new TypeName(index, len, h);
n
}
+ def append(ch: Char): TermName = append("" + ch)
def append(suffix: String): TermName = newTermName(this + suffix)
def append(suffix: Name): TermName = append(suffix.toString)
def companionName: TypeName = toTypeName
@@ -400,6 +414,7 @@ trait Names extends api.Names {
}
def toTypeName: TypeName = this
+ def append(ch: Char): TypeName = append("" + ch)
def append(suffix: String): TypeName = newTypeName(this + suffix)
def append(suffix: Name): TypeName = append(suffix.toString)
def companionName: TermName = toTermName
diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala
index bc0c81a54b..0c57f0c43a 100644
--- a/src/compiler/scala/reflect/internal/Symbols.scala
+++ b/src/compiler/scala/reflect/internal/Symbols.scala
@@ -756,7 +756,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
/** If this symbol has an expanded name, its original name, otherwise its name itself.
* @see expandName
*/
- def originalName = nme.originalName(name)
+ def originalName: Name = nme.originalName(name)
/** The name of the symbol before decoding, e.g. `\$eq\$eq` instead of `==`.
*/
@@ -764,20 +764,28 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
/** The decoded name of the symbol, e.g. `==` instead of `\$eq\$eq`.
*/
- def decodedName: String = stripNameString(NameTransformer.decode(encodedName))
+ def decodedName: String = nme.dropLocalSuffix(name).decode
- /** Either "$" or "" depending on whether this is a module class.
- */
+ private def addModuleSuffix(n: Name): Name =
+ if (needsModuleSuffix) n append nme.MODULE_SUFFIX_STRING else n
+
def moduleSuffix: String = (
- if (hasModuleFlag && !isMethod && !isImplClass && !isJavaDefined) nme.MODULE_SUFFIX_STRING
+ if (needsModuleSuffix) nme.MODULE_SUFFIX_STRING
else ""
)
-
+ /** Whether this symbol needs nme.MODULE_SUFFIX_STRING (aka $) appended on the java platform.
+ */
+ def needsModuleSuffix = (
+ hasModuleFlag
+ && !isMethod
+ && !isImplClass
+ && !isJavaDefined
+ )
/** These should be moved somewhere like JavaPlatform.
*/
- def javaSimpleName = ("" + simpleName).trim + moduleSuffix
- def javaBinaryName = fullNameInternal('/') + moduleSuffix
- def javaClassName = fullNameInternal('.') + moduleSuffix
+ def javaSimpleName: String = addModuleSuffix(nme.dropLocalSuffix(simpleName)).toString
+ def javaBinaryName: String = addModuleSuffix(fullNameInternal('/')).toString
+ def javaClassName: String = addModuleSuffix(fullNameInternal('.')).toString
/** The encoded full path name of this symbol, where outer names and inner names
* are separated by `separator` characters.
@@ -785,23 +793,17 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
* Never adds id.
* Drops package objects.
*/
- final def fullName(separator: Char): String = stripNameString(fullNameInternal(separator))
+ final def fullName(separator: Char): String = nme.dropLocalSuffix(fullNameInternal(separator)).toString
/** Doesn't drop package objects, for those situations (e.g. classloading)
* where the true path is needed.
*/
- private def fullNameInternal(separator: Char): String = (
- if (isRoot || isRootPackage || this == NoSymbol) this.toString
- else if (owner.isEffectiveRoot) encodedName
- else effectiveOwner.enclClass.fullName(separator) + separator + encodedName
+ private def fullNameInternal(separator: Char): Name = (
+ if (isRoot || isRootPackage || this == NoSymbol) name
+ else if (owner.isEffectiveRoot) name
+ else effectiveOwner.enclClass.fullName(separator) append separator append name
)
- /** Strip package objects and any local suffix.
- */
- private def stripNameString(s: String) =
- if (settings.debug.value) s
- else s stripSuffix nme.LOCAL_SUFFIX_STRING
-
/** The encoded full path name of this symbol, where outer names and inner names
* are separated by periods.
*/
@@ -1702,7 +1704,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
*/
final def getter(base: Symbol): Symbol = base.info.decl(getterName) filter (_.hasAccessorFlag)
- def getterName = (
+ def getterName: Name = (
if (isSetter) nme.setterToGetter(name)
else if (nme.isLocalName(name)) nme.localToGetter(name)
else name
@@ -1800,7 +1802,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
// ------ toString -------------------------------------------------------------------
/** A tag which (in the ideal case) uniquely identifies class symbols */
- final def tag = fullName.##
+ final def tag: Int = fullName.##
/** The simple name of this Symbol */
final def simpleName: Name = name
@@ -1810,7 +1812,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
* (the initial Name) before falling back on id, which varies depending
* on exactly when a symbol is loaded.
*/
- final def sealedSortName = initName + "#" + id
+ final def sealedSortName: String = initName + "#" + id
/** String representation of symbol's definition key word */
final def keyString: String =
@@ -1878,7 +1880,10 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
* E.g. $eq => =.
* If settings.uniqid, adds id.
*/
- def nameString = decodedName + idString
+ def nameString: String = (
+ if (settings.uniqid.value) decodedName + "#" + id
+ else "" + decodedName
+ )
/** If settings.uniqid is set, the symbol's id, else "" */
final def idString = if (settings.uniqid.value) "#"+id else ""
@@ -1886,14 +1891,14 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
/** String representation, including symbol's kind e.g., "class Foo", "method Bar".
* If hasMeaninglessName is true, uses the owner's name to disambiguate identity.
*/
- override def toString = compose(
+ override def toString: String = compose(
kindString,
if (hasMeaninglessName) owner.decodedName + idString else nameString
)
/** String representation of location.
*/
- def ownsString = {
+ def ownsString: String = {
val owns = effectiveOwner
if (owns.isClass && !owns.isEmptyPrefix) "" + owns else ""
}
@@ -1901,12 +1906,12 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
/** String representation of location, plus a preposition. Doesn't do much,
* for backward compatibility reasons.
*/
- def locationString = ownsString match {
+ def locationString: String = ownsString match {
case "" => ""
case s => " in " + s
}
- def fullLocationString = toString + locationString
- def signatureString = if (hasRawInfo) infoString(rawInfo) else "<_>"
+ def fullLocationString: String = toString + locationString
+ def signatureString: String = if (hasRawInfo) infoString(rawInfo) else "<_>"
/** String representation of symbol's definition following its name */
final def infoString(tp: Type): String = {
diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala
index d17747e22a..2db957410b 100644
--- a/src/compiler/scala/reflect/internal/Types.scala
+++ b/src/compiler/scala/reflect/internal/Types.scala
@@ -5713,7 +5713,7 @@ A type's typeSymbol should never be inspected directly.
}
val res = lub0(ts)
if (printLubs) {
- indent = indent dropRight 2
+ indent = indent stripSuffix " "
println(indent + "lub of " + ts + " is " + res)//debug
}
if (ts forall (_.isNotNull)) res.notNull else res
@@ -6172,7 +6172,7 @@ A type's typeSymbol should never be inspected directly.
Console.println(indent + tp1 + " " + op + " " + arg2 + "?" /* + "("+tp1.getClass+","+arg2.getClass+")"*/)
indent = indent + " "
val result = p(tp1, arg2)
- indent = indent dropRight 2
+ indent = indent stripSuffix " "
Console.println(indent + result)
result
}
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
index e80927f620..a2c4f16bf1 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
@@ -172,7 +172,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
val PublicStatic = ACC_PUBLIC | ACC_STATIC
val PublicStaticFinal = ACC_PUBLIC | ACC_STATIC | ACC_FINAL
- val StringBuilderClassName = definitions.StringBuilderClass.fullName
+ val StringBuilderClassName = javaName(definitions.StringBuilderClass)
val BoxesRunTime = "scala.runtime.BoxesRunTime"
val StringBuilderType = new JObjectType(StringBuilderClassName)
diff --git a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala
index 74eb450960..d56a0740d9 100644
--- a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala
+++ b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala
@@ -248,10 +248,9 @@ abstract class Inliners extends SubComponent {
}
private def isMonadicMethod(sym: Symbol) = {
- val (origName, _, _) = nme.splitSpecializedName(sym.name)
- origName match {
+ nme.unspecializedName(sym.name) match {
case nme.foreach | nme.filter | nme.withFilter | nme.map | nme.flatMap => true
- case _ => false
+ case _ => false
}
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/IMain.scala b/src/compiler/scala/tools/nsc/interpreter/IMain.scala
index 861f617ed6..8e4ff8aa37 100644
--- a/src/compiler/scala/tools/nsc/interpreter/IMain.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/IMain.scala
@@ -186,7 +186,10 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
lazy val compiler: global.type = global
import global._
- import definitions.{ ScalaPackage, JavaLangPackage, PredefModule, RootClass }
+ import definitions.{
+ ScalaPackage, JavaLangPackage, PredefModule, RootClass,
+ getClassIfDefined, getModuleIfDefined
+ }
private implicit def privateTreeOps(t: Tree): List[Tree] = {
(new Traversable[Tree] {
@@ -1114,35 +1117,18 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
private def findName(name: Name) = definedSymbols find (_.name == name)
- private def missingOpt(op: => Symbol): Option[Symbol] =
- try Some(op)
- catch { case _: MissingRequirementError => None }
- private def missingWrap(op: => Symbol): Symbol =
- try op
- catch { case _: MissingRequirementError => NoSymbol }
-
- def optCompilerClass(name: String) = missingOpt(definitions.getClass(name))
- def optCompilerModule(name: String) = missingOpt(definitions.getModule(name))
- def getCompilerClass(name: String) = missingWrap(definitions.getClass(name))
- def getCompilerModule(name: String) = missingWrap(definitions.getModule(name))
-
/** Translate a repl-defined identifier into a Symbol.
*/
- def apply(name: String): Symbol = {
- val tpname = newTypeName(name)
- (
- findName(tpname)
- orElse findName(tpname.companionName)
- orElse optCompilerClass(name)
- orElse optCompilerModule(name)
- getOrElse NoSymbol
- )
- }
+ def apply(name: String): Symbol =
+ types(name) orElse terms(name)
+
def types(name: String): Symbol = {
- findName(newTypeName(name)) getOrElse getCompilerClass(name)
+ val tpname = newTypeName(name)
+ findName(tpname) getOrElse getClassIfDefined(tpname)
}
def terms(name: String): Symbol = {
- findName(newTermName(name)) getOrElse getCompilerModule(name)
+ val termname = newTypeName(name)
+ findName(termname) getOrElse getModuleIfDefined(termname)
}
/** the previous requests this interpreter has processed */
diff --git a/src/compiler/scala/tools/nsc/interpreter/Power.scala b/src/compiler/scala/tools/nsc/interpreter/Power.scala
index db2f9573ec..ac7c2b1ecc 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Power.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Power.scala
@@ -59,10 +59,10 @@ abstract class Power(
val intp: IMain
) extends SharesGlobal {
import intp.{
- beQuietDuring, typeOfExpression, getCompilerClass, getCompilerModule,
- interpret, parse
+ beQuietDuring, typeOfExpression, interpret, parse
}
import global._
+ import definitions.{ getClassIfDefined, getModuleIfDefined }
abstract class SymSlurper {
def isKeep(sym: Symbol): Boolean
@@ -108,7 +108,7 @@ abstract class Power(
}
class PackageSlurper(pkgName: String) extends SymSlurper {
- val pkgSymbol = getCompilerModule(pkgName)
+ val pkgSymbol = getModuleIfDefined(pkgName)
val modClass = pkgSymbol.moduleClass
/** Looking for dwindling returns */
@@ -185,12 +185,13 @@ abstract class Power(
// information into the toString method. Boo.
private def manifestToType(m: Manifest[_]): Type = m match {
case x: AnyValManifest[_] =>
- getCompilerClass("scala." + x).tpe
+ getClassIfDefined("scala." + x).tpe
case _ =>
val name = m.erasure.getName
- if (name endsWith nme.MODULE_SUFFIX_STRING) getCompilerModule(name dropRight 1).tpe
+ if (name endsWith nme.MODULE_SUFFIX_STRING)
+ getModuleIfDefined(name stripSuffix nme.MODULE_SUFFIX_STRING).tpe
else {
- val sym = getCompilerClass(name)
+ val sym = getClassIfDefined(name)
val args = m.typeArguments
if (args.isEmpty) sym.tpe
@@ -198,7 +199,7 @@ abstract class Power(
}
}
- def symbol_ : Symbol = getCompilerClass(erasure.getName)
+ def symbol_ : Symbol = getClassIfDefined(erasure.getName)
def tpe_ : Type = manifestToType(man)
def name_ : Name = symbol.name
def companion = symbol.companionSymbol
@@ -222,7 +223,7 @@ abstract class Power(
def bts = info.baseTypeSeq.toList
def btsmap = bts map (x => (x, x.decls.toList)) toMap
def pkgName = Option(erasure.getPackage) map (_.getName)
- def pkg = pkgName map getCompilerModule getOrElse NoSymbol
+ def pkg = pkgName map getModuleIfDefined getOrElse NoSymbol
def pkgmates = pkg.tpe.members
def pkgslurp = pkgName match {
case Some(name) => new PackageSlurper(name) slurp()
@@ -369,8 +370,8 @@ abstract class Power(
object Implicits extends Implicits2 { }
trait ReplUtilities {
- def module[T: Manifest] = getCompilerModule(manifest[T].erasure.getName stripSuffix nme.MODULE_SUFFIX_STRING)
- def clazz[T: Manifest] = getCompilerClass(manifest[T].erasure.getName)
+ def module[T: Manifest] = getModuleIfDefined(manifest[T].erasure.getName stripSuffix nme.MODULE_SUFFIX_STRING)
+ def clazz[T: Manifest] = getClassIfDefined(manifest[T].erasure.getName)
def info[T: Manifest] = InternalInfo[T]
def ?[T: Manifest] = InternalInfo[T]
def url(s: String) = {
diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala
index 00b72bdc1c..342c298e1d 100644
--- a/src/compiler/scala/tools/nsc/transform/Constructors.scala
+++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala
@@ -285,10 +285,11 @@ abstract class Constructors extends Transform with ast.TreeDSL {
specBuf ++= specializedStats
def specializedAssignFor(sym: Symbol): Option[Tree] =
- specializedStats.find {
- case Assign(sel @ Select(This(_), _), rhs) if sel.symbol.hasFlag(SPECIALIZED) =>
- val (generic, _, _) = nme.splitSpecializedName(nme.localToGetter(sel.symbol.name))
- generic == nme.localToGetter(sym.name)
+ specializedStats find {
+ case Assign(sel @ Select(This(_), _), rhs) =>
+ ( (sel.symbol hasFlag SPECIALIZED)
+ && (nme.unspecializedName(nme.localToGetter(sel.symbol.name)) == nme.localToGetter(sym.name))
+ )
case _ => false
}
@@ -378,11 +379,12 @@ abstract class Constructors extends Transform with ast.TreeDSL {
EmptyTree)
List(localTyper.typed(tree))
- } else if (clazz.hasFlag(SPECIALIZED)) {
+ }
+ else if (clazz.hasFlag(SPECIALIZED)) {
// add initialization from its generic class constructor
- val (genericName, _, _) = nme.splitSpecializedName(clazz.name)
+ val genericName = nme.unspecializedName(clazz.name)
val genericClazz = clazz.owner.info.decl(genericName.toTypeName)
- assert(genericClazz != NoSymbol)
+ assert(genericClazz != NoSymbol, clazz)
guardedCtorStats.get(genericClazz) match {
case Some(stats1) => mergeConstructors(genericClazz, stats1, stats)
diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
index 212785a525..9c4889eba9 100644
--- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
+++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
@@ -407,7 +407,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
*/
private def typeParamSubAnyRef(sym: Symbol, cls: Symbol) = (
anyrefSpecCache.getOrElseUpdate(sym,
- cls.newTypeParameter(sym.pos, newTypeName(sym.name + "$sp"))
+ cls.newTypeParameter(sym.pos, sym.name append nme.SPECIALIZED_SUFFIX_NAME toTypeName)
setInfo TypeBounds(sym.info.bounds.lo, AnyRefClass.tpe)
).tpe
)
@@ -1702,10 +1702,11 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
* - there is a getter for the original (non-specialized) field in the same class
* - there is a getter for the specialized field in the same class
*/
- def initializesSpecializedField(f: Symbol): Boolean =
- (f.name.endsWith("$sp")
- && clazz.info.member(nme.originalName(f.name)).isPublic
- && (clazz.info.decl(f.name).suchThat(_.isGetter) != NoSymbol))
+ def initializesSpecializedField(f: Symbol) = (
+ (f.name endsWith nme.SPECIALIZED_SUFFIX_NAME)
+ && clazz.info.member(nme.originalName(f.name)).isPublic
+ && clazz.info.decl(f.name).suchThat(_.isGetter) != NoSymbol
+ )
val argss = paramss map (_ map (x =>
if (initializesSpecializedField(x.symbol))
@@ -1717,7 +1718,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
}
/** Concrete methods that use a specialized type, or override such methods. */
- private val concreteSpecMethods: mutable.Set[Symbol] = new mutable.HashSet
+ private val concreteSpecMethods = new mutable.HashSet[Symbol]()
/** Add method m to the set of symbols for which we need an implementation tree
* in the tree transformer.