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: content/binary-api.md
+17-11Lines changed: 17 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -121,29 +121,35 @@ In the bytecode, `@binaryAPIAccessor` generated accessors will have the [ACC_PUB
121
121
122
122
#### Binary API and inlining
123
123
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`.
125
128
126
129
Example 3:
127
130
~~~scala
128
131
classC {
129
-
@binaryAPI protecteddefa:Int= ...
130
-
protecteddefb:Int= ...
131
-
inlinedeffoo:Int= a + b
132
+
@binaryAPIAccessor privatedefa:Int= ...
133
+
privatedefb:Int= ...
134
+
@binaryAPI protecteddefc:Int= ...
135
+
protecteddefd:Int= ...
136
+
inlinedeffoo:Int= a + b + c + d
132
137
}
133
138
~~~
134
139
before inlining the compiler will generate the accessors for inlined definitions
135
140
~~~scala
136
141
classC {
137
-
@binaryAPI protecteddefa:Int= ...
138
-
protecteddefb:Int= ...
139
-
finaldefC$inline$b:Int= ...
140
-
inlinedeffoo:Int= a +C$inline$b
142
+
@binaryAPIAccessor privatedefa:Int= ...
143
+
privatedefb:Int= ...
144
+
@binaryAPI protecteddefc:Int= ...
145
+
protecteddefd:Int= ...
146
+
finaldefC$inline$a:Int= ... // generated by `@binaryAPIAccessor`
147
+
finaldefC$inline$b:Int= ... // warn: `b` should be annotated with `@binaryAPIAccessor` + migration code
148
+
finaldefC$inline$d:Int= ... // warn: `d` should be annotated with `@binaryAPI` + migration code
149
+
inlinedeffoo:Int=C$inline$a +C$inline$b + c +C$inline$d
141
150
}
142
151
~~~
143
152
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
-
147
153
### Specification
148
154
149
155
We must add `binaryAPI` and `binaryAPIAccessor` to the standard library.
0 commit comments