Remove fix for tail-placed branch operations in suspend functions

It has been introduced in 2286027bed
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 2286027bed tests

NB: There's still a problem that now we work a bit suboptimally
because actually these samples can be generated without state
machines
This commit is contained in:
Denis Zharkov
2017-05-03 18:10:20 +03:00
parent 7803c9c0ba
commit 0b99c5c54e
3 changed files with 3 additions and 32 deletions
@@ -428,16 +428,6 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> 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<StackValue, StackValue> 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(
@@ -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<KtElementInstruction>()?.element?.safeAs<KtExpression>()?.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) {
@@ -135,7 +135,6 @@ public interface BindingContext {
WritableSlice<Call, FunctionDescriptor> ENCLOSING_SUSPEND_FUNCTION_FOR_SUSPEND_FUNCTION_CALL = Slices.createSimpleSlice();
WritableSlice<FunctionDescriptor, Boolean> CONTAINS_NON_TAIL_SUSPEND_CALLS = Slices.createSimpleSetSlice();
WritableSlice<KtExpression, Boolean> IS_TAIL_EXPRESSION_IN_SUSPEND_FUNCTION = Slices.createSimpleSetSlice();
WritableSlice<VariableAccessorDescriptor, ResolvedCall<FunctionDescriptor>> DELEGATED_PROPERTY_RESOLVED_CALL = Slices.createSimpleSlice();
WritableSlice<VariableAccessorDescriptor, Call> DELEGATED_PROPERTY_CALL = Slices.createSimpleSlice();