From 630fab19523575909e3d6cb6c2121d2881dc3a15 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Tue, 17 Jan 2017 11:29:25 +0300 Subject: [PATCH] Fix signature of accessor for suspend function It must be a suspend function too to have an additional Continuation parameter #KT-15715 Fixed --- .../AccessorForFunctionDescriptor.java | 12 ++++++ .../box/coroutines/accessorForSuspend.kt | 34 +++++++++++++++++ .../coroutines/accessorForSuspend.txt | 37 +++++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 6 +++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 +++ ...LightAnalysisModeCodegenTestGenerated.java | 6 +++ .../impl/FunctionDescriptorImpl.java | 2 +- .../semantics/JsCodegenBoxTestGenerated.java | 6 +++ 8 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/coroutines/accessorForSuspend.kt create mode 100644 compiler/testData/codegen/light-analysis/coroutines/accessorForSuspend.txt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForFunctionDescriptor.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForFunctionDescriptor.java index ae813003af1..59296a7027f 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForFunctionDescriptor.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForFunctionDescriptor.java @@ -18,10 +18,13 @@ package org.jetbrains.kotlin.codegen; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.kotlin.codegen.coroutines.CoroutineCodegenUtilKt; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.resolve.DescriptorUtils; +import java.util.LinkedHashMap; + public class AccessorForFunctionDescriptor extends AbstractAccessorForFunctionDescriptor implements AccessorForCallableDescriptor { private final FunctionDescriptor calleeDescriptor; private final ClassDescriptor superCallTarget; @@ -46,6 +49,15 @@ public class AccessorForFunctionDescriptor extends AbstractAccessorForFunctionDe descriptor.getReturnType(), Modality.FINAL, Visibilities.LOCAL); + + setSuspend(descriptor.isSuspend()); + if (descriptor.getUserData(CoroutineCodegenUtilKt.INITIAL_DESCRIPTOR_FOR_SUSPEND_FUNCTION) != null) { + userDataMap = new LinkedHashMap, Object>(); + userDataMap.put( + CoroutineCodegenUtilKt.INITIAL_DESCRIPTOR_FOR_SUSPEND_FUNCTION, + descriptor.getUserData(CoroutineCodegenUtilKt.INITIAL_DESCRIPTOR_FOR_SUSPEND_FUNCTION) + ); + } } @NotNull diff --git a/compiler/testData/codegen/box/coroutines/accessorForSuspend.kt b/compiler/testData/codegen/box/coroutines/accessorForSuspend.kt new file mode 100644 index 00000000000..364267d68fe --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/accessorForSuspend.kt @@ -0,0 +1,34 @@ +// WITH_RUNTIME +// WITH_COROUTINES +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +class A { + suspend private fun a(): String = suspendCoroutineOrReturn { x -> + x.resume("OK") + SUSPENDED_MARKER + } + + suspend fun myfun(): String { + var result = "fail" + builder { + result = a() + } + + return result + } +} + +fun box(): String { + var result = "" + + builder { + result = A().myfun() + } + + return result +} diff --git a/compiler/testData/codegen/light-analysis/coroutines/accessorForSuspend.txt b/compiler/testData/codegen/light-analysis/coroutines/accessorForSuspend.txt new file mode 100644 index 00000000000..f8672f23a66 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/coroutines/accessorForSuspend.txt @@ -0,0 +1,37 @@ +@kotlin.Metadata +public final class A { + public method (): void + private final method a(p0: kotlin.coroutines.Continuation): java.lang.Object + public final @org.jetbrains.annotations.Nullable method myfun(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): java.lang.Object +} + +@kotlin.Metadata +public final class AccessorForSuspendKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static method builder(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): void +} + +@kotlin.Metadata +public final class CoroutineUtilKt { + public final static @org.jetbrains.annotations.NotNull method handleExceptionContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): kotlin.coroutines.Continuation + public final static @org.jetbrains.annotations.NotNull method handleResultContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): kotlin.coroutines.Continuation +} + +@kotlin.Metadata +public class EmptyContinuation { + public final static field Companion: EmptyContinuation.Companion + private final @org.jetbrains.annotations.NotNull field context: kotlin.coroutines.CoroutineContext + inner class EmptyContinuation/Companion + public @synthetic.kotlin.jvm.GeneratedByJvmOverloads method (): void + public method (@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.CoroutineContext): void + public synthetic method (p0: kotlin.coroutines.CoroutineContext, p1: int, p2: kotlin.jvm.internal.DefaultConstructorMarker): void + public @org.jetbrains.annotations.NotNull method getContext(): kotlin.coroutines.CoroutineContext + public method resume(@org.jetbrains.annotations.Nullable p0: java.lang.Object): void + public method resumeWithException(@org.jetbrains.annotations.NotNull p0: java.lang.Throwable): void +} + +@kotlin.Metadata +public final static class EmptyContinuation/Companion { + inner class EmptyContinuation/Companion + private method (): void +} diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index c592290a591..5e8a374341c 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -4561,6 +4561,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class Coroutines extends AbstractIrBlackBoxCodegenTest { + @TestMetadata("accessorForSuspend.kt") + public void testAccessorForSuspend() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/accessorForSuspend.kt"); + doTest(fileName); + } + public void testAllFilesPresentInCoroutines() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index f0da36e51a5..2c174024627 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -4561,6 +4561,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class Coroutines extends AbstractBlackBoxCodegenTest { + @TestMetadata("accessorForSuspend.kt") + public void testAccessorForSuspend() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/accessorForSuspend.kt"); + doTest(fileName); + } + public void testAllFilesPresentInCoroutines() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java index 77886a47ad5..a5d495ea6de 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java @@ -4561,6 +4561,12 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class Coroutines extends AbstractLightAnalysisModeCodegenTest { + @TestMetadata("accessorForSuspend.kt") + public void testAccessorForSuspend() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/accessorForSuspend.kt"); + doTest(fileName); + } + public void testAllFilesPresentInCoroutines() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java index a254324ab00..74e59307c30 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java @@ -60,7 +60,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo @Nullable private FunctionDescriptor initialSignatureDescriptor = null; - private Map, Object> userDataMap = null; + protected Map, Object> userDataMap = null; protected FunctionDescriptorImpl( @NotNull DeclarationDescriptor containingDeclaration, diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 12c62f2570d..ce4db34b56f 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -5306,6 +5306,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class Coroutines extends AbstractJsCodegenBoxTest { + @TestMetadata("accessorForSuspend.kt") + public void testAccessorForSuspend() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/accessorForSuspend.kt"); + doTest(fileName); + } + public void testAllFilesPresentInCoroutines() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); }