From 7c621488ad5ee8e864a853b04a8b74de797acc44 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Tue, 31 Oct 2017 18:27:40 +0300 Subject: [PATCH] Remove unnecessary CONTAINS_NON_TAIL_SUSPEND_CALLS slice --- .../cfg/ControlFlowInformationProvider.kt | 42 ------------------- .../kotlin/resolve/BindingContext.java | 1 - 2 files changed, 43 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt index c7a575651d8..b408ca0cb47 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt @@ -873,48 +873,6 @@ class ControlFlowInformationProvider private constructor( val subroutineDescriptor = trace.get(BindingContext.DECLARATION_TO_DESCRIPTOR, subroutine) as? FunctionDescriptor ?: return markAndCheckRecursiveTailCalls(subroutineDescriptor) - checkSuspendCalls(subroutineDescriptor) - } - - private fun checkSuspendCalls(currentFunction: FunctionDescriptor) { - if (!currentFunction.isSuspend) return - var containsNonTailCalls = false - - traverseCalls { instruction, resolvedCall -> - val calleeDescriptor = resolvedCall.resultingDescriptor as? FunctionDescriptor ?: return@traverseCalls - if (!calleeDescriptor.isSuspend) return@traverseCalls - - // Suspend functions are allowed to be called only within coroutines (may be non-tail calls of course) - // or another suspend function (here they must be called only in tail position) - val enclosingSuspendFunction = - trace.get(BindingContext.ENCLOSING_SUSPEND_FUNCTION_FOR_SUSPEND_FUNCTION_CALL, resolvedCall.call) - ?.let(DescriptorToSourceUtils::descriptorToDeclaration) as? KtElement - ?: return@traverseCalls - - val element = instruction.element - val isUsedAsExpression = instruction.owner.getUsages(instruction.outputValue).isNotEmpty() - - if (!isUsedAsExpression || !instruction.isTailCall(enclosingSuspendFunction) || isInsideTry(element)) { - containsNonTailCalls = true - } - } - - pseudocode.traverse(TraversalOrder.FORWARD) { instruction -> - if (instruction !is VariableDeclarationInstruction || instruction.element !is KtProperty || !instruction.element.hasDelegate()) return@traverse - - val variableDescriptor = - trace[BindingContext.DECLARATION_TO_DESCRIPTOR, instruction.element] as? VariableDescriptorWithAccessors - ?: return@traverse - - containsNonTailCalls = - containsNonTailCalls || variableDescriptor.accessors.any { - trace[BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, it]?.candidateDescriptor?.isSuspend == true - } - } - - if (containsNonTailCalls) { - trace.record(BindingContext.CONTAINS_NON_TAIL_SUSPEND_CALLS, currentFunction.original) - } } private fun markAndCheckRecursiveTailCalls(subroutineDescriptor: FunctionDescriptor) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java index b20bdf1722c..839fefd2b98 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java @@ -142,7 +142,6 @@ public interface BindingContext { WritableSlice> LOOP_RANGE_NEXT_RESOLVED_CALL = Slices.createSimpleSlice(); WritableSlice ENCLOSING_SUSPEND_FUNCTION_FOR_SUSPEND_FUNCTION_CALL = Slices.createSimpleSlice(); - WritableSlice CONTAINS_NON_TAIL_SUSPEND_CALLS = Slices.createSimpleSetSlice(); WritableSlice> DELEGATED_PROPERTY_RESOLVED_CALL = Slices.createSimpleSlice(); WritableSlice DELEGATED_PROPERTY_CALL = Slices.createSimpleSlice();