Fix argument original type order in InlineCodegen

Arguments are put on stack in the direct order, and then stored into
local variables for inlining in the reversed order:

    <arg0>
    <arg1>
    <arg2>
    store <param2>
    store <param1>
    store <param0>

Original value parameter types were taken in direct order, though.
This commit is contained in:
Dmitry Petrov
2018-08-22 14:59:15 +03:00
parent 25b32b8e1d
commit 6e2d05cd94
8 changed files with 89 additions and 1 deletions
@@ -1042,7 +1042,8 @@ class MethodInliner(
val safeToUseArgumentKotlinType =
directOrder.size == directOrderOfArguments.size && directOrderOfArguments.size == directOrderOfInvokeParameters.size
directOrder.asReversed().forEachIndexed { index, type ->
for (index in directOrder.lastIndex downTo 0) {
val type = directOrder[index]
currentShift -= type.size
val typeOnStack = actualParams[index]
@@ -0,0 +1,25 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
inline class Z(val int: Int)
inline class L(val long: Long)
inline fun <T, R> s0(x: T, fn: (Int, T) -> R) = fn(0, x)
inline fun <T, R> weirdMix(x: T, fn: (Int, T, Long, T) -> R) = fn(0, x, 0L, x)
fun testS0Z(x: Z) = s0(x) { _, xx -> Z(xx.int + 1) }
fun testS0L(x: L) = s0(x) { _, xx -> L(xx.long + 1L) }
fun testWeirdMixZ(x: Z) = weirdMix(x) { _, xx, _, _ -> Z(xx.int + 1) }
fun testWeirdMixL(x: L) = weirdMix(x) { _, xx, _, _ -> L(xx.long + 1L) }
fun box(): String {
if (testS0Z(Z(42)).int != 43) throw AssertionError()
if (testS0L(L(42L)).long != 43L) throw AssertionError()
if (testWeirdMixZ(Z(42)).int != 43) throw AssertionError()
if (testWeirdMixL(L(42L)).long != 43L) throw AssertionError()
return "OK"
}
@@ -0,0 +1,12 @@
// IGNORE_BACKEND: JVM_IR, JS, JS_IR
// WITH_UNSIGNED
fun box(): String {
val a = listOf(1u, 2u, 3u)
var sum = 0
a.forEachIndexed { index, uInt ->
sum = sum * 10 + (index + 1) * uInt.toInt()
}
if (sum != 149) throw AssertionError()
return "OK"
}
@@ -11570,6 +11570,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesCheckCast.kt");
}
@TestMetadata("inlineClassesInInlineLambdaParameters.kt")
public void testInlineClassesInInlineLambdaParameters() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesInInlineLambdaParameters.kt");
}
@TestMetadata("inlineFunctionInsideInlineClass.kt")
public void testInlineFunctionInsideInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt");
@@ -22000,6 +22005,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/unsignedTypes/evaluateConstructorOfUnsignedType.kt");
}
@TestMetadata("forEachIndexedInListOfUInts.kt")
public void testForEachIndexedInListOfUInts() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt");
}
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
public void testIterateOverArrayOfUnsignedValues() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
@@ -11570,6 +11570,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesCheckCast.kt");
}
@TestMetadata("inlineClassesInInlineLambdaParameters.kt")
public void testInlineClassesInInlineLambdaParameters() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesInInlineLambdaParameters.kt");
}
@TestMetadata("inlineFunctionInsideInlineClass.kt")
public void testInlineFunctionInsideInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt");
@@ -22000,6 +22005,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/unsignedTypes/evaluateConstructorOfUnsignedType.kt");
}
@TestMetadata("forEachIndexedInListOfUInts.kt")
public void testForEachIndexedInListOfUInts() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt");
}
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
public void testIterateOverArrayOfUnsignedValues() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
@@ -11570,6 +11570,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesCheckCast.kt");
}
@TestMetadata("inlineClassesInInlineLambdaParameters.kt")
public void testInlineClassesInInlineLambdaParameters() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesInInlineLambdaParameters.kt");
}
@TestMetadata("inlineFunctionInsideInlineClass.kt")
public void testInlineFunctionInsideInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt");
@@ -22000,6 +22005,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/unsignedTypes/evaluateConstructorOfUnsignedType.kt");
}
@TestMetadata("forEachIndexedInListOfUInts.kt")
public void testForEachIndexedInListOfUInts() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt");
}
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
public void testIterateOverArrayOfUnsignedValues() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
@@ -10130,6 +10130,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesCheckCast.kt");
}
@TestMetadata("inlineClassesInInlineLambdaParameters.kt")
public void testInlineClassesInInlineLambdaParameters() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesInInlineLambdaParameters.kt");
}
@TestMetadata("inlineFunctionInsideInlineClass.kt")
public void testInlineFunctionInsideInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt");
@@ -19850,6 +19855,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/unsignedTypes/boxConstValOfUnsignedType.kt");
}
@TestMetadata("forEachIndexedInListOfUInts.kt")
public void testForEachIndexedInListOfUInts() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt");
}
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
public void testIterateOverArrayOfUnsignedValues() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
@@ -11190,6 +11190,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesCheckCast.kt");
}
@TestMetadata("inlineClassesInInlineLambdaParameters.kt")
public void testInlineClassesInInlineLambdaParameters() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesInInlineLambdaParameters.kt");
}
@TestMetadata("inlineFunctionInsideInlineClass.kt")
public void testInlineFunctionInsideInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt");
@@ -20910,6 +20915,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/unsignedTypes/boxConstValOfUnsignedType.kt");
}
@TestMetadata("forEachIndexedInListOfUInts.kt")
public void testForEachIndexedInListOfUInts() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt");
}
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
public void testIterateOverArrayOfUnsignedValues() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");