Github user marmbrus commented on the pull request:
https://github.com/apache/spark/pull/9126#issuecomment-148234664
Unfortunately, I think these annotations may not be worthless and we might
be hitting a bug in the scala compiler. Consider the following class: `class
A(a: A) { def b = a }`
While `a` isn't explicitly declared as a `val`, the compiler is still
silently promoting it to a class field so that it can be used both in the
constructor and in function `b`. In Scala 2.10 at least this results in the
following bytecode:
```
...
private final int a;
flags: ACC_PRIVATE, ACC_FINAL
...
```
Where as `class A(@transient a: Int) { def b = a }` results in:
```
...
private final transient int a;
flags: ACC_PRIVATE, ACC_FINAL, ACC_TRANSIENT
...
```
You can play around with this yourself in the REPL:
```scala
$ build/sbt catalyst/console
scala> class A(a: Int) { def b = a }
defined class A
scala> org.apache.spark.sql.catalyst.expressions.codegen.DumpByteCode(new
A(1))
Classfile
/private/var/folders/36/cjkbrr953xg2p_krwrmn8h_r0000gn/T/spark-292994a3-dd85-4f32-bf2e-ba6f1365712e/$line3/$read$$iw$$iw$A.class
Last modified Oct 14, 2015; size 532 bytes
MD5 checksum f2a93222131c1a1c914498fd7d22ec13
Compiled from "<console>"
public class $line3.$read$$iw$$iw$A
SourceFile: "<console>"
InnerClasses:
public static #23= #20 of #22; //$iw$=class $line3/$read$$iw$ of
class $line3/$read
public static #23= #25 of #20; //$iw$=class $line3/$read$$iw$$iw$ of
class $line3/$read$$iw$
public static #26= #2 of #25; //A=class $line3/$read$$iw$$iw$A of
class $line3/$read$$iw$$iw$
Scala: length = 0x0
minor version: 0
major version: 50
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Utf8 $line3/$read$$iw$$iw$A
#2 = Class #1 // $line3/$read$$iw$$iw$A
#3 = Utf8 java/lang/Object
#4 = Class #3 // java/lang/Object
#5 = Utf8 <console>
#6 = Utf8 a
#7 = Utf8 I
#8 = Utf8 b
#9 = Utf8 ()I
#10 = NameAndType #6:#7 // a:I
#11 = Fieldref #2.#10 // $line3/$read$$iw$$iw$A.a:I
#12 = Utf8 this
#13 = Utf8 L$line3/$read$$iw$$iw$A;
#14 = Utf8 <init>
#15 = Utf8 (I)V
#16 = Utf8 ()V
#17 = NameAndType #14:#16 // "<init>":()V
#18 = Methodref #4.#17 // java/lang/Object."<init>":()V
#19 = Utf8 $line3/$read$$iw$
#20 = Class #19 // $line3/$read$$iw$
#21 = Utf8 $line3/$read
#22 = Class #21 // $line3/$read
#23 = Utf8 $iw$
#24 = Utf8 $line3/$read$$iw$$iw$
#25 = Class #24 // $line3/$read$$iw$$iw$
#26 = Utf8 A
#27 = Utf8 Code
#28 = Utf8 LocalVariableTable
#29 = Utf8 LineNumberTable
#30 = Utf8 SourceFile
#31 = Utf8 InnerClasses
#32 = Utf8 Scala
{
private final int a;
flags: ACC_PRIVATE, ACC_FINAL
public int b();
flags: ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: getfield #11 // Field a:I
4: ireturn
LocalVariableTable:
Start Length Slot Name Signature
0 5 0 this L$line3/$read$$iw$$iw$A;
LineNumberTable:
line 7: 0
public $line3.$read$$iw$$iw$A(int);
flags: ACC_PUBLIC
Code:
stack=2, locals=2, args_size=2
0: aload_0
1: iload_1
2: putfield #11 // Field a:I
5: aload_0
6: invokespecial #18 // Method
java/lang/Object."<init>":()V
9: return
LocalVariableTable:
Start Length Slot Name Signature
0 10 0 this L$line3/$read$$iw$$iw$A;
0 10 1 a I
LineNumberTable:
line 7: 0
}
```
```scala
scala> class A(@transient a: Int) { def b = a }
defined class A
scala> org.apache.spark.sql.catalyst.expressions.codegen.DumpByteCode(new
A(1))
Classfile
/private/var/folders/36/cjkbrr953xg2p_krwrmn8h_r0000gn/T/spark-292994a3-dd85-4f32-bf2e-ba6f1365712e/$line7/$read$$iw$$iw$A.class
Last modified Oct 14, 2015; size 532 bytes
MD5 checksum 0dc1337c7731bd1a88bf8f33bbfb9e4b
Compiled from "<console>"
public class $line7.$read$$iw$$iw$A
SourceFile: "<console>"
InnerClasses:
public static #23= #20 of #22; //$iw$=class $line7/$read$$iw$ of
class $line7/$read
public static #23= #25 of #20; //$iw$=class $line7/$read$$iw$$iw$ of
class $line7/$read$$iw$
public static #26= #2 of #25; //A=class $line7/$read$$iw$$iw$A of
class $line7/$read$$iw$$iw$
Scala: length = 0x0
minor version: 0
major version: 50
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Utf8 $line7/$read$$iw$$iw$A
#2 = Class #1 // $line7/$read$$iw$$iw$A
#3 = Utf8 java/lang/Object
#4 = Class #3 // java/lang/Object
#5 = Utf8 <console>
#6 = Utf8 a
#7 = Utf8 I
#8 = Utf8 b
#9 = Utf8 ()I
#10 = NameAndType #6:#7 // a:I
#11 = Fieldref #2.#10 // $line7/$read$$iw$$iw$A.a:I
#12 = Utf8 this
#13 = Utf8 L$line7/$read$$iw$$iw$A;
#14 = Utf8 <init>
#15 = Utf8 (I)V
#16 = Utf8 ()V
#17 = NameAndType #14:#16 // "<init>":()V
#18 = Methodref #4.#17 // java/lang/Object."<init>":()V
#19 = Utf8 $line7/$read$$iw$
#20 = Class #19 // $line7/$read$$iw$
#21 = Utf8 $line7/$read
#22 = Class #21 // $line7/$read
#23 = Utf8 $iw$
#24 = Utf8 $line7/$read$$iw$$iw$
#25 = Class #24 // $line7/$read$$iw$$iw$
#26 = Utf8 A
#27 = Utf8 Code
#28 = Utf8 LocalVariableTable
#29 = Utf8 LineNumberTable
#30 = Utf8 SourceFile
#31 = Utf8 InnerClasses
#32 = Utf8 Scala
{
private final transient int a;
flags: ACC_PRIVATE, ACC_FINAL, ACC_TRANSIENT
public int b();
flags: ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: getfield #11 // Field a:I
4: ireturn
LocalVariableTable:
Start Length Slot Name Signature
0 5 0 this L$line7/$read$$iw$$iw$A;
LineNumberTable:
line 7: 0
public $line7.$read$$iw$$iw$A(int);
flags: ACC_PUBLIC
Code:
stack=2, locals=2, args_size=2
0: aload_0
1: iload_1
2: putfield #11 // Field a:I
5: aload_0
6: invokespecial #18 // Method
java/lang/Object."<init>":()V
9: return
LocalVariableTable:
Start Length Slot Name Signature
0 10 0 this L$line7/$read$$iw$$iw$A;
0 10 1 a I
LineNumberTable:
line 7: 0
}
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]