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
This commit is contained in:
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
|||||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor
|
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
object DebuggerUtils {
|
object DebuggerUtils {
|
||||||
@@ -101,7 +102,8 @@ object DebuggerUtils {
|
|||||||
fun analyzeInlinedFunctions(
|
fun analyzeInlinedFunctions(
|
||||||
resolutionFacadeForFile: ResolutionFacade,
|
resolutionFacadeForFile: ResolutionFacade,
|
||||||
file: KtFile,
|
file: KtFile,
|
||||||
analyzeOnlyReifiedInlineFunctions: Boolean
|
analyzeOnlyReifiedInlineFunctions: Boolean,
|
||||||
|
bindingContext: BindingContext? = null
|
||||||
): Pair<BindingContext, List<KtFile>> {
|
): Pair<BindingContext, List<KtFile>> {
|
||||||
val analyzedElements = HashSet<KtElement>()
|
val analyzedElements = HashSet<KtElement>()
|
||||||
val context = analyzeElementWithInline(
|
val context = analyzeElementWithInline(
|
||||||
@@ -109,7 +111,8 @@ object DebuggerUtils {
|
|||||||
file,
|
file,
|
||||||
1,
|
1,
|
||||||
analyzedElements,
|
analyzedElements,
|
||||||
!analyzeOnlyReifiedInlineFunctions)
|
!analyzeOnlyReifiedInlineFunctions, bindingContext
|
||||||
|
)
|
||||||
|
|
||||||
//We processing another files just to annotate anonymous classes within their inline functions
|
//We processing another files just to annotate anonymous classes within their inline functions
|
||||||
//Bytecode not produced for them cause of filtering via generateClassFilter
|
//Bytecode not produced for them cause of filtering via generateClassFilter
|
||||||
@@ -135,11 +138,14 @@ object DebuggerUtils {
|
|||||||
element: KtElement,
|
element: KtElement,
|
||||||
deep: Int,
|
deep: Int,
|
||||||
analyzedElements: MutableSet<KtElement>,
|
analyzedElements: MutableSet<KtElement>,
|
||||||
analyzeInlineFunctions: Boolean): BindingContext {
|
analyzeInlineFunctions: Boolean,
|
||||||
|
fullResolveContext: BindingContext? = null
|
||||||
|
): BindingContext {
|
||||||
val project = element.project
|
val project = element.project
|
||||||
val inlineFunctions = HashSet<KtNamedFunction>()
|
val inlineFunctions = HashSet<KtNamedFunction>()
|
||||||
|
|
||||||
val innerContexts = ArrayList<BindingContext>()
|
val innerContexts = ArrayList<BindingContext>()
|
||||||
|
innerContexts.addIfNotNull(fullResolveContext)
|
||||||
|
|
||||||
element.accept(object : KtTreeVisitorVoid() {
|
element.accept(object : KtTreeVisitorVoid() {
|
||||||
override fun visitExpression(expression: KtExpression) {
|
override fun visitExpression(expression: KtExpression) {
|
||||||
|
|||||||
@@ -292,8 +292,11 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
|
|||||||
) {
|
) {
|
||||||
ResolutionFacade resolutionFacade = ResolutionUtils.getResolutionFacade(ktFile);
|
ResolutionFacade resolutionFacade = ResolutionUtils.getResolutionFacade(ktFile);
|
||||||
|
|
||||||
|
BindingContext bindingContextForFile = resolutionFacade.analyzeFullyAndGetResult(Collections.singletonList(ktFile)).getBindingContext();
|
||||||
|
|
||||||
kotlin.Pair<BindingContext, List<KtFile>> result = DebuggerUtils.INSTANCE.analyzeInlinedFunctions(
|
kotlin.Pair<BindingContext, List<KtFile>> result = DebuggerUtils.INSTANCE.analyzeInlinedFunctions(
|
||||||
resolutionFacade, ktFile, configuration.getBoolean(CommonConfigurationKeys.DISABLE_INLINE)
|
resolutionFacade, ktFile, configuration.getBoolean(CommonConfigurationKeys.DISABLE_INLINE),
|
||||||
|
bindingContextForFile
|
||||||
);
|
);
|
||||||
|
|
||||||
BindingContext bindingContext = result.getFirst();
|
BindingContext bindingContext = result.getFirst();
|
||||||
|
|||||||
Reference in New Issue
Block a user