Since we do not inline Kotlin_mm_* functions on watchos_arm32 and
ios_arm32 targets, there are a lot of unnecessary subsequent safepoints.
To reduce binary size and avoid unnecessary safepoints we apply a simple
optimization: remove all calls to Kotlin_mm_safePointFunctionPrologue in
a basic block except the first one.
^KT-51737 fixed.
Since runtime is split into several LLVM modules there is no LTO
optimizations between them during debug compilation because the latter
performs almost no optimizations to preserve debug info.
Of course, it affects runtime performance of debug binaries. To improve
it, we can link and aggressively optimize runtime modules and then link
optimized module into unoptimized Kotlin LLVM module.
This commit also introduces `linkRuntime` binary option that forces the
way we link runtime modules.
Previously it was like "null cannot be cast to MyObject" or
"MyObject cannot be cast to null", because `KClass.qualifiedName` is
`null` for local classes (including anonymous ones).
Use `KClass.toString()` instead, for both object actual dynamic type
and cast target type. This string representation is generally more
meaningful for such cases, and contains useful details for local
classes.
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.
unitSuspendFunctionObjCExport=legacy binary option can be used to
enable the legacy behaviour. It will be removed in a future release.
^KT-49928 Fixed
This enables using exported Frameworks with `-fmodules-decluse`.
One use-case for this is ensuring that distributed builds are
explicitly providing all required modules; this is important for
reproducibility.
For more background on `use` declarations, see:
https://clang.llvm.org/docs/Modules.html#use-declaration
The easiest way to reproduce this locally is by compiling a framework,
and emitting a pcm file with `swiftc`. Note that this requires a
reference to a pcm for Foundation, which can be found in the clang
ModuleCache.
```
kotlin-native/dist/bin/kotlinc-native ~/test.kt -produce framework -o /tmp/TestFramework.framework
swiftc -emit-pcm -module-name TestFramework -o /tmp/TestFramework.pcm /tmp/TestFramework.framework/Modules/module.modulemap -Xcc -fmodules-decluse -Xcc -fmodule-file=Foundation=$HOME/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/1IQ2SWDEIAPH0/Foundation-2FJBXN8U6QRTS.pcm
```
If we are compiling metadata, make synthetic forward declarations
`expect`, because otherwise `getFirstClassifierDiscriminateHeaders`
would prefer it over a "real" `expect` declaration from a commonized
interop library, which would ruin the whole idea of using synthetic
forward declarations only when no proper definitions are found.
^KT-51377 Fixed
It included "konan/lib/*.jar", which became incorrect after adding
kotlin-native-compiler-embeddable.jar to K/N dist in 2baf344f5f:
after that, the classpath included both kotlin-native.jar and
kotlin-native-compiler-embeddable.jar, so it contained duplicating
classes.
Fix this by choosing particular .jar files from konan/lib, and use
kotlin-native-compiler-embeddable.jar.
Custom dist is already in place and has the compiler, so we don't have
to build and copy the compiler to dist.
Moreover, if we do copy it, it might overwrite the compiler files
already loaded by this Gradle process (including the jar loaded to the
custom classloader), causing hard-to-debug errors.
To workaround this, we disable the distCompiler task and don't add any
dependencies to it when custom dist is used.
It is `@OutputDirectory`, so Gradle can invoke it early, even before the
klib itself is built.
Instead of reading `uniqName` from klib files, require specifying it
explicitly.