From 1f397abaafed7bac3828463835cff53e632b16a8 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Mon, 20 Jan 2020 12:08:15 +0300 Subject: [PATCH] Enable -Xobjc-generics by default --- OBJC_INTEROP.md | 29 +++++++++---------- .../org/jetbrains/kotlin/cli/bc/K2Native.kt | 2 +- .../cli/bc/K2NativeCompilerArguments.kt | 4 +-- backend.native/tests/build.gradle | 4 +-- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/OBJC_INTEROP.md b/OBJC_INTEROP.md index 46ec9871f58..c20636f0c36 100644 --- a/OBJC_INTEROP.md +++ b/OBJC_INTEROP.md @@ -232,21 +232,6 @@ generics defined on classes to help provide additional type information to the c Generic feature support for Objc and Swift differ from Kotlin, so the translation will inevitably lose some information, but the features supported retain meaningful information. -### To Use - -Generics are currently not enabled by default. To have the framework header written with generics, add an experimental -flag to the compiler config: - -
- -```kotlin -binaries.framework { - freeCompilerArgs += "-Xobjc-generics" -} -``` - -
- #### Limitations Objective-C generics do not support all features of either Kotlin or Swift, so there will be some information lost @@ -327,6 +312,20 @@ In Kotlin you can provide upper bounds for a generic type. Objective-C also supp in more complex cases, and is currently not supported in the Kotlin - Objective-C interop. The exception here being a non-null upper bound will make Objective-C methods/properties non-null. +### To disable + +To have the framework header written without generics, add the flag to the compiler config: + +
+ +```kotlin +binaries.framework { + freeCompilerArgs += "-Xno-objc-generics" +} +``` + +
+ ## Casting between mapped types When writing Kotlin code, an object may need to be converted from a Kotlin type diff --git a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt index cbcd8851595..98aa3ed7698 100644 --- a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt +++ b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt @@ -218,7 +218,7 @@ class K2Native : CLICompiler() { put(COVERAGE, arguments.coverage) put(LIBRARIES_TO_COVER, arguments.coveredLibraries.toNonNullList()) arguments.coverageFile?.let { put(PROFRAW_PATH, it) } - put(OBJC_GENERICS, arguments.objcGenerics) + put(OBJC_GENERICS, !arguments.noObjcGenerics) put(LIBRARIES_TO_CACHE, parseLibrariesToCache(arguments, configuration, outputKind)) val libraryToAddToCache = parseLibraryToAddToCache(arguments, configuration, outputKind) diff --git a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt index 52cfcade235..69b1def3542 100644 --- a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt +++ b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt @@ -236,8 +236,8 @@ class K2NativeCompilerArguments : CommonCompilerArguments() { @Argument(value = "-Xcoverage-file", valueDescription = "", description = "Save coverage information to the given file") var coverageFile: String? = null - @Argument(value = "-Xobjc-generics", description = "Enable experimental generics support for framework header") - var objcGenerics: Boolean = false + @Argument(value = "-Xno-objc-generics", description = "Disable generics support for framework header") + var noObjcGenerics: Boolean = false @Argument(value="-Xoverride-clang-options", valueDescription = "", description = "Explicit list of Clang options") var clangOptions: Array? = null diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index a819e707bb2..eac8bf8a89f 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -3788,7 +3788,6 @@ if (isAppleTarget(project)) { } extraOpts "-Xembed-bitcode-marker" - extraOpts "-Xobjc-generics" extraOpts "-Xemit-lazy-objc-header=$lazyHeader" extraOpts project.globalTestArgs } @@ -3810,7 +3809,7 @@ if (isAppleTarget(project)) { dependsOn ":${target}CrossDistRuntime", ':commonDistRuntime', ':distCompiler' } - extraOpts "-Xembed-bitcode-marker", "-Xobjc-generics" + extraOpts "-Xembed-bitcode-marker" extraOpts project.globalTestArgs } } @@ -3832,7 +3831,6 @@ if (isAppleTarget(project)) { } extraOpts "-Xembed-bitcode" - extraOpts "-Xobjc-generics" extraOpts project.globalTestArgs } }