[FIR] Create string interpolating call even for single argument

Before this commit, questionable optimization existed which
unwrapped string interpolating call with single argument to this argument.
However, this led to source element loss and the necessity of sub-hacks.
In this commit we dropped this optimization (anyway user can remove
this single-expression string template in code if needed) to keep
source elements intact.
This commit is contained in:
Mikhail Glukhikh
2020-11-24 09:58:35 +03:00
parent 915a66f4fa
commit 1c71e64f58
9 changed files with 13 additions and 15 deletions
@@ -1,9 +1,9 @@
FILE: RedundantSingleExpressionStringTemplateChecker.kt
public final val x: R|kotlin/String| = String(Hello)
public get(): R|kotlin/String|
public final val y: R|kotlin/String| = R|/x|.R|kotlin/Any.toString|()
public final val y: R|kotlin/String| = <strcat>(R|/x|.R|kotlin/Any.toString|())
public get(): R|kotlin/String|
public final val z: R|kotlin/String| = R|/y|.R|kotlin/Any.hashCode|().R|kotlin/Any.toString|()
public final val z: R|kotlin/String| = <strcat>(R|/y|.R|kotlin/Any.hashCode|().R|kotlin/Any.toString|())
public get(): R|kotlin/String|
public final fun toString(x: R|kotlin/String|): R|kotlin/String| {
^toString <strcat>(String(IC), R|<local>/x|.R|kotlin/Any.toString|())
@@ -2,7 +2,7 @@ FILE: NotNullTypeChain.kt
public final val list1: R|kotlin/collections/List<kotlin/Int>| = R|kotlin/collections/listOf|<R|kotlin/Int|>(Int(1))
public get(): R|kotlin/collections/List<kotlin/Int>|
public final val list: R|kotlin/collections/List<kotlin/String>| = R|/list1|.R|kotlin/collections/orEmpty|<R|kotlin/Int|>().R|kotlin/collections/map|<R|kotlin/Int|, R|kotlin/String|>(<L> = map@fun <anonymous>(it: R|kotlin/Int|): R|kotlin/String| <kind=UNKNOWN> {
^ R|<local>/it|.R|kotlin/Any.toString|()
^ <strcat>(R|<local>/it|.R|kotlin/Any.toString|())
}
)
public get(): R|kotlin/collections/List<kotlin/String>|
@@ -8,5 +8,5 @@ FILE: stringTemplates.kt
public final fun foo(s: R|kotlin/String|): R|kotlin/Unit| {
}
public final fun test(a: R|A|): R|kotlin/Unit| {
R|/foo|(R|<local>/a|.R|kotlin/Any.toString|())
R|/foo|(<strcat>(R|<local>/a|.R|kotlin/Any.toString|()))
}
@@ -386,7 +386,6 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
source = base?.toFirSourceElement()
// Fast-pass if there is no non-const string expressions
if (!hasExpressions) return buildConstExpression(source, FirConstKind.String, sb.toString())
argumentList.arguments.singleOrNull()?.let { return it }
}
}
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// WITH_RUNTIME
@@ -1,5 +1,4 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND_FIR: JVM_IR
// FILE: Z.kt
inline class Z(val value: Int)
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants
// JVM_TARGET: 9
// FILE: JavaClass.java
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
fun f(s: String) = "$s"
fun g(s: String?) = "$s"
@@ -74,8 +74,9 @@ FILE fqName:<root> fileName:/stringTemplates.kt
PROPERTY name:test7 visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:test7 type:kotlin.String visibility:private [final,static]
EXPRESSION_BODY
CALL 'public open fun toString (): kotlin.String [fake_override] declared in kotlin.String' type=kotlin.String origin=null
$this: CALL 'public final fun <get-test1> (): kotlin.String declared in <root>' type=kotlin.String origin=GET_PROPERTY
STRING_CONCATENATION type=kotlin.String
CALL 'public open fun toString (): kotlin.String [fake_override] declared in kotlin.String' type=kotlin.String origin=null
$this: CALL 'public final fun <get-test1> (): kotlin.String declared in <root>' type=kotlin.String origin=GET_PROPERTY
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test7> visibility:public modality:FINAL <> () returnType:kotlin.String
correspondingProperty: PROPERTY name:test7 visibility:public modality:FINAL [val]
BLOCK_BODY
@@ -84,8 +85,9 @@ FILE fqName:<root> fileName:/stringTemplates.kt
PROPERTY name:test8 visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:test8 type:kotlin.String visibility:private [final,static]
EXPRESSION_BODY
CALL 'public open fun toString (): kotlin.String [fake_override] declared in kotlin.String' type=kotlin.String origin=null
$this: CALL 'public final fun foo (): kotlin.String declared in <root>' type=kotlin.String origin=null
STRING_CONCATENATION type=kotlin.String
CALL 'public open fun toString (): kotlin.String [fake_override] declared in kotlin.String' type=kotlin.String origin=null
$this: CALL 'public final fun foo (): kotlin.String declared in <root>' type=kotlin.String origin=null
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test8> visibility:public modality:FINAL <> () returnType:kotlin.String
correspondingProperty: PROPERTY name:test8 visibility:public modality:FINAL [val]
BLOCK_BODY
@@ -94,8 +96,9 @@ FILE fqName:<root> fileName:/stringTemplates.kt
PROPERTY name:test9 visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:test9 type:kotlin.String visibility:private [final,static]
EXPRESSION_BODY
CALL 'public open fun toString (): kotlin.String [fake_override] declared in kotlin.Int' type=kotlin.String origin=null
$this: CALL 'public final fun <get-x> (): kotlin.Int declared in <root>' type=kotlin.Int origin=GET_PROPERTY
STRING_CONCATENATION type=kotlin.String
CALL 'public open fun toString (): kotlin.String [fake_override] declared in kotlin.Int' type=kotlin.String origin=null
$this: CALL 'public final fun <get-x> (): kotlin.Int declared in <root>' type=kotlin.Int origin=GET_PROPERTY
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test9> visibility:public modality:FINAL <> () returnType:kotlin.String
correspondingProperty: PROPERTY name:test9 visibility:public modality:FINAL [val]
BLOCK_BODY