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

AnyRef specialization seems broken in master

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Specialization
    • Labels:
      None
    • Environment:

      Linux

      Description

      So, while working on SI-3575 I noticed that AnyRef specialization didn't seem to be working. I created a simple test of AnyRef specialization, noted the failure with master, then tried compiling an example with Scala 2.9.1 and it worked.

      Here's the program:

      class C[@specialized(Int, AnyRef) A](v:A)                                                                                   
                                                                                                                                  
      object Test {                                                                                                               
        def main(args:Array[String]) {                                                                                            
          println(new C(123).getClass.getName)                                                                                    
          println(new C("abc").getClass.getName)                                                                                  
        }                                                                                                                         
      }
      

      The output on 2.9.1 is:

      C$mcI$sp
      C$mcT$sp
      

      Whereas on master it is:

      C$mcI$sp
      C
      

      I know that there was a change recently from using the (totally arbitrary) T to the (Java standard) L for referring to Object/AnyRef, as well as other AnyRef bugfixes. I'm currently trying to do a bisect to figure out when this example stopped working, but haven't figured it out yet.

        Activity

        Hide
        Erik Osheim added a comment -

        The reason why specializing a single parameter is nice is that in principle it will let us use @final/inline methods from C$mcL$sp instead of from C. I guess that's a little bit perverse since it's working around the weird subtyping/specialization stuff, but I think we're stuck with that design so we might as well make the best of it.

        But I agree, your example is a more realistic case.

        Show
        Erik Osheim added a comment - The reason why specializing a single parameter is nice is that in principle it will let us use @final/inline methods from C$mcL$sp instead of from C. I guess that's a little bit perverse since it's working around the weird subtyping/specialization stuff, but I think we're stuck with that design so we might as well make the best of it. But I agree, your example is a more realistic case.
        Hide
        Paul Phillips added a comment -

        I found it. Thanks for catching it so quickly.

        Show
        Paul Phillips added a comment - I found it. Thanks for catching it so quickly.
        Hide
        Paul Phillips added a comment -

        If I create LL/LLL/etc specializations, the compiler crashes during mixin finding duplicate members. I don't think it makes any sense to create L specializations but not LL, LLL, etc. so the upshot is that your test case still behaves the same even though this is fixed. Mine on the other hand prints

        C0$mcIII$sp
        C0$mcIIL$sp
        C0$mcILI$sp
        C0$mcILL$sp
        C0$mcLII$sp
        C0$mcLIL$sp
        C0$mcLLI$sp
        C0
        

        If there is sufficient motivation we can look into whether it makes sense to generate those all-AnyRef specializations, but I have no more time for this right now.

        Show
        Paul Phillips added a comment - If I create LL/LLL/etc specializations, the compiler crashes during mixin finding duplicate members. I don't think it makes any sense to create L specializations but not LL, LLL, etc. so the upshot is that your test case still behaves the same even though this is fixed. Mine on the other hand prints C0$mcIII$sp C0$mcIIL$sp C0$mcILI$sp C0$mcILL$sp C0$mcLII$sp C0$mcLIL$sp C0$mcLLI$sp C0 If there is sufficient motivation we can look into whether it makes sense to generate those all-AnyRef specializations, but I have no more time for this right now.
        Hide
        Erik Osheim added a comment -

        OK, that's fair. I'll put that on my list of things to look at later.

        Show
        Erik Osheim added a comment - OK, that's fair. I'll put that on my list of things to look at later.
        Hide
        Paul Phillips added a comment -

        1e648c3862

        Show
        Paul Phillips added a comment - 1e648c3862

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Erik Osheim
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development