Do not spill fake variables
#KT-28309
This commit is contained in:
+10
-2
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer
|
|||||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
import org.jetbrains.kotlin.config.isReleaseCoroutines
|
import org.jetbrains.kotlin.config.isReleaseCoroutines
|
||||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||||
|
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||||
@@ -496,6 +497,12 @@ class CoroutineTransformerMethodVisitor(
|
|||||||
val frames = performRefinedTypeAnalysis(methodNode, containingClassInternalName)
|
val frames = performRefinedTypeAnalysis(methodNode, containingClassInternalName)
|
||||||
fun AbstractInsnNode.index() = instructions.indexOf(this)
|
fun AbstractInsnNode.index() = instructions.indexOf(this)
|
||||||
|
|
||||||
|
fun Int.isInlinerFakeVariable(index: Int) = methodNode.localVariables.any {
|
||||||
|
(it.name.startsWith(JvmAbi.LOCAL_VARIABLE_NAME_PREFIX_INLINE_ARGUMENT) || it.name.startsWith(JvmAbi.LOCAL_VARIABLE_NAME_PREFIX_INLINE_FUNCTION))
|
||||||
|
&& it.index == this
|
||||||
|
&& it.start.index() <= index && index <= it.end.index()
|
||||||
|
}
|
||||||
|
|
||||||
// We postpone these actions because they change instruction indices that we use when obtaining frames
|
// We postpone these actions because they change instruction indices that we use when obtaining frames
|
||||||
val postponedActions = mutableListOf<() -> Unit>()
|
val postponedActions = mutableListOf<() -> Unit>()
|
||||||
val maxVarsCountByType = mutableMapOf<Type, Int>()
|
val maxVarsCountByType = mutableMapOf<Type, Int>()
|
||||||
@@ -537,8 +544,9 @@ class CoroutineTransformerMethodVisitor(
|
|||||||
// k + 2 - exception
|
// k + 2 - exception
|
||||||
val variablesToSpill =
|
val variablesToSpill =
|
||||||
(0 until localsCount)
|
(0 until localsCount)
|
||||||
.filter { it !in setOf(continuationIndex, dataIndex, exceptionIndex) }
|
.filterNot {
|
||||||
.map { Pair(it, frame.getLocal(it)) }
|
it in setOf(continuationIndex, dataIndex, exceptionIndex) || it.isInlinerFakeVariable(suspensionCallBegin.index())
|
||||||
|
}.map { Pair(it, frame.getLocal(it)) }
|
||||||
.filter { (index, value) ->
|
.filter { (index, value) ->
|
||||||
(index == 0 && needDispatchReceiver && isForNamedFunction) ||
|
(index == 0 && needDispatchReceiver && isForNamedFunction) ||
|
||||||
(value != StrictBasicValue.UNINITIALIZED_VALUE && livenessFrame.isAlive(index))
|
(value != StrictBasicValue.UNINITIALIZED_VALUE && livenessFrame.isAlive(index))
|
||||||
|
|||||||
Reference in New Issue
Block a user