diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/StringConcatGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/StringConcatGenerator.kt index 335774d1b7c..22b6ff25a4d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/StringConcatGenerator.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/StringConcatGenerator.kt @@ -9,7 +9,7 @@ import com.google.common.collect.Sets import org.jetbrains.kotlin.codegen.BranchedValue.Companion.FALSE import org.jetbrains.kotlin.codegen.BranchedValue.Companion.TRUE import org.jetbrains.kotlin.codegen.state.GenerationState -import org.jetbrains.kotlin.config.JvmRuntimeStringConcat +import org.jetbrains.kotlin.config.JvmStringConcat import org.jetbrains.kotlin.resolve.jvm.AsmTypes import org.jetbrains.kotlin.resolve.jvm.AsmTypes.JAVA_STRING_TYPE import org.jetbrains.kotlin.types.KotlinType @@ -19,7 +19,7 @@ import org.jetbrains.org.objectweb.asm.Type import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter import java.lang.StringBuilder -class StringConcatGenerator(val mode: JvmRuntimeStringConcat, val mv: InstructionAdapter) { +class StringConcatGenerator(val mode: JvmStringConcat, val mv: InstructionAdapter) { private val template = StringBuilder("") private val paramTypes = arrayListOf() @@ -39,7 +39,7 @@ class StringConcatGenerator(val mode: JvmRuntimeStringConcat, val mv: Instructio @JvmOverloads fun putValueOrProcessConstant(stackValue: StackValue, type: Type = stackValue.type, kotlinType: KotlinType? = stackValue.kotlinType) { justFlushed = false - if (mode == JvmRuntimeStringConcat.ENABLE) { + if (mode == JvmStringConcat.INDY_WITH_CONSTANTS) { when (stackValue) { is StackValue.Constant -> { template.append(stackValue.value) @@ -91,7 +91,7 @@ class StringConcatGenerator(val mode: JvmRuntimeStringConcat, val mv: Instructio } else { //if state was flushed in `invokeAppend` do nothing if (justFlushed) return - if (mode == JvmRuntimeStringConcat.ENABLE) { + if (mode == JvmStringConcat.INDY_WITH_CONSTANTS) { val bootstrap = Handle( Opcodes.H_INVOKESTATIC, "java/lang/invoke/StringConcatFactory", diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt index 87549650be1..6b627aec3dd 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt @@ -193,8 +193,8 @@ class GenerationState private constructor( val target = configuration.get(JVMConfigurationKeys.JVM_TARGET) ?: JvmTarget.DEFAULT val runtimeStringConcat = if (target.bytecodeVersion >= JvmTarget.JVM_9.bytecodeVersion) - configuration.get(JVMConfigurationKeys.RUNTIME_STRING_CONCAT) ?: JvmRuntimeStringConcat.DISABLE - else JvmRuntimeStringConcat.DISABLE + configuration.get(JVMConfigurationKeys.STRING_CONCAT) ?: JvmStringConcat.INLINE + else JvmStringConcat.INLINE val moduleName: String = moduleName ?: JvmCodegenUtil.getModuleName(module) val classBuilderMode: ClassBuilderMode = builderFactory.classBuilderMode 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 6fd6fb15d06..f83fc1fc18d 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 @@ -335,14 +335,14 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { var emitJvmTypeAnnotations: Boolean by FreezableVar(false) @Argument( - value = "-Xruntime-string-concat", - valueDescription = "{disable|enable|indy}", + value = "-Xstring-concat", + valueDescription = "{indy-with-constants|indy|inline}", description = """Switch a way in which string concatenation is performed. --Xruntime-string-concat=enable Performs string concatenation via `invokedynamic` 'makeConcatWithConstants'. Works only with `-jvm-target 9` or greater --Xruntime-string-concat=indy Performs string concatenation via `invokedynamic` 'makeConcat'. Works only with `-jvm-target 9` or greater --Xruntime-string-concat=disable Performs string concatenation via `StringBuilder`""" +-Xstring-concat=indy-with-constants Performs string concatenation via `invokedynamic` 'makeConcatWithConstants'. Works only with `-jvm-target 9` or greater +-Xstring-concat=indy Performs string concatenation via `invokedynamic` 'makeConcat'. Works only with `-jvm-target 9` or greater +-Xstring-concat=inline Performs string concatenation via `StringBuilder`""" ) - var runtimeStringConcat: String? by NullableStringFreezableVar(JvmRuntimeStringConcat.DISABLE.name.toLowerCase()) + var stringConcat: String? by NullableStringFreezableVar(JvmStringConcat.INLINE.description) @Argument( value = "-Xklib", 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 7af288eb305..c3a21bfff66 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt @@ -49,20 +49,20 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu } } - if (arguments.runtimeStringConcat != null) { - val runtimeStringConcat = JvmRuntimeStringConcat.fromString(arguments.runtimeStringConcat!!) + if (arguments.stringConcat != null) { + val runtimeStringConcat = JvmStringConcat.fromString(arguments.stringConcat!!) if (runtimeStringConcat != null) { - put(JVMConfigurationKeys.RUNTIME_STRING_CONCAT, runtimeStringConcat) - if (jvmTarget.bytecodeVersion < JvmTarget.JVM_9.bytecodeVersion && runtimeStringConcat != JvmRuntimeStringConcat.DISABLE) { + put(JVMConfigurationKeys.STRING_CONCAT, runtimeStringConcat) + if (jvmTarget.bytecodeVersion < JvmTarget.JVM_9.bytecodeVersion && runtimeStringConcat != JvmStringConcat.INLINE) { messageCollector.report( WARNING, - "`-Xruntime-string-concat=${arguments.runtimeStringConcat}` does nothing with JVM target `${jvmTarget.description}`." + "`-Xstring-concat=${arguments.stringConcat}` does nothing with JVM target `${jvmTarget.description}`." ) } } else { messageCollector.report( - ERROR, "Unknown `runtime-string-concat` mode: ${arguments.jvmTarget}\n" + - "Supported versions: ${JvmRuntimeStringConcat.values().joinToString { it.name.toLowerCase() }}" + ERROR, "Unknown `string-concat` mode: ${arguments.jvmTarget}\n" + + "Supported versions: ${JvmStringConcat.values().joinToString { it.name.toLowerCase() }}" ) } } diff --git a/compiler/config.jvm/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java b/compiler/config.jvm/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java index 13000fccced..bbf60562df3 100644 --- a/compiler/config.jvm/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java +++ b/compiler/config.jvm/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java @@ -111,7 +111,7 @@ public class JVMConfigurationKeys { public static final CompilerConfigurationKey EMIT_JVM_TYPE_ANNOTATIONS = CompilerConfigurationKey.create("Emit JVM type annotations in bytecode"); - public static final CompilerConfigurationKey RUNTIME_STRING_CONCAT = + public static final CompilerConfigurationKey STRING_CONCAT = CompilerConfigurationKey.create("Specifies string concatenation scheme"); public static final CompilerConfigurationKey> KLIB_PATHS = diff --git a/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmRuntimeStringConcat.kt b/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmStringConcat.kt similarity index 51% rename from compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmRuntimeStringConcat.kt rename to compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmStringConcat.kt index 94a21b27480..cdefa0c7975 100644 --- a/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmRuntimeStringConcat.kt +++ b/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmStringConcat.kt @@ -5,16 +5,16 @@ package org.jetbrains.kotlin.config -enum class JvmRuntimeStringConcat { - DISABLE, - ENABLE, // makeConcatWithConstants - INDY; // makeConcat +enum class JvmStringConcat(val description: String) { + INLINE("inline"), + INDY_WITH_CONSTANTS("indy-with-constants"), // makeConcatWithConstants + INDY("indy"); // makeConcat val isDynamic - get() = this != DISABLE + get() = this != INLINE companion object { @JvmStatic - fun fromString(string: String) = values().find { it.name == string.toUpperCase() } + fun fromString(string: String) = values().find { it.description == string } } } \ No newline at end of file diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index bcf80c1b924..c7c4bd7ea09 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -81,11 +81,6 @@ where advanced options include: profilerPath is a path to libasyncProfiler.so Example: -Xprofile=/async-profiler/build/libasyncProfiler.so:event=cpu,interval=1ms,threads,start,framebuf=50000000: -Xrepeat= Debug option: Repeats modules compilation times - -Xruntime-string-concat={disable|enable|indy} - Switch a way in which string concatenation is performed. - -Xruntime-string-concat=enable Performs string concatenation via `invokedynamic` 'makeConcatWithConstants'. Works only with `-jvm-target 9` or greater - -Xruntime-string-concat=indy Performs string concatenation via `invokedynamic` 'makeConcat'. Works only with `-jvm-target 9` or greater - -Xruntime-string-concat=disable Performs string concatenation via `StringBuilder` -Xsanitize-parentheses Transform '(' and ')' in method names to some other character sequence. This mode can BREAK BINARY COMPATIBILITY and is only supposed to be used to workaround problems with parentheses in identifiers on certain platforms @@ -97,6 +92,11 @@ where advanced options include: Generate nullability assertions for non-null Java expressions -Xgenerate-strict-metadata-version Generate metadata with strict version semantics (see kdoc on Metadata.extraInt) + -Xstring-concat={indy-with-constants|indy|inline} + Switch a way in which string concatenation is performed. + -Xstring-concat=indy-with-constants Performs string concatenation via `invokedynamic` 'makeConcatWithConstants'. Works only with `-jvm-target 9` or greater + -Xstring-concat=indy Performs string concatenation via `invokedynamic` 'makeConcat'. Works only with `-jvm-target 9` or greater + -Xstring-concat=inline Performs string concatenation via `StringBuilder` -Xsupport-compatqual-checker-framework-annotations=enable|disable Specify behavior for Checker Framework compatqual annotations (NullableDecl/NonNullDecl). Default value is 'enable' diff --git a/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamic.kt b/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamic.kt index 677a8986890..e6543f6acd4 100644 --- a/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamic.kt +++ b/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamic.kt @@ -1,4 +1,4 @@ -// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable +// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants // JVM_TARGET: 9 class A diff --git a/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamic200.kt b/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamic200.kt index 24b8e54a992..7a2a1106ccb 100644 --- a/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamic200.kt +++ b/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamic200.kt @@ -1,4 +1,4 @@ -// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable +// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants // JVM_TARGET: 9 fun box() { diff --git a/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamic201.kt b/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamic201.kt index 3c66aae3184..58e88933106 100644 --- a/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamic201.kt +++ b/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamic201.kt @@ -1,4 +1,4 @@ -// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable +// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants // JVM_TARGET: 9 fun box() { val z = "0" diff --git a/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicConstants.kt b/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicConstants.kt index a3b0336fef5..882806bf9ad 100644 --- a/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicConstants.kt +++ b/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicConstants.kt @@ -1,4 +1,4 @@ -// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable +// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants // JVM_TARGET: 9 class A @@ -10,6 +10,6 @@ fun box(a: String, b: String?) { val s = a + "1" + "2" + 3 + 4L + b + 5.0 + 6F + '7' + A() } -// 1INVOKEDYNAMIC makeConcatWithConstants +// 1 INVOKEDYNAMIC makeConcatWithConstants // 0 append // 0 stringPlus \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicIndy.kt b/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicIndy.kt index 3f574a8222a..d8ed0a68ff5 100644 --- a/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicIndy.kt +++ b/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicIndy.kt @@ -1,4 +1,4 @@ -// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=indy +// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy // JVM_TARGET: 9 class A diff --git a/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicIndy201.kt b/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicIndy201.kt index 45b9023422e..bf450fc4679 100644 --- a/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicIndy201.kt +++ b/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicIndy201.kt @@ -1,4 +1,4 @@ -// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=indy +// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy // JVM_TARGET: 9 fun box() { val z = "0" diff --git a/compiler/testData/codegen/bytecodeText/stringOperations/concatNotDynamic.kt b/compiler/testData/codegen/bytecodeText/stringOperations/concatNotDynamic.kt index 74a1decb9a2..9ee0ca65348 100644 --- a/compiler/testData/codegen/bytecodeText/stringOperations/concatNotDynamic.kt +++ b/compiler/testData/codegen/bytecodeText/stringOperations/concatNotDynamic.kt @@ -1,4 +1,4 @@ -// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable +// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants // JVM_TARGET: 9 fun box(a: String, b: String?) { val sb = StringBuilder(); diff --git a/compiler/testData/codegen/java9/box/concatDynamic.kt b/compiler/testData/codegen/java9/box/concatDynamic.kt index fd564f233f3..2c684da3f4e 100644 --- a/compiler/testData/codegen/java9/box/concatDynamic.kt +++ b/compiler/testData/codegen/java9/box/concatDynamic.kt @@ -1,4 +1,4 @@ -// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable +// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants // JVM_TARGET: 9 fun box(): String { val p = 3147483648u diff --git a/compiler/testData/codegen/java9/box/concatDynamic200.kt b/compiler/testData/codegen/java9/box/concatDynamic200.kt index 8628b545d87..8748f1603c1 100644 --- a/compiler/testData/codegen/java9/box/concatDynamic200.kt +++ b/compiler/testData/codegen/java9/box/concatDynamic200.kt @@ -1,4 +1,4 @@ -// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable +// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants // JVM_TARGET: 9 fun box(): String { val z = "0" diff --git a/compiler/testData/codegen/java9/box/concatDynamic201.kt b/compiler/testData/codegen/java9/box/concatDynamic201.kt index 12e7fb0b267..de3808a0035 100644 --- a/compiler/testData/codegen/java9/box/concatDynamic201.kt +++ b/compiler/testData/codegen/java9/box/concatDynamic201.kt @@ -1,4 +1,4 @@ -// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable +// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants // JVM_TARGET: 9 fun box(): String { val z = "0" diff --git a/compiler/testData/codegen/java9/box/concatDynamicIndy200.kt b/compiler/testData/codegen/java9/box/concatDynamicIndy200.kt index 232e28bb268..7aef336f88f 100644 --- a/compiler/testData/codegen/java9/box/concatDynamicIndy200.kt +++ b/compiler/testData/codegen/java9/box/concatDynamicIndy200.kt @@ -1,4 +1,4 @@ -// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=indy +// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy // JVM_TARGET: 9 fun box(): String { val z = "0" diff --git a/compiler/testData/codegen/java9/box/concatDynamicIndy201.kt b/compiler/testData/codegen/java9/box/concatDynamicIndy201.kt index 66dce61bb0d..a76dfaa790b 100644 --- a/compiler/testData/codegen/java9/box/concatDynamicIndy201.kt +++ b/compiler/testData/codegen/java9/box/concatDynamicIndy201.kt @@ -1,4 +1,4 @@ -// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=indy +// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy // JVM_TARGET: 9 fun box(): String { val z = "0" diff --git a/compiler/testData/codegen/java9/box/concatDynamicInlineClasses.kt b/compiler/testData/codegen/java9/box/concatDynamicInlineClasses.kt index 59c389d307e..39933ea1bd0 100644 --- a/compiler/testData/codegen/java9/box/concatDynamicInlineClasses.kt +++ b/compiler/testData/codegen/java9/box/concatDynamicInlineClasses.kt @@ -1,4 +1,4 @@ -// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable +// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants // JVM_TARGET: 9 inline class Str(val s: String) inline class NStr(val s: String?) diff --git a/compiler/testData/codegen/java9/box/concatDynamicWithInline.kt b/compiler/testData/codegen/java9/box/concatDynamicWithInline.kt index 6a2df7c3d94..b430a20d795 100644 --- a/compiler/testData/codegen/java9/box/concatDynamicWithInline.kt +++ b/compiler/testData/codegen/java9/box/concatDynamicWithInline.kt @@ -1,4 +1,4 @@ -// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable +// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants // JVM_TARGET: 9 inline fun test(crossinline s: (String) -> String): String { var result = "1" + s("2") + "3" + 4 + { diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt index 57ebd904df2..32198172ce9 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt @@ -157,7 +157,7 @@ abstract class KotlinBaseTest : KtUsefulTestCase() "CONSTRUCTOR_CALL_NORMALIZATION_MODE=([a-zA-Z_\\-0-9]*)" ) private val ASSERTIONS_MODE_FLAG_PATTERN = Pattern.compile("ASSERTIONS_MODE=([a-zA-Z_0-9-]*)") - private val RUNTIME_STRING_CONCAT = Pattern.compile("RUNTIME_STRING_CONCAT=([a-zA-Z_0-9-]*)") + private val STRING_CONCAT = Pattern.compile("STRING_CONCAT=([a-zA-Z_0-9-]*)") private fun tryApplyBooleanFlag( configuration: CompilerConfiguration, @@ -296,12 +296,12 @@ abstract class KotlinBaseTest : KtUsefulTestCase() configuration.put(JVMConfigurationKeys.ASSERTIONS_MODE, mode) } - m = RUNTIME_STRING_CONCAT.matcher(flag) + m = STRING_CONCAT.matcher(flag) if (m.matches()) { val flagValueString = m.group(1) - val mode = JvmRuntimeStringConcat.fromString(flagValueString) - ?: error("Wrong RUNTIME_STRING_CONCAT value: $flagValueString") - configuration.put(JVMConfigurationKeys.RUNTIME_STRING_CONCAT, mode) + val mode = JvmStringConcat.fromString(flagValueString) + ?: error("Wrong STRING_CONCAT value: $flagValueString") + configuration.put(JVMConfigurationKeys.STRING_CONCAT, mode) } } }