Constructor call normalization mode depends on language version

This commit is contained in:
Dmitry Petrov
2018-07-26 15:40:11 +03:00
parent 14b1f0ef6a
commit 566b5856ec
18 changed files with 66 additions and 19 deletions
@@ -229,10 +229,13 @@ class GenerationState private constructor(
val shouldInlineConstVals = languageVersionSettings.supportsFeature(LanguageFeature.InlineConstVals)
val constructorCallNormalizationMode = configuration.get(
JVMConfigurationKeys.CONSTRUCTOR_CALL_NORMALIZATION_MODE,
JVMConstructorCallNormalizationMode.DEFAULT
)
val constructorCallNormalizationMode =
configuration.get(JVMConfigurationKeys.CONSTRUCTOR_CALL_NORMALIZATION_MODE) ?: run {
if (languageVersionSettings.supportsFeature(LanguageFeature.NormalizeConstructorCalls))
JVMConstructorCallNormalizationMode.ENABLE
else
JVMConstructorCallNormalizationMode.DISABLE
}
val jvmDefaultMode = languageVersionSettings.getFlag(AnalysisFlag.jvmDefaultMode)
@@ -112,7 +112,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
valueDescription = "{disable|enable}",
description = "Normalize constructor calls (disable: don't normalize; enable: normalize), default is disable"
)
var constructorCallNormalizationMode: String? by FreezableVar(JVMConstructorCallNormalizationMode.DEFAULT.description)
var constructorCallNormalizationMode: String? by FreezableVar(null)
@Argument(
value = "-Xassertions", valueDescription = "{always-enable|always-disable|jvm|legacy}",
@@ -359,19 +359,22 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
)
configuration.put(JVMConfigurationKeys.DISABLE_OPTIMIZATION, arguments.noOptimize)
val constructorCallNormalizationMode =
JVMConstructorCallNormalizationMode.fromStringOrNull(arguments.constructorCallNormalizationMode)
if (constructorCallNormalizationMode == null) {
if (!JVMConstructorCallNormalizationMode.isSupportedValue(arguments.constructorCallNormalizationMode)) {
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
)
val constructorCallNormalizationMode =
JVMConstructorCallNormalizationMode.fromStringOrNull(arguments.constructorCallNormalizationMode)
if (constructorCallNormalizationMode != null) {
configuration.put(
JVMConfigurationKeys.CONSTRUCTOR_CALL_NORMALIZATION_MODE,
constructorCallNormalizationMode
)
}
val assertionsMode =
JVMAssertionsMode.fromStringOrNull(arguments.assertionsMode)
@@ -17,9 +17,9 @@
package org.jetbrains.kotlin.config
enum class JVMConstructorCallNormalizationMode(
val description: String,
val isEnabled: Boolean,
val shouldPreserveClassInitialization: Boolean
val description: String,
val isEnabled: Boolean,
val shouldPreserveClassInitialization: Boolean
) {
DISABLE("disable", false, false),
ENABLE("enable", true, false),
@@ -27,10 +27,12 @@ enum class JVMConstructorCallNormalizationMode(
;
companion object {
@JvmField
val DEFAULT = DISABLE
@JvmStatic
fun isSupportedValue(string: String?) =
string == null || values().any { it.description == string }
@JvmStatic
fun fromStringOrNull(string: String?) = values().find { it.description == string }
fun fromStringOrNull(string: String?) =
values().find { it.description == string }
}
}
@@ -1,3 +1,4 @@
// !LANGUAGE: -NormalizeConstructorCalls
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: test.kt
@@ -1,3 +1,4 @@
// !LANGUAGE: -NormalizeConstructorCalls
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: test.kt
@@ -1,3 +1,4 @@
// !LANGUAGE: -NormalizeConstructorCalls
// TARGET_BACKEND: JVM
// WITH_RUNTIME
inline fun ok(): String {
@@ -1,3 +1,4 @@
// !LANGUAGE: -NormalizeConstructorCalls
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: test.kt
@@ -1,3 +1,4 @@
// !LANGUAGE: -NormalizeConstructorCalls
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: test.kt
@@ -1,3 +1,4 @@
// !LANGUAGE: -NormalizeConstructorCalls
// IGNORE_BACKEND: JVM_IR
// TARGET_BACKEND: JVM
// WITH_RUNTIME
@@ -0,0 +1,15 @@
// !LANGUAGE: +NormalizeConstructorCalls
// IGNORE_BACKEND: JVM_IR
// TARGET_BACKEND: JVM
// WITH_RUNTIME
open class A(val s: String)
inline fun test(crossinline z: () -> String): String {
return object : A(listOf(1).map { it.toString() }.joinToString()) {
val value = z()
}.value
}
fun box(): String {
return test { "OK" }
}
@@ -1,3 +1,4 @@
// !LANGUAGE: -NormalizeConstructorCalls
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: test.kt
@@ -1,3 +1,4 @@
// !LANGUAGE: -NormalizeConstructorCalls
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: test.kt
@@ -243,7 +243,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
private static final Pattern BOOLEAN_FLAG_PATTERN = Pattern.compile("([+-])(([a-zA-Z_0-9]*)\\.)?([a-zA-Z_0-9]*)");
private static final Pattern CONSTRUCTOR_CALL_NORMALIZATION_MODE_FLAG_PATTERN = Pattern.compile(
"CONSTRUCTOR_CALL_NORMALIZATION_MODE=([a-zA-Z_0-9]*)");
"CONSTRUCTOR_CALL_NORMALIZATION_MODE=([a-zA-Z_\\-0-9]*)");
private static final Pattern ASSERTIONS_MODE_FLAG_PATTERN = Pattern.compile("ASSERTIONS_MODE=([a-zA-Z_0-9-]*)");
private static void updateConfigurationWithFlags(@NotNull CompilerConfiguration configuration, @NotNull List<String> flags) {
@@ -4215,6 +4215,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCallWithEnabledNormalization.kt");
}
@TestMetadata("loopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13.kt")
public void testLoopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13.kt");
}
@TestMetadata("loopInInlineFunWithEnabledNormalization.kt")
public void testLoopInInlineFunWithEnabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunWithEnabledNormalization.kt");
@@ -4215,6 +4215,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCallWithEnabledNormalization.kt");
}
@TestMetadata("loopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13.kt")
public void testLoopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13.kt");
}
@TestMetadata("loopInInlineFunWithEnabledNormalization.kt")
public void testLoopInInlineFunWithEnabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunWithEnabledNormalization.kt");
@@ -4215,6 +4215,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCallWithEnabledNormalization.kt");
}
@TestMetadata("loopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13.kt")
public void testLoopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13.kt");
}
@TestMetadata("loopInInlineFunWithEnabledNormalization.kt")
public void testLoopInInlineFunWithEnabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunWithEnabledNormalization.kt");
@@ -82,6 +82,7 @@ enum class LanguageFeature(
FunctionTypesWithBigArity(KOTLIN_1_3, sinceApiVersion = ApiVersion.KOTLIN_1_3),
RestrictRetentionForExpressionAnnotations(KOTLIN_1_3, kind = BUG_FIX),
NoConstantValueAttributeForNonConstVals(KOTLIN_1_3, kind = BUG_FIX),
NormalizeConstructorCalls(KOTLIN_1_3),
RestrictReturnStatementTarget(KOTLIN_1_4, kind = BUG_FIX),