JVM_IR. Support runtime string concatenation

This commit is contained in:
Mikhael Bogdanov
2020-09-30 11:25:26 +02:00
parent 1938f9459f
commit cf5bd38bec
4 changed files with 158 additions and 65 deletions
@@ -2,12 +2,15 @@
// JVM_TARGET: 9
class A
inline class IC(val x: String)
inline fun test(s: (String) -> Unit) {
s("456")
}
fun box(a: String, b: String?) {
val s = a + "1" + "2" + 3 + 4L + b + 5.0 + 6F + '7' + A() + true + false + 1u
fun box(a: String, b: String?, x: IC?) {
val p = 3147483648u
val s = a + "1" + "2" + 3 + 4L + b + 5.0 + 6F + '7' + A() + true + false + 3147483647u + p + x
a.plus(b)
b?.plus(a)
@@ -17,9 +20,27 @@ fun box(a: String, b: String?) {
test("123"::plus)
}
// unsigned constant 1u processed as argument (last \u0001)
// 1 "\\u00011234\\u00015.06.07\\u0001truefalse\\u0001"
// 6 INVOKEDYNAMIC makeConcatWithConstants
// 7 INVOKEDYNAMIC makeConcatWithConstants
// 1 "IC\(x=\\u0001\)"
// 0 append
// 0 stringPlus
// 0 stringPlus
// JVM_TEMPLATES
// unsigned constant 3147483647u is processed as argument (\u0001) and it adds additional `UInt.toString-impl` call
// 1 "\\u00011234\\u00015.06.07\\u0001truefalse\\u0001\\u0001\\u0001"
// 2 INVOKESTATIC kotlin/UInt.toString-impl
// Old backend perform inline class boxing...
// 1 INVOKESTATIC IC.box-impl
// one in IC.toString()
// 1 INVOKESTATIC IC.toString-impl
// JVM_IR_TEMPLATES
// unsigned constant 3147483647u is inlined
// 1 "\\u00011234\\u00015.06.07\\u0001truefalse3147483647\\u0001\\u0001"
// 1 INVOKESTATIC kotlin/UInt.toString-impl
// .. but ir backend performs wise `toString-impl` call
// one in IC.toString() + one in concatenation
// 2 INVOKESTATIC IC.toString-impl