Restore accidentally removed parameter index passing to call generator
Parameter index was removed in
7690a8bc3e commit:
"Get rid of redundant 'afterParameterPut' method from call generators"
#KT-17653 Fixed
This commit is contained in:
@@ -64,7 +64,7 @@ public class CallBasedArgumentGenerator extends ArgumentGenerator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void generateDefault(int i, @NotNull DefaultValueArgument argument) {
|
protected void generateDefault(int i, @NotNull DefaultValueArgument argument) {
|
||||||
callGenerator.putValueIfNeeded(valueParameterTypes.get(i), createDefaulValue(valueParameterTypes.get(i)), ValueKind.DEFAULT_PARAMETER);
|
callGenerator.putValueIfNeeded(valueParameterTypes.get(i), createDefaulValue(valueParameterTypes.get(i)), ValueKind.DEFAULT_PARAMETER, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -73,7 +73,7 @@ public class CallBasedArgumentGenerator extends ArgumentGenerator {
|
|||||||
// Upper bound for type of vararg parameter should always have a form of 'Array<out T>',
|
// Upper bound for type of vararg parameter should always have a form of 'Array<out T>',
|
||||||
// while its lower bound may be Nothing-typed after approximation
|
// while its lower bound may be Nothing-typed after approximation
|
||||||
StackValue lazyVararg = codegen.genVarargs(argument, FlexibleTypesKt.upperIfFlexible(parameter.getType()));
|
StackValue lazyVararg = codegen.genVarargs(argument, FlexibleTypesKt.upperIfFlexible(parameter.getType()));
|
||||||
callGenerator.putValueIfNeeded(valueParameterTypes.get(i), lazyVararg);
|
callGenerator.putValueIfNeeded(valueParameterTypes.get(i), lazyVararg, ValueKind.GENERAL_VARARG, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -23,10 +23,11 @@ import org.jetbrains.org.objectweb.asm.Type
|
|||||||
|
|
||||||
enum class ValueKind {
|
enum class ValueKind {
|
||||||
GENERAL,
|
GENERAL,
|
||||||
|
GENERAL_VARARG,
|
||||||
DEFAULT_PARAMETER,
|
DEFAULT_PARAMETER,
|
||||||
DEFAULT_MASK,
|
DEFAULT_MASK,
|
||||||
METHOD_HANDLE_IN_DEFAULT,
|
METHOD_HANDLE_IN_DEFAULT,
|
||||||
CAPTURED
|
CAPTURED,
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class CallGenerator {
|
abstract class CallGenerator {
|
||||||
@@ -68,7 +69,7 @@ abstract class CallGenerator {
|
|||||||
stackValue.put(stackValue.type, codegen.v)
|
stackValue.put(stackValue.type, codegen.v)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun putValueIfNeeded(parameterType: Type, value: StackValue, kind: ValueKind) {
|
override fun putValueIfNeeded(parameterType: Type, value: StackValue, kind: ValueKind, parameterIndex: Int) {
|
||||||
value.put(value.type, codegen.v)
|
value.put(value.type, codegen.v)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +122,8 @@ abstract class CallGenerator {
|
|||||||
abstract fun putValueIfNeeded(
|
abstract fun putValueIfNeeded(
|
||||||
parameterType: Type,
|
parameterType: Type,
|
||||||
value: StackValue,
|
value: StackValue,
|
||||||
kind: ValueKind)
|
kind: ValueKind = ValueKind.GENERAL,
|
||||||
|
parameterIndex: Int = -1)
|
||||||
|
|
||||||
abstract fun putCapturedValueOnStack(
|
abstract fun putCapturedValueOnStack(
|
||||||
stackValue: StackValue,
|
stackValue: StackValue,
|
||||||
|
|||||||
@@ -904,7 +904,7 @@ public class InlineCodegen extends CallGenerator {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
StackValue value = codegen.gen(argumentExpression);
|
StackValue value = codegen.gen(argumentExpression);
|
||||||
putValueIfNeeded(parameterType, value, valueParameterDescriptor.getIndex(), ValueKind.GENERAL);
|
putValueIfNeeded(parameterType, value, ValueKind.GENERAL, valueParameterDescriptor.getIndex());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -923,16 +923,12 @@ public class InlineCodegen extends CallGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putValueIfNeeded(@NotNull Type parameterType, @NotNull StackValue value, @NotNull ValueKind kind) {
|
public void putValueIfNeeded(@NotNull Type parameterType, @NotNull StackValue value, @NotNull ValueKind kind, int parameterIndex) {
|
||||||
putValueIfNeeded(parameterType, value, -1, kind);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void putValueIfNeeded(@NotNull Type parameterType, @NotNull StackValue value, int index, @NotNull ValueKind kind) {
|
|
||||||
if (processDefaultMaskOrMethodHandler(value, kind)) return;
|
if (processDefaultMaskOrMethodHandler(value, kind)) return;
|
||||||
|
|
||||||
assert maskValues.isEmpty() : "Additional default call arguments should be last ones, but " + value;
|
assert maskValues.isEmpty() : "Additional default call arguments should be last ones, but " + value;
|
||||||
|
|
||||||
putArgumentOrCapturedToLocalVal(parameterType, value, -1, index, kind);
|
putArgumentOrCapturedToLocalVal(parameterType, value, -1, parameterIndex, kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean processDefaultMaskOrMethodHandler(@NotNull StackValue value, @NotNull ValueKind kind) {
|
private boolean processDefaultMaskOrMethodHandler(@NotNull StackValue value, @NotNull ValueKind kind) {
|
||||||
|
|||||||
+1
-1
@@ -91,7 +91,7 @@ class InlineCodegenForDefaultBody(
|
|||||||
throw UnsupportedOperationException("Shouldn't be called")
|
throw UnsupportedOperationException("Shouldn't be called")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun putValueIfNeeded(parameterType: Type, value: StackValue, kind: ValueKind) {
|
override fun putValueIfNeeded(parameterType: Type, value: StackValue, kind: ValueKind, parameterIndex: Int) {
|
||||||
//original method would be inlined directly into default impl body without any inline magic
|
//original method would be inlined directly into default impl body without any inline magic
|
||||||
//so we no need to load variables on stack to further method call
|
//so we no need to load variables on stack to further method call
|
||||||
}
|
}
|
||||||
|
|||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
// NO_CHECK_LAMBDA_INLINING
|
||||||
|
// FILE: 1.kt
|
||||||
|
// WITH_RUNTIME
|
||||||
|
package test
|
||||||
|
|
||||||
|
open class A(val value: String)
|
||||||
|
|
||||||
|
var invokeOrder = ""
|
||||||
|
|
||||||
|
inline fun inlineFun(
|
||||||
|
receiver: String = { invokeOrder += " default receiver"; "DEFAULT" }(),
|
||||||
|
init: String,
|
||||||
|
vararg constraints: A
|
||||||
|
): String {
|
||||||
|
return constraints.map { it.value }.joinToString() + ", " + receiver + ", " + init
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: 2.kt
|
||||||
|
import test.*
|
||||||
|
|
||||||
|
|
||||||
|
var result = ""
|
||||||
|
fun box(): String {
|
||||||
|
|
||||||
|
result = ""
|
||||||
|
invokeOrder = ""
|
||||||
|
result = inlineFun(constraints = { invokeOrder += "constraints";A("C") }(),
|
||||||
|
receiver = { invokeOrder += " receiver"; "R" }(),
|
||||||
|
init = { invokeOrder += " init"; "I" }())
|
||||||
|
if (result != "C, R, I") return "fail 1: $result"
|
||||||
|
|
||||||
|
//Change test after KT-17691 FIX
|
||||||
|
if (invokeOrder != " receiver initconstraints") return "fail 2: $invokeOrder"
|
||||||
|
|
||||||
|
result = ""
|
||||||
|
invokeOrder = ""
|
||||||
|
result = inlineFun(init = { invokeOrder += "init"; "I" }(),
|
||||||
|
constraints = { invokeOrder += "constraints";A("C") }(),
|
||||||
|
receiver = { invokeOrder += " receiver"; "R" }()
|
||||||
|
)
|
||||||
|
if (result != "C, R, I") return "fail 3: $result"
|
||||||
|
//Change test after KT-17691 FIX
|
||||||
|
if (invokeOrder != "init receiverconstraints") return "fail 4: $invokeOrder"
|
||||||
|
|
||||||
|
result = ""
|
||||||
|
invokeOrder = ""
|
||||||
|
result = inlineFun(init = { invokeOrder += "init"; "I" }(),
|
||||||
|
constraints = { invokeOrder += " constraints";A("C") }())
|
||||||
|
if (result != "C, DEFAULT, I") return "fail 5: $result"
|
||||||
|
if (invokeOrder != "init constraints default receiver") return "fail 6: $invokeOrder"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
// NO_CHECK_LAMBDA_INLINING
|
||||||
|
// FILE: 1.kt
|
||||||
|
// WITH_RUNTIME
|
||||||
|
package test
|
||||||
|
|
||||||
|
open class A(val value: String)
|
||||||
|
|
||||||
|
var invokeOrder = ""
|
||||||
|
|
||||||
|
inline fun inlineFun(
|
||||||
|
vararg constraints: A,
|
||||||
|
receiver: String = { invokeOrder += " default receiver"; "DEFAULT" }(),
|
||||||
|
init: String
|
||||||
|
): String {
|
||||||
|
return constraints.map { it.value }.joinToString() + ", " + receiver + ", " + init
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: 2.kt
|
||||||
|
import test.*
|
||||||
|
|
||||||
|
|
||||||
|
var result = ""
|
||||||
|
fun box(): String {
|
||||||
|
|
||||||
|
result = ""
|
||||||
|
invokeOrder = ""
|
||||||
|
result = inlineFun(constraints = { invokeOrder += "constraints";A("C") }(),
|
||||||
|
receiver = { invokeOrder += " receiver"; "R" }(),
|
||||||
|
init = { invokeOrder += " init"; "I" }())
|
||||||
|
if (result != "C, R, I") return "fail 1: $result"
|
||||||
|
|
||||||
|
//Change test after KT-17691 FIX
|
||||||
|
if (invokeOrder != " receiver initconstraints") return "fail 2: $invokeOrder"
|
||||||
|
|
||||||
|
result = ""
|
||||||
|
invokeOrder = ""
|
||||||
|
result = inlineFun(init = { invokeOrder += "init"; "I" }(),
|
||||||
|
constraints = { invokeOrder += "constraints";A("C") }(),
|
||||||
|
receiver = { invokeOrder += " receiver"; "R" }()
|
||||||
|
)
|
||||||
|
if (result != "C, R, I") return "fail 3: $result"
|
||||||
|
//Change test after KT-17691 FIX
|
||||||
|
if (invokeOrder != "init receiverconstraints") return "fail 4: $invokeOrder"
|
||||||
|
|
||||||
|
result = ""
|
||||||
|
invokeOrder = ""
|
||||||
|
result = inlineFun(init = { invokeOrder += "init"; "I" }(),
|
||||||
|
constraints = { invokeOrder += " constraints";A("C") }())
|
||||||
|
if (result != "C, DEFAULT, I") return "fail 5: $result"
|
||||||
|
if (invokeOrder != "init constraints default receiver") return "fail 6: $invokeOrder"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// FILE: 1.kt
|
||||||
|
|
||||||
|
package test
|
||||||
|
|
||||||
|
inline fun inlineFun(vararg constraints: String, init: String.() -> String): String {
|
||||||
|
return "O".init()
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: 2.kt
|
||||||
|
|
||||||
|
import test.*
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return inlineFun {
|
||||||
|
this + "K"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// FILE: 1.kt
|
||||||
|
|
||||||
|
package test
|
||||||
|
|
||||||
|
inline fun inlineFun(vararg constraints: String, receiver: String = "O", init: String.() -> String): String {
|
||||||
|
return receiver.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: 2.kt
|
||||||
|
|
||||||
|
import test.*
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return inlineFun {
|
||||||
|
this + "K"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// FILE: 1.kt
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
package test
|
||||||
|
inline fun inlineFun(vararg constraints: String, receiver: String = "K", init: String.() -> String): String {
|
||||||
|
return (constraints.joinToString() + receiver).init()
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: 2.kt
|
||||||
|
|
||||||
|
import test.*
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return inlineFun("O") {
|
||||||
|
this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -461,6 +461,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("defaultParametersAndLastVararg.kt")
|
||||||
|
public void testDefaultParametersAndLastVararg() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/argumentOrder/defaultParametersAndLastVararg.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("extension.kt")
|
@TestMetadata("extension.kt")
|
||||||
public void testExtension() throws Exception {
|
public void testExtension() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/argumentOrder/extension.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/argumentOrder/extension.kt");
|
||||||
@@ -496,6 +502,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/argumentOrder/simpleInClass.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/argumentOrder/simpleInClass.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("varargAndDefaultParameters.kt")
|
||||||
|
public void testVarargAndDefaultParameters() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/argumentOrder/varargAndDefaultParameters.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/boxInline/arrayConvention")
|
@TestMetadata("compiler/testData/codegen/boxInline/arrayConvention")
|
||||||
@@ -2732,4 +2744,31 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/codegen/boxInline/varargs")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Varargs extends AbstractBlackBoxInlineCodegenTest {
|
||||||
|
public void testAllFilesPresentInVarargs() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/varargs"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt17653.kt")
|
||||||
|
public void testKt17653() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/varargs/kt17653.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("varargAndDefaultParameters.kt")
|
||||||
|
public void testVarargAndDefaultParameters() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/varargs/varargAndDefaultParameters.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("varargAndDefaultParameters2.kt")
|
||||||
|
public void testVarargAndDefaultParameters2() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/varargs/varargAndDefaultParameters2.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+39
@@ -461,6 +461,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("defaultParametersAndLastVararg.kt")
|
||||||
|
public void testDefaultParametersAndLastVararg() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/argumentOrder/defaultParametersAndLastVararg.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("extension.kt")
|
@TestMetadata("extension.kt")
|
||||||
public void testExtension() throws Exception {
|
public void testExtension() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/argumentOrder/extension.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/argumentOrder/extension.kt");
|
||||||
@@ -496,6 +502,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/argumentOrder/simpleInClass.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/argumentOrder/simpleInClass.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("varargAndDefaultParameters.kt")
|
||||||
|
public void testVarargAndDefaultParameters() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/argumentOrder/varargAndDefaultParameters.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/boxInline/arrayConvention")
|
@TestMetadata("compiler/testData/codegen/boxInline/arrayConvention")
|
||||||
@@ -2732,4 +2744,31 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/codegen/boxInline/varargs")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Varargs extends AbstractCompileKotlinAgainstInlineKotlinTest {
|
||||||
|
public void testAllFilesPresentInVarargs() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/varargs"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt17653.kt")
|
||||||
|
public void testKt17653() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/varargs/kt17653.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("varargAndDefaultParameters.kt")
|
||||||
|
public void testVarargAndDefaultParameters() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/varargs/varargAndDefaultParameters.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("varargAndDefaultParameters2.kt")
|
||||||
|
public void testVarargAndDefaultParameters2() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/varargs/varargAndDefaultParameters2.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user