Commit 66f8988
committed
WIP Emit trait method bodies in statics
And use this as the target of the default methods or
statically resolved super or $init calls.
The call-site change is predicated on `-Yuse-trait-statics`
as a stepping stone for experimentation / bootstrapping.
I have performed this transformation in the backend,
rather than trying to reflect this in the view from
Scala symbols + ASTs.
Once we commit to this change, we can remove the
`lateInterfaces` bookkeeping from the backend, as we no
long will need to add ancestor interfaces as direct
parents to allow use of invokespecial for super calls.
```
> ;scalac sandbox/test.scala ; scala Test
[info] Running scala.tools.nsc.MainGenericRunner -usejavacp Test
T
C
[success] Total time: 2 s, completed 04/05/2016 11:07:13 AM
> eval "javap -classpath . -c -private C".!!
[info] ans: String = Compiled from "test.scala"
[info] public class C implements T {
[info] public C();
[info] Code:
[info] 0: aload_0
[info] 1: invokespecial #14 // Method java/lang/Object."<init>":()V
[info] 4: aload_0
[info] 5: invokespecial #17 // Method T.$init$:()V
[info] 8: getstatic #23 // Field scala/Predef$.MODULE$:Lscala/Predef$;
[info] 11: ldc #24 // String C
[info] 13: invokevirtual #28 // Method scala/Predef$.println:(Ljava/lang/Object;)V
[info] 16: aload_0
[info] 17: invokespecial #32 // Method T.foo:()I
[info] 20: pop
[info] 21: return
[info] }
> ;scalac -Yuse-trait-statics sandbox/test.scala ; scala Test
[info] Running scala.tools.nsc.MainGenericRunner -usejavacp Test
T
C
[success] Total time: 2 s, completed 04/05/2016 11:07:39 AM
> eval "javap -classpath . -c -private C".!!
[info] ans: String = Compiled from "test.scala"
[info] public class C implements T {
[info] public C();
[info] Code:
[info] 0: aload_0
[info] 1: invokespecial #14 // Method java/lang/Object."<init>":()V
[info] 4: aload_0
[info] 5: invokestatic #18 // Method T.$init$:(LT;)V
[info] 8: getstatic #24 // Field scala/Predef$.MODULE$:Lscala/Predef$;
[info] 11: ldc #25 // String C
[info] 13: invokevirtual #29 // Method scala/Predef$.println:(Ljava/lang/Object;)V
[info] 16: aload_0
[info] 17: invokestatic #33 // Method T.foo:(LT;)I
[info] 20: pop
[info] 21: return
[info] }
> eval "javap -classpath . -c -private T".!!
[info] ans: String = Compiled from "test.scala"
[info] public interface T {
[info] public static int foo(T);
[info] Code:
[info] 0: iconst_0
[info] 1: ireturn
[info]
[info] public int foo();
[info] Code:
[info] 0: aload_0
[info] 1: invokestatic #15 // Method foo:(LT;)I
[info] 4: ireturn
[info]
[info] public static void $init$(T);
[info] Code:
[info] 0: getstatic #24 // Field scala/Predef$.MODULE$:Lscala/Predef$;
[info] 3: ldc #25 // String T
[info] 5: invokevirtual #29 // Method scala/Predef$.println:(Ljava/lang/Object;)V
[info] 8: return
[info]
[info] public void $init$();
[info] Code:
[info] 0: aload_0
[info] 1: invokestatic #32 // Method $init$:(LT;)V
[info] 4: return
[info] }
```1 parent 1b1bc81 commit 66f8988
File tree
4 files changed
+30
-5
lines changed- project
- src/compiler/scala/tools/nsc
- backend/jvm
- settings
4 files changed
+30
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1061 | 1061 | | |
1062 | 1062 | | |
1063 | 1063 | | |
1064 | | - | |
| 1064 | + | |
1065 | 1065 | | |
1066 | 1066 | | |
1067 | 1067 | | |
| |||
1082 | 1082 | | |
1083 | 1083 | | |
1084 | 1084 | | |
1085 | | - | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
1086 | 1090 | | |
1087 | 1091 | | |
1088 | 1092 | | |
| |||
Lines changed: 22 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
489 | 489 | | |
490 | 490 | | |
491 | 491 | | |
492 | | - | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
493 | 513 | | |
494 | 514 | | |
495 | 515 | | |
| |||
554 | 574 | | |
555 | 575 | | |
556 | 576 | | |
557 | | - | |
| 577 | + | |
558 | 578 | | |
559 | 579 | | |
560 | 580 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| 205 | + | |
205 | 206 | | |
206 | 207 | | |
207 | 208 | | |
| |||
0 commit comments