Scala Programming Language
  1. Scala Programming Language
  2. SI-4794

Composing specialized traits in method argument does not lead to method specialization

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.8.1, Scala 2.9.0, Scala 2.9.1
    • Fix Version/s: None
    • Component/s: Misc Compiler
    • Labels:
    • Environment:

      Description

      Methods in specialized classes should have specialized versions if their type parameters require it. In particular, if you pass in a specialized class or trait of the same type, the method should be specialized. Unfortunately, this rule is lost if traits are composed, yielding unspecialized code.

      Minimal example:

      package spectest2 {
      trait Mutable[@specialized A]

      { def a: A; def a_=(a0: A): Unit }

      trait NotSpecialized

      { def not: String }

      class Arr[@specialized A](val arr: Array[A]) {
      def lode(m: Mutable[A])

      { m.a = arr(0) }
      def load(m: Mutable[A] with NotSpecialized) { m.a = arr(0) }

      }
      }

      In this case, method "lode" is correctly specialized in, for example, the Int version of the class. However, method "load" is not. Even if the second trait is in fact specialized, the same behavior is observed.

        Activity

        Hide
        Commit Message Bot added a comment -

        (extempore in r25613) Intersection types made specializable.

        Formerly a specializable type parameter would be missed if in
        an intersection.

        trait Trait[@specialized T]

        { def f[T](x: Foo[T] with Bar) = x }

        Now that is specialized, as it already was in the "Foo[T]" case.
        Closes SI-4794, no review.

        Show
        Commit Message Bot added a comment - (extempore in r25613 ) Intersection types made specializable. Formerly a specializable type parameter would be missed if in an intersection. trait Trait [@specialized T] { def f[T](x: Foo[T] with Bar) = x } Now that is specialized, as it already was in the "Foo [T] " case. Closes SI-4794 , no review.

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Rex Kerr
          • Votes:
            4 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development