Skip to content

Commit 3421241

Browse files
committed
Update experimental-backend.md
1 parent 9278a29 commit 3421241

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

experimental-backend.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Experimental Backend in Scala 2.11
22

3-
Scala 2.11 ships with an experimental backend named "GenBCode", originally implemented by [Miguel Garcia](https://github.com/magarciaEPFL).
3+
Scala 2.11 ships with an experimental backend named "GenBCode", originally implemented by [@magarciaEPFL](https://github.com/magarciaEPFL).
44
This backend will become the new default in Scala 2.12.
55
Given that the new backend is experimental in Scala 2.11, it can be modified and extended without compatibility concerns.
66
Most of the work towards the Scala 2.12 backend happens in the 2.11 branch and flows into 2.11.x minor releases.
@@ -15,8 +15,49 @@ GenBCode without any further compiler flags is a drop-in replacement for the cur
1515
The generated bytecode is binary compatible, altough not exactly the same; some instruction sequences may differ.
1616
If you find a binary incompatibility, please [report an issue](https://issues.scala-lang.org/secure/Dashboard.jspa).
1717

18+
## Delambdafy-Method
1819

20+
`-Ydelambdafy:method` is an experimental option in Scala 2.11 to alter the translation of lambdas, implemented by [@JamesIry](https://github.com/JamesIry).
1921

20-
## Delambdafy-Method
22+
Traditionally, the anonymous class generated for a lambda contains the lambda body in the `apply` method of the class.
23+
When using delambdafy-method, a method containing the lambda body is generated for each lambda, and the anonymous class delegates to this method.
24+
25+
Delambdafy-method is a requiement for emitting lambdas in Java 8 style, as explained in detail in [this Gist by @retronym](https://gist.github.com/retronym/0178c212e4bacffed568).
26+
27+
## Target jvm-1.8
28+
29+
`-target:jvm-1.8` instructs the Scala compiler to generate classfiles of version 52 (the default is `jvm-1.6`, generating classfiles of version 50).
30+
31+
This option is one of the requirements to enable emitting lambdas in Java 8 style.
32+
33+
## Scala-Java8-Compat
34+
35+
The [`scala-java8-compat` library](https://github.com/scala/scala-java8-compat) defines subtypes of Scala's `FunctionN` that have a single abstract method.
36+
37+
The `FunctionN` traits in Scala are compiled to interface classfiles with multiple abstract methods (`compose`, `apply`, `andThen`, specialized variants of `apply`).
38+
The compat library compiles to Java 8 bytecode and makes use of [default methods](https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html) for all methods but `apply`.
39+
40+
## Emitting Java 8 Style Lambdas
41+
42+
The Scala 2.11.7 compiler emits lambdas in Java 8 style (using `invokedynamic` and LambdaMetaFactory) if the following conditions are met:
43+
- the compiler is running on Java 8
44+
- `-Ybackend:GenBCode` is enabled
45+
- `-Ydelambdafy:method` is enabled
46+
- `-target:jvm-1.8` is enabled
47+
- the scala-java8-compat library is on the compiler's classpath
48+
49+
In an SBT project, this can be achieved using the following settins:
50+
51+
libraryDependencies += "org.scala-lang.modules" %% "scala-java8-compat" % "0.5.0"
52+
53+
scalacOptions ++= List("-Ybackend:GenBCode", "-Ydelambdafy:method", "-target:jvm-1.8")
54+
55+
An sbt project with these options can be found here: https://github.com/lrytz/experimental-backend-2.11/tree/master
56+
57+
## New Optimizer
2158

59+
`-Yopt:l:classpath` enables the new optimizer.
2260

61+
As part of the new backend for Scala 2.12 we are developing a new inliner and bytecode optimizer.
62+
The inliner is already available in Scala 2.11.7 and can be enabled using the `-Yopt` compiler option.
63+
Use `-Yopt:help` to see the available optimizations.

0 commit comments

Comments
 (0)