Rename -Xno-use-ir -> -Xuse-old-backend, add Gradle option

As soon as JVM IR is enabled by default (in language version 1.5), use
the CLI argument `-Xuse-old-backend` or Gradle option `useOldBackend` to
switch to the old JVM backend.
This commit is contained in:
Alexander Udalov
2020-12-30 21:33:48 +01:00
parent b8fb1ce83c
commit 22d0e5eb65
8 changed files with 43 additions and 20 deletions
@@ -85,8 +85,9 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
@Argument(value = "-Xuse-ir", description = "Use the IR backend") @Argument(value = "-Xuse-ir", description = "Use the IR backend")
var useIR: Boolean by FreezableVar(false) var useIR: Boolean by FreezableVar(false)
@Argument(value = "-Xno-use-ir", description = "Do not use the IR backend. Useful for a custom-built compiler where IR backend is enabled by default") @GradleOption(DefaultValues.BooleanFalseDefault::class)
var noUseIR: Boolean by FreezableVar(false) @Argument(value = "-Xuse-old-backend", description = "Use the old JVM backend")
var useOldBackend: Boolean by FreezableVar(false)
@Argument( @Argument(
value = "-Xallow-unstable-dependencies", value = "-Xallow-unstable-dependencies",
@@ -462,7 +463,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
} }
override fun checkIrSupport(languageVersionSettings: LanguageVersionSettings, collector: MessageCollector) { override fun checkIrSupport(languageVersionSettings: LanguageVersionSettings, collector: MessageCollector) {
if (!useIR) return if (!useIR || useOldBackend) return
if (languageVersionSettings.languageVersion < LanguageVersion.KOTLIN_1_3 if (languageVersionSettings.languageVersion < LanguageVersion.KOTLIN_1_3
|| languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_3 || languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_3
@@ -165,7 +165,7 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr
put(JVMConfigurationKeys.PARAMETERS_METADATA, arguments.javaParameters) put(JVMConfigurationKeys.PARAMETERS_METADATA, arguments.javaParameters)
val useIR = (arguments.useIR && !arguments.noUseIR) || arguments.useFir val useIR = (arguments.useIR && !arguments.useOldBackend) || arguments.useFir
put(JVMConfigurationKeys.IR, useIR) put(JVMConfigurationKeys.IR, useIR)
val abiStability = JvmAbiStability.fromStringOrNull(arguments.abiStability) val abiStability = JvmAbiStability.fromStringOrNull(arguments.abiStability)
@@ -242,11 +242,9 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr
} }
fun CompilerConfiguration.configureKlibPaths(arguments: K2JVMCompilerArguments) { fun CompilerConfiguration.configureKlibPaths(arguments: K2JVMCompilerArguments) {
assert(arguments.useIR || arguments.klibLibraries == null) { "Klib libraries can only be used with IR backend" } val libraries = arguments.klibLibraries ?: return
arguments.klibLibraries?.split(File.pathSeparator.toRegex()) assert(arguments.useIR && !arguments.useOldBackend) { "Klib libraries can only be used with IR backend" }
?.toTypedArray() put(JVMConfigurationKeys.KLIB_PATHS, libraries.split(File.pathSeparator.toRegex()).filterNot(String::isEmpty))
?.filterNot { it.isEmpty() }
?.let { put(JVMConfigurationKeys.KLIB_PATHS, it) }
} }
private val CompilerConfiguration.messageCollector: MessageCollector private val CompilerConfiguration.messageCollector: MessageCollector
+1 -1
View File
@@ -86,7 +86,6 @@ where advanced options include:
-Xno-receiver-assertions Don't generate not-null assertion for extension receiver arguments of platform types -Xno-receiver-assertions Don't generate not-null assertion for extension receiver arguments of platform types
-Xno-reset-jar-timestamps Do not reset jar entry timestamps to a fixed date -Xno-reset-jar-timestamps Do not reset jar entry timestamps to a fixed date
-Xno-unified-null-checks Use pre-1.4 exception types in null checks instead of java.lang.NPE. See KT-22275 for more details -Xno-unified-null-checks Use pre-1.4 exception types in null checks instead of java.lang.NPE. See KT-22275 for more details
-Xno-use-ir Do not use the IR backend. Useful for a custom-built compiler where IR backend is enabled by default
-Xprofile=<profilerPath:command:outputDir> -Xprofile=<profilerPath:command:outputDir>
Debug option: Run compiler with async profiler, save snapshots to outputDir, command is passed to async-profiler on start Debug option: Run compiler with async profiler, save snapshots to outputDir, command is passed to async-profiler on start
You'll have to provide async-profiler.jar on classpath to use this You'll have to provide async-profiler.jar on classpath to use this
@@ -116,6 +115,7 @@ where advanced options include:
Suppress the "cannot access built-in declaration" error (useful with -no-stdlib) Suppress the "cannot access built-in declaration" error (useful with -no-stdlib)
-Xuse-ir Use the IR backend -Xuse-ir Use the IR backend
-Xuse-javac Use javac for Java source and class files analysis -Xuse-javac Use javac for Java source and class files analysis
-Xuse-old-backend Use the old JVM backend
-Xuse-old-class-files-reading Use old class files reading implementation. This may slow down the build and cause problems with Groovy interop. -Xuse-old-class-files-reading Use old class files reading implementation. This may slow down the build and cause problems with Groovy interop.
Should be used in case of problems with the new implementation Should be used in case of problems with the new implementation
-Xuse-14-inline-classes-mangling-scheme -Xuse-14-inline-classes-mangling-scheme
@@ -17,6 +17,7 @@ import com.intellij.psi.MultiRangeReference
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import com.intellij.util.containers.MultiMap import com.intellij.util.containers.MultiMap
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.config.KotlinFacetSettings
import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Diagnostic
@@ -273,14 +274,19 @@ private class ElementAnnotator(
} }
private fun isUnstableAbiClassDiagnosticForModulesWithEnabledUnstableAbi(diagnostic: Diagnostic): Boolean { private fun isUnstableAbiClassDiagnosticForModulesWithEnabledUnstableAbi(diagnostic: Diagnostic): Boolean {
val setting = when (diagnostic.factory) { val factory = diagnostic.factory
Errors.IR_WITH_UNSTABLE_ABI_COMPILED_CLASS -> K2JVMCompilerArguments::useIR if (factory != Errors.IR_WITH_UNSTABLE_ABI_COMPILED_CLASS && factory != Errors.FIR_COMPILED_CLASS) return false
Errors.FIR_COMPILED_CLASS -> K2JVMCompilerArguments::useFir
else -> return false
}
val module = element.module ?: return false val module = element.module ?: return false
val moduleFacetSettings = KotlinFacetSettingsProvider.getInstance(element.project)?.getSettings(module) ?: return false val moduleFacetSettings = KotlinFacetSettingsProvider.getInstance(element.project)?.getSettings(module) ?: return false
return moduleFacetSettings.isCompilerSettingPresent(setting) return when (factory) {
Errors.IR_WITH_UNSTABLE_ABI_COMPILED_CLASS ->
moduleFacetSettings.isCompilerSettingPresent(K2JVMCompilerArguments::useIR) &&
!moduleFacetSettings.isCompilerSettingPresent(K2JVMCompilerArguments::useOldBackend)
Errors.FIR_COMPILED_CLASS ->
moduleFacetSettings.isCompilerSettingPresent(K2JVMCompilerArguments::useFir)
else -> error(factory)
}
} }
companion object { companion object {
@@ -51,7 +51,8 @@ tasks {
"-Xopt-in=kotlin.contracts.ExperimentalContracts", "-Xopt-in=kotlin.contracts.ExperimentalContracts",
"-Xcoroutines=enable", "-Xcoroutines=enable",
"-XXLanguage:-ReleaseCoroutines", "-XXLanguage:-ReleaseCoroutines",
"-Xno-use-ir" "-Xno-use-ir",
"-Xuse-old-backend"
) )
moduleName = "kotlin-coroutines-experimental-compat" moduleName = "kotlin-coroutines-experimental-compat"
} }
@@ -62,7 +63,8 @@ tasks {
apiVersion = "1.2" apiVersion = "1.2"
freeCompilerArgs = listOf( freeCompilerArgs = listOf(
"-Xcoroutines=enable", "-Xcoroutines=enable",
"-Xno-use-ir" "-Xno-use-ir",
"-Xuse-old-backend"
) )
} }
} }
@@ -71,7 +73,8 @@ tasks {
languageVersion = "1.3" languageVersion = "1.3"
apiVersion = "1.3" apiVersion = "1.3"
freeCompilerArgs = listOf( freeCompilerArgs = listOf(
"-Xno-use-ir" "-Xno-use-ir",
"-Xuse-old-backend"
) )
} }
} }
@@ -17,4 +17,4 @@ interface KotlinCommonOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonToo
* Default value: null * Default value: null
*/ */
var languageVersion: kotlin.String? var languageVersion: kotlin.String?
} }
@@ -58,4 +58,10 @@ interface KotlinJvmOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOption
* Default value: false * Default value: false
*/ */
var useIR: kotlin.Boolean var useIR: kotlin.Boolean
/**
* Use the old JVM backend
* Default value: false
*/
var useOldBackend: kotlin.Boolean
} }
@@ -102,6 +102,13 @@ internal abstract class KotlinJvmOptionsBase : org.jetbrains.kotlin.gradle.dsl.K
useIRField = value useIRField = value
} }
private var useOldBackendField: kotlin.Boolean? = null
override var useOldBackend: kotlin.Boolean
get() = useOldBackendField ?: false
set(value) {
useOldBackendField = value
}
internal open fun updateArguments(args: org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments) { internal open fun updateArguments(args: org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments) {
allWarningsAsErrorsField?.let { args.allWarningsAsErrors = it } allWarningsAsErrorsField?.let { args.allWarningsAsErrors = it }
suppressWarningsField?.let { args.suppressWarnings = it } suppressWarningsField?.let { args.suppressWarnings = it }
@@ -117,6 +124,7 @@ internal abstract class KotlinJvmOptionsBase : org.jetbrains.kotlin.gradle.dsl.K
noReflectField?.let { args.noReflect = it } noReflectField?.let { args.noReflect = it }
noStdlibField?.let { args.noStdlib = it } noStdlibField?.let { args.noStdlib = it }
useIRField?.let { args.useIR = it } useIRField?.let { args.useIR = it }
useOldBackendField?.let { args.useOldBackend = it }
} }
} }
@@ -135,4 +143,5 @@ internal fun org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments.fi
noReflect = true noReflect = true
noStdlib = true noStdlib = true
useIR = false useIR = false
useOldBackend = false
} }