Skip to content

Commit e2e93d6

Browse files
committed
Get rid of using label field in named function
It preventing from making it protected (as it was before) #KT-17898 In progress
1 parent 52b2e63 commit e2e93d6

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,7 @@ class CoroutineTransformerMethodVisitor(
113113
*withInstructionAdapter { loadCoroutineSuspendedMarker() }.toArray(),
114114
VarInsnNode(Opcodes.ASTORE, suspendMarkerVarIndex),
115115
VarInsnNode(Opcodes.ALOAD, continuationIndex),
116-
FieldInsnNode(
117-
Opcodes.GETFIELD,
118-
COROUTINE_IMPL_ASM_TYPE.internalName,
119-
COROUTINE_LABEL_FIELD_NAME, Type.INT_TYPE.descriptor
120-
),
116+
createInsnForReadingLabel(),
121117
TableSwitchInsnNode(0,
122118
suspensionPoints.size,
123119
defaultLabel,
@@ -140,6 +136,38 @@ class CoroutineTransformerMethodVisitor(
140136
methodNode.removeEmptyCatchBlocks()
141137
}
142138

139+
private fun createInsnForReadingLabel() =
140+
if (isForNamedFunction)
141+
MethodInsnNode(
142+
Opcodes.INVOKEVIRTUAL,
143+
classBuilderForCoroutineState.thisName,
144+
"getLabel",
145+
Type.getMethodDescriptor(Type.INT_TYPE),
146+
false
147+
)
148+
else
149+
FieldInsnNode(
150+
Opcodes.GETFIELD,
151+
COROUTINE_IMPL_ASM_TYPE.internalName,
152+
COROUTINE_LABEL_FIELD_NAME, Type.INT_TYPE.descriptor
153+
)
154+
155+
private fun createInsnForSettingLabel() =
156+
if (isForNamedFunction)
157+
MethodInsnNode(
158+
Opcodes.INVOKEVIRTUAL,
159+
classBuilderForCoroutineState.thisName,
160+
"setLabel",
161+
Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE),
162+
false
163+
)
164+
else
165+
FieldInsnNode(
166+
Opcodes.PUTFIELD,
167+
COROUTINE_IMPL_ASM_TYPE.internalName,
168+
COROUTINE_LABEL_FIELD_NAME, Type.INT_TYPE.descriptor
169+
)
170+
143171
private fun updateMaxStack(methodNode: MethodNode) {
144172
methodNode.instructions.resetLabels()
145173
methodNode.accept(
@@ -441,18 +469,7 @@ class CoroutineTransformerMethodVisitor(
441469
insnListOf(
442470
VarInsnNode(Opcodes.ALOAD, continuationIndex),
443471
*withInstructionAdapter { iconst(id) }.toArray(),
444-
if (isForNamedFunction)
445-
MethodInsnNode(
446-
Opcodes.INVOKEVIRTUAL, classBuilderForCoroutineState.thisName,
447-
"setLabel",
448-
Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE),
449-
false
450-
)
451-
else
452-
FieldInsnNode(
453-
Opcodes.PUTFIELD, COROUTINE_IMPL_ASM_TYPE.internalName, COROUTINE_LABEL_FIELD_NAME,
454-
Type.INT_TYPE.descriptor
455-
)
472+
createInsnForSettingLabel()
456473
)
457474
)
458475

0 commit comments

Comments
 (0)