diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt index 0c217daed93..7379c779c1a 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt @@ -95,18 +95,18 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { var irCheckLocalNames: Boolean by FreezableVar(false) @Argument( - value = "-Xallow-jvm-ir-dependencies", - description = "When not using the IR backend, do not report errors on those classes in dependencies, " + - "which were compiled by the IR backend" + value = "-Xallow-unstable-dependencies", + description = "Do not report errors on classes in dependencies, which were compiled by an unstable version of the Kotlin compiler" ) - var allowJvmIrDependencies: Boolean by FreezableVar(false) + var allowUnstableDependencies: Boolean by FreezableVar(false) @Argument( - value = "-Xir-binary-with-stable-abi", - description = "When using the IR backend, produce binaries which can be read by non-IR backend.\n" + - "The author is responsible for verifying that the resulting binaries do indeed have the correct ABI" + value = "-Xabi-stability", + valueDescription = "{stable|unstable}", + description = "When using unstable compiler features such as FIR or JVM IR, use 'stable' to mark generated class files as stable\n" + + "to prevent diagnostics from stable compilers at the call site.\n" ) - var isIrWithStableAbi: Boolean by FreezableVar(false) + var abiStability: String? by FreezableVar(null) @Argument( value = "-Xir-do-not-clear-binding-context", @@ -446,7 +446,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { result[JvmAnalysisFlags.suppressMissingBuiltinsError] = suppressMissingBuiltinsError result[JvmAnalysisFlags.irCheckLocalNames] = irCheckLocalNames result[JvmAnalysisFlags.enableJvmPreview] = enableJvmPreview - result[AnalysisFlags.allowUnstableDependencies] = allowJvmIrDependencies || useIR || useFir + result[AnalysisFlags.allowUnstableDependencies] = allowUnstableDependencies || useIR || useFir result[JvmAnalysisFlags.disableUltraLightClasses] = disableUltraLightClasses return result } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/AnalyzerWithCompilerReport.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/AnalyzerWithCompilerReport.kt index 50ce24605f3..eb2bfba7765 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/AnalyzerWithCompilerReport.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/AnalyzerWithCompilerReport.kt @@ -186,7 +186,7 @@ class AnalyzerWithCompilerReport( messageCollector.report( ERROR, "Classes compiled by a new Kotlin compiler backend were found in dependencies. " + - "Remove them from the classpath or use '-Xallow-jvm-ir-dependencies' to suppress errors" + "Remove them from the classpath or use '-Xallow-unstable-dependencies' to suppress errors" ) } @@ -194,7 +194,7 @@ class AnalyzerWithCompilerReport( messageCollector.report( ERROR, "Classes compiled by the new Kotlin compiler frontend were found in dependencies. " + - "Remove them from the classpath or use '-Xallow-jvm-ir-dependencies' to suppress errors" + "Remove them from the classpath or use '-Xallow-unstable-dependencies' to suppress errors" ) } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt index 0df11b8c373..e3429a8fe25 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt @@ -173,7 +173,17 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr put(JVMConfigurationKeys.IR, arguments.useIR && !arguments.noUseIR) - put(JVMConfigurationKeys.ABI_STABILITY, if (arguments.isIrWithStableAbi) JvmAbiStability.STABLE else JvmAbiStability.UNSTABLE) + val abiStability = JvmAbiStability.fromStringOrNull(arguments.abiStability) + if (arguments.abiStability != null) { + if (abiStability == null) { + getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report( + ERROR, + "Unknown ABI stability mode: ${arguments.abiStability}, supported modes: ${JvmAbiStability.values().map { it.description }}" + ) + } else { + put(JVMConfigurationKeys.ABI_STABILITY, abiStability) + } + } put(JVMConfigurationKeys.DO_NOT_CLEAR_BINDING_CONTEXT, arguments.doNotClearBindingContext) put(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, arguments.noCallAssertions) diff --git a/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmAbiStability.kt b/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmAbiStability.kt index 90fd1ca9d64..e40ecfae2c6 100644 --- a/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmAbiStability.kt +++ b/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmAbiStability.kt @@ -9,4 +9,9 @@ enum class JvmAbiStability(val description: String) { STABLE("stable"), UNSTABLE("unstable"), ; + + companion object { + fun fromStringOrNull(string: String?): JvmAbiStability? = + values().find { it.description == string } + } } diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 7d8bc2eaba4..2a2236368da 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -1,9 +1,13 @@ Usage: kotlinc-jvm where advanced options include: + -Xabi-stability={stable|unstable} + When using unstable compiler features such as FIR or JVM IR, use 'stable' to mark generated class files as stable + to prevent diagnostics from stable compilers at the call site. + -Xadd-modules= Root modules to resolve in addition to the initial modules, or all modules on the module path if is ALL-MODULE-PATH - -Xallow-jvm-ir-dependencies When not using the IR backend, do not report errors on those classes in dependencies, which were compiled by the IR backend -Xallow-no-source-files Allow no source files + -Xallow-unstable-dependencies Do not report errors on classes in dependencies, which were compiled by an unstable version of the Kotlin compiler -Xassertions={always-enable|always-disable|jvm|legacy} Assert calls behaviour -Xassertions=always-enable: enable, ignore jvm assertion settings; @@ -27,8 +31,6 @@ where advanced options include: -Xfriend-paths= Paths to output directories for friend modules (whose internals should be visible) -Xmultifile-parts-inherit Compile multifile classes as a hierarchy of parts and facade -Xir-check-local-names Check that names of local classes and anonymous objects are the same in the IR backend as in the old backend - -Xir-binary-with-stable-abi When using the IR backend, produce binaries which can be read by non-IR backend. - The author is responsible for verifying that the resulting binaries do indeed have the correct ABI -Xmodule-path= Paths where to find Java 9+ modules -Xjava-package-prefix Package prefix for Java files -Xjava-source-roots= Paths to directories with Java source files diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt index 3b5c02d2a9b..402dbe9f360 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt @@ -685,13 +685,13 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration } fun testOldAgainstJvmIrWithStableAbi() { - val library = compileLibrary("library", additionalOptions = listOf("-Xuse-ir", "-Xir-binary-with-stable-abi")) + val library = compileLibrary("library", additionalOptions = listOf("-Xuse-ir", "-Xabi-stability=stable")) compileKotlin("source.kt", tmpdir, listOf(library)) } fun testOldAgainstJvmIrWithAllowIrDependencies() { val library = compileLibrary("library", additionalOptions = listOf("-Xuse-ir")) - compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-Xallow-jvm-ir-dependencies")) + compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-Xallow-unstable-dependencies")) } fun testSealedClassesAndInterfaces() {