summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/reflect/internal/NameManglers.scala14
-rw-r--r--src/compiler/scala/reflect/internal/StdNames.scala1
-rw-r--r--src/compiler/scala/reflect/internal/Symbols.scala22
-rw-r--r--src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala38
-rw-r--r--test/files/run/t5488-fn.check10
-rw-r--r--test/files/run/t5488-fn.scala26
-rw-r--r--test/files/run/t5500b.check28
-rw-r--r--test/files/run/t5500b.scala51
-rw-r--r--test/pending/run/t4996.scala15
9 files changed, 142 insertions, 63 deletions
diff --git a/src/compiler/scala/reflect/internal/NameManglers.scala b/src/compiler/scala/reflect/internal/NameManglers.scala
index 97a74c2383..c4ee7254dc 100644
--- a/src/compiler/scala/reflect/internal/NameManglers.scala
+++ b/src/compiler/scala/reflect/internal/NameManglers.scala
@@ -76,12 +76,14 @@ trait NameManglers {
val PROTECTED_PREFIX = "protected$"
val PROTECTED_SET_PREFIX = PROTECTED_PREFIX + "set"
val SINGLETON_SUFFIX = ".type"
- val SPECIALIZED_SUFFIX_STRING = "$sp"
val SUPER_PREFIX_STRING = "super$"
val TRAIT_SETTER_SEPARATOR_STRING = "$_setter_$"
+ val SETTER_SUFFIX: TermName = encode("_=")
- val SETTER_SUFFIX: TermName = encode("_=")
- val SPECIALIZED_SUFFIX_NAME: TermName = SPECIALIZED_SUFFIX_STRING
+ @deprecated("2.10.0", "Use SPECIALIZED_SUFFIX")
+ def SPECIALIZED_SUFFIX_STRING = SPECIALIZED_SUFFIX.toString
+ @deprecated("2.10.0", "Use SPECIALIZED_SUFFIX")
+ def SPECIALIZED_SUFFIX_NAME: TermName = SPECIALIZED_SUFFIX.toTermName
def isConstructorName(name: Name) = name == CONSTRUCTOR || name == MIXIN_CONSTRUCTOR
def isExceptionResultName(name: Name) = name startsWith EXCEPTION_RESULT_PREFIX
@@ -120,7 +122,7 @@ trait NameManglers {
}
def unspecializedName(name: Name): Name = (
- if (name endsWith SPECIALIZED_SUFFIX_NAME)
+ if (name endsWith SPECIALIZED_SUFFIX)
name.subName(0, name.lastIndexOf('m') - 1)
else name
)
@@ -140,8 +142,8 @@ trait NameManglers {
* and another one belonging to the enclosing class, on Double.
*/
def splitSpecializedName(name: Name): (Name, String, String) =
- if (name endsWith SPECIALIZED_SUFFIX_NAME) {
- val name1 = name dropRight SPECIALIZED_SUFFIX_NAME.length
+ if (name endsWith SPECIALIZED_SUFFIX) {
+ val name1 = name dropRight SPECIALIZED_SUFFIX.length
val idxC = name1 lastIndexOf 'c'
val idxM = name1 lastIndexOf 'm'
diff --git a/src/compiler/scala/reflect/internal/StdNames.scala b/src/compiler/scala/reflect/internal/StdNames.scala
index b4c404a80c..f61fe7a457 100644
--- a/src/compiler/scala/reflect/internal/StdNames.scala
+++ b/src/compiler/scala/reflect/internal/StdNames.scala
@@ -99,6 +99,7 @@ trait StdNames extends NameManglers { self: SymbolTable =>
val MODULE_VAR_SUFFIX: NameType = "$module"
val ROOT: NameType = "<root>"
val PACKAGE: NameType = "package"
+ val SPECIALIZED_SUFFIX: NameType = "$sp"
// value types (and AnyRef) are all used as terms as well
// as (at least) arguments to the @specialize annotation.
diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala
index b3ff2c6329..8e9788e8b6 100644
--- a/src/compiler/scala/reflect/internal/Symbols.scala
+++ b/src/compiler/scala/reflect/internal/Symbols.scala
@@ -1383,15 +1383,25 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
cloneSymbol(owner)
/** A clone of this symbol, but with given owner. */
- final def cloneSymbol(owner: Symbol): Symbol = cloneSymbol(owner, this.rawflags)
- final def cloneSymbol(owner: Symbol, newFlags: Long): Symbol = {
- val newSym = cloneSymbolImpl(owner, newFlags)
- ( newSym
+ final def cloneSymbol(newOwner: Symbol): Symbol =
+ cloneSymbol(newOwner, this.rawflags)
+ final def cloneSymbol(newOwner: Symbol, newFlags: Long): Symbol =
+ cloneSymbol(newOwner, newFlags, nme.NO_NAME)
+ final def cloneSymbol(newOwner: Symbol, newFlags: Long, newName: Name): Symbol = {
+ val clone = cloneSymbolImpl(newOwner, newFlags)
+ ( clone
setPrivateWithin privateWithin
- setInfo (info cloneInfo newSym)
+ setInfo (this.info cloneInfo clone)
setAnnotations this.annotations
)
+ if (clone.thisSym != clone)
+ clone.typeOfThis = (clone.typeOfThis cloneInfo clone)
+ if (newName != nme.NO_NAME)
+ clone.name = newName
+
+ clone
}
+
/** Internal method to clone a symbol's implementation with the given flags and no info. */
def cloneSymbolImpl(owner: Symbol, newFlags: Long): Symbol
def cloneSymbolImpl(owner: Symbol): Symbol = cloneSymbolImpl(owner, 0L)
@@ -2327,7 +2337,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
*/
def existentialBound: Type = abort("unexpected type: "+this.getClass+ " "+debugLocationString)
- override def name: TypeName = super.name.asInstanceOf[TypeName]
+ override def name: TypeName = super.name.toTypeName
final override def isType = true
override def isNonClassType = true
override def isAbstractType = {
diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
index 468518d938..3254844344 100644
--- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
+++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
@@ -87,10 +87,9 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
/** Map class symbols to the type environments where they were created. */
private val typeEnv = mutable.HashMap[Symbol, TypeEnv]() withDefaultValue emptyEnv
- // holds mappings from regular type parameter symbols and their class to
- // symbols of specialized type parameters which are subtypes of AnyRef
- // e.g. (sym, clazz) => specializedSym
- private val anyrefSpecCache = perRunCaches.newMap[(Symbol, Symbol), Symbol]()
+ // Key: a specialized class or method
+ // Value: a map from tparams in the original class to tparams in the specialized class.
+ private val anyrefSpecCache = perRunCaches.newMap[Symbol, mutable.Map[Symbol, Symbol]]()
// holds mappings from members to the type variables in the class
// that they were already specialized for, so that they don't get
@@ -432,29 +431,24 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
case _ => Set()
}
- /** Returns the type parameter in the specialized class `clazz` that corresponds to type parameter
- * `sym` in the original class. It will create it if needed or use the one from the cache.
+ /** Returns the type parameter in the specialized class `sClass` that corresponds to type parameter
+ * `tparam` in the original class. It will create it if needed or use the one from the cache.
*/
- private def typeParamSubAnyRef(sym: Symbol, clazz: Symbol) = (
- anyrefSpecCache.getOrElseUpdate((sym, clazz),
- clazz.newTypeParameter(sym.name append nme.SPECIALIZED_SUFFIX_NAME toTypeName, sym.pos)
- setInfo TypeBounds(sym.info.bounds.lo, AnyRefClass.tpe)
+ private def typeParamSubAnyRef(tparam: Symbol, sClass: Symbol): Type = {
+ val sClassMap = anyrefSpecCache.getOrElseUpdate(sClass, mutable.Map[Symbol, Symbol]())
+
+ sClassMap.getOrElseUpdate(tparam,
+ tparam.cloneSymbol(sClass, tparam.flags, tparam.name append tpnme.SPECIALIZED_SUFFIX)
+ modifyInfo (info => TypeBounds(info.bounds.lo, AnyRefClass.tpe))
).tpe
- )
+ }
/** Cleans the anyrefSpecCache of all type parameter symbols of a class.
*/
- private def cleanAnyRefSpecCache(clazz: Symbol, decls: List[Symbol]) = (
+ private def cleanAnyRefSpecCache(clazz: Symbol, decls: List[Symbol]) {
// remove class type parameters and those of normalized members.
- clazz :: decls foreach {
- _.tpe match {
- case PolyType(tparams, _) => tparams.foreach {
- s => anyrefSpecCache.remove((s, clazz))
- }
- case _ => ()
- }
- }
- )
+ clazz :: decls foreach (anyrefSpecCache remove _)
+ }
/** Type parameters that survive when specializing in the specified environment. */
def survivingParams(params: List[Symbol], env: TypeEnv) =
@@ -1710,7 +1704,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
* - there is a getter for the specialized field in the same class
*/
def initializesSpecializedField(f: Symbol) = (
- (f.name endsWith nme.SPECIALIZED_SUFFIX_NAME)
+ (f.name endsWith nme.SPECIALIZED_SUFFIX)
&& clazz.info.member(nme.originalName(f.name)).isPublic
&& clazz.info.decl(f.name).suchThat(_.isGetter) != NoSymbol
)
diff --git a/test/files/run/t5488-fn.check b/test/files/run/t5488-fn.check
index 196f58d063..18907d0ab8 100644
--- a/test/files/run/t5488-fn.check
+++ b/test/files/run/t5488-fn.check
@@ -1,17 +1,17 @@
B$mcII$sp
-B
+B$mcIL$sp
B$mcIV$sp
B$mcLI$sp
B
B$mcLV$sp
B$mcVI$sp
-B
+B$mcVL$sp
B$mcVV$sp
C$mcIII$sp
-C
+C$mcIIL$sp
C$mcILI$sp
-C
+C$mcILL$sp
C$mcLII$sp
-C
+C$mcLIL$sp
C$mcLLI$sp
C
diff --git a/test/files/run/t5488-fn.scala b/test/files/run/t5488-fn.scala
index 9e4f60002b..d17bcf90a5 100644
--- a/test/files/run/t5488-fn.scala
+++ b/test/files/run/t5488-fn.scala
@@ -1,8 +1,5 @@
-class B[@specialized(Int, AnyRef, Unit) A, @specialized(Int, Unit) B](f: A => B)
-class C[@specialized(Int, AnyRef) A, @specialized(Int, AnyRef) B, @specialized(Int) C](f: (A, B) => C)
-// Not yet:
-// class B[@specialized(Int, AnyRef, Unit) A, @specialized(Int, AnyRef, Unit) B](f: A => B)
-// class C[@specialized(Int, AnyRef) A, @specialized(Int, AnyRef) B, @specialized(Int, AnyRef) C](f: (A, B) => C)
+class B[@specialized(Int, AnyRef, Unit) A, @specialized(Int, AnyRef, Unit) B](f: A => B)
+class C[@specialized(Int, AnyRef) A, @specialized(Int, AnyRef) B, @specialized(Int, AnyRef) C](f: (A, B) => C)
object Test {
def main(args:Array[String]) {
@@ -28,22 +25,3 @@ object Test {
show(new C((x: AnyRef, y: AnyRef) => "abc"))
}
}
-/** If the return types are specialized on AnyRef as well:
-
-files/run/t5488-fn.scala:18: error: type mismatch;
- found : Unit => String
- required: Unit => B$sp
- show(new B((x: Unit) => "abc"))
- ^
-files/run/t5488-fn.scala:24: error: type mismatch;
- found : (Int, Object) => String
- required: (Int, B$sp) => C$sp
- show(new C((x: Int, y: AnyRef) => "abc"))
- ^
-files/run/t5488-fn.scala:26: error: type mismatch;
- found : (Object, Int) => String
- required: (A$sp, Int) => C$sp
- show(new C((x: AnyRef, y: Int) => "abc"))
- ^
-three errors found
-**/
diff --git a/test/files/run/t5500b.check b/test/files/run/t5500b.check
new file mode 100644
index 0000000000..4259b24b53
--- /dev/null
+++ b/test/files/run/t5500b.check
@@ -0,0 +1,28 @@
+C1A$mcLI$sp
+C1A$mcLD$sp
+C1A
+C1A$mcII$sp
+C1A$mcID$sp
+C1A$mcIL$sp
+C1A$mcDI$sp
+C1A$mcDD$sp
+C1A$mcDL$sp
+C1B$mcLI$sp
+C1B$mcLD$sp
+C1B
+C1B$mcII$sp
+C1B$mcID$sp
+C1B$mcIL$sp
+C1B$mcDI$sp
+C1B$mcDD$sp
+C1B$mcDL$sp
+C1C$mcLI$sp
+C1C$mcLI$sp
+C1C$mcLD$sp
+C1C
+C1C$mcII$sp
+C1C$mcID$sp
+C1C$mcIL$sp
+C1C$mcDI$sp
+C1C$mcDD$sp
+C1C$mcDL$sp
diff --git a/test/files/run/t5500b.scala b/test/files/run/t5500b.scala
new file mode 100644
index 0000000000..32de858e7b
--- /dev/null
+++ b/test/files/run/t5500b.scala
@@ -0,0 +1,51 @@
+import scala.{specialized => spec}
+
+class C1A[
+ @spec(Double, Int, AnyRef) A,
+ @spec(Double, Int, AnyRef) B
+]
+
+class C1B[
+ @spec(Double, Int, AnyRef) A,
+ @spec(Double, Int, AnyRef) B
+](v: A)
+
+class C1C[
+ @spec(Double, Int, AnyRef) A,
+ @spec(Double, Int, AnyRef) B
+](v:A, w:B)
+
+object Test {
+ def main(args:Array[String]) {
+ println(new C1A[String, Int].getClass.getName)
+ println(new C1A[String, Double].getClass.getName)
+ println(new C1A[String, String].getClass.getName)
+ println(new C1A[Int, Int].getClass.getName)
+ println(new C1A[Int, Double].getClass.getName)
+ println(new C1A[Int, String].getClass.getName)
+ println(new C1A[Double, Int].getClass.getName)
+ println(new C1A[Double, Double].getClass.getName)
+ println(new C1A[Double, String].getClass.getName)
+
+ println(new C1B[String, Int]("abc").getClass.getName)
+ println(new C1B[String, Double]("abc").getClass.getName)
+ println(new C1B[String, String]("abc").getClass.getName)
+ println(new C1B[Int, Int](1).getClass.getName)
+ println(new C1B[Int, Double](1).getClass.getName)
+ println(new C1B[Int, String](1).getClass.getName)
+ println(new C1B[Double, Int](1d).getClass.getName)
+ println(new C1B[Double, Double](1d).getClass.getName)
+ println(new C1B[Double, String](1d).getClass.getName)
+
+ println(new C1C("abc", 123).getClass.getName)
+ println(new C1C("abc", 123).getClass.getName)
+ println(new C1C("a", 1d).getClass.getName)
+ println(new C1C("a", "a").getClass.getName)
+ println(new C1C(1, 1).getClass.getName)
+ println(new C1C(1, 1d).getClass.getName)
+ println(new C1C(1, "a").getClass.getName)
+ println(new C1C(1d, 1).getClass.getName)
+ println(new C1C(1d, 1d).getClass.getName)
+ println(new C1C(1d, "a").getClass.getName)
+ }
+}
diff --git a/test/pending/run/t4996.scala b/test/pending/run/t4996.scala
new file mode 100644
index 0000000000..58a8fe16a3
--- /dev/null
+++ b/test/pending/run/t4996.scala
@@ -0,0 +1,15 @@
+object SpecializationAbstractOverride {
+
+ trait A[@specialized(Int) T] { def foo(t: T) }
+ trait B extends A[Int] { def foo(t: Int) { println("B.foo") } }
+ trait M extends B { abstract override def foo(t: Int) { super.foo(t) ; println ("M.foo") } }
+ object C extends B with M
+
+ object D extends B { override def foo(t: Int) { super.foo(t); println("M.foo") } }
+
+ def main(args: Array[String]) {
+ D.foo(42) // OK, prints B.foo M.foo
+ C.foo(42) // StackOverflowError
+ }
+}
+