JVM_IR fix counter loop optimization with Composable
This commit is contained in:
+8
-5
@@ -49,17 +49,20 @@ class JavaLikeCounterLoopBuilder(private val context: CommonBackendContext) {
|
|||||||
// )
|
// )
|
||||||
val bodyBlock = newBody as? IrContainerExpression
|
val bodyBlock = newBody as? IrContainerExpression
|
||||||
?: throw AssertionError("newBody: ${newBody?.dump()}")
|
?: throw AssertionError("newBody: ${newBody?.dump()}")
|
||||||
val forLoopNextBlock = bodyBlock.statements[0] as? IrContainerExpression
|
val forLoopNextBlockIndex = bodyBlock.statements.indexOfFirst {
|
||||||
?: throw AssertionError("bodyBlock[0]: ${bodyBlock.statements[0].dump()}")
|
it is IrContainerExpression && it.origin == IrStatementOrigin.FOR_LOOP_NEXT
|
||||||
if (forLoopNextBlock.origin != IrStatementOrigin.FOR_LOOP_NEXT)
|
}
|
||||||
throw AssertionError("FOR_LOOP_NEXT expected: ${forLoopNextBlock.dump()}")
|
if (forLoopNextBlockIndex < 0) {
|
||||||
|
throw AssertionError("No FOR_LOOP_NEXT block in bodyBlock: ${bodyBlock.dump()}")
|
||||||
|
}
|
||||||
|
val forLoopNextBlock = bodyBlock.statements[forLoopNextBlockIndex] as IrContainerExpression
|
||||||
val inductionVariableUpdate = forLoopNextBlock.statements.last() as? IrSetValue
|
val inductionVariableUpdate = forLoopNextBlock.statements.last() as? IrSetValue
|
||||||
?: throw AssertionError("forLoopNextBlock.last: ${forLoopNextBlock.statements.last().dump()}")
|
?: throw AssertionError("forLoopNextBlock.last: ${forLoopNextBlock.statements.last().dump()}")
|
||||||
|
|
||||||
val doWhileLoop = IrDoWhileLoopImpl(oldLoop.startOffset, oldLoop.endOffset, oldLoop.type, loopOrigin)
|
val doWhileLoop = IrDoWhileLoopImpl(oldLoop.startOffset, oldLoop.endOffset, oldLoop.type, loopOrigin)
|
||||||
doWhileLoop.label = oldLoop.label
|
doWhileLoop.label = oldLoop.label
|
||||||
|
|
||||||
bodyBlock.statements[0] = IrCompositeImpl(
|
bodyBlock.statements[forLoopNextBlockIndex] = IrCompositeImpl(
|
||||||
forLoopNextBlock.startOffset, forLoopNextBlock.endOffset,
|
forLoopNextBlock.startOffset, forLoopNextBlock.endOffset,
|
||||||
forLoopNextBlock.type,
|
forLoopNextBlock.type,
|
||||||
forLoopNextBlock.origin,
|
forLoopNextBlock.origin,
|
||||||
|
|||||||
Reference in New Issue
Block a user