JVM_IR. support big arity

This commit is contained in:
Georgy Bronnikov
2018-08-31 12:00:32 +03:00
parent 03f092fd39
commit f04733ef33
22 changed files with 473 additions and 37 deletions
@@ -1,7 +1,6 @@
// !LANGUAGE: +FunctionTypesWithBigArity
// WITH_RUNTIME
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM_IR
// FILE: J.java
import kotlin.jvm.functions.FunctionN;
@@ -0,0 +1,77 @@
// !LANGUAGE: +FunctionTypesWithBigArity
// WITH_RUNTIME
// TARGET_BACKEND: JVM_IR
// FILE: J.java
// import kotlin.jvm.functions.Arity;
import kotlin.jvm.functions.FunctionN;
import kotlin.Unit;
import java.util.Arrays;
public class J {
// TODO: uncomment arity as soon as Arity is introduced
public static void test(/* @Arity(30) */ FunctionN<Integer> f) {
Object o = new Integer(0);
for (int i = 0; i < 42; i++) {
Object[] args = new Object[i];
Arrays.fill(args, o);
try {
if (f.invoke(args).intValue() != 300 + i) {
throw new AssertionError("Bad return value from function");
}
} catch (IllegalArgumentException e) {
if (i == 3 || i == 13 || i == 30 || i == 33) {
throw new AssertionError(String.format("Call with %d arguments is expected to succeed", i), e);
}
// OK
if (!e.getMessage().contains("30")) {
throw new AssertionError("Exception must specify the expected number of arguments: " + e.getMessage(), e);
}
continue;
} catch (Throwable e) {
throw new AssertionError(
"Incorrect exception (IllegalArgumentException expected): " + e.getClass().getName() + ", i = " + i, e
);
}
if (i != 3 && i != 13 && i != 30 && i != 33) {
throw new AssertionError ("IllegalArgumentException expected, but nothing was thrown, i = " + i);
}
}
}
}
// FILE: K.kt
class Fun : (Int, Int, Int) -> Int,
(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Int,
(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int,
Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Int,
(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int,
Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) -> Int {
override fun invoke(p00: Int, p01: Int, p02: Int): Int = 303
override fun invoke(
p00: Int, p01: Int, p02: Int, p03: Int, p04: Int, p05: Int, p06: Int, p07: Int, p08: Int, p09: Int,
p10: Int, p11: Int, p12: Int
): Int = 313
override fun invoke(
p00: Int, p01: Int, p02: Int, p03: Int, p04: Int, p05: Int, p06: Int, p07: Int, p08: Int, p09: Int,
p10: Int, p11: Int, p12: Int, p13: Int, p14: Int, p15: Int, p16: Int, p17: Int, p18: Int, p19: Int,
p20: Int, p21: Int, p22: Int, p23: Int, p24: Int, p25: Int, p26: Int, p27: Int, p28: Int, p29: Int
): Int = 330
override fun invoke(
p00: Int, p01: Int, p02: Int, p03: Int, p04: Int, p05: Int, p06: Int, p07: Int, p08: Int, p09: Int,
p10: Int, p11: Int, p12: Int, p13: Int, p14: Int, p15: Int, p16: Int, p17: Int, p18: Int, p19: Int,
p20: Int, p21: Int, p22: Int, p23: Int, p24: Int, p25: Int, p26: Int, p27: Int, p28: Int, p29: Int,
p30: Int, p31: Int, p32: Int
): Int = 333
}
fun box(): String {
J.test(Fun() as kotlin.jvm.functions.FunctionN<Int>)
return "OK"
}
@@ -1,7 +1,6 @@
// !LANGUAGE: +FunctionTypesWithBigArity
// WITH_RUNTIME
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM_IR
// FILE: J.java
// import kotlin.jvm.functions.Arity;
@@ -1,6 +1,5 @@
// !LANGUAGE: +FunctionTypesWithBigArity
// IGNORE_BACKEND: JS_IR
// IGNORE_BACKEND: JVM_IR
class A(val value: Int) {
// for (i in 1..254) { print("p${"%03d".format(i)}: A, "); if (i % 10 == 0) println() }; println()
@@ -1,5 +1,4 @@
// !LANGUAGE: +FunctionTypesWithBigArity
// IGNORE_BACKEND: JVM_IR
class A
@@ -1,5 +1,4 @@
// !LANGUAGE: +FunctionTypesWithBigArity
// IGNORE_BACKEND: JVM_IR
class A(val value: Int)
@@ -0,0 +1,17 @@
// !LANGUAGE: +FunctionTypesWithBigArity
class A {
fun foo(
p00: A, p01: A, p02: A, p03: A, p04: A, p05: A, p06: A, p07: A, p08: A, p09: A,
p10: A, p11: A, p12: A, p13: A, p14: A, p15: A, p16: A, p17: A, p18: A, p19: A,
p20: A, p21: A, p22: A, p23: A, p24: A, p25: A, p26: A, p27: A, p28: A, p29: A
): String {
return "OK"
}
}
fun box(): String {
val a = A()
val ref = a::foo
return ref(a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a)
}
@@ -1,7 +1,6 @@
// !LANGUAGE: +FunctionTypesWithBigArity
// WITH_RUNTIME
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM_IR
// FILE: J.java
// import kotlin.jvm.functions.Arity;
@@ -1,9 +1,8 @@
// !LANGUAGE: -FunctionTypesWithBigArity
// IGNORE_BACKEND: JVM_IR
// This test does not make sense for JVM because a diagnostic is reported when function types with big arity are not available
// (see diagnostics/tests/sourceCompatibility/noBigFunctionTypes.kt)
// IGNORE_BACKEND: JVM
// IGNORE_BACKEND: JVM, JVM_IR
class A