Properly process big types

This commit is contained in:
Mikhael Bogdanov
2021-06-25 09:18:10 +02:00
parent 0fd1f549a9
commit 5f62b72c82
14 changed files with 207 additions and 1 deletions
@@ -24,6 +24,7 @@ class StringConcatGenerator(val mode: JvmStringConcat, val mv: InstructionAdapte
private val template = StringBuilder("")
private val specialSymbolsInTemplate = arrayListOf<String>()
private val paramTypes = arrayListOf<Type>()
private var paramSlots = 0
private var justFlushed = false
@JvmOverloads
@@ -84,8 +85,9 @@ class StringConcatGenerator(val mode: JvmStringConcat, val mv: InstructionAdapte
} else {
justFlushed = false
paramTypes.add(type)
paramSlots += type.size
template.append("\u0001")
if (paramTypes.size == 200) {
if (paramSlots >= 200) {
// Concatenate current arguments into string
// because of `StringConcatFactory` limitation add use it as new argument for further processing:
// "The number of parameter slots in {@code concatType} is less than or equal to 200"
@@ -132,11 +134,15 @@ class StringConcatGenerator(val mode: JvmStringConcat, val mv: InstructionAdapte
arrayOf()
)
}
//clear old template
template.clear()
specialSymbolsInTemplate.clear()
paramTypes.clear()
//add just flushed string
paramTypes.add(JAVA_STRING_TYPE)
template.append("\u0001")
paramSlots = JAVA_STRING_TYPE.size
}
}
@@ -40266,6 +40266,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/strings"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("concatDynamicWithConstants.kt")
public void testConcatDynamicWithConstants() throws Exception {
runTest("compiler/testData/codegen/box/strings/concatDynamicWithConstants.kt");
}
@Test
@TestMetadata("concatDynamicWithSpecialSymbols.kt")
public void testConcatDynamicWithSpecialSymbols() throws Exception {
runTest("compiler/testData/codegen/box/strings/concatDynamicWithSpecialSymbols.kt");
}
@Test
@TestMetadata("constInStringTemplate.kt")
public void testConstInStringTemplate() throws Exception {
@@ -0,0 +1,24 @@
// Will be executed on JDK 9, 11, 15
// IGNORE_BACKEND: ANDROID
// DONT_TARGET_EXACT_BACKEND: WASM
fun test(z: Int): String {
val result = "" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" +
z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" +
z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" +
z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" +
z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" +
z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" +
z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1" + z + "1"
return result
}
fun box(): String {
val result = test(0)
if (result.length != 280)
return "fail 1: ${result.length}"
return if (result != "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101") "fail 2: ${result}" else "OK"
}
@@ -0,0 +1,26 @@
// Will be executed on JDK 9, 11, 15
// IGNORE_BACKEND: ANDROID
// DONT_TARGET_EXACT_BACKEND: WASM
fun test(z: Int): String {
val result = "" + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() +
z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() +
z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() +
z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() +
z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() +
z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() +
z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 1.toChar() + z + 2.toChar()
return result
}
fun box(): String {
val result = test(0)
if (result.length != 280)
return "fail 1: ${result.length}"
return if (result != "0\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u00010\u0002")
"fail 2: ${result}"
else "OK"
}
@@ -0,0 +1,27 @@
// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants
// JVM_TARGET: 9
fun test(z: Long): String {
val result = "" + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z //200 z
return result
}
fun box(): String {
val result = test(0L)
if (result.length != 200)
return "fail 1: ${result.length}"
return if (result != "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
"fail 2: ${result}"
else "OK"
}
@@ -0,0 +1,27 @@
// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy
// JVM_TARGET: 9
fun test(z: Long): String {
val result = "" + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z +
z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z + z //200 z
return result
}
fun box(): String {
val result = test(0L)
if (result.length != 200)
return "fail 1: ${result.length}"
return if (result != "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
"fail 2: ${result}"
else "OK"
}
@@ -40224,6 +40224,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/strings"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@Test
@TestMetadata("concatDynamicWithConstants.kt")
public void testConcatDynamicWithConstants() throws Exception {
runTest("compiler/testData/codegen/box/strings/concatDynamicWithConstants.kt");
}
@Test
@TestMetadata("concatDynamicWithSpecialSymbols.kt")
public void testConcatDynamicWithSpecialSymbols() throws Exception {
runTest("compiler/testData/codegen/box/strings/concatDynamicWithSpecialSymbols.kt");
}
@Test
@TestMetadata("constInStringTemplate.kt")
public void testConstInStringTemplate() throws Exception {
@@ -40266,6 +40266,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/strings"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("concatDynamicWithConstants.kt")
public void testConcatDynamicWithConstants() throws Exception {
runTest("compiler/testData/codegen/box/strings/concatDynamicWithConstants.kt");
}
@Test
@TestMetadata("concatDynamicWithSpecialSymbols.kt")
public void testConcatDynamicWithSpecialSymbols() throws Exception {
runTest("compiler/testData/codegen/box/strings/concatDynamicWithSpecialSymbols.kt");
}
@Test
@TestMetadata("constInStringTemplate.kt")
public void testConstInStringTemplate() throws Exception {
@@ -39,6 +39,11 @@ public class Jdk9BlackBoxCodegenTestGenerated extends AbstractJdk9BlackBoxCodege
runTest("compiler/testData/codegen/java9/box/concatDynamic200.kt");
}
@TestMetadata("concatDynamic200Long.kt")
public void testConcatDynamic200Long() throws Exception {
runTest("compiler/testData/codegen/java9/box/concatDynamic200Long.kt");
}
@TestMetadata("concatDynamic201.kt")
public void testConcatDynamic201() throws Exception {
runTest("compiler/testData/codegen/java9/box/concatDynamic201.kt");
@@ -49,6 +54,11 @@ public class Jdk9BlackBoxCodegenTestGenerated extends AbstractJdk9BlackBoxCodege
runTest("compiler/testData/codegen/java9/box/concatDynamicIndy200.kt");
}
@TestMetadata("concatDynamicIndy200Long.kt")
public void testConcatDynamicIndy200Long() throws Exception {
runTest("compiler/testData/codegen/java9/box/concatDynamicIndy200Long.kt");
}
@TestMetadata("concatDynamicIndy201.kt")
public void testConcatDynamicIndy201() throws Exception {
runTest("compiler/testData/codegen/java9/box/concatDynamicIndy201.kt");
@@ -40,6 +40,11 @@ public class Jdk9IrBlackBoxCodegenTestGenerated extends AbstractJdk9IrBlackBoxCo
runTest("compiler/testData/codegen/java9/box/concatDynamic200.kt");
}
@TestMetadata("concatDynamic200Long.kt")
public void testConcatDynamic200Long() throws Exception {
runTest("compiler/testData/codegen/java9/box/concatDynamic200Long.kt");
}
@TestMetadata("concatDynamic201.kt")
public void testConcatDynamic201() throws Exception {
runTest("compiler/testData/codegen/java9/box/concatDynamic201.kt");
@@ -50,6 +55,11 @@ public class Jdk9IrBlackBoxCodegenTestGenerated extends AbstractJdk9IrBlackBoxCo
runTest("compiler/testData/codegen/java9/box/concatDynamicIndy200.kt");
}
@TestMetadata("concatDynamicIndy200Long.kt")
public void testConcatDynamicIndy200Long() throws Exception {
runTest("compiler/testData/codegen/java9/box/concatDynamicIndy200Long.kt");
}
@TestMetadata("concatDynamicIndy201.kt")
public void testConcatDynamicIndy201() throws Exception {
runTest("compiler/testData/codegen/java9/box/concatDynamicIndy201.kt");
@@ -32259,6 +32259,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/strings"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("concatDynamicWithConstants.kt")
public void testConcatDynamicWithConstants() throws Exception {
runTest("compiler/testData/codegen/box/strings/concatDynamicWithConstants.kt");
}
@TestMetadata("concatDynamicWithSpecialSymbols.kt")
public void testConcatDynamicWithSpecialSymbols() throws Exception {
runTest("compiler/testData/codegen/box/strings/concatDynamicWithSpecialSymbols.kt");
}
@TestMetadata("constInStringTemplate.kt")
public void testConstInStringTemplate() throws Exception {
runTest("compiler/testData/codegen/box/strings/constInStringTemplate.kt");
@@ -27014,6 +27014,16 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/strings"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@TestMetadata("concatDynamicWithConstants.kt")
public void testConcatDynamicWithConstants() throws Exception {
runTest("compiler/testData/codegen/box/strings/concatDynamicWithConstants.kt");
}
@TestMetadata("concatDynamicWithSpecialSymbols.kt")
public void testConcatDynamicWithSpecialSymbols() throws Exception {
runTest("compiler/testData/codegen/box/strings/concatDynamicWithSpecialSymbols.kt");
}
@TestMetadata("constInStringTemplate.kt")
public void testConstInStringTemplate() throws Exception {
runTest("compiler/testData/codegen/box/strings/constInStringTemplate.kt");
@@ -26420,6 +26420,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/strings"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@TestMetadata("concatDynamicWithConstants.kt")
public void testConcatDynamicWithConstants() throws Exception {
runTest("compiler/testData/codegen/box/strings/concatDynamicWithConstants.kt");
}
@TestMetadata("concatDynamicWithSpecialSymbols.kt")
public void testConcatDynamicWithSpecialSymbols() throws Exception {
runTest("compiler/testData/codegen/box/strings/concatDynamicWithSpecialSymbols.kt");
}
@TestMetadata("constInStringTemplate.kt")
public void testConstInStringTemplate() throws Exception {
runTest("compiler/testData/codegen/box/strings/constInStringTemplate.kt");
@@ -26380,6 +26380,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/strings"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
@TestMetadata("concatDynamicWithConstants.kt")
public void testConcatDynamicWithConstants() throws Exception {
runTest("compiler/testData/codegen/box/strings/concatDynamicWithConstants.kt");
}
@TestMetadata("concatDynamicWithSpecialSymbols.kt")
public void testConcatDynamicWithSpecialSymbols() throws Exception {
runTest("compiler/testData/codegen/box/strings/concatDynamicWithSpecialSymbols.kt");
}
@TestMetadata("constInStringTemplate.kt")
public void testConstInStringTemplate() throws Exception {
runTest("compiler/testData/codegen/box/strings/constInStringTemplate.kt");