Debugger: Fix breakpoints and stepping for inline-only function lambda arguments (#KT-23064)

This commit is contained in:
Yan Zhulanow
2018-03-06 00:46:29 +03:00
parent ae37cc30a1
commit eec9c6bffa
16 changed files with 238 additions and 49 deletions
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.codegen.inline
import org.jetbrains.kotlin.backend.jvm.codegen.IrExpressionLambda
import org.jetbrains.kotlin.builtins.isFunctionType
import org.jetbrains.kotlin.codegen.AsmUtil
import org.jetbrains.kotlin.codegen.ClosureCodegen
import org.jetbrains.kotlin.codegen.StackValue
@@ -368,7 +369,14 @@ class MethodInliner(
)
val transformationVisitor = object : MethodVisitor(API, transformedNode) {
private val GENERATE_DEBUG_INFO = GENERATE_SMAP && inlineOnlySmapSkipper == null
/*
Ignore simple @InlineOnly functions such as 'error()' or 'assert()' without lambda parameters,
as we likely to want to have a line number from the call site in a stack trace.
*/
private val GENERATE_LINE_NUMBERS = GENERATE_SMAP && (inlineOnlySmapSkipper == null || run {
val callableDescriptor = inliningContext.root.sourceCompilerForInline.callableDescriptor
callableDescriptor != null && callableDescriptor.valueParameters.any { it.type.isFunctionType }
})
private val isInliningLambda = nodeRemapper.isInsideInliningLambda
@@ -400,7 +408,7 @@ class MethodInliner(
}
override fun visitLineNumber(line: Int, start: Label) {
if (isInliningLambda || GENERATE_DEBUG_INFO) {
if (isInliningLambda || GENERATE_LINE_NUMBERS) {
super.visitLineNumber(line, start)
}
}
@@ -428,7 +436,7 @@ class MethodInliner(
override fun visitLocalVariable(
name: String, desc: String, signature: String?, start: Label, end: Label, index: Int
) {
if (isInliningLambda || GENERATE_DEBUG_INFO) {
if (isInliningLambda || (GENERATE_SMAP && inlineOnlySmapSkipper == null)) {
val varSuffix = if (inliningContext.isRoot && !isFakeLocalVariableForInline(name)) INLINE_FUN_VAR_SUFFIX else ""
val varName = if (!varSuffix.isEmpty() && name == "this") name + "_" else name
super.visitLocalVariable(varName + varSuffix, desc, signature, start, end, getNewIndex(index))
@@ -46,6 +46,8 @@ interface SourceCompilerForInline {
val callElement: Any
val callableDescriptor: CallableDescriptor?
val lookupLocation: LookupLocation
val callElementText: String
@@ -99,6 +101,8 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
override val lookupLocation = KotlinLookupLocation(callElement)
override val callableDescriptor: CallableDescriptor?
get() = (this.context as? MethodContext)?.functionDescriptor
override val callElementText by lazy {
callElement.text