Mark Unit unspillable if it is merged with unspillable Unit

#KT-42004: Fixed
This commit is contained in:
Ilmir Usmanov
2020-09-17 19:06:38 +02:00
parent f6e4705d9c
commit b406022315
9 changed files with 87 additions and 1 deletions
@@ -136,7 +136,11 @@ private class UnitSourceInterpreter(private val localVariables: Set<Int>) : Basi
override fun merge(value1: BasicValue?, value2: BasicValue?): BasicValue? =
if (value1 is UnitValue && value2 is UnitValue) {
UnitValue(value1.insns.union(value2.insns))
val newValue = UnitValue(value1.insns.union(value2.insns))
if (newValue.insns.any { it in unspillableUnitValues }) {
markUnspillable(newValue)
}
newValue
} else {
// Mark unit values as unspillable if we merge them with non-unit values here.
// This is conservative since the value could turn out to be unused.
@@ -8997,6 +8997,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
public void testRefinedIntTypesAnalysis() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt");
}
@TestMetadata("safeCallElvis.kt")
public void testSafeCallElvis() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.kt");
}
}
}
@@ -0,0 +1,32 @@
// WITH_RUNTIME
import kotlin.coroutines.*
var res: String = "FAIL"
class Log {
fun error(message: Any?) {
res = message as String
}
}
private val log = Log()
class C {
fun method() {}
}
fun <T : Any> df(t: T, r: suspend (T) -> Unit) {
r.startCoroutine(t, Continuation(EmptyCoroutineContext) {})
}
fun foo(s: String, c: C?) {
df(s) {
c?.method() ?: log.error(it)
}
}
fun box(): String {
foo("OK", null)
return res
}
@@ -10392,6 +10392,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
public void testRefinedIntTypesAnalysis() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt");
}
@TestMetadata("safeCallElvis.kt")
public void testSafeCallElvis() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.kt");
}
}
}
@@ -10392,6 +10392,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
public void testRefinedIntTypesAnalysis() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt");
}
@TestMetadata("safeCallElvis.kt")
public void testSafeCallElvis() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.kt");
}
}
}
@@ -8997,6 +8997,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
public void testRefinedIntTypesAnalysis() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt");
}
@TestMetadata("safeCallElvis.kt")
public void testSafeCallElvis() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.kt");
}
}
}
@@ -7622,6 +7622,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
public void testRefinedIntTypesAnalysis() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt");
}
@TestMetadata("safeCallElvis.kt")
public void testSafeCallElvis() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.kt");
}
}
}
@@ -7622,6 +7622,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
public void testRefinedIntTypesAnalysis() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt");
}
@TestMetadata("safeCallElvis.kt")
public void testSafeCallElvis() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.kt");
}
}
}
@@ -7622,6 +7622,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
public void testRefinedIntTypesAnalysis() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt");
}
@TestMetadata("safeCallElvis.kt")
public void testSafeCallElvis() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.kt");
}
}
}
@@ -21419,6 +21424,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/ranges/unsigned/expression/emptyRange.kt");
}
@TestMetadata("inexactDownToMinValue.kt")
public void testInexactDownToMinValue() throws Exception {
runTest("compiler/testData/codegen/box/ranges/unsigned/expression/inexactDownToMinValue.kt");
}
@TestMetadata("inexactSteppedDownTo.kt")
public void testInexactSteppedDownTo() throws Exception {
runTest("compiler/testData/codegen/box/ranges/unsigned/expression/inexactSteppedDownTo.kt");
@@ -21464,11 +21474,21 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/ranges/unsigned/expression/openRange.kt");
}
@TestMetadata("overflowZeroDownToMaxValue.kt")
public void testOverflowZeroDownToMaxValue() throws Exception {
runTest("compiler/testData/codegen/box/ranges/unsigned/expression/overflowZeroDownToMaxValue.kt");
}
@TestMetadata("overflowZeroToMinValue.kt")
public void testOverflowZeroToMinValue() throws Exception {
runTest("compiler/testData/codegen/box/ranges/unsigned/expression/overflowZeroToMinValue.kt");
}
@TestMetadata("progressionDownToMinValue.kt")
public void testProgressionDownToMinValue() throws Exception {
runTest("compiler/testData/codegen/box/ranges/unsigned/expression/progressionDownToMinValue.kt");
}
@TestMetadata("progressionMaxValueMinusTwoToMaxValue.kt")
public void testProgressionMaxValueMinusTwoToMaxValue() throws Exception {
runTest("compiler/testData/codegen/box/ranges/unsigned/expression/progressionMaxValueMinusTwoToMaxValue.kt");