kotlin
kotlin copied to clipboard
RefinedForObjC and RefinedInSwift annotations
Relates to KT-42297.
The Kotlin ObjC/Swift is pretty great, but at the moment there are also some gaps (especially with the Swift interop) like suspend functions and enum classes. With some boilerplate code the interop for such code can be improved, which can even be automated with a compiler plugin/annotation processor. However one limitation of such boilerplate code is that it adds unnecessary declarations to your public API.
With the RefinedForObjC and RefinedInSwift annotations we can hide these unnecessary declarations from the public API.
We also have the meta-annotations RefinesForObjC and RefinesInSwift such that annotation processors can generate ObjC/Swift friendly APIs while automatically hiding the original declaration.
RefinedForObjC
Functions and properties annotated with the RefinedForObjC annotation won't be exported to ObjC.
This allows you to create a more ObjC friendly version in your Kotlin code.
With the
ObjCNameannotation from #4815 you could even use the original name of the function/property for your ObjC friendly version.
RefinedInSwift
The RefinedInSwift annotation adds the swift_private attribute to the declaration.
This results in the declarations being prefixed with __, which make them "invisible" from Swift.
These declarations can still be used in your Swift code to create your Swift friendly API, but won't be shown in e.g. the Xcode autocomplete.
Hi. Thank you for the PR! We will take a look later, hopefully next week.
@rickclephas could you please run :compiler:tests-for-compiler-generator:generateTests Gradle task and push the resulting changes?
@SvyatoslavScherbina done 👍🏻
@rickclephas Thank you! From the side of FIR part everything is ok. If @SvyatoslavScherbina also thinks that PR is ready, then I will ask for one more thing: can you please cleanup commit history?
- squash commits with fixes
- add prefixes to commit messages to indicate which subsystem is modified (
[FE 1.0]for old frontend,[FIR]for FIR frontend,[Native]for native backend, etc)
Cool! Updated the name and squashed the commits into three new ones.
@demiurg906 would you like a PR for the FIR checkers (with similar improvements) for @ObjCName (#4815) as well?:
@rickclephas Yes, it would be nice
Thank you!