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

Specialization not visiting local methods - is there a fundamental reason for this?

    Details

      Description

      $ cat spec-local.scala 
      object Test {
        def meth = {
          def specMe[@specialized(Int) T](t: T) = ???
        }
      }
      
      $ ../build/quick/bin/scalac -Xprint:specialize spec-local.scala 
      [[syntax trees at end of                specialize]] // spec-local.scala
      package <empty> {
        object Test extends Object {
          def <init>(): Test.type = {
            Test.super.<init>();
            ()
          };
          def meth(): Unit = {
            // specMe doesn't deserve specialization? :(
            def specMe[@specialized(scala.Int) T >: Nothing <: Any](t: T): Nothing = scala.this.Predef.???();
            ()
          }
        }
      }
      

      A question is whether this was overlooked or is there a serious reason that specialization does not visit local methods. Btw, this bit us while working on https://github.com/nicolasstucki/specialized/.

        Activity

        Hide
        Paul Phillips added a comment -

        This was just brought up by rex kerr as well. I feel safe in saying there's no reason not to specialize local methods; quite the opposite, they should be prioritized because the limited visibility means they won't be subject to most of the problems which plague specialization.

        Show
        Paul Phillips added a comment - This was just brought up by rex kerr as well. I feel safe in saying there's no reason not to specialize local methods; quite the opposite, they should be prioritized because the limited visibility means they won't be subject to most of the problems which plague specialization.
        Hide
        Vlad Ureche added a comment -

        A little digging into this bug shows there's an undocumented assumption in specialization: normalized members (methods whose type parameters are specialized) should always belong to classes. This assumption is visible in the info transformer, which only matches `ClassInfoType`s and in the tree transformer which only creates empty bodies for methods inside `ClassDef`s.

        It shouldn't be impossible to undo this assumption, but it may take some hacking to have a PR ready.

        Show
        Vlad Ureche added a comment - A little digging into this bug shows there's an undocumented assumption in specialization: normalized members (methods whose type parameters are specialized) should always belong to classes. This assumption is visible in the info transformer, which only matches `ClassInfoType`s and in the tree transformer which only creates empty bodies for methods inside `ClassDef`s. It shouldn't be impossible to undo this assumption, but it may take some hacking to have a PR ready.
        Show
        Vlad Ureche added a comment - https://github.com/scala/scala/pull/2655
        Hide
        Adriaan Moors added a comment -

        merged for 2.10.x
        master: https://github.com/scala/scala/pull/2683 pending review

        Show
        Adriaan Moors added a comment - merged for 2.10.x master: https://github.com/scala/scala/pull/2683 pending review

          People

          • Assignee:
            Vlad Ureche
            Reporter:
            Vlad Ureche
          • Votes:
            1 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development