Skip to content

Commit 2857ccd

Browse files
committed
Update binary API and inlining example
1 parent 19165b1 commit 2857ccd

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

content/binary-api.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,29 +121,35 @@ In the bytecode, `@binaryAPIAccessor` generated accessors will have the [ACC_PUB
121121

122122
#### Binary API and inlining
123123

124-
If there is a reference to a binary API in an inline method we can use the definition without needing an inline accessor.
124+
A non-public reference in an inline method is handled as follows:
125+
- if the reference is a `@binaryAPI` the reference is used;
126+
- if the reference is a `@binaryAPIAccessor` the accessor is used;
127+
- otherwise, an accessor is automatically generated and used. We will emit a warning with an actionable diagnostic containing the code needed to migrate to `@binaryAPI` or `@binaryAPIAccessor`.
125128

126129
Example 3:
127130
~~~ scala
128131
class C {
129-
@binaryAPI protected def a: Int = ...
130-
protected def b: Int = ...
131-
inline def foo: Int = a + b
132+
@binaryAPIAccessor private def a: Int = ...
133+
private def b: Int = ...
134+
@binaryAPI protected def c: Int = ...
135+
protected def d: Int = ...
136+
inline def foo: Int = a + b + c + d
132137
}
133138
~~~
134139
before inlining the compiler will generate the accessors for inlined definitions
135140
~~~ scala
136141
class C {
137-
@binaryAPI protected def a: Int = ...
138-
protected def b: Int = ...
139-
final def C$inline$b: Int = ...
140-
inline def foo: Int = a + C$inline$b
142+
@binaryAPIAccessor private def a: Int = ...
143+
private def b: Int = ...
144+
@binaryAPI protected def c: Int = ...
145+
protected def d: Int = ...
146+
final def C$inline$a: Int = ... // generated by `@binaryAPIAccessor`
147+
final def C$inline$b: Int = ... // warn: `b` should be annotated with `@binaryAPIAccessor` + migration code
148+
final def C$inline$d: Int = ... // warn: `d` should be annotated with `@binaryAPI` + migration code
149+
inline def foo: Int = C$inline$a + C$inline$b + c + C$inline$d
141150
}
142151
~~~
143152

144-
Note that if the inlined member is `a` would be private, we would generate the accessor `C$inline$a`, which happens to be binary compatible with the automatically generated one.
145-
This is only a tiny mitigation of binary compatibility issues compared with all the different ways accessors can be generated.
146-
147153
### Specification
148154

149155
We must add `binaryAPI` and `binaryAPIAccessor` to the standard library.

0 commit comments

Comments
 (0)