Skip to content

Commit 810637b

Browse files
committed
@binaryComatible: fixes and clarifications.
1 parent 0a8d6aa commit 810637b

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

Diff for: sips/pending/_posts/2017-01-13-binary-compatibility.md

+19-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ disqus: true
66

77
__Dmitry Petrashko__
88

9-
__first submitted 13 February 2017__
9+
__first submitted 13 January 2017__
1010

1111
## Introduction ##
1212

@@ -19,7 +19,15 @@ As long as signatures of methods in source is not changed, `@binaryCompatible` a
1919
will be compatible across major version of Scala.
2020

2121
## Use Cases
22-
Dotty currently uses java defined interfaces as public API for SBT in order to ensure binary compatibility.
22+
In case there's a need to develop an API that will be used by clients compiled using different major versions of Scala,
23+
the current approach is to either develop them in Java or to use best guess to restrict what Scala features should be used.
24+
There's also a different approach which is used by SBT: instead of publishing a binary `compiler-interface`, sources are published instead
25+
that would be locally compiled.
26+
27+
There's also a use-case of defining a class which is supposed to be also used from Java.
28+
`@binaryCompatible` will ensure that there are no not-expected methods that would show up in members of a class or an interface.
29+
30+
Dotty currently uses java defined interfaces as public API for IntelliJ in order to ensure binary compatibility.
2331
These interfaces can be replaced by `@binaryCompatible` annotated traits to reach the same goal.
2432

2533
## Design Guidelines
@@ -55,7 +63,6 @@ trait AbstractFile {
5563

5664
@binaryCompatible
5765
trait SourceFile extends AbstractFile {
58-
/** @return The content of this file as seen by the compiler. */
5966
def content(): Array[Char]
6067
}
6168

@@ -75,13 +82,22 @@ object Diagnostic {
7582
@static final val INFO: Int = 0
7683
}
7784

85+
@binaryCompatible
86+
class FeaturesInBodies {
87+
def apiMethod: Int = {
88+
// as body of the method isn't part of the public interface, one can use all features of Scala here.
89+
lazy val result = 0 // while lazy vals are prohibited in the class, they are allowed in the bodies of methods
90+
result
91+
}
92+
}
7893
{% endhighlight %}
7994
```
8095

8196
## Features that will fail compilation with `@binaryCompatible`
8297
The features listed below have complex encodings that may change in future versions. We prefer not to compromise on them.
8398
Most of those features can be simulated in a binary compatible way by writing a verbose re-impelemtation
8499
which won't rely on desugaring performed inside compiler.
100+
Note that while those features are prohibited in the public API, they can be safely used inside bodies of the methods.
85101

86102
- public fields. Can be simulated by explicitly defining public getters and setters that access a private field;
87103
- lazy vals. Can be simulated by explicitly writing an implementation in source;

0 commit comments

Comments
 (0)