From ba0f8b908fe1a363e7ed5a9880c3d81828793423 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Sun, 22 Jan 2017 20:57:13 +0300 Subject: [PATCH] Fix Kotlin bytecode toolwindow showing wrong code for suspend functions Use binding context from the full resolve, because otherwise control-flow analysis is not being run, that is very important for suspend functions (tail-call optimizations) #KT-15827 Fixed --- .../jetbrains/kotlin/idea/debugger/DebuggerUtils.kt | 12 +++++++++--- .../idea/internal/KotlinBytecodeToolWindow.java | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/DebuggerUtils.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/DebuggerUtils.kt index 7428a598d2b..eebf8fcb9b9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/DebuggerUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/DebuggerUtils.kt @@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.inline.InlineUtil import org.jetbrains.kotlin.resolve.jvm.JvmClassName import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor +import org.jetbrains.kotlin.utils.addIfNotNull import java.util.* object DebuggerUtils { @@ -101,7 +102,8 @@ object DebuggerUtils { fun analyzeInlinedFunctions( resolutionFacadeForFile: ResolutionFacade, file: KtFile, - analyzeOnlyReifiedInlineFunctions: Boolean + analyzeOnlyReifiedInlineFunctions: Boolean, + bindingContext: BindingContext? = null ): Pair> { val analyzedElements = HashSet() val context = analyzeElementWithInline( @@ -109,7 +111,8 @@ object DebuggerUtils { file, 1, analyzedElements, - !analyzeOnlyReifiedInlineFunctions) + !analyzeOnlyReifiedInlineFunctions, bindingContext + ) //We processing another files just to annotate anonymous classes within their inline functions //Bytecode not produced for them cause of filtering via generateClassFilter @@ -135,11 +138,14 @@ object DebuggerUtils { element: KtElement, deep: Int, analyzedElements: MutableSet, - analyzeInlineFunctions: Boolean): BindingContext { + analyzeInlineFunctions: Boolean, + fullResolveContext: BindingContext? = null + ): BindingContext { val project = element.project val inlineFunctions = HashSet() val innerContexts = ArrayList() + innerContexts.addIfNotNull(fullResolveContext) element.accept(object : KtTreeVisitorVoid() { override fun visitExpression(expression: KtExpression) { diff --git a/idea/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.java b/idea/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.java index 42e6866a008..8ffe0cd71bb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.java +++ b/idea/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.java @@ -292,8 +292,11 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable { ) { ResolutionFacade resolutionFacade = ResolutionUtils.getResolutionFacade(ktFile); + BindingContext bindingContextForFile = resolutionFacade.analyzeFullyAndGetResult(Collections.singletonList(ktFile)).getBindingContext(); + kotlin.Pair> result = DebuggerUtils.INSTANCE.analyzeInlinedFunctions( - resolutionFacade, ktFile, configuration.getBoolean(CommonConfigurationKeys.DISABLE_INLINE) + resolutionFacade, ktFile, configuration.getBoolean(CommonConfigurationKeys.DISABLE_INLINE), + bindingContextForFile ); BindingContext bindingContext = result.getFirst();