JVM_IR: correctly name $$forInline versions of @JvmName suspend funs

Using a hack similar to $default stubs.
This commit is contained in:
pyos
2020-02-06 10:26:42 +01:00
committed by Ilmir Usmanov
parent 08074bb60e
commit 2bf50cc91a
7 changed files with 75 additions and 1 deletions
@@ -7,12 +7,14 @@ package org.jetbrains.kotlin.backend.jvm.ir
import org.jetbrains.kotlin.backend.common.lower.IrLoweringContext
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
import org.jetbrains.kotlin.backend.jvm.JvmSymbols
import org.jetbrains.kotlin.backend.jvm.codegen.isInlineOnly
import org.jetbrains.kotlin.backend.jvm.codegen.isJvmInterface
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmDeclarationFactory
import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.unboxInlineClass
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.codegen.inline.coroutines.FOR_INLINE_SUFFIX
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope
@@ -128,7 +130,12 @@ fun IrDeclaration.getJvmNameFromAnnotation(): String? {
// TODO lower @JvmName?
val const = getAnnotation(DescriptorUtils.JVM_NAME)?.getValueArgument(0) as? IrConst<*> ?: return null
val value = const.value as? String ?: return null
return if (origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER) "$value\$default" else value
return when (origin) {
IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER -> "$value\$default"
JvmLoweredDeclarationOrigin.FOR_INLINE_STATE_MACHINE_TEMPLATE,
JvmLoweredDeclarationOrigin.FOR_INLINE_STATE_MACHINE_TEMPLATE_CAPTURES_CROSSINLINE -> "$value$FOR_INLINE_SUFFIX"
else -> value
}
}
val IrFunction.propertyIfAccessor: IrDeclaration
@@ -618,6 +618,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
if (view.isInline) JvmLoweredDeclarationOrigin.FOR_INLINE_STATE_MACHINE_TEMPLATE
else JvmLoweredDeclarationOrigin.FOR_INLINE_STATE_MACHINE_TEMPLATE_CAPTURES_CROSSINLINE
}.apply {
annotations += view.annotations.map { it.deepCopyWithSymbols(this) }
copyTypeParameters(view.typeParameters)
dispatchReceiverParameter = view.dispatchReceiverParameter?.copyTo(this)
extensionReceiverParameter = view.extensionReceiverParameter?.copyTo(this)
+36
View File
@@ -0,0 +1,36 @@
// FILE: test.kt
// COMMON_COROUTINES_TEST
// WITH_RUNTIME
// WITH_COROUTINES
// NO_CHECK_LAMBDA_INLINING
// TARGET_BACKEND: JVM
import COROUTINES_PACKAGE.*
import helpers.*
class Result<T>(val x: T)
@JvmName("foo") // + foo$$forInline
suspend inline fun test(c: Result<Int>) = c.x
@JvmName("bar") // + bar$$forInline
suspend inline fun test(c: Result<String>) = c.x
// FILE: box.kt
// COMMON_COROUTINES_TEST
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
import helpers.*
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box() : String {
var res = "FAIL"
builder {
res = test(Result("OK"))
}
return res
}
@@ -3758,6 +3758,16 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/inlineSuspendOfSuspend.kt", "kotlin.coroutines");
}
@TestMetadata("jvmName.kt")
public void testJvmName_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/jvmName.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("jvmName.kt")
public void testJvmName_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/jvmName.kt", "kotlin.coroutines");
}
@TestMetadata("kt26658.kt")
public void testKt26658() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/kt26658.kt");
@@ -3758,6 +3758,16 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/inlineSuspendOfSuspend.kt", "kotlin.coroutines");
}
@TestMetadata("jvmName.kt")
public void testJvmName_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/jvmName.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("jvmName.kt")
public void testJvmName_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/jvmName.kt", "kotlin.coroutines");
}
@TestMetadata("kt26658.kt")
public void testKt26658() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/kt26658.kt");
@@ -3698,6 +3698,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/inlineSuspendOfSuspend.kt", "kotlin.coroutines");
}
@TestMetadata("jvmName.kt")
public void testJvmName_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/jvmName.kt", "kotlin.coroutines");
}
@TestMetadata("kt26658.kt")
public void testKt26658() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/kt26658.kt");
@@ -3698,6 +3698,11 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/inlineSuspendOfSuspend.kt", "kotlin.coroutines");
}
@TestMetadata("jvmName.kt")
public void testJvmName_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/boxInline/suspend/jvmName.kt", "kotlin.coroutines");
}
@TestMetadata("kt26658.kt")
public void testKt26658() throws Exception {
runTest("compiler/testData/codegen/boxInline/suspend/kt26658.kt");