[IR BE] Fix array constructor loop. Use index parameter as immutable value

This commit is contained in:
Roman Artemev
2019-05-17 12:43:47 +03:00
committed by romanart
parent dfa38f4a4d
commit 72f7287ad2
8 changed files with 65 additions and 3 deletions
@@ -80,11 +80,16 @@ class ArrayConstructorLowering(val context: CommonBackendContext) : IrElementTra
putValueArgument(1, irGet(sizeVar))
}
body = irBlock {
val value =
lambda?.inline(listOf(index)) ?: irCallOp(invoke.symbol, invoke.returnType, irGet(invokableVar!!), irGet(index))
val tempIndex = irTemporary(irGet(index))
val value = lambda?.inline(listOf(tempIndex)) ?: irCallOp(
invoke.symbol,
invoke.returnType,
irGet(invokableVar!!),
irGet(tempIndex)
)
+irCall(result.type.getClass()!!.functions.single { it.name == OperatorNameConventions.SET }).apply {
dispatchReceiver = irGet(result)
putValueArgument(0, irGet(index))
putValueArgument(0, irGet(tempIndex))
putValueArgument(1, value)
}
val inc = index.type.getClass()!!.functions.single { it.name == OperatorNameConventions.INC }
@@ -0,0 +1,27 @@
// WITH_RUNTIME
import kotlin.test.assertEquals
val size = 10
fun box(): String {
val intArray = IntArray(size)
val array = Array(size) { i -> { intArray[i]++ } }
for (i in intArray) {
assertEquals(0, i)
}
for (a in array) {
a()
}
for (i in intArray) {
assertEquals(1, i)
}
return "OK"
}
@@ -310,6 +310,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("arrayConstructorWithNonInlineLambda.kt")
public void testArrayConstructorWithNonInlineLambda() throws Exception {
runTest("compiler/testData/codegen/box/arrays/arrayConstructorWithNonInlineLambda.kt");
}
@TestMetadata("arrayConstructorsSimple.kt")
public void testArrayConstructorsSimple() throws Exception {
runTest("compiler/testData/codegen/box/arrays/arrayConstructorsSimple.kt");
@@ -310,6 +310,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("arrayConstructorWithNonInlineLambda.kt")
public void testArrayConstructorWithNonInlineLambda() throws Exception {
runTest("compiler/testData/codegen/box/arrays/arrayConstructorWithNonInlineLambda.kt");
}
@TestMetadata("arrayConstructorsSimple.kt")
public void testArrayConstructorsSimple() throws Exception {
runTest("compiler/testData/codegen/box/arrays/arrayConstructorsSimple.kt");
@@ -310,6 +310,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true);
}
@TestMetadata("arrayConstructorWithNonInlineLambda.kt")
public void testArrayConstructorWithNonInlineLambda() throws Exception {
runTest("compiler/testData/codegen/box/arrays/arrayConstructorWithNonInlineLambda.kt");
}
@TestMetadata("arrayConstructorsSimple.kt")
public void testArrayConstructorsSimple() throws Exception {
runTest("compiler/testData/codegen/box/arrays/arrayConstructorsSimple.kt");
@@ -165,6 +165,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true);
}
@TestMetadata("arrayConstructorWithNonInlineLambda.kt")
public void testArrayConstructorWithNonInlineLambda() throws Exception {
runTest("compiler/testData/codegen/box/arrays/arrayConstructorWithNonInlineLambda.kt");
}
@TestMetadata("arrayConstructorsSimple.kt")
public void testArrayConstructorsSimple() throws Exception {
runTest("compiler/testData/codegen/box/arrays/arrayConstructorsSimple.kt");
@@ -165,6 +165,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
}
@TestMetadata("arrayConstructorWithNonInlineLambda.kt")
public void testArrayConstructorWithNonInlineLambda() throws Exception {
runTest("compiler/testData/codegen/box/arrays/arrayConstructorWithNonInlineLambda.kt");
}
@TestMetadata("arrayConstructorsSimple.kt")
public void testArrayConstructorsSimple() throws Exception {
runTest("compiler/testData/codegen/box/arrays/arrayConstructorsSimple.kt");
@@ -29,6 +29,11 @@ public class JsLegacyPrimitiveArraysBoxTestGenerated extends AbstractJsLegacyPri
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
}
@TestMetadata("arrayConstructorWithNonInlineLambda.kt")
public void testArrayConstructorWithNonInlineLambda() throws Exception {
runTest("compiler/testData/codegen/box/arrays/arrayConstructorWithNonInlineLambda.kt");
}
@TestMetadata("arrayConstructorsSimple.kt")
public void testArrayConstructorsSimple() throws Exception {
runTest("compiler/testData/codegen/box/arrays/arrayConstructorsSimple.kt");