Skip to content

Commit

Permalink
[kotlin] rename getInlineFunctionNamesAndBorders to getInlineFunction…
Browse files Browse the repository at this point in the history
…AndArgumentVariablesToBordersMap

(cherry picked from commit c76f491dec0f8ed038c2b38175b51463aab61255)

IJ-MR-21181

GitOrigin-RevId: bd1cf1a178c7d4dfef005dc25028245c163ec779
  • Loading branch information
Nikita Nazarov authored and intellij-monorepo-bot committed Apr 4, 2022
1 parent fa5c2b8 commit f8afa22
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.intellij.xdebugger.frame.XStackFrame
import com.sun.jdi.*
import com.sun.jdi.request.ClassPrepareRequest
import org.jetbrains.kotlin.codegen.inline.KOTLIN_STRATA_NAME
import org.jetbrains.kotlin.codegen.inline.isFakeLocalVariableForInline
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.KotlinFileTypeFactoryUtils
Expand All @@ -51,8 +52,6 @@ import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
import org.jetbrains.kotlin.idea.util.application.getServiceSafe
import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.load.java.JvmAbi.LOCAL_VARIABLE_NAME_PREFIX_INLINE_ARGUMENT
import org.jetbrains.kotlin.load.java.JvmAbi.LOCAL_VARIABLE_NAME_PREFIX_INLINE_FUNCTION
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.inline.InlineUtil
Expand Down Expand Up @@ -227,7 +226,7 @@ class KotlinPositionManager(private val debugProcess: DebugProcess) : MultiReque
}

private fun Method.getInlineFunctionBorders(sourceFileName: String): List<ClosedRange<Location>> {
return getInlineFunctionLocalVariables()
return getInlineFunctionOrArgumentVariables()
.mapNotNull { it.getBorders() }
.filter { it.start.safeSourceName() == sourceFileName }
.toList()
Expand Down Expand Up @@ -479,8 +478,8 @@ class KotlinPositionManager(private val debugProcess: DebugProcess) : MultiReque
}
}

internal fun Method.getInlineFunctionNamesAndBorders(): Map<LocalVariable, ClosedRange<Location>> {
return getInlineFunctionLocalVariables()
internal fun Method.getInlineFunctionAndArgumentVariablesToBordersMap(): Map<LocalVariable, ClosedRange<Location>> {
return getInlineFunctionOrArgumentVariables()
.mapNotNull {
val borders = it.getBorders()
if (borders == null)
Expand All @@ -491,17 +490,13 @@ internal fun Method.getInlineFunctionNamesAndBorders(): Map<LocalVariable, Close
.toMap()
}

private fun Method.getInlineFunctionLocalVariables(): Sequence<LocalVariable> {
private fun Method.getInlineFunctionOrArgumentVariables(): Sequence<LocalVariable> {
val localVariables = safeVariables() ?: return emptySequence()
return localVariables
.asSequence()
.filter { it.isInlineFunctionLocalVariable() }
.filter { isFakeLocalVariableForInline(it.name()) }
}

private fun LocalVariable.isInlineFunctionLocalVariable() =
name().startsWith(LOCAL_VARIABLE_NAME_PREFIX_INLINE_FUNCTION) ||
name().startsWith(LOCAL_VARIABLE_NAME_PREFIX_INLINE_ARGUMENT)

fun Location.getClassName(): String? {
val currentLocationFqName = declaringType().name() ?: return null
return JvmClassName.byFqNameWithoutInnerClasses(FqName(currentLocationFqName)).internalName.replace('/', '.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ internal fun createKotlinInlineFilter(suspendContext: SuspendContextImpl): Kotli
}

internal class KotlinInlineFilter(location: Location, method: Method) {
private val borders = method.getInlineFunctionNamesAndBorders().values.filter { location !in it }
private val borders =
method.getInlineFunctionAndArgumentVariablesToBordersMap()
.values.filter { location !in it }

fun isNestedInline(context: SuspendContextImpl?): Boolean {
if (context === null) return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.idea.debugger.DebuggerUtils.trimIfMangledInBytecode
import org.jetbrains.kotlin.idea.debugger.getInlineFunctionNamesAndBorders
import org.jetbrains.kotlin.idea.debugger.getInlineFunctionAndArgumentVariablesToBordersMap
import org.jetbrains.kotlin.idea.debugger.safeMethod
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.psi.KtClass
Expand Down Expand Up @@ -88,7 +88,7 @@ open class KotlinMethodFilter(
// A correct way here is to memorize the original location (where smart step into was started)
// and filter out ranges that contain that original location.
// Otherwise, nested inline with the same method name will not work correctly.
method.getInlineFunctionNamesAndBorders()
method.getInlineFunctionAndArgumentVariablesToBordersMap()
.filter { location in it.value }
.any { it.key.isInlinedFromFunction(targetMethodName, isNameMangledInBytecode) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.intellij.debugger.PositionManager
import com.intellij.debugger.jdi.GeneratedLocation
import com.intellij.psi.util.parentOfType
import com.sun.jdi.Location
import org.jetbrains.kotlin.idea.debugger.getInlineFunctionNamesAndBorders
import org.jetbrains.kotlin.idea.debugger.getInlineFunctionAndArgumentVariablesToBordersMap
import org.jetbrains.kotlin.idea.debugger.safeMethod
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.psi.KtNamedFunction
Expand All @@ -16,16 +16,16 @@ class KotlinSmartStepTargetFiltererAdapter(
private val positionManager: PositionManager,
private val targetFilterer: KotlinSmartStepTargetFilterer
) : LineMatchingMethodVisitor(lines) {
private val inlineFunctionNamesAndBorders = location.safeMethod()
?.getInlineFunctionNamesAndBorders()
private val inlineFunctionVariablesAndBorders = location.safeMethod()
?.getInlineFunctionAndArgumentVariablesToBordersMap()
?.toList()
.orEmpty()
private var inInline = false

public override fun reportOpcode(opcode: Int) {
if (!lineEverMatched) return

val inlineCall = inlineFunctionNamesAndBorders.firstOrNull {
val inlineCall = inlineFunctionVariablesAndBorders.firstOrNull {
currentLine in it.second.toLineNumberRange()
}
if (inlineCall == null) {
Expand Down

0 comments on commit f8afa22

Please sign in to comment.