Do not generate $suspendImpl for JvmDefault functions in interfaces

#KT-44533 Fixed
This commit is contained in:
Alexander Udalov
2021-01-27 10:10:49 +01:00
parent 5f71cd5476
commit acd8c4503b
8 changed files with 184 additions and 1 deletions
@@ -20793,6 +20793,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/jvm8/defaults/superCall.kt");
}
@Test
@TestMetadata("suspendFunction.kt")
public void testSuspendFunction() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/suspendFunction.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/jvm8/defaults/allCompatibility")
@TestDataPath("$PROJECT_ROOT")
@@ -20970,6 +20976,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/simpleFunction.kt");
}
@Test
@TestMetadata("suspendFunction.kt")
public void testSuspendFunction() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/suspendFunction.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/delegationBy")
@TestDataPath("$PROJECT_ROOT")
@@ -21292,6 +21304,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/simpleFunction.kt");
}
@Test
@TestMetadata("suspendFunction.kt")
public void testSuspendFunction() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/suspendFunction.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/delegationBy")
@TestDataPath("$PROJECT_ROOT")
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
import org.jetbrains.kotlin.backend.jvm.codegen.continuationParameter
import org.jetbrains.kotlin.backend.jvm.codegen.hasContinuation
import org.jetbrains.kotlin.backend.jvm.codegen.isInvokeSuspendOfContinuation
import org.jetbrains.kotlin.backend.jvm.codegen.isJvmInterface
import org.jetbrains.kotlin.backend.jvm.ir.defaultValue
import org.jetbrains.kotlin.backend.jvm.ir.isStaticInlineClassReplacement
import org.jetbrains.kotlin.backend.jvm.localDeclarationsPhase
@@ -302,7 +303,7 @@ private class AddContinuationLowering(context: JvmBackendContext) : SuspendLower
}
}
val newFunction = if (function.isOverridable) {
val newFunction = if (function.isOverridable && !function.parentAsClass.isJvmInterface) {
// Create static method for the suspend state machine method so that reentering the method
// does not lead to virtual dispatch to the wrong method.
createStaticSuspendImpl(view).also { result += it }
@@ -0,0 +1,38 @@
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_COROUTINES
// WITH_RUNTIME
import kotlin.coroutines.*
import helpers.*
interface S {
suspend fun foo()
}
interface T : S {
override suspend fun foo() {
bar()
}
fun bar()
}
object O : T {
var result = ""
override fun bar() {
result = "OK"
}
}
fun builder(block: suspend () -> Unit) {
block.startCoroutine(EmptyContinuation)
}
fun box(): String {
builder { O.foo() }
return O.result
}
@@ -0,0 +1,37 @@
// !JVM_DEFAULT_MODE: all
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_COROUTINES
// WITH_RUNTIME
import kotlin.coroutines.*
import helpers.*
interface S {
suspend fun foo()
}
interface T : S {
override suspend fun foo() {
bar()
}
fun bar()
}
object O : T {
var result = ""
override fun bar() {
result = "OK"
}
}
fun builder(block: suspend () -> Unit) {
block.startCoroutine(EmptyContinuation)
}
fun box(): String {
builder { O.foo() }
return O.result
}
@@ -0,0 +1,38 @@
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_COROUTINES
// WITH_RUNTIME
import kotlin.coroutines.*
import helpers.*
interface S {
suspend fun foo()
}
interface T : S {
@JvmDefault
override suspend fun foo() {
bar()
}
fun bar()
}
object O : T {
var result = ""
override fun bar() {
result = "OK"
}
}
fun builder(block: suspend () -> Unit) {
block.startCoroutine(EmptyContinuation)
}
fun box(): String {
builder { O.foo() }
return O.result
}
@@ -20793,6 +20793,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/jvm8/defaults/superCall.kt");
}
@Test
@TestMetadata("suspendFunction.kt")
public void testSuspendFunction() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/suspendFunction.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/jvm8/defaults/allCompatibility")
@TestDataPath("$PROJECT_ROOT")
@@ -20970,6 +20976,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/simpleFunction.kt");
}
@Test
@TestMetadata("suspendFunction.kt")
public void testSuspendFunction() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/suspendFunction.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/delegationBy")
@TestDataPath("$PROJECT_ROOT")
@@ -21292,6 +21304,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/simpleFunction.kt");
}
@Test
@TestMetadata("suspendFunction.kt")
public void testSuspendFunction() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/suspendFunction.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/delegationBy")
@TestDataPath("$PROJECT_ROOT")
@@ -20793,6 +20793,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/jvm8/defaults/superCall.kt");
}
@Test
@TestMetadata("suspendFunction.kt")
public void testSuspendFunction() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/suspendFunction.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/jvm8/defaults/allCompatibility")
@TestDataPath("$PROJECT_ROOT")
@@ -20970,6 +20976,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/simpleFunction.kt");
}
@Test
@TestMetadata("suspendFunction.kt")
public void testSuspendFunction() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/suspendFunction.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/delegationBy")
@TestDataPath("$PROJECT_ROOT")
@@ -21292,6 +21304,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/simpleFunction.kt");
}
@Test
@TestMetadata("suspendFunction.kt")
public void testSuspendFunction() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/suspendFunction.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/delegationBy")
@TestDataPath("$PROJECT_ROOT")
@@ -17479,6 +17479,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/jvm8/defaults/superCall.kt");
}
@TestMetadata("suspendFunction.kt")
public void testSuspendFunction() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/suspendFunction.kt");
}
@TestMetadata("compiler/testData/codegen/box/jvm8/defaults/allCompatibility")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -17631,6 +17636,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/simpleFunction.kt");
}
@TestMetadata("suspendFunction.kt")
public void testSuspendFunction() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/suspendFunction.kt");
}
@TestMetadata("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/delegationBy")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -17918,6 +17928,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/simpleFunction.kt");
}
@TestMetadata("suspendFunction.kt")
public void testSuspendFunction() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/suspendFunction.kt");
}
@TestMetadata("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/delegationBy")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)