From 3ee62cb1b2d645a05a91d5116034454beb9703d6 Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Tue, 23 Feb 2021 14:51:39 +0100 Subject: [PATCH] JVM IR: Do not generate private suspend functions as synthetic package-private #KT-26592 --- .../kotlin/backend/jvm/codegen/FunctionCodegen.kt | 1 - .../jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt | 4 ---- .../kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt | 2 -- .../box/coroutines/suspendConversion/onInlineArgument.kt | 1 + .../coroutines/suspendConversion/onInlineArgument_ir.txt | 1 + .../bytecodeListing/coroutines/privateAccessor_ir.txt | 7 +++++++ .../bytecodeListing/coroutines/privateSuspendFun_ir.txt | 6 ++++-- 7 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 compiler/testData/codegen/bytecodeListing/coroutines/privateAccessor_ir.txt diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt index 44e2ff2661c..46a6640d5af 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt @@ -165,7 +165,6 @@ class FunctionCodegen( } val isSynthetic = origin.isSynthetic || hasAnnotation(JVM_SYNTHETIC_ANNOTATION_FQ_NAME) || - (isSuspend && DescriptorVisibilities.isPrivate(visibility) && !isInline) || isReifiable() || isDeprecatedHidden() diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt index a9d18685a60..4bf7dbc30c0 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt @@ -208,10 +208,6 @@ private fun IrDeclarationWithVisibility.specialCaseVisibility(kind: OwnerKind?): return null } - if (this is IrSimpleFunction && isSuspend) { - return AsmUtil.NO_FLAG_PACKAGE_PRIVATE - } - if (this is IrConstructor && parentAsClass.kind === ClassKind.ENUM_ENTRY) { return AsmUtil.NO_FLAG_PACKAGE_PRIVATE } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt index 7077b5aa87e..a3cb675b7c4 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt @@ -679,8 +679,6 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle val fromSubclassOfReceiversClass = !throughCrossinlineLambda && context.isSubclassOf(ownerClass) && (thisObjReference == null || context.symbol.isSubtypeOfClass(thisObjReference)) return when { - // private suspend functions are generated as synthetic package private - declaration is IrFunction && declaration.isSuspend && declaration.visibility.isPrivate && samePackage -> true declaration.visibility.isPrivate && (throughCrossinlineLambda || ownerClass != context) -> false declaration.visibility.isProtected && !samePackage && !fromSubclassOfReceiversClass -> false withSuper && !fromSubclassOfReceiversClass -> false diff --git a/compiler/testData/codegen/box/coroutines/suspendConversion/onInlineArgument.kt b/compiler/testData/codegen/box/coroutines/suspendConversion/onInlineArgument.kt index e8cb5ec713c..2db89ebcc68 100644 --- a/compiler/testData/codegen/box/coroutines/suspendConversion/onInlineArgument.kt +++ b/compiler/testData/codegen/box/coroutines/suspendConversion/onInlineArgument.kt @@ -2,6 +2,7 @@ // WITH_RUNTIME // WITH_COROUTINES // IGNORE_BACKEND: JVM, NATIVE +// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_LIGHT_ANALYSIS // `lambda` should not be wrapped in yet another object (so no OnInlineArgumentKt$box$1$1). diff --git a/compiler/testData/codegen/box/coroutines/suspendConversion/onInlineArgument_ir.txt b/compiler/testData/codegen/box/coroutines/suspendConversion/onInlineArgument_ir.txt index 6c9913ff606..706a082c98a 100644 --- a/compiler/testData/codegen/box/coroutines/suspendConversion/onInlineArgument_ir.txt +++ b/compiler/testData/codegen/box/coroutines/suspendConversion/onInlineArgument_ir.txt @@ -8,6 +8,7 @@ final class OnInlineArgumentKt$box$1 { field label: int inner (anonymous) class OnInlineArgumentKt$box$1 method (p0: kotlin.jvm.internal.Ref$ObjectRef, p1: kotlin.jvm.functions.Function1, p2: kotlin.coroutines.Continuation): void + public synthetic final static method access$invokeSuspend$suspendConversion0(p0: kotlin.jvm.functions.Function1, p1: java.lang.String, p2: kotlin.coroutines.Continuation): java.lang.Object public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation public final @org.jetbrains.annotations.Nullable method invoke(@org.jetbrains.annotations.Nullable p0: kotlin.coroutines.Continuation): java.lang.Object public synthetic bridge method invoke(p0: java.lang.Object): java.lang.Object diff --git a/compiler/testData/codegen/bytecodeListing/coroutines/privateAccessor_ir.txt b/compiler/testData/codegen/bytecodeListing/coroutines/privateAccessor_ir.txt new file mode 100644 index 00000000000..58c097b5876 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/coroutines/privateAccessor_ir.txt @@ -0,0 +1,7 @@ +@kotlin.Metadata +public final class PrivateAccessorKt { + // source: 'privateAccessor.kt' + public synthetic final static method access$bar(p0: kotlin.coroutines.Continuation): java.lang.Object + private final static method bar(p0: kotlin.coroutines.Continuation): java.lang.Object + private final static method foo(): void +} diff --git a/compiler/testData/codegen/bytecodeListing/coroutines/privateSuspendFun_ir.txt b/compiler/testData/codegen/bytecodeListing/coroutines/privateSuspendFun_ir.txt index 6c6c584acbf..1a77d18c87d 100644 --- a/compiler/testData/codegen/bytecodeListing/coroutines/privateSuspendFun_ir.txt +++ b/compiler/testData/codegen/bytecodeListing/coroutines/privateSuspendFun_ir.txt @@ -2,11 +2,13 @@ public final class A { // source: 'privateSuspendFun.kt' public method (): void - synthetic final method foo(p0: kotlin.coroutines.Continuation): java.lang.Object + public synthetic final static method access$foo(p0: A, p1: kotlin.coroutines.Continuation): java.lang.Object + private final method foo(p0: kotlin.coroutines.Continuation): java.lang.Object } @kotlin.Metadata public final class PrivateSuspendFunKt { // source: 'privateSuspendFun.kt' - synthetic final static method foo(p0: kotlin.coroutines.Continuation): java.lang.Object + public synthetic final static method access$foo(p0: kotlin.coroutines.Continuation): java.lang.Object + private final static method foo(p0: kotlin.coroutines.Continuation): java.lang.Object }