JVM_IR KT-49136 don't optimize null checks on fields and calls
This commit is contained in:
+12
@@ -27486,6 +27486,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt22410.kt");
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt22410.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49136.kt")
|
||||||
|
public void testKt49136() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt49136.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49136a.kt")
|
||||||
|
public void testKt49136a() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt49136a.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt7774.kt")
|
@TestMetadata("kt7774.kt")
|
||||||
public void testKt7774() throws Exception {
|
public void testKt7774() throws Exception {
|
||||||
|
|||||||
+3
@@ -64,4 +64,7 @@ interface CommonBackendContext : BackendContext, LoggingContext {
|
|||||||
|
|
||||||
val optimizeLoopsOverUnsignedArrays: Boolean
|
val optimizeLoopsOverUnsignedArrays: Boolean
|
||||||
get() = false
|
get() = false
|
||||||
|
|
||||||
|
val optimizeNullChecksUsingKotlinNullability: Boolean
|
||||||
|
get() = true
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -146,9 +146,9 @@ class IfNullExpressionsFusionLowering(val context: CommonBackendContext) : FileL
|
|||||||
is IrGetClass ->
|
is IrGetClass ->
|
||||||
false
|
false
|
||||||
is IrCall ->
|
is IrCall ->
|
||||||
if (!type.isNullable()) false else null
|
if (context.optimizeNullChecksUsingKotlinNullability && !type.isNullable()) false else null
|
||||||
is IrGetField ->
|
is IrGetField ->
|
||||||
if (!type.isNullable()) false else null
|
if (context.optimizeNullChecksUsingKotlinNullability && !type.isNullable()) false else null
|
||||||
is IrBlock -> {
|
is IrBlock -> {
|
||||||
val singleExpr = statements.singleOrNull()
|
val singleExpr = statements.singleOrNull()
|
||||||
if (singleExpr is IrExpression && singleExpr.type == type)
|
if (singleExpr is IrExpression && singleExpr.type == type)
|
||||||
|
|||||||
@@ -221,6 +221,9 @@ class JvmBackendContext(
|
|||||||
override val doWhileCounterLoopOrigin: IrStatementOrigin
|
override val doWhileCounterLoopOrigin: IrStatementOrigin
|
||||||
get() = JvmLoweredStatementOrigin.DO_WHILE_COUNTER_LOOP
|
get() = JvmLoweredStatementOrigin.DO_WHILE_COUNTER_LOOP
|
||||||
|
|
||||||
|
override val optimizeNullChecksUsingKotlinNullability: Boolean
|
||||||
|
get() = false
|
||||||
|
|
||||||
inner class JvmIr(
|
inner class JvmIr(
|
||||||
irModuleFragment: IrModuleFragment,
|
irModuleFragment: IrModuleFragment,
|
||||||
symbolTable: SymbolTable
|
symbolTable: SymbolTable
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// FULL_JDK
|
||||||
|
// WITH_REFLECT
|
||||||
|
|
||||||
|
class A(val b: B)
|
||||||
|
|
||||||
|
class B(val c: String)
|
||||||
|
|
||||||
|
fun createByReflection(): A? =
|
||||||
|
A(B("aaa")).apply {
|
||||||
|
val field = javaClass.declaredFields.find { it.name == "b" }!!
|
||||||
|
field.isAccessible = true
|
||||||
|
field.set(this, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a = createByReflection()
|
||||||
|
println(a?.b?.c)
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
abstract class Z {
|
||||||
|
init {
|
||||||
|
check(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract val b: B
|
||||||
|
}
|
||||||
|
|
||||||
|
class A(override val b: B) : Z()
|
||||||
|
|
||||||
|
class B(val c: String)
|
||||||
|
|
||||||
|
fun use(a: Any?) {}
|
||||||
|
|
||||||
|
fun check(z: Z) {
|
||||||
|
use(z?.b?.c)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
A(B(""))
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+12
@@ -27348,6 +27348,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt22410.kt");
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt22410.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49136.kt")
|
||||||
|
public void testKt49136() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt49136.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49136a.kt")
|
||||||
|
public void testKt49136a() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt49136a.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt7774.kt")
|
@TestMetadata("kt7774.kt")
|
||||||
public void testKt7774() throws Exception {
|
public void testKt7774() throws Exception {
|
||||||
|
|||||||
+12
@@ -27486,6 +27486,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt22410.kt");
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt22410.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49136.kt")
|
||||||
|
public void testKt49136() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt49136.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49136a.kt")
|
||||||
|
public void testKt49136a() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt49136a.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt7774.kt")
|
@TestMetadata("kt7774.kt")
|
||||||
public void testKt7774() throws Exception {
|
public void testKt7774() throws Exception {
|
||||||
|
|||||||
+10
@@ -23199,6 +23199,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt22410.kt");
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt22410.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt49136.kt")
|
||||||
|
public void testKt49136() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt49136.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt49136a.kt")
|
||||||
|
public void testKt49136a() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt49136a.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt7774.kt")
|
@TestMetadata("kt7774.kt")
|
||||||
public void testKt7774() throws Exception {
|
public void testKt7774() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt7774.kt");
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt7774.kt");
|
||||||
|
|||||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -18138,6 +18138,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
|||||||
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt22410.kt");
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt22410.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt49136a.kt")
|
||||||
|
public void testKt49136a() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt49136a.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt7774.kt")
|
@TestMetadata("kt7774.kt")
|
||||||
public void testKt7774() throws Exception {
|
public void testKt7774() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt7774.kt");
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt7774.kt");
|
||||||
|
|||||||
Generated
+5
@@ -17544,6 +17544,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt22410.kt");
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt22410.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt49136a.kt")
|
||||||
|
public void testKt49136a() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt49136a.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt7774.kt")
|
@TestMetadata("kt7774.kt")
|
||||||
public void testKt7774() throws Exception {
|
public void testKt7774() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt7774.kt");
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt7774.kt");
|
||||||
|
|||||||
Generated
+5
@@ -17574,6 +17574,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt22410.kt");
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt22410.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt49136a.kt")
|
||||||
|
public void testKt49136a() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt49136a.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt7774.kt")
|
@TestMetadata("kt7774.kt")
|
||||||
public void testKt7774() throws Exception {
|
public void testKt7774() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt7774.kt");
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt7774.kt");
|
||||||
|
|||||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+5
@@ -14323,6 +14323,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
|||||||
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt22410.kt");
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt22410.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt49136a.kt")
|
||||||
|
public void testKt49136a() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt49136a.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt7774.kt")
|
@TestMetadata("kt7774.kt")
|
||||||
public void testKt7774() throws Exception {
|
public void testKt7774() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt7774.kt");
|
runTest("compiler/testData/codegen/box/nullCheckOptimization/kt7774.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user