Commit c8e6050
committed
New trait encoding: use default methods, jettison impl classes
Until now, concrete methods in traits were encoded with
"trait implementation classes".
- Such a trait would compile to two class files
- the trait interface, a Java interface, and
- the implementation class, containing "trait implementation methods"
- trait implementation methods are static methods has an explicit self
parameter.
- some methods don't require addition of an interface method, such as
private methods. Calls to these directly call the implementation method
- classes that mixin a trait install "trait forwarders", which implement
the abstract method in the interface by forwarding to the trait
implementation method.
The new encoding:
- no longer emits trait implementation classes or trait implementation
methods.
- instead, concrete methods are simply retained in the interface, as JVM 8
default interface methods (the JVM spec changes in
[JSR-335](http://download.oracle.com/otndocs/jcp/lambda-0_9_3-fr-eval-spec/index.html)
pave the way)
- use `invokespecial` to call private or particular super implementations
of a method (rather `invokestatic`)
- in cases when we `invokespecial` to a method in an indirect ancestor, we add
that ancestor redundantly as a direct parent. We are investigating alternatives
approaches here.
- we still emit trait fowrarders, although we are
[investigating](scala/scala-dev#98) ways to only do
this when the JVM would be unable to resolve the correct method using its rules
for default method resolution.
Here's an example:
```
trait T {
println("T")
def m1 = m2
private def m2 = "m2"
}
trait U extends T {
println("T")
override def m1 = super[T].m1
}
class C extends U {
println("C")
def test = m1
}
```
The old and new encodings are displayed and diffed here: https://gist.github.com/retronym/f174d23f859f0e053580
Some notes in the implementation:
- No need to filter members from class decls at all in AddInterfaces
(although we do have to trigger side effecting info transformers)
- We can now emit an EnclosingMethod attribute for classes nested
in private trait methods
- Created a factory method for an AST shape that is used in
a number of places to symbolically bind to a particular
super method without needed to specify the qualifier of
the `Super` tree (which is too limiting, as it only allows
you to refer to direct parents.)
- I also found a similar tree shape created in Delambdafy,
that is better expressed with an existing tree creation
factory method, mkSuperInit.1 parent 699a5d9 commit c8e6050
File tree
41 files changed
+294
-893
lines changed- src
- compiler/scala/tools/nsc
- ast
- backend/jvm
- opt
- transform
- typechecker
- reflect/scala/reflect
- internal
- runtime
- test
- files
- jvm/innerClassAttribute
- pos
- junit/scala/tools/nsc
- backend/jvm/opt
- symtab
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
41 files changed
+294
-893
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
| |||
Lines changed: 40 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
535 | 535 | | |
536 | 536 | | |
537 | 537 | | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
538 | 554 | | |
539 | 555 | | |
540 | 556 | | |
| |||
582 | 598 | | |
583 | 599 | | |
584 | 600 | | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
595 | | - | |
596 | | - | |
597 | | - | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
598 | 614 | | |
599 | 615 | | |
600 | 616 | | |
| |||
1050 | 1066 | | |
1051 | 1067 | | |
1052 | 1068 | | |
1053 | | - | |
| 1069 | + | |
1054 | 1070 | | |
1055 | 1071 | | |
1056 | 1072 | | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
1057 | 1076 | | |
1058 | 1077 | | |
1059 | | - | |
| 1078 | + | |
1060 | 1079 | | |
1061 | 1080 | | |
1062 | 1081 | | |
1063 | | - | |
| 1082 | + | |
1064 | 1083 | | |
1065 | 1084 | | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
1066 | 1089 | | |
1067 | 1090 | | |
1068 | 1091 | | |
| |||
1342 | 1365 | | |
1343 | 1366 | | |
1344 | 1367 | | |
1345 | | - | |
| 1368 | + | |
1346 | 1369 | | |
1347 | 1370 | | |
1348 | 1371 | | |
| |||
Lines changed: 9 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
148 | | - | |
149 | | - | |
| 148 | + | |
150 | 149 | | |
151 | 150 | | |
152 | 151 | | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 152 | + | |
| 153 | + | |
157 | 154 | | |
158 | 155 | | |
159 | 156 | | |
| |||
248 | 245 | | |
249 | 246 | | |
250 | 247 | | |
251 | | - | |
| 248 | + | |
252 | 249 | | |
253 | 250 | | |
254 | 251 | | |
| |||
259 | 256 | | |
260 | 257 | | |
261 | 258 | | |
262 | | - | |
| 259 | + | |
263 | 260 | | |
264 | 261 | | |
265 | 262 | | |
| |||
284 | 281 | | |
285 | 282 | | |
286 | 283 | | |
287 | | - | |
| 284 | + | |
288 | 285 | | |
289 | 286 | | |
290 | 287 | | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
| 288 | + | |
318 | 289 | | |
319 | 290 | | |
320 | 291 | | |
321 | | - | |
| 292 | + | |
322 | 293 | | |
323 | 294 | | |
324 | 295 | | |
| |||
866 | 837 | | |
867 | 838 | | |
868 | 839 | | |
869 | | - | |
870 | 840 | | |
871 | 841 | | |
872 | 842 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
| 177 | + | |
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| |||
563 | 563 | | |
564 | 564 | | |
565 | 565 | | |
566 | | - | |
| 566 | + | |
567 | 567 | | |
568 | 568 | | |
569 | 569 | | |
| |||
Lines changed: 5 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
175 | | - | |
176 | 175 | | |
177 | 176 | | |
178 | 177 | | |
| |||
337 | 336 | | |
338 | 337 | | |
339 | 338 | | |
340 | | - | |
| 339 | + | |
341 | 340 | | |
342 | 341 | | |
343 | 342 | | |
| |||
603 | 602 | | |
604 | 603 | | |
605 | 604 | | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
| 605 | + | |
611 | 606 | | |
612 | 607 | | |
613 | 608 | | |
| |||
684 | 679 | | |
685 | 680 | | |
686 | 681 | | |
687 | | - | |
| 682 | + | |
688 | 683 | | |
689 | 684 | | |
690 | 685 | | |
| |||
697 | 692 | | |
698 | 693 | | |
699 | 694 | | |
700 | | - | |
| 695 | + | |
701 | 696 | | |
702 | 697 | | |
703 | 698 | | |
704 | 699 | | |
705 | | - | |
| 700 | + | |
706 | 701 | | |
707 | 702 | | |
708 | 703 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
| 140 | + | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| |||
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
302 | | - | |
| 302 | + | |
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
0 commit comments