Fix default parameter remapping on inlining: support store instruction
#KT-7963 Fixed
This commit is contained in:
@@ -443,4 +443,8 @@ public class InlineCodegenUtil {
|
|||||||
public static int getLoadStoreArgSize(int opcode) {
|
public static int getLoadStoreArgSize(int opcode) {
|
||||||
return opcode == Opcodes.DSTORE || opcode == Opcodes.LSTORE || opcode == Opcodes.DLOAD || opcode == Opcodes.LLOAD ? 2 : 1;
|
return opcode == Opcodes.DSTORE || opcode == Opcodes.LSTORE || opcode == Opcodes.DLOAD || opcode == Opcodes.LLOAD ? 2 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isStoreInstruction(int opcode) {
|
||||||
|
return opcode >= Opcodes.ISTORE && opcode <= Opcodes.ASTORE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,7 +114,11 @@ public class LocalVarRemapper {
|
|||||||
StackValue value = remapInfo.value;
|
StackValue value = remapInfo.value;
|
||||||
if (value instanceof StackValue.Local) {
|
if (value instanceof StackValue.Local) {
|
||||||
if (remapInfo.parameterInfo != null) {
|
if (remapInfo.parameterInfo != null) {
|
||||||
opcode = value.type.getOpcode(Opcodes.ILOAD);
|
//All remapped value parameters can't be rewritten except case of default ones.
|
||||||
|
//On remapping default parameter to actual value there is only one instruction that writes to it according to mask value
|
||||||
|
//but if such parameter remapped then it passed and this mask branch code never executed
|
||||||
|
//TODO add assertion about parameter default value: descriptor is required
|
||||||
|
opcode = value.type.getOpcode(InlineCodegenUtil.isStoreInstruction(opcode) ? Opcodes.ISTORE : Opcodes.ILOAD);
|
||||||
}
|
}
|
||||||
mv.visitVarInsn(opcode, ((StackValue.Local) value).index);
|
mv.visitVarInsn(opcode, ((StackValue.Local) value).index);
|
||||||
if (remapInfo.parameterInfo != null) {
|
if (remapInfo.parameterInfo != null) {
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import test.*
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val z = "OK".b { a, b ->
|
||||||
|
a + b
|
||||||
|
}
|
||||||
|
|
||||||
|
return if (z == "s1OK") "OK" else "fail $z"
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
inline fun a(s1: String = "s1", s2: String = "s2", body: (a1: String, a2: String) -> String) = body(s1, s2)
|
||||||
|
|
||||||
|
inline fun String.b(body: (a1: String, a2: String) -> String) = a(s2 = this, body = body)
|
||||||
+6
@@ -274,6 +274,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
|||||||
doTestMultiFileWithInlineCheck(fileName);
|
doTestMultiFileWithInlineCheck(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("defaultParamRemapping.1.kt")
|
||||||
|
public void testDefaultParamRemapping() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/defaultParamRemapping.1.kt");
|
||||||
|
doTestMultiFileWithInlineCheck(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inlineInDefaultParameter.1.kt")
|
@TestMetadata("inlineInDefaultParameter.1.kt")
|
||||||
public void testInlineInDefaultParameter() throws Exception {
|
public void testInlineInDefaultParameter() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/inlineInDefaultParameter.1.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/inlineInDefaultParameter.1.kt");
|
||||||
|
|||||||
+6
@@ -274,6 +274,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
|||||||
doBoxTestWithInlineCheck(fileName);
|
doBoxTestWithInlineCheck(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("defaultParamRemapping.1.kt")
|
||||||
|
public void testDefaultParamRemapping() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/defaultParamRemapping.1.kt");
|
||||||
|
doBoxTestWithInlineCheck(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inlineInDefaultParameter.1.kt")
|
@TestMetadata("inlineInDefaultParameter.1.kt")
|
||||||
public void testInlineInDefaultParameter() throws Exception {
|
public void testInlineInDefaultParameter() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/inlineInDefaultParameter.1.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/inlineInDefaultParameter.1.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user