Use doResume name for suspend lambdas context (KT-16481)

#KT-16481 Fixed
This commit is contained in:
Nikolay Krasko
2017-02-25 02:35:41 +03:00
committed by Nikolay Krasko
parent dffbe0f707
commit f0be88fc07
5 changed files with 54 additions and 8 deletions
@@ -328,6 +328,11 @@ class CoroutineCodegen private constructor(
}
companion object {
fun shouldCreateByLambda(
originalSuspendLambdaDescriptor: CallableDescriptor,
declaration: KtElement): Boolean {
return (declaration is KtFunctionLiteral && originalSuspendLambdaDescriptor.isSuspendLambda)
}
@JvmStatic
fun createByLambda(
@@ -336,8 +341,7 @@ class CoroutineCodegen private constructor(
declaration: KtElement,
classBuilder: ClassBuilder
): ClosureCodegen? {
if (declaration !is KtFunctionLiteral) return null
if (!originalSuspendLambdaDescriptor.isSuspendLambda) return null
if (!shouldCreateByLambda(originalSuspendLambdaDescriptor, declaration)) return null
return CoroutineCodegen(
expressionCodegen,
@@ -30,6 +30,7 @@ import com.intellij.psi.search.searches.ReferencesSearch
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.xdebugger.impl.XDebugSessionImpl
import org.jetbrains.kotlin.codegen.binding.CodegenBinding
import org.jetbrains.kotlin.codegen.coroutines.CoroutineCodegen
import org.jetbrains.kotlin.codegen.coroutines.DO_RESUME_METHOD_NAME
import org.jetbrains.kotlin.codegen.coroutines.containsNonTailSuspensionCalls
import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil
@@ -51,6 +52,7 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.psi.psiUtil.parents
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.inline.InlineUtil
import org.jetbrains.kotlin.resolve.source.getPsi
@@ -221,12 +223,16 @@ class DebuggerClassNameProvider(val myDebugProcess: DebugProcess, val scopes: Li
val inlineFunctionName = resolvedCall.resultingDescriptor.name
val ownerDescriptor = lexicalScope.ownerDescriptor
val ownerDescriptorName = if (isFunctionWithSuspendStateMachine(ownerDescriptor, typeMapper.bindingContext)) {
Name.identifier(DO_RESUME_METHOD_NAME)
}
else {
ownerDescriptor.name
}
val ownerDeclaration = if (ownerDescriptor is DeclarationDescriptor) DescriptorToSourceUtils.getSourceFromDescriptor(ownerDescriptor) else null
val ownerDescriptorName =
if (isFunctionWithSuspendStateMachine(ownerDescriptor, typeMapper.bindingContext) ||
(ownerDescriptor is CallableDescriptor && ownerDeclaration is KtElement && CoroutineCodegen.shouldCreateByLambda(ownerDescriptor, ownerDeclaration))) {
Name.identifier(DO_RESUME_METHOD_NAME)
}
else {
ownerDescriptor.name
}
val ownerJvmName = if (ownerDescriptorName.isSpecial) InlineCodegenUtil.SPECIAL_TRANSFORMATION_NAME else ownerDescriptorName.asString()
val mangledInternalClassName =
@@ -0,0 +1,8 @@
LineBreakpoint created at stopInCrossinlineInSuspend.kt:12
!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !OUTPUT_PATH!;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! stopInCrossinlineInSuspend.StopInCrossinlineInSuspendKt
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
stopInCrossinlineInSuspend.kt:12
stopInCrossinlineInSuspend.kt:13
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
Process finished with exit code 0
@@ -0,0 +1,22 @@
package stopInCrossinlineInSuspend
import forTests.builder
fun main(args: Array<String>) {
val a = 12
builder {
ci {
{
//Breakpoint!
foo(a)
}()
}
}
}
fun foo(a: Any? = null) {}
inline fun ci(crossinline builder: () -> Unit) {
builder()
}
@@ -716,6 +716,12 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest {
doStepOverTest(fileName);
}
@TestMetadata("stopInCrossinlineInSuspend.kt")
public void testStopInCrossinlineInSuspend() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInCrossinlineInSuspend.kt");
doStepOverTest(fileName);
}
@TestMetadata("stopInInlineCallLocalFunLambda.kt")
public void testStopInInlineCallLocalFunLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/stepOver/stopInInlineCallLocalFunLambda.kt");