You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sips/pending/_posts/2017-01-13-binary-compatibility.md
+11-7Lines changed: 11 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -13,11 +13,12 @@ __first submitted 13 January 2017__
13
13
Scala is a language which evolves fast and thus made a decision to only promise binary compatibility across minor releases\[[3]\].
14
14
At the same time, there is a demand to develop APIs that live longer than a major release cycle of Scala.
15
15
This SIP introduces an annotation `@stableABI` that checks that `what you write is what you get`.
16
-
It will fail compilation in case compilation scheme of this class requires changes to methods signatures,
17
-
making them different from those written by developers and introducing implicit dependency on version of this desugaring.
18
16
17
+
`@stableABI` is a linter, that does not change binary output, but will fail compilation if Public API of a class uses features
18
+
of Scala that are desugared by compiler and may be binary incompatible across major releases.
19
+
19
20
As long as declarations in source have not changed, `@stableABI` annotated class will be compatible across major versions of Scala.
20
-
21
+
It complements MiMa\[[2]\] in indicating if a class will remain binary compatible across major Scala releases.
21
22
22
23
## Term definitions
23
24
* #####Binary descriptors
@@ -58,8 +59,10 @@ As long as declarations in source have not changed, `@stableABI` annotated class
58
59
2. Defining a class which is supposed to be also used from other JVM languages such as Java\Kotlin.
59
60
`@stableABI` will ensure both binary compatibility and that there are no unexpected methods
60
61
that would show up in members of a class or an interface.
62
+
3. Library authors can take advantage of language features introduced in new major versions of Scala
63
+
while still serving users on older language versions by defining their Public API as `@stableABI`.
61
64
62
-
The biggest use-case envisioned here by the authors is migration to Dotty.
65
+
The important use-case envisioned here by the authors is migration to Dotty.
63
66
We envision that there might be code-bases that for some reason don't compile either with Dotty or with Scalac.
64
67
This can be either because they rely on union types, only present in Dotty,
65
68
or because they need early initializers, which are only supported by Scalac.
@@ -83,7 +86,7 @@ These interfaces can be replaced by `@stableABI` annotated traits to reach the s
83
86
## Design Guidelines
84
87
`@stableABI` is a feature which is supposed to be used by a small subset of the ecosystem to be binary compatible across major versions of Scala.
85
88
Thus this is designed as an advanced feature that is used rarely and thus is intentionally verbose.
86
-
It's designed to provide strong guarantees, in some cases sacrificing ease of use.
89
+
It's designed to provide strong guarantees, in some cases sacrificing ease of use and be used in combination with MiMa\[[2]\]
87
90
88
91
The limitations enforced by `@stableABI` are designed to be an overapproximation:
89
92
instead of permitting a list of features known to be compatible, `@stableABI` enforces a stronger
@@ -155,7 +158,7 @@ Note that while those features are prohibited in the public API, they can be saf
155
158
156
159
- public fields. Can be simulated by explicitly defining public getters and setters that access a private field;
157
160
- lazy vals. Can be simulated by explicitly writing an implementation in source;
158
-
- case classes. Can be simulated by explicitly defining getters and other members synthesized for a case class(`copy`, `productArity`, `apply`, `unApply`, `unapply`).
161
+
- case classes. Can be simulated by explicitly defining getters and other members synthesized for a case class(`copy`, `productArity`, `apply`, `unapply`, etc).
159
162
160
163
The features listed below cannot be easily re-implemented in a class or trait annotated with `@stableABI`.
161
164
- default arguments;
@@ -201,7 +204,8 @@ as well as methods and implicit conversions imported from `scala` and `Predef`.
201
204
As such Standard library is expected would be the biggest source of warnings defined in previous section.
202
205
203
206
We propose to consider either making some classes in standard library use `@stableABI` or define new `@stableABI`
204
-
super-interfaces for them that should be used in `@stableABI` classes. This would also allow to consume Scala classes from other JVM languages such as Kotlin and Java.
207
+
super-interfaces for them that should be used in `@stableABI` classes.
208
+
This would also allow to consume Scala classes from other JVM languages such as Kotlin and Java.
205
209
## `@stableABI` and Scala.js
206
210
207
211
Allowing to write API-defining classes in Scala instead of Java will allow them to compile with Scala.js,
0 commit comments