Provide configurable constructor call normalization
Three modes: - 'disable' (default): normalize constructor calls in coroutines only (required because uninitialized objects can't be stored in fields), don't insert additional code for forced class initialization; - 'enable': normalize constructor calls, don't insert additional code for forced class initialization; - 'preserve-class-initialization': normalize constructor calls, insert additional code for forced class initialization.
This commit is contained in:
+11
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.cli.common.arguments
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.config.AnalysisFlag
|
||||
import org.jetbrains.kotlin.config.JVMConstructorCallNormalizationMode
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.utils.Jsr305State
|
||||
import org.jetbrains.kotlin.utils.ReportLevel
|
||||
@@ -108,6 +109,16 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
@Argument(value = "-Xno-optimize", description = "Disable optimizations")
|
||||
var noOptimize: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(
|
||||
value = "-Xnormalize-constructor-calls",
|
||||
valueDescription = "{disable|enable|preserve-class-initialization}",
|
||||
description = "Normalize constructor calls " +
|
||||
"(disable: don't normalize; enable: normalize; " +
|
||||
"preserve-class-initialization: normalize preserving class initialization order), " +
|
||||
"default is disable"
|
||||
)
|
||||
var constructorCallNormalizationMode: String? by FreezableVar(JVMConstructorCallNormalizationMode.DEFAULT.description)
|
||||
|
||||
@Argument(value = "-Xreport-perf", description = "Report detailed performance statistics")
|
||||
var reportPerf: Boolean by FreezableVar(false)
|
||||
|
||||
|
||||
@@ -349,6 +349,16 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
configuration.put(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, arguments.noParamAssertions)
|
||||
configuration.put(JVMConfigurationKeys.NO_EXCEPTION_ON_EXPLICIT_EQUALS_FOR_BOXED_NULL, arguments.noExceptionOnExplicitEqualsForBoxedNull);
|
||||
configuration.put(JVMConfigurationKeys.DISABLE_OPTIMIZATION, arguments.noOptimize)
|
||||
|
||||
val constructorCallNormalizationMode = JVMConstructorCallNormalizationMode.fromStringOrNull(arguments.constructorCallNormalizationMode)
|
||||
if (constructorCallNormalizationMode == null) {
|
||||
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
.report(ERROR, "Unknown constructor call normalization mode: ${arguments.constructorCallNormalizationMode}, " +
|
||||
"supported modes: ${JVMConstructorCallNormalizationMode.values().map { it.description }}")
|
||||
}
|
||||
configuration.put(JVMConfigurationKeys.CONSTRUCTOR_CALL_NORMALIZATION_MODE,
|
||||
constructorCallNormalizationMode ?: JVMConstructorCallNormalizationMode.DEFAULT)
|
||||
|
||||
configuration.put(JVMConfigurationKeys.INHERIT_MULTIFILE_PARTS, arguments.inheritMultifileParts)
|
||||
configuration.put(JVMConfigurationKeys.SKIP_RUNTIME_VERSION_CHECK, arguments.skipRuntimeVersionCheck)
|
||||
configuration.put(JVMConfigurationKeys.USE_FAST_CLASS_FILES_READING, !arguments.useOldClassFilesReading)
|
||||
|
||||
Reference in New Issue
Block a user