From 85a3fefcc61fe2801503a57de4f69ad60e112285 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Sat, 14 Jan 2017 13:54:04 +0300 Subject: [PATCH] Get rid of SuspendFunctionX interfaces Use a pair of effectively abstract methods in CoroutineImpl instead --- .../kotlin/codegen/JvmRuntimeTypes.kt | 6 ----- .../src/kotlin/jvm/internal/CoroutineImpl.kt | 13 ++++++++- .../kotlin/jvm/internal/SuspendFunctions.kt | 27 ------------------- .../kotlin/coroutines/CoroutinesLibrary.kt | 4 +-- .../reference-public-api/kotlin-runtime.txt | 10 ++----- 5 files changed, 16 insertions(+), 44 deletions(-) delete mode 100644 core/runtime.jvm/src/kotlin/jvm/internal/SuspendFunctions.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.kt index df269206ba5..2f8b49e24d0 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.codegen import org.jetbrains.kotlin.builtins.createFunctionType -import org.jetbrains.kotlin.builtins.isExtensionFunctionType import org.jetbrains.kotlin.codegen.coroutines.createJvmSuspendFunctionView import org.jetbrains.kotlin.coroutines.isSuspendLambda import org.jetbrains.kotlin.descriptors.* @@ -29,7 +28,6 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils -import org.jetbrains.kotlin.utils.addIfNotNull class JvmRuntimeTypes(module: ModuleDescriptor) { private val kotlinJvmInternalPackage = MutablePackageFragmentDescriptor(module, FqName("kotlin.jvm.internal")) @@ -89,10 +87,6 @@ class JvmRuntimeTypes(module: ModuleDescriptor) { add(coroutineImplClass.defaultType) if (descriptor.isSuspendLambda) { - val parametersNumber = - descriptor.valueParameters.size + (if (functionType.isExtensionFunctionType) 1 else 0) - - addIfNotNull(suspendFunctions.getOrNull(parametersNumber)?.defaultType) add(functionType) } } diff --git a/core/runtime.jvm/src/kotlin/jvm/internal/CoroutineImpl.kt b/core/runtime.jvm/src/kotlin/jvm/internal/CoroutineImpl.kt index 782854c3c2d..78935849ac0 100644 --- a/core/runtime.jvm/src/kotlin/jvm/internal/CoroutineImpl.kt +++ b/core/runtime.jvm/src/kotlin/jvm/internal/CoroutineImpl.kt @@ -16,7 +16,10 @@ package kotlin.jvm.internal -import kotlin.coroutines.* +import java.lang.IllegalStateException +import kotlin.coroutines.Continuation +import kotlin.coroutines.ContinuationInterceptor +import kotlin.coroutines.CoroutineContext import kotlin.coroutines.intrinsics.SUSPENDED_MARKER abstract class CoroutineImpl( @@ -63,4 +66,12 @@ abstract class CoroutineImpl( } protected abstract fun doResume(data: Any?, exception: Throwable?): Any? + + open fun create(completion: Continuation<*>): Continuation { + throw IllegalStateException("create(Continuation) has not been overridden") + } + + open fun create(value: Any?, completion: Continuation<*>): Continuation { + throw IllegalStateException("create(Any?;Continuation) has not been overridden") + } } diff --git a/core/runtime.jvm/src/kotlin/jvm/internal/SuspendFunctions.kt b/core/runtime.jvm/src/kotlin/jvm/internal/SuspendFunctions.kt deleted file mode 100644 index 04f1343a584..00000000000 --- a/core/runtime.jvm/src/kotlin/jvm/internal/SuspendFunctions.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package kotlin.jvm.internal - -import kotlin.coroutines.Continuation - -interface SuspendFunction0 { - fun create(resultingContinuation: Continuation): Continuation -} - -interface SuspendFunction1 { - fun create(value: T, resultingContinuation: Continuation): Continuation -} diff --git a/libraries/stdlib/src/kotlin/coroutines/CoroutinesLibrary.kt b/libraries/stdlib/src/kotlin/coroutines/CoroutinesLibrary.kt index 24df601efd9..ed1f31d1ddc 100644 --- a/libraries/stdlib/src/kotlin/coroutines/CoroutinesLibrary.kt +++ b/libraries/stdlib/src/kotlin/coroutines/CoroutinesLibrary.kt @@ -17,7 +17,7 @@ import kotlin.coroutines.intrinsics.* public fun (suspend R.() -> T).createCoroutine( receiver: R, completion: Continuation -): Continuation = (this as kotlin.jvm.internal.SuspendFunction1).create(receiver, completion) +): Continuation = (this as kotlin.jvm.internal.CoroutineImpl).create(receiver, completion) /** * Starts coroutine with receiver type [R] and result type [T]. @@ -43,7 +43,7 @@ public fun (suspend R.() -> T).startCoroutine( @Suppress("UNCHECKED_CAST") public fun (suspend () -> T).createCoroutine( completion: Continuation -): Continuation = (this as kotlin.jvm.internal.SuspendFunction0).create(completion) +): Continuation = (this as kotlin.jvm.internal.CoroutineImpl).create(completion) /** * Starts coroutine without receiver and with result type [T]. diff --git a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-runtime.txt b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-runtime.txt index fe2f517a30c..04a9f837a0e 100644 --- a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-runtime.txt +++ b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-runtime.txt @@ -485,6 +485,8 @@ public abstract class kotlin/jvm/internal/CoroutineImpl : kotlin/jvm/internal/La protected field completion Lkotlin/coroutines/Continuation; protected field label I public fun (ILkotlin/coroutines/Continuation;)V + public fun create (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Lkotlin/coroutines/Continuation; + public fun create (Lkotlin/coroutines/Continuation;)Lkotlin/coroutines/Continuation; protected abstract fun doResume (Ljava/lang/Object;Ljava/lang/Throwable;)Ljava/lang/Object; public fun getContext ()Lkotlin/coroutines/CoroutineContext; public final fun getFacade ()Lkotlin/coroutines/Continuation; @@ -903,14 +905,6 @@ public final class kotlin/jvm/internal/StringCompanionObject { public static final field INSTANCE Lkotlin/jvm/internal/StringCompanionObject; } -public abstract interface class kotlin/jvm/internal/SuspendFunction0 { - public abstract fun create (Lkotlin/coroutines/Continuation;)Lkotlin/coroutines/Continuation; -} - -public abstract interface class kotlin/jvm/internal/SuspendFunction1 { - public abstract fun create (Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Lkotlin/coroutines/Continuation; -} - public class kotlin/jvm/internal/TypeIntrinsics { public fun ()V public static fun asMutableCollection (Ljava/lang/Object;)Ljava/util/Collection;