Add -Xno-optimized-callable-references to disable KT-27362 optimization

This argument is useful in situations where the stdlib version which the
code compiles against is different from the one which is available at
runtime, such as the case of kotlin-gradle-plugin, which depends on the
compiler/stdlib compiled by 1.4, but may be executed in Gradle where
only 1.3.x is available.

 #KT-37435
This commit is contained in:
Alexander Udalov
2020-03-12 14:04:37 +01:00
parent ae4629a5a6
commit a9f7ff254b
6 changed files with 22 additions and 3 deletions
@@ -26,12 +26,17 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.KotlinType
class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSettings: LanguageVersionSettings) {
class JvmRuntimeTypes(
module: ModuleDescriptor,
private val languageVersionSettings: LanguageVersionSettings,
forceNoOptimizedCallableReferences: Boolean
) {
private val kotlinJvmInternalPackage = MutablePackageFragmentDescriptor(module, FqName("kotlin.jvm.internal"))
private val kotlinCoroutinesJvmInternalPackage =
MutablePackageFragmentDescriptor(module, languageVersionSettings.coroutinesJvmInternalPackageFqName())
val generateOptimizedCallableReferenceSuperClasses = languageVersionSettings.apiVersion >= ApiVersion.KOTLIN_1_4
val generateOptimizedCallableReferenceSuperClasses =
languageVersionSettings.apiVersion >= ApiVersion.KOTLIN_1_4 && !forceNoOptimizedCallableReferences
private fun internal(className: String, packageFragment: PackageFragmentDescriptor = kotlinJvmInternalPackage): Lazy<ClassDescriptor> =
lazy { createClass(packageFragment, className) }
@@ -219,7 +219,9 @@ class GenerationState private constructor(
val samWrapperClasses: SamWrapperClasses = SamWrapperClasses(this)
val globalInlineContext: GlobalInlineContext = GlobalInlineContext(diagnostics)
val mappingsClassesForWhenByEnum: MappingsClassesForWhenByEnum = MappingsClassesForWhenByEnum(this)
val jvmRuntimeTypes: JvmRuntimeTypes = JvmRuntimeTypes(module, configuration.languageVersionSettings)
val jvmRuntimeTypes: JvmRuntimeTypes = JvmRuntimeTypes(
module, configuration.languageVersionSettings, configuration.getBoolean(JVMConfigurationKeys.NO_OPTIMIZED_CALLABLE_REFERENCES)
)
val factory: ClassFileFactory
private var duplicateSignatureFactory: BuilderFactoryForDuplicateSignatureDiagnostics? = null
@@ -323,6 +323,12 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
)
var klibLibraries: String? by NullableStringFreezableVar(null)
@Argument(
value = "-Xno-optimized-callable-references",
description = "Do not use optimized callable reference superclasses available from 1.4"
)
var noOptimizedCallableReferences: Boolean by FreezableVar(false)
override fun configureAnalysisFlags(collector: MessageCollector): MutableMap<AnalysisFlag<*>, Any> {
val result = super.configureAnalysisFlags(collector)
result[JvmAnalysisFlags.strictMetadataVersionSemantics] = strictMetadataVersionSemantics
@@ -153,6 +153,7 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr
)
put(JVMConfigurationKeys.DISABLE_OPTIMIZATION, arguments.noOptimize)
put(JVMConfigurationKeys.EMIT_JVM_TYPE_ANNOTATIONS, arguments.emitJvmTypeAnnotations)
put(JVMConfigurationKeys.NO_OPTIMIZED_CALLABLE_REFERENCES, arguments.noOptimizedCallableReferences)
if (!JVMConstructorCallNormalizationMode.isSupportedValue(arguments.constructorCallNormalizationMode)) {
getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
@@ -119,4 +119,7 @@ public class JVMConfigurationKeys {
public static final CompilerConfigurationKey<Boolean> IS_IR_WITH_STABLE_ABI =
CompilerConfigurationKey.create("Is IR with stable ABI");
public static final CompilerConfigurationKey<Boolean> NO_OPTIMIZED_CALLABLE_REFERENCES =
CompilerConfigurationKey.create("Do not use optimized callable reference superclasses available from 1.4");
}
+2
View File
@@ -50,6 +50,8 @@ where advanced options include:
-Xno-exception-on-explicit-equals-for-boxed-null
Do not throw NPE on explicit 'equals' call for null receiver of platform boxed primitive type
-Xno-optimize Disable optimizations
-Xno-optimized-callable-references
Do not use optimized callable reference superclasses available from 1.4
-Xno-param-assertions Don't generate not-null assertions on parameters of methods accessible from Java
-Xno-receiver-assertions Don't generate not-null assertion for extension receiver arguments of platform types
-Xno-use-ir Do not use the IR backend. Useful for a custom-built compiler where IR backend is enabled by default