Expanding macros such as __FILE__ or __TIME__ exposes
arbitrary generated filenames and timestamps from the compiler
pipeline which are not useful for interop and makes the klib
generation non-deterministic. This patch instead redefines
the macros to just map to their name in the properties
available from Kotlin.
Co-authored-by: Johan Bay <jobay@google.com>
If a suspend function is called from `autoreleasepool {}` block, this
might cause the autoreleasepool frame to be removed earlier than
expected. See https://youtrack.jetbrains.com/issue/KT-50786 for more
details.
^KT-50786 Fixed
Previous implementation of `@ExportObjCClass` relied on the fact that
initialization of top-level fields was eager, i.e. happened during
Kotlin runtime initialization, when Kotlin code is accesses for the
first time.
With the new MM, initialization of top-level fields became lazy, it
happens when the particular file is accessed for the first time.
This commit fixes `@ExportObjCClass` with the new MM by making the
initialization of particular top-level fields eager.
^KT-53373 Fixed
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.
For some reason, libclang's indexer doesn't index categories with
__attribute__((external_source_symbol(language="Swift",...))),
so we have to additionally enumerate them explicitly.
^KT-49455 Fixed
^KT-48816 Fixed
Native compiler uses lazy IR for declarations provided by cinterop.
The problem: `FakeOverrideBuilder` requests super types during
type checking, accessing `.owner` for them. So if a type and super type
are represented as lazy IR, and lazy IR generation is not enabled yet,
then the super type symbol won't be bound by this moment, and the access
will fail.
This happens in KT-48816: fake override builder tries to access `.owner`
for `IrClassSymbol` of `NSObject` (super type of `NSDate` and `NSUUID`).
Fix this by enabling lazy IR generation before building fake overrides.
By default, C functions compiled to bitcode by clang have the
nounwind attribute. If such functions throws an exception, the
behaviour is undefined.
Our interop machinery can process foreign exceptions on call sites
(terminate or wrap them in Kotlin exceptions). But if the interop
bridges have the nounwind attribute, LLVM optimizations (particularly
inlining) may lead to the situation when a foreign exception is ignored by
our foreign exception handler.
This patch fixes the issue by compiling bridges with -fexceptions flag.
This flag makes clang to not set the nounwind attribute, so exceptions
can be thrown through C frames.