From bba5c16653b482a2cc33dde6507876482647d9ff Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 16 Dec 2016 00:19:04 +0300 Subject: [PATCH] JS: change how coroutine start intrinsic gets detected --- .../callTranslator/CallTranslator.kt | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallTranslator.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallTranslator.kt index 90cce43d2f1..2756a472320 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallTranslator.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallTranslator.kt @@ -18,8 +18,9 @@ package org.jetbrains.kotlin.js.translate.callTranslator import com.google.dart.compiler.backend.js.ast.* import com.google.dart.compiler.backend.js.ast.metadata.* -import org.jetbrains.kotlin.backend.common.getBuiltInSuspendWithCurrentContinuation +import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.js.translate.context.TranslationContext @@ -31,14 +32,14 @@ import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils import org.jetbrains.kotlin.js.translate.utils.JsAstUtils import org.jetbrains.kotlin.js.translate.utils.TranslationUtils import org.jetbrains.kotlin.js.translate.utils.setInlineCallMetadata +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.Call.CallType import org.jetbrains.kotlin.psi.KtExpression -import org.jetbrains.kotlin.resolve.DescriptorEquivalenceForOverrides import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isInvokeCallOnVariable import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall -import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.* +import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.inline.InlineStrategy import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue @@ -131,8 +132,7 @@ private fun translateFunctionCall( explicitReceivers: ExplicitReceivers ): JsExpression { val descriptorToCall = resolvedCall.resultingDescriptor - if (descriptorToCall is FunctionDescriptor && DescriptorEquivalenceForOverrides.areEquivalent( - descriptorToCall.getBuiltInSuspendWithCurrentContinuation(), descriptorToCall.original)) { + if (descriptorToCall is FunctionDescriptor && descriptorToCall.isSuspendCoroutineOrReturn()) { return translateCallWithContinuation(context, resolvedCall) } @@ -157,6 +157,14 @@ private fun translateFunctionCall( return callExpression } +private val SUSPEND_COROUTINE_OR_RETURN = Name.identifier("suspendCoroutineOrReturn") +private val COROUTINE_INTRINSICS = KotlinBuiltIns.COROUTINES_PACKAGE_FQ_NAME.child(Name.identifier("CoroutineIntrinsics")) + +private fun FunctionDescriptor.isSuspendCoroutineOrReturn(): Boolean { + val containingClass = containingDeclaration as? ClassDescriptor ?: return false + return containingClass.fqNameSafe == COROUTINE_INTRINSICS && name == SUSPEND_COROUTINE_OR_RETURN +} + private fun translateCallWithContinuation(context: TranslationContext, resolvedCall: ResolvedCall): JsExpression { val arguments = CallArgumentTranslator.translate(resolvedCall, null, context) val coroutineArgument = TranslationUtils.getEnclosingContinuationParameter(context) @@ -180,7 +188,7 @@ fun computeExplicitReceiversForInvoke( val dispatchReceiver = resolvedCall.dispatchReceiver val extensionReceiver = resolvedCall.extensionReceiver - if (dispatchReceiver != null && extensionReceiver != null && resolvedCall.explicitReceiverKind == ExplicitReceiverKind.BOTH_RECEIVERS) { + if (dispatchReceiver != null && extensionReceiver != null && resolvedCall.explicitReceiverKind == BOTH_RECEIVERS) { assert(explicitReceivers.extensionOrDispatchReceiver != null) { "No explicit receiver for 'invoke' resolved call with both receivers: $callElement, text: ${callElement.text}" + "Dispatch receiver: $dispatchReceiver Extension receiver: $extensionReceiver"