[JVM] Do not unbox when local variable initialized with null.
This is already the case for straightline code such as
```
inline fun <R> f(size: Int, block: () -> R): R {
var result: R
result = block()
return result
}
```
However, if the local variable introduction happens at a merge
point as in the following example, we allow the unboxing but
only do it halfway. The initialization of the local is still
done with a null value.
```
inline fun <R> f(size: Int, block: () -> R): R {
var result: R
while (true) {
result = block()
if (size == 0) break
}
return result
}
```
This change disallows unboxing for this move complicated
case as well by bailing out if a local use is with a
TaintedBoxedValue (merge of Object and Integer).
^KT-48394 Fixed.
This commit is contained in:
committed by
TeamCityServer
parent
580f1d51f6
commit
8dee3c1ca0
+1
-1
@@ -129,7 +129,7 @@ class RedundantBoxingMethodTransformer(private val generationState: GenerationSt
|
|||||||
private fun isUnsafeToRemoveBoxingForConnectedValues(usedValues: List<BasicValue>, unboxedType: Type): Boolean =
|
private fun isUnsafeToRemoveBoxingForConnectedValues(usedValues: List<BasicValue>, unboxedType: Type): Boolean =
|
||||||
usedValues.any { input ->
|
usedValues.any { input ->
|
||||||
if (input === StrictBasicValue.UNINITIALIZED_VALUE) return@any false
|
if (input === StrictBasicValue.UNINITIALIZED_VALUE) return@any false
|
||||||
if (input !is BoxedBasicValue) return@any true
|
if (input !is CleanBoxedValue) return@any true
|
||||||
|
|
||||||
val descriptor = input.descriptor
|
val descriptor = input.descriptor
|
||||||
!descriptor.isSafeToRemove || descriptor.unboxedType != unboxedType
|
!descriptor.isSafeToRemove || descriptor.unboxedType != unboxedType
|
||||||
|
|||||||
+6
@@ -1808,6 +1808,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt48394.kt")
|
||||||
|
public void testKt48394() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt48394.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt5493.kt")
|
@TestMetadata("kt5493.kt")
|
||||||
public void testKt5493() throws Exception {
|
public void testKt5493() throws Exception {
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
inline fun <R> f(size: Int, block: () -> R): R {
|
||||||
|
var result: R
|
||||||
|
while (true) {
|
||||||
|
result = block()
|
||||||
|
if (size == 0) break
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
fun computeResult(size: Int) = f(size) {
|
||||||
|
42
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() = if (computeResult(0) == 42) "OK" else "FAIL"
|
||||||
+6
@@ -1706,6 +1706,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt48394.kt")
|
||||||
|
public void testKt48394() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt48394.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt5493.kt")
|
@TestMetadata("kt5493.kt")
|
||||||
public void testKt5493() throws Exception {
|
public void testKt5493() throws Exception {
|
||||||
|
|||||||
+6
@@ -1808,6 +1808,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt48394.kt")
|
||||||
|
public void testKt48394() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt48394.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt5493.kt")
|
@TestMetadata("kt5493.kt")
|
||||||
public void testKt5493() throws Exception {
|
public void testKt5493() throws Exception {
|
||||||
|
|||||||
+5
@@ -1510,6 +1510,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt48394.kt")
|
||||||
|
public void testKt48394() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt48394.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt5493.kt")
|
@TestMetadata("kt5493.kt")
|
||||||
public void testKt5493() throws Exception {
|
public void testKt5493() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/boxingOptimization/kt5493.kt");
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt5493.kt");
|
||||||
|
|||||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -990,6 +990,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
|||||||
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt48394.kt")
|
||||||
|
public void testKt48394() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt48394.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt5493.kt")
|
@TestMetadata("kt5493.kt")
|
||||||
public void testKt5493() throws Exception {
|
public void testKt5493() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/boxingOptimization/kt5493.kt");
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt5493.kt");
|
||||||
|
|||||||
Generated
+5
@@ -990,6 +990,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt48394.kt")
|
||||||
|
public void testKt48394() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt48394.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt5493.kt")
|
@TestMetadata("kt5493.kt")
|
||||||
public void testKt5493() throws Exception {
|
public void testKt5493() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/boxingOptimization/kt5493.kt");
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt5493.kt");
|
||||||
|
|||||||
Generated
+5
@@ -990,6 +990,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt48394.kt")
|
||||||
|
public void testKt48394() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt48394.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt5493.kt")
|
@TestMetadata("kt5493.kt")
|
||||||
public void testKt5493() throws Exception {
|
public void testKt5493() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/boxingOptimization/kt5493.kt");
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt5493.kt");
|
||||||
|
|||||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+5
@@ -875,6 +875,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
|||||||
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt48394.kt")
|
||||||
|
public void testKt48394() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt48394.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt5588.kt")
|
@TestMetadata("kt5588.kt")
|
||||||
public void testKt5588() throws Exception {
|
public void testKt5588() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/boxingOptimization/kt5588.kt");
|
runTest("compiler/testData/codegen/box/boxingOptimization/kt5588.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user