diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt index 84e055f66d3..9f27b365067 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt @@ -810,7 +810,8 @@ class MethodInliner( removeFakeVariablesInitializationIfPresent(node) - val frames = FastStackAnalyzer("", node, FixStackInterpreter()).analyze() + val analyzer = FastStackAnalyzer("", node, FixStackInterpreter()) { nLocals, nStack -> Frame(nLocals, nStack) } + val frames = analyzer.analyze() val localReturnsNormalizer = LocalReturnsNormalizer() diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastAnalyzer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastAnalyzer.kt index eb08a07bd34..54e087eff7a 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastAnalyzer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastAnalyzer.kt @@ -20,6 +20,7 @@ abstract class FastAnalyzer>( private val method: MethodNode, private val interpreter: Interpreter, private val pruneExceptionEdges: Boolean, + private val newFrame: (Int, Int) -> F ) { private val nInsns = method.instructions.size() private val frames: Array?> = arrayOfNulls(nInsns) @@ -32,8 +33,6 @@ abstract class FastAnalyzer>( private val queue = IntArray(nInsns) private var top = 0 - protected abstract fun newFrame(nLocals: Int, nStack: Int): F - @Suppress("UNCHECKED_CAST") fun getFrame(insn: AbstractInsnNode): F? = frames[insn.indexOf()] as? F diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastMethodAnalyzer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastMethodAnalyzer.kt index 54a441ddfb5..ab2229a98ca 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastMethodAnalyzer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/common/FastMethodAnalyzer.kt @@ -38,16 +38,11 @@ import org.jetbrains.org.objectweb.asm.tree.analysis.Frame import org.jetbrains.org.objectweb.asm.tree.analysis.Interpreter import org.jetbrains.org.objectweb.asm.tree.analysis.Value -/** - * @see org.jetbrains.kotlin.codegen.optimization.fixStack.FastStackAnalyzer - */ class FastMethodAnalyzer @JvmOverloads constructor( owner: String, method: MethodNode, interpreter: Interpreter, pruneExceptionEdges: Boolean = false, - private val createFrame: (Int, Int) -> Frame = { nLocals, nStack -> Frame(nLocals, nStack) } -) : FastAnalyzer>(owner, method, interpreter, pruneExceptionEdges) { - override fun newFrame(nLocals: Int, nStack: Int): Frame = createFrame(nLocals, nStack) -} + newFrame: (Int, Int) -> Frame = { nLocals, nStack -> Frame(nLocals, nStack) } +) : FastAnalyzer>(owner, method, interpreter, pruneExceptionEdges, newFrame) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FastStackAnalyzer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FastStackAnalyzer.kt index 19a8724582f..c01be5fbe44 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FastStackAnalyzer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FastStackAnalyzer.kt @@ -39,19 +39,14 @@ import org.jetbrains.org.objectweb.asm.tree.analysis.Frame import org.jetbrains.org.objectweb.asm.tree.analysis.Interpreter import org.jetbrains.org.objectweb.asm.tree.analysis.Value -/** - * @see org.jetbrains.kotlin.codegen.optimization.common.FastMethodAnalyzer - */ // This is a very specific version of method bytecode analyzer that doesn't perform any DFA, // but infers stack types for reachable instructions instead. internal open class FastStackAnalyzer>( owner: String, method: MethodNode, interpreter: Interpreter, - private val createFrame: (Int, Int) -> Frame = { nLocals, nStack -> Frame(nLocals, nStack) } -) : FastAnalyzer(owner, method, interpreter, pruneExceptionEdges = false) { - @Suppress("UNCHECKED_CAST") - override fun newFrame(nLocals: Int, nStack: Int): F = createFrame(nLocals, nStack) as F + newFrame: (Int, Int) -> F +) : FastAnalyzer(owner, method, interpreter, pruneExceptionEdges = false, newFrame) { // Don't have to visit the same exception handler multiple times - we care only about stack state at TCB start. override fun useFastComputeExceptionHandlers(): Boolean = true diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/temporaryVals/FastStoreLoadAnalyzer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/temporaryVals/FastStoreLoadAnalyzer.kt index 509df2f1cae..807e7a92efd 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/temporaryVals/FastStoreLoadAnalyzer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/temporaryVals/FastStoreLoadAnalyzer.kt @@ -65,7 +65,6 @@ class StoreLoadFrame(val maxLocals: Int) : Frame(maxLocals, 0) { class FastStoreLoadAnalyzer( owner: String, method: MethodNode, - interpreter: Interpreter -) : FastAnalyzer>(owner, method, interpreter, pruneExceptionEdges = false) { - override fun newFrame(nLocals: Int, nStack: Int): StoreLoadFrame = StoreLoadFrame(nLocals) -} \ No newline at end of file + interpreter: Interpreter, + newFrame: (Int, Int) -> StoreLoadFrame = { nLocals, _ -> StoreLoadFrame(nLocals) } +) : FastAnalyzer>(owner, method, interpreter, pruneExceptionEdges = false, newFrame)