Rename runtime-string-concat option into 'string-concat'

This commit is contained in:
Mikhael Bogdanov
2020-10-05 19:57:52 +02:00
parent 402f7df0d4
commit d2c4be18a0
22 changed files with 51 additions and 51 deletions
@@ -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.FALSE
import org.jetbrains.kotlin.codegen.BranchedValue.Companion.TRUE import org.jetbrains.kotlin.codegen.BranchedValue.Companion.TRUE
import org.jetbrains.kotlin.codegen.state.GenerationState 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
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.JAVA_STRING_TYPE import org.jetbrains.kotlin.resolve.jvm.AsmTypes.JAVA_STRING_TYPE
import org.jetbrains.kotlin.types.KotlinType 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 org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
import java.lang.StringBuilder 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 template = StringBuilder("")
private val paramTypes = arrayListOf<Type>() private val paramTypes = arrayListOf<Type>()
@@ -39,7 +39,7 @@ class StringConcatGenerator(val mode: JvmRuntimeStringConcat, val mv: Instructio
@JvmOverloads @JvmOverloads
fun putValueOrProcessConstant(stackValue: StackValue, type: Type = stackValue.type, kotlinType: KotlinType? = stackValue.kotlinType) { fun putValueOrProcessConstant(stackValue: StackValue, type: Type = stackValue.type, kotlinType: KotlinType? = stackValue.kotlinType) {
justFlushed = false justFlushed = false
if (mode == JvmRuntimeStringConcat.ENABLE) { if (mode == JvmStringConcat.INDY_WITH_CONSTANTS) {
when (stackValue) { when (stackValue) {
is StackValue.Constant -> { is StackValue.Constant -> {
template.append(stackValue.value) template.append(stackValue.value)
@@ -91,7 +91,7 @@ class StringConcatGenerator(val mode: JvmRuntimeStringConcat, val mv: Instructio
} else { } else {
//if state was flushed in `invokeAppend` do nothing //if state was flushed in `invokeAppend` do nothing
if (justFlushed) return if (justFlushed) return
if (mode == JvmRuntimeStringConcat.ENABLE) { if (mode == JvmStringConcat.INDY_WITH_CONSTANTS) {
val bootstrap = Handle( val bootstrap = Handle(
Opcodes.H_INVOKESTATIC, Opcodes.H_INVOKESTATIC,
"java/lang/invoke/StringConcatFactory", "java/lang/invoke/StringConcatFactory",
@@ -193,8 +193,8 @@ class GenerationState private constructor(
val target = configuration.get(JVMConfigurationKeys.JVM_TARGET) ?: JvmTarget.DEFAULT val target = configuration.get(JVMConfigurationKeys.JVM_TARGET) ?: JvmTarget.DEFAULT
val runtimeStringConcat = val runtimeStringConcat =
if (target.bytecodeVersion >= JvmTarget.JVM_9.bytecodeVersion) if (target.bytecodeVersion >= JvmTarget.JVM_9.bytecodeVersion)
configuration.get(JVMConfigurationKeys.RUNTIME_STRING_CONCAT) ?: JvmRuntimeStringConcat.DISABLE configuration.get(JVMConfigurationKeys.STRING_CONCAT) ?: JvmStringConcat.INLINE
else JvmRuntimeStringConcat.DISABLE else JvmStringConcat.INLINE
val moduleName: String = moduleName ?: JvmCodegenUtil.getModuleName(module) val moduleName: String = moduleName ?: JvmCodegenUtil.getModuleName(module)
val classBuilderMode: ClassBuilderMode = builderFactory.classBuilderMode val classBuilderMode: ClassBuilderMode = builderFactory.classBuilderMode
@@ -335,14 +335,14 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
var emitJvmTypeAnnotations: Boolean by FreezableVar(false) var emitJvmTypeAnnotations: Boolean by FreezableVar(false)
@Argument( @Argument(
value = "-Xruntime-string-concat", value = "-Xstring-concat",
valueDescription = "{disable|enable|indy}", valueDescription = "{indy-with-constants|indy|inline}",
description = """Switch a way in which string concatenation is performed. 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 -Xstring-concat=indy-with-constants 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 -Xstring-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=inline Performs string concatenation via `StringBuilder`"""
) )
var runtimeStringConcat: String? by NullableStringFreezableVar(JvmRuntimeStringConcat.DISABLE.name.toLowerCase()) var stringConcat: String? by NullableStringFreezableVar(JvmStringConcat.INLINE.description)
@Argument( @Argument(
value = "-Xklib", value = "-Xklib",
@@ -49,20 +49,20 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu
} }
} }
if (arguments.runtimeStringConcat != null) { if (arguments.stringConcat != null) {
val runtimeStringConcat = JvmRuntimeStringConcat.fromString(arguments.runtimeStringConcat!!) val runtimeStringConcat = JvmStringConcat.fromString(arguments.stringConcat!!)
if (runtimeStringConcat != null) { if (runtimeStringConcat != null) {
put(JVMConfigurationKeys.RUNTIME_STRING_CONCAT, runtimeStringConcat) put(JVMConfigurationKeys.STRING_CONCAT, runtimeStringConcat)
if (jvmTarget.bytecodeVersion < JvmTarget.JVM_9.bytecodeVersion && runtimeStringConcat != JvmRuntimeStringConcat.DISABLE) { if (jvmTarget.bytecodeVersion < JvmTarget.JVM_9.bytecodeVersion && runtimeStringConcat != JvmStringConcat.INLINE) {
messageCollector.report( messageCollector.report(
WARNING, 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 { } else {
messageCollector.report( messageCollector.report(
ERROR, "Unknown `runtime-string-concat` mode: ${arguments.jvmTarget}\n" + ERROR, "Unknown `string-concat` mode: ${arguments.jvmTarget}\n" +
"Supported versions: ${JvmRuntimeStringConcat.values().joinToString { it.name.toLowerCase() }}" "Supported versions: ${JvmStringConcat.values().joinToString { it.name.toLowerCase() }}"
) )
} }
} }
@@ -111,7 +111,7 @@ public class JVMConfigurationKeys {
public static final CompilerConfigurationKey<Boolean> EMIT_JVM_TYPE_ANNOTATIONS = public static final CompilerConfigurationKey<Boolean> EMIT_JVM_TYPE_ANNOTATIONS =
CompilerConfigurationKey.create("Emit JVM type annotations in bytecode"); CompilerConfigurationKey.create("Emit JVM type annotations in bytecode");
public static final CompilerConfigurationKey<JvmRuntimeStringConcat> RUNTIME_STRING_CONCAT = public static final CompilerConfigurationKey<JvmStringConcat> STRING_CONCAT =
CompilerConfigurationKey.create("Specifies string concatenation scheme"); CompilerConfigurationKey.create("Specifies string concatenation scheme");
public static final CompilerConfigurationKey<List<String>> KLIB_PATHS = public static final CompilerConfigurationKey<List<String>> KLIB_PATHS =
@@ -5,16 +5,16 @@
package org.jetbrains.kotlin.config package org.jetbrains.kotlin.config
enum class JvmRuntimeStringConcat { enum class JvmStringConcat(val description: String) {
DISABLE, INLINE("inline"),
ENABLE, // makeConcatWithConstants INDY_WITH_CONSTANTS("indy-with-constants"), // makeConcatWithConstants
INDY; // makeConcat INDY("indy"); // makeConcat
val isDynamic val isDynamic
get() = this != DISABLE get() = this != INLINE
companion object { companion object {
@JvmStatic @JvmStatic
fun fromString(string: String) = values().find { it.name == string.toUpperCase() } fun fromString(string: String) = values().find { it.description == string }
} }
} }
+5 -5
View File
@@ -81,11 +81,6 @@ where advanced options include:
profilerPath is a path to libasyncProfiler.so profilerPath is a path to libasyncProfiler.so
Example: -Xprofile=<PATH_TO_ASYNC_PROFILER>/async-profiler/build/libasyncProfiler.so:event=cpu,interval=1ms,threads,start,framebuf=50000000:<SNAPSHOT_DIR_PATH> Example: -Xprofile=<PATH_TO_ASYNC_PROFILER>/async-profiler/build/libasyncProfiler.so:event=cpu,interval=1ms,threads,start,framebuf=50000000:<SNAPSHOT_DIR_PATH>
-Xrepeat=<number> Debug option: Repeats modules compilation <number> times -Xrepeat=<number> Debug option: Repeats modules compilation <number> 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. -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 This mode can BREAK BINARY COMPATIBILITY and is only supposed to be used to workaround
problems with parentheses in identifiers on certain platforms problems with parentheses in identifiers on certain platforms
@@ -97,6 +92,11 @@ where advanced options include:
Generate nullability assertions for non-null Java expressions Generate nullability assertions for non-null Java expressions
-Xgenerate-strict-metadata-version -Xgenerate-strict-metadata-version
Generate metadata with strict version semantics (see kdoc on Metadata.extraInt) 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 -Xsupport-compatqual-checker-framework-annotations=enable|disable
Specify behavior for Checker Framework compatqual annotations (NullableDecl/NonNullDecl). Specify behavior for Checker Framework compatqual annotations (NullableDecl/NonNullDecl).
Default value is 'enable' Default value is 'enable'
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable // KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants
// JVM_TARGET: 9 // JVM_TARGET: 9
class A class A
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable // KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants
// JVM_TARGET: 9 // JVM_TARGET: 9
fun box() { fun box() {
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable // KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants
// JVM_TARGET: 9 // JVM_TARGET: 9
fun box() { fun box() {
val z = "0" val z = "0"
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable // KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants
// JVM_TARGET: 9 // JVM_TARGET: 9
class A 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() val s = a + "1" + "2" + 3 + 4L + b + 5.0 + 6F + '7' + A()
} }
// 1INVOKEDYNAMIC makeConcatWithConstants // 1 INVOKEDYNAMIC makeConcatWithConstants
// 0 append // 0 append
// 0 stringPlus // 0 stringPlus
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=indy // KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy
// JVM_TARGET: 9 // JVM_TARGET: 9
class A class A
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=indy // KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy
// JVM_TARGET: 9 // JVM_TARGET: 9
fun box() { fun box() {
val z = "0" val z = "0"
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable // KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants
// JVM_TARGET: 9 // JVM_TARGET: 9
fun box(a: String, b: String?) { fun box(a: String, b: String?) {
val sb = StringBuilder(); val sb = StringBuilder();
+1 -1
View File
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable // KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants
// JVM_TARGET: 9 // JVM_TARGET: 9
fun box(): String { fun box(): String {
val p = 3147483648u val p = 3147483648u
+1 -1
View File
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable // KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants
// JVM_TARGET: 9 // JVM_TARGET: 9
fun box(): String { fun box(): String {
val z = "0" val z = "0"
+1 -1
View File
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable // KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants
// JVM_TARGET: 9 // JVM_TARGET: 9
fun box(): String { fun box(): String {
val z = "0" val z = "0"
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=indy // KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy
// JVM_TARGET: 9 // JVM_TARGET: 9
fun box(): String { fun box(): String {
val z = "0" val z = "0"
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=indy // KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy
// JVM_TARGET: 9 // JVM_TARGET: 9
fun box(): String { fun box(): String {
val z = "0" val z = "0"
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable // KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants
// JVM_TARGET: 9 // JVM_TARGET: 9
inline class Str(val s: String) inline class Str(val s: String)
inline class NStr(val s: String?) inline class NStr(val s: String?)
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable // KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants
// JVM_TARGET: 9 // JVM_TARGET: 9
inline fun test(crossinline s: (String) -> String): String { inline fun test(crossinline s: (String) -> String): String {
var result = "1" + s("2") + "3" + 4 + { var result = "1" + s("2") + "3" + 4 + {
@@ -157,7 +157,7 @@ abstract class KotlinBaseTest<F : KotlinBaseTest.TestFile> : KtUsefulTestCase()
"CONSTRUCTOR_CALL_NORMALIZATION_MODE=([a-zA-Z_\\-0-9]*)" "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 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( private fun tryApplyBooleanFlag(
configuration: CompilerConfiguration, configuration: CompilerConfiguration,
@@ -296,12 +296,12 @@ abstract class KotlinBaseTest<F : KotlinBaseTest.TestFile> : KtUsefulTestCase()
configuration.put(JVMConfigurationKeys.ASSERTIONS_MODE, mode) configuration.put(JVMConfigurationKeys.ASSERTIONS_MODE, mode)
} }
m = RUNTIME_STRING_CONCAT.matcher(flag) m = STRING_CONCAT.matcher(flag)
if (m.matches()) { if (m.matches()) {
val flagValueString = m.group(1) val flagValueString = m.group(1)
val mode = JvmRuntimeStringConcat.fromString(flagValueString) val mode = JvmStringConcat.fromString(flagValueString)
?: error("Wrong RUNTIME_STRING_CONCAT value: $flagValueString") ?: error("Wrong STRING_CONCAT value: $flagValueString")
configuration.put(JVMConfigurationKeys.RUNTIME_STRING_CONCAT, mode) configuration.put(JVMConfigurationKeys.STRING_CONCAT, mode)
} }
} }
} }