Do not duplicate $$forInline counterpart of inline capturing function

This commit is contained in:
Ilmir Usmanov
2019-04-15 20:29:04 +03:00
parent 20b9d8b2f3
commit 7c14f4c6ae
10 changed files with 229 additions and 35 deletions
@@ -65,8 +65,10 @@ open class SuspendFunctionGenerationStrategy(
)
val forInline = state.bindingContext[CodegenBinding.CAPTURES_CROSSINLINE_LAMBDA, originalSuspendDescriptor] == true
// Yegor Bugayenko style
return if (forInline)
// Both capturing and inline functions share the same suffix, however, inline functions can also be capturing
// they are already covered by SuspendInlineFunctionGenerationStrategy, thus, if we generate yet another copy,
// we will get name+descriptor clash
return if (forInline && !originalSuspendDescriptor.isInline)
AddConstructorCallForCoroutineRegeneration(
MethodNodeCopyingMethodVisitor(
SurroundSuspendLambdaCallsWithSuspendMarkersMethodVisitor(
@@ -48,8 +48,6 @@ class CoroutineTransformer(
fun shouldGenerateStateMachine(node: MethodNode): Boolean {
// Continuations are similar to lambdas from bird's view, but we should never generate state machine for them
if (isContinuationNotLambda()) return false
// The method does not have state-machine, but should. Generate it
if (node.name.endsWith(FOR_INLINE_SUFFIX)) return true
// there can be suspend lambdas inside inline functions, which do not
// capture crossinline lambdas, thus, there is no need to transform them
return isSuspendFunctionWithFakeConstructorCall(node) || (isSuspendLambda(node) && !isStateMachine(node))
@@ -225,7 +223,7 @@ class SurroundSuspendLambdaCallsWithSuspendMarkersMethodVisitor(
if (insn.opcode != Opcodes.INVOKEINTERFACE) continue
insn as MethodInsnNode
if (!isInvokeOnLambda(insn.owner, insn.name)) continue
val frame = sourceFrames[insn.index()]
val frame = sourceFrames[insn.index()] ?: continue
val receiver = findReceiverOfInvoke(frame, insn).takeIf { it?.isSuspendLambda(insn) == true } as? FieldInsnNode ?: continue
val aload = receiver.findPreviousOrNull { it.opcode != Opcodes.GETFIELD } ?: error("GETFIELD cannot be the first instruction")
assert(aload.opcode == Opcodes.ALOAD) { "Before GETFIELD there shall be ALOAD" }