From 0b99c5c54e1896dd6f1b9af311a79dba94d767be Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Wed, 3 May 2017 18:10:20 +0300 Subject: [PATCH] Remove fix for tail-placed branch operations in suspend functions It has been introduced in 2286027bed22001adc658a6246bc836a433fb74f and should've help to avoid verify error Now it became both impossible and unnecessary: - It's impossible now since we can't determine in codegen if we'll needa state machine (it depends from inline functions' contents) - It's unnecessary since we'll introduce the state machines for cases described in the 2286027bed22001adc658a6246bc836a433fb74f tests NB: There's still a problem that now we work a bit suboptimally because actually these samples can be generated without state machines --- .../kotlin/codegen/ExpressionCodegen.java | 16 +++------------- .../cfg/ControlFlowInformationProvider.kt | 18 ------------------ .../kotlin/resolve/BindingContext.java | 1 - 3 files changed, 3 insertions(+), 32 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 907eb4fc0ba..91cbaa2ded4 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -428,16 +428,6 @@ public class ExpressionCodegen extends KtVisitor impleme return typeMapper.mapType(type); } - @NotNull - private Type expressionTypeForBranchingOperation(@Nullable KtExpression expression) { - if (context.getFunctionDescriptor().isSuspend() && - !CoroutineCodegenUtilKt.isStateMachineNeeded(context.getFunctionDescriptor(), bindingContext) && - Boolean.TRUE.equals(bindingContext.get(IS_TAIL_EXPRESSION_IN_SUSPEND_FUNCTION, expression))) { - return AsmTypes.OBJECT_TYPE; - } - return expressionType(expression); - } - @NotNull public Type expressionType(@Nullable KtExpression expression) { return CodegenUtilKt.asmType(expression, typeMapper, bindingContext); @@ -478,7 +468,7 @@ public class ExpressionCodegen extends KtVisitor impleme } /* package */ StackValue generateIfExpression(@NotNull KtIfExpression expression, boolean isStatement) { - Type asmType = isStatement ? Type.VOID_TYPE : expressionTypeForBranchingOperation(expression); + Type asmType = isStatement ? Type.VOID_TYPE : expressionType(expression); StackValue condition = gen(expression.getCondition()); KtExpression thenExpression = expression.getThen(); @@ -3767,7 +3757,7 @@ The "returned" value of try expression with no finally is either the last expres (or blocks). */ - Type expectedAsmType = isStatement ? Type.VOID_TYPE : expressionTypeForBranchingOperation(expression); + Type expectedAsmType = isStatement ? Type.VOID_TYPE : expressionType(expression); return StackValue.operation(expectedAsmType, v -> { KtFinallySection finallyBlock = expression.getFinallyBlock(); @@ -4034,7 +4024,7 @@ The "returned" value of try expression with no finally is either the last expres KtExpression expr = expression.getSubjectExpression(); Type subjectType = expressionType(expr); - Type resultType = isStatement ? Type.VOID_TYPE : expressionTypeForBranchingOperation(expression); + Type resultType = isStatement ? Type.VOID_TYPE : expressionType(expression); return StackValue.operation(resultType, v -> { SwitchCodegen switchCodegen = SwitchCodegenUtil.buildAppropriateSwitchCodegenIfPossible( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt index 44763077ccf..a2e0c36c68e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt @@ -60,7 +60,6 @@ import org.jetbrains.kotlin.types.TypeUtils.* import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils import org.jetbrains.kotlin.types.isFlexible import org.jetbrains.kotlin.util.OperatorNameConventions -import org.jetbrains.kotlin.utils.addToStdlib.safeAs import java.util.* class ControlFlowInformationProvider private constructor( @@ -879,23 +878,6 @@ class ControlFlowInformationProvider private constructor( if (containsNonTailCalls) { trace.record(BindingContext.CONTAINS_NON_TAIL_SUSPEND_CALLS, currentFunction.original) } - else { - val tailInstructionDetector = TailInstructionDetector(subroutine) - traverseFollowingInstructions( - pseudocode.sinkInstruction, - order = TraversalOrder.BACKWARD - ) { instruction -> - - instruction.safeAs()?.element?.safeAs()?.let { expression -> - trace.record(BindingContext.IS_TAIL_EXPRESSION_IN_SUSPEND_FUNCTION, expression) - } - - if (instruction.accept(tailInstructionDetector)) - TraverseInstructionResult.CONTINUE - else - TraverseInstructionResult.SKIP - } - } } 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 c0019378ed9..e5e97147fa3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java @@ -135,7 +135,6 @@ public interface BindingContext { WritableSlice ENCLOSING_SUSPEND_FUNCTION_FOR_SUSPEND_FUNCTION_CALL = Slices.createSimpleSlice(); WritableSlice CONTAINS_NON_TAIL_SUSPEND_CALLS = Slices.createSimpleSetSlice(); - WritableSlice IS_TAIL_EXPRESSION_IN_SUSPEND_FUNCTION = Slices.createSimpleSetSlice(); WritableSlice> DELEGATED_PROPERTY_RESOLVED_CALL = Slices.createSimpleSlice(); WritableSlice DELEGATED_PROPERTY_CALL = Slices.createSimpleSlice();