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.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<Type>()
@@ -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",
@@ -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
@@ -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",
@@ -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() }}"
)
}
}
@@ -111,7 +111,7 @@ public class JVMConfigurationKeys {
public static final CompilerConfigurationKey<Boolean> EMIT_JVM_TYPE_ANNOTATIONS =
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");
public static final CompilerConfigurationKey<List<String>> KLIB_PATHS =
@@ -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 }
}
}
+5 -5
View File
@@ -81,11 +81,6 @@ where advanced options include:
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>
-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.
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'
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable
// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants
// JVM_TARGET: 9
class A
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=enable
// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants
// JVM_TARGET: 9
fun box() {
@@ -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"
@@ -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
@@ -1,4 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: RUNTIME_STRING_CONCAT=indy
// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy
// JVM_TARGET: 9
class A
@@ -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"
@@ -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();
+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
fun box(): String {
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
fun box(): String {
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
fun box(): String {
val z = "0"
@@ -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"
@@ -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"
@@ -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?)
@@ -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 + {
@@ -157,7 +157,7 @@ abstract class KotlinBaseTest<F : KotlinBaseTest.TestFile> : 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<F : KotlinBaseTest.TestFile> : 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)
}
}
}