Commit Graph

40 Commits

Author SHA1 Message Date
Mark Mann 47f6cb663e Native: add flag that disables ObjC method name mangling for methods in different Kotlin Interfaces (#5070) 2023-01-20 21:27:44 +01:00
Pavel Kunyavskiy 5674722742 [K/N] Fix crash on exporting cached suspend function
^KT-55736
2023-01-13 16:28:53 +00:00
Svyatoslav Scherbina e2640b4afa Native: add an option to disable exported Swift member name mangling
This commit supports `objcExportDisableSwiftMemberNameMangling=true`
binary option, which disables mangling for Swift names in generated
Objective-C headers, but keeps mangling for Objective-C names.

Enabling it might cause issues in some cases with actual clashes.

^KT-53638 Fixed
2023-01-11 08:57:12 +00:00
Mads Ager 35e94a1ef7 [K/N] Fully rename parameters based on ObjCName annotations.
The original name was still left in the ObjC code for cases
such as:

```
class A(@property:ObjCName("y") @ObjCName("y") val x: Int)
```

which compiled to:

```
@interface FrameworkA : FrameworkBase
- (instancetype)initWithY:(int32_t)x __attribute__((swift_name("init(y:)"))) __attribute__((objc_designated_initializer));
@property (readonly) int32_t y __attribute__((swift_name("y")));
@end
```

This change renames the `x` ocurrence in `initWithY` which is
important in case ObjCName is used to avoid using names that
conflict with ObjC preprocessor macros.
2023-01-02 18:57:21 +00:00
Pavel Kunyavskiy 17e9a6a781 [klib] Fix serialization of missing annotations
^KT-42490
^KT-44625
2022-12-20 20:06:51 +00:00
Gleb Lukianets a3e396e7e4 [K/N] KT-53069: Guard against recursive generic type argument constraints during objc export
Merge-request: KT-MR-7872
Merged-by: Gleb Lukianets <Gleb.Lukianets@jetbrains.com>
2022-12-08 14:03:45 +00:00
Svyatoslav Scherbina 39c73e25a4 Native: improve thread state switches for NSSet/NSDictionary adapters
^KT-54119
2022-09-22 07:37:44 +00:00
Svyatoslav Scherbina 728fe918fe Native: don't expect that startCoroutineUninterceptedOrReturn receiver is FunctionN+1
Previous implementation of startCoroutineUninterceptedOrReturn expected
that the receiver (i.e. the suspend function object to start) of type
SuspendFunctionN (i.e. suspend function type with arity = N) is also an
instance of FunctionN+1 (i.e. regular function type with arity = N + 1)
with proper convention.

While compiler tries to achieve that (for better compatibility with
Kotlin/JVM, by generating additional supertypes and methods for classes
implementing suspend function types), this doesn't work e.g. for
implementations defined in Swift.

Fix this by adding fallbacks for cases when the receiver is not
a FunctionN+1, while keeping the fastpath for default FunctionN+1
cases.

^KT-51043 Fixed
2022-09-01 09:35:22 +00:00
Rick Clephas 6ae517a2df [Native] Add HiddenFromObjC and ShouldRefineInSwift annotations 2022-08-22 16:10:44 +02:00
Sergey Bogolepov 89d3b9819b [K/N] Mute test parts that cause KT-53317 2022-07-25 16:28:49 +00:00
Rick Clephas 5a5e6ad8cd [K/N] Add ObjCName annotation (#4815) 2022-07-23 18:58:06 +02:00
Sergey Bogolepov be29052a64 [K/N] Update tests for KT-42641 2022-07-21 06:50:25 +00:00
Vladimir Sukharev 680fec06d3 Add note comment for protected properties
^KT-51593 Fixed

Merge-request: KT-MR-6593
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2022-07-04 14:24:21 +00:00
Vladimir Sukharev 409d959816 KT-51593 Include more information in Objective-C header documentation
#KT-51593 Fixed

Merge-request: KT-MR-6437
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2022-06-23 07:35:06 +00:00
Diego Gomez Olvera 9a430efbe7 [KT-52681] Remove unnecessary semicolon after Objective-C @end
Objective-c `@end` doesn't need a semicolon, however KMM exported header
file, for instance:
```
__attribute__((swift_name("KotlinIterator")))
@protocol MyProjectKotlinIterator
@required
- (BOOL)hasNext __attribute__((swift_name("hasNext()")));
- (id _Nullable)next __attribute__((swift_name("next()")));
@end;
```
This creates problems with some code checkers that will not expect it
there, so it seems best to remove it.
2022-06-10 15:46:27 +03:00
Igor Chevdar 46f448b5d1 [K/N][tests] Fixed ObjC invalid identifiers test
Some identifiers will be invalid in Kotlin 1.7
2022-02-24 15:20:14 +03:00
Svyatoslav Scherbina ad72545647 ObjCExport: deprecate exporting data class componentN methods to Obj-C
The Objective-C methods for Kotlin data class componentN methods
shouldn't have been generated in the first place -- the corresponding
Kotlin methods are required to make the destructuring work in Kotlin,
and don't help in Objective-C or Swift.

Calling them manually from Objective-C or Swift doesn't make much sense.
So now we deprecate this, in order to remove these methods from
Objective-C header completely later.

^KT-42641
^KT-49516 Fixed
2022-02-11 06:55:47 +00:00
Svyatoslav Scherbina 085e2448cd ObjCExport: don't use autorelease when sending arguments to Swift/Obj-C 2022-02-08 15:17:04 +00:00
Svyatoslav Scherbina 4cd60090e0 ObjCExport: fix replacing Kotlin class methods by Swift extensions
^KT-49937 Fixed
2022-01-28 11:15:39 +00:00
Pavel Kunyavskiy 3798920183 [K/N] Any.isFrozen is now always false when freezing is disabled 2022-01-24 13:38:30 +00:00
Svyatoslav Scherbina 776154881b ObjCExport: prohibit Kotlin exceptions leaking through native code back
If a Kotlin exceptions is thrown out of a native code in ObjCExport
(when calling Swift/Obj-C method overriding Kotlin method, or calling
Swift/Obj-C block as Kotlin function type), treat this exception as
fatal and terminate the process.
This could happen if the Kotlin exception leaked from Kotlin to native
code before.
In other words, when calling Kotlin -> Swift/Obj-C -> Kotlin, if Kotlin
exception passes from the last to the first part, terminate.

^KT-50830
2022-01-18 08:15:13 +00:00
Svyatoslav Scherbina 2bd53e3dea Native, old MM: fix releasing foreign refs to circular frozen graphs
^KT-49497
2021-12-20 14:56:38 +00:00
Svyatoslav Scherbina 2664a4460b ObjCExport: test that completion is properly retained by continuation
Add a test that checks that Kotlin Continuation wrapping Objective-C
completion handler has strong reference to it, i.e. completion handler
doesn't get reclaimed too early.

Follow-up to 4dcfd38.
2021-12-10 10:35:36 +00:00
Svyatoslav Scherbina 59bae29d64 ObjCExport: add test for calling Unit-typed completion asynchronously
Follow-up to 4dcfd38.
2021-12-10 10:35:36 +00:00
Pavel Kunyavskiy 8b4540f7e4 [K/N] Add test for suspend function inheritance in ObjCExport
^KT-49395
2021-12-01 07:50:39 +00:00
Nikolay Kasyanov 4dcfd38236 ObjCExport: remove KotlinUnit from suspend funs returning Unit (#4635)
With `unitSuspendFunctionObjCExport=proper` binary option,
for Unit-returning suspend functions ObjCExport now generates
completion handlers without redundant `KotlinUnit*` result parameter.

So Swift (5.5+) can import these functions as Void-returning async
functions.

^KT-47399 Fixed
2021-11-18 10:01:33 +03:00
Pavel Kunyavskiy 68445deae8 [K/N] Forbid calling sealed class constructor from objc 2021-10-08 11:39:42 +00:00
Svyatoslav Scherbina b32ab48596 Native: add tests for autorelease optimization in ObjCExport
The compiler should do its best to avoid putting objects to autorelease
pools.
2021-09-15 11:48:17 +00:00
Svyatoslav Scherbina eeffa49cd9 Native: don't generate .companion in ObjCExport if the companion is not exported
^KT-47462 Fixed
2021-06-28 08:19:12 +00:00
Svyatoslav Scherbina 786cb47450 Native: improve ObjCExport test for companion enum entry clash 2021-06-28 08:19:11 +00:00
Svyatoslav Scherbina 04e8140162 Native: emit _Nullable_result attribute when generating Objective-C header
^KT-47042 Fixed
2021-06-22 16:12:37 +00:00
Svyatoslav Scherbina 9b49d0cf76 Native: fix testObjCExport testdata after 53baef88
(was broken during rebase)
2021-06-22 12:49:09 +03:00
Svyatoslav Scherbina 53baef8892 Add more tests for Native ObjCExport virtual adapters machinery 2021-06-22 09:29:30 +00:00
Svyatoslav Scherbina 5d5628f56e Native: apply ObjCExport virtual adapters from interfaces of supers
Previously they were skipped, and this was an incorrect optimization:
even if super class implements the interface too, this doesn't mean
that virtual adapters provided by that interface are inherited
by non-exported subclass that needs them;
for example, this doesn't happen when the super class is exported
(i.e. Obj-C class is not created at runtime).

Remove incorrect optimization instead of making it more sophisticated,
because it is useless anyway.

^KT-46431 Fixed
2021-06-22 09:29:29 +00:00
Pavel Kunyavskiy d7a3310042 [K/N] KT-43780: support of more convenient objects using from objC/Swift 2021-06-18 08:02:22 +00:00
Vladimir Ivanov 2165cc8f0d [Native] Fix test data for testObjCExportNoGeneric (#4424) 2021-06-02 11:13:07 +03:00
Alexander Shabalin af1f57007a https://channel9.msdn.com/Shows/Going+Deep/Cpp-and-Beyond-2012-Herb-Sutter-atomic-Weapons-2-of-2 2021-05-27 17:18:55 +00:00
Svyatoslav Scherbina d531df1643 Native: add KotlinThrowable.asError() to the generated Obj-C framework
This method can be useful when overriding a throwing Kotlin method in
Swift or Obj-C. In this case, a user can call asError to wrap Kotlin exception
to (NS)Error and then throw it to Kotlin, which will unwrap it back.

^KT-45127 Fixed
2021-04-15 08:21:30 +00:00
Vladimir Ivanov c5f06d6e3f Patch expectedLazyNoGenerics.h to corresond with new test (#4271) 2021-04-02 19:38:22 +03:00
Florian Kistner bd614aba0b Retain typed generics in ObjC export stubs (#4727)
* Add ObjC export test with disabled generics
* Retain typed generics in ObjC export stubs
* Introduce ObjC variance enum to decouple stubs from Kotlin variance

(cherry picked from commit 4d7c78b952a467ca3318c8c49d36b768fdc1ef9c)
2021-03-09 20:19:31 +00:00