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

Compiler generates different bytecode with -Ydebug -Ylog:specialize

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.2, Scala 2.10.0
    • Fix Version/s: Scala 2.10.0-M6
    • Component/s: None
    • Labels:
      None

      Description

      Here's a pretty simple program:

      class Bar[@specialized(Int) Q](q:Q) {
        def qux[@specialized(Int) Z](f:Q => Z) = new Bar(f(q))
      }
      

      When compiled with -Ylog:specialize -Ydebug it generates different bytecode than what would otherwise be created. Here is a diff of the Bar$mcI$sp bytecode I generated using "javap -c 'Bar$mcI$sp'":

      23a24,41
      > public Bar qux$mIc$sp(scala.Function1);
      >   Code:
      >    0: aload_0
      >    1: aload_1
      >    2: invokevirtual   #39; //Method qux$mIcI$sp:(Lscala/Function1;)LBar;>    5: areturn
      > 
      > public Bar qux$mIcI$sp(scala.Function1);
      >   Code:
      >    0: new     #2; //class Bar$mcI$sp
      >    3: dup
      >    4: aload_1
      >    5: aload_0
      >    6: getfield        #19; //Field q$mcI$sp:I
      >    9: invokeinterface #43,  2; //InterfaceMethod scala/Function1.apply$mcII$sp:(I)I
      >    14:        invokespecial   #46; //Method "<init>":(I)V
      >    17:        areturn
      >
      

      As you can see, two extra methods are being created.

      I think that scalac should be generating these methods in all cases, so as you can imagine I'm quite interested in why they only get generated when doing debugging!

      I will comment on this ticket as I learn more.

        Activity

        Hide
        Erik Osheim added a comment -

        This will be fixed if https://github.com/scala/scala/pull/1128 is merged.

        Show
        Erik Osheim added a comment - This will be fixed if https://github.com/scala/scala/pull/1128 is merged.
        Hide
        Erik Osheim added a comment -

        Fixed in 97ae6f6.

        Show
        Erik Osheim added a comment - Fixed in 97ae6f6.
        Hide
        Erik Osheim added a comment -

        Fixed in 97ae6f6.

        Show
        Erik Osheim added a comment - Fixed in 97ae6f6.

          People

          • Assignee:
            Erik Osheim
            Reporter:
            Erik Osheim
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development