Do not inline non-const vals
#KT-10425 Fixed
This commit is contained in:
@@ -1246,6 +1246,9 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
if (compileTimeValue == null) {
|
if (compileTimeValue == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (compileTimeValue.getUsesNonConstValAsConstant()) return null;
|
||||||
|
|
||||||
KotlinType expectedType = bindingContext.getType(expression);
|
KotlinType expectedType = bindingContext.getType(expression);
|
||||||
return compileTimeValue.toConstantValue(expectedType);
|
return compileTimeValue.toConstantValue(expectedType);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
val x = 1
|
||||||
|
|
||||||
|
class A {
|
||||||
|
val b = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): Int {
|
||||||
|
when ("abc".length) {
|
||||||
|
x -> return 0
|
||||||
|
else -> A()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x == 0) return 1
|
||||||
|
|
||||||
|
val a = A()
|
||||||
|
when ("cde".length) {
|
||||||
|
a.b -> return 0
|
||||||
|
else -> A()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.b == 0) return 1
|
||||||
|
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 1 GETSTATIC is located within `x` public getter, other 2 are accesses that should not be inlined */
|
||||||
|
// 3 GETSTATIC NoInlineNonConstKt\.x : I
|
||||||
|
// 2 INVOKEVIRTUAL A\.getB \(\)I
|
||||||
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
|
const val y = "cde"
|
||||||
|
|
||||||
fun foo(x : String) : String {
|
fun foo(x : String) : String {
|
||||||
val y = "cde"
|
|
||||||
when (x) {
|
when (x) {
|
||||||
"abc", "${y}" -> return "abc_cde"
|
"abc", "${y}" -> return "abc_cde"
|
||||||
"e" + "fg", "ghi" -> return "efg_ghi"
|
"e" + "fg", "ghi" -> return "efg_ghi"
|
||||||
|
|||||||
@@ -592,6 +592,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noInlineNonConst.kt")
|
||||||
|
public void testNoInlineNonConst() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/constants/noInlineNonConst.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nullableByteAndShort.kt")
|
@TestMetadata("nullableByteAndShort.kt")
|
||||||
public void testNullableByteAndShort() throws Exception {
|
public void testNullableByteAndShort() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/constants/nullableByteAndShort.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/constants/nullableByteAndShort.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user