Permalink
Browse files

SI-7329 duplicate default getters for specialized parameters.

The default getter is generated with @specialized annotation if the
type parameter corresponding to the type of the parameter is
specialized. Consequently specialize pass tries to generate overloads.

Rather than pruning overloads to exclude duplicates, let's notice
that default getter specialization is not needed at all:
  - The dynamic scope of default getter doesn't include specialized
    method or class constructor.
  - generic default getter is called even when calling specialized
    method:
    object V {
      @specialized def foo[@specialized B](b: B = (??? : B)) = {}
      foo[Int]()
    }
    gives:
      invokevirtual Method V$.foo$default$1:()Ljava/lang/Object;
      invokestatic (unboxToInt)
      invokevirtual Method V$.foo$mIc$sp:(I)V
  • Loading branch information...
1 parent 58ae1ca commit aa6723c500b5c226a68609418f98f94adab7a8bf @vigdorchik vigdorchik committed Apr 7, 2013
Showing with 6 additions and 1 deletion.
  1. +5 −1 src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
  2. +1 −0 test/files/pos/t7329.scala
@@ -796,7 +796,11 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
private def normalizeMember(owner: Symbol, sym: Symbol, outerEnv: TypeEnv): List[Symbol] = {
sym :: (
if (!sym.isMethod || beforeTyper(sym.typeParams.isEmpty)) Nil
- else {
+ else if (sym.hasDefault) {
+ /* Specializing default getters is useless, also see SI-7329 . */
+ sym.resetFlag(SPECIALIZED)
+ Nil
+ } else {
// debuglog("normalizeMember: " + sym.fullNameAsName('.').decode)
var specializingOn = specializedParams(sym)
val unusedStvars = specializingOn filterNot specializedTypeVars(sym.info)
@@ -0,0 +1 @@
+class TwoParamSpecializedWithDefault[@specialized A, @specialized B](a: A, b: B = (??? : B))

0 comments on commit aa6723c

Please sign in to comment.