* - bridges building
- bridges support in vtable and methods table

* FunctionDescriptor.signature fix + some assertions

* tests

* refactoring

* refactoring

* removed debug output

* refactoring

* review fixes

* implemented bridge construction for parameters

* tests

* refactoring

* removed custom box/unbox

* added bridge for extension receiver
This commit is contained in:
Igor Chevdar
2017-02-16 15:26:57 +05:00
committed by GitHub
parent 70cb8ced5a
commit c746da3ce4
29 changed files with 837 additions and 95 deletions
@@ -0,0 +1,15 @@
// vtable call
open class A {
open fun foo(): Any = "A"
}
open class C : A() {
override fun foo(): Int = 42
}
fun main(args: Array<String>) {
val c = C()
val a: A = c
println(c.foo().toString())
println(a.foo().toString())
}
@@ -0,0 +1,18 @@
// interface call, bridge overridden
interface Z1 {
fun foo(x: Int) : Any
}
open class A : Z1 {
override fun foo(x: Int) : Int = 5
}
open class B : A() {
override fun foo(x: Int) : Int = 42
}
fun main(args: Array<String>) {
val z1: A = B()
println((z1.foo(1) + 1000).toString())
}
@@ -0,0 +1,28 @@
open class A<T> {
open fun foo(x: T) {
println(x.toString())
}
}
interface I {
fun foo(x: Int)
}
class B : A<Int>(), I {
var z: Int = 5
override fun foo(x: Int) {
z = x
}
}
fun zzz(a: A<Int>) {
a.foo(42)
}
fun main(args: Array<String>) {
val b = B()
zzz(b)
val a = A<Int>()
zzz(a)
println(b.z)
}
@@ -0,0 +1,20 @@
interface I {
fun foo(x: Int)
}
abstract class A<T> {
abstract fun foo(x: T)
}
class B : A<Int>(), I {
override fun foo(x: Int) = println(x)
}
fun main(args: Array<String>) {
val b = B()
val a: A<Int> = b
val c: I = b
b.foo(42)
a.foo(42)
c.foo(42)
}
@@ -0,0 +1,24 @@
abstract class A<in T> {
abstract fun foo(x: T)
}
class B : A<Int>() {
override fun foo(x: Int) {
println("B: $x")
}
}
class C : A<Any>() {
override fun foo(x: Any) {
println("C: $x")
}
}
fun foo(arg: A<Int>) {
arg.foo(42)
}
fun main(args: Array<String>) {
foo(B())
foo(C())
}
@@ -0,0 +1,22 @@
open class A<T> {
open fun T.foo() {
println(this.toString())
}
fun bar(x: T) {
x.foo()
}
}
open class B: A<Int>() {
override fun Int.foo() {
println(this)
}
}
fun main(args : Array<String>) {
val b = B()
val a = A<Int>()
b.bar(42)
a.bar(42)
}
@@ -0,0 +1,17 @@
// vtable call, bridge inherited
open class A {
open fun foo(): Any = "A"
}
open class C : A() {
override fun foo(): Int = 42
}
open class D: C()
fun main(args: Array<String>) {
val c = D()
val a: A = c
println(c.foo().toString())
println(a.foo().toString())
}
@@ -0,0 +1,30 @@
// non-generic interface, generic impl, non-virtual call + interface call
open class A<T> {
var size: T = 56 as T
}
interface C {
var size: Int
}
class B : C, A<Int>()
fun box(): String {
val b = B()
if (b.size != 56) return "fail 1"
b.size = 55
if (b.size != 55) return "fail 2"
val c: C = b
if (c.size != 55) return "fail 3"
c.size = 57
if (c.size != 57) return "fail 4"
return "OK"
}
fun main(args: Array<String>) {
println(box())
}
@@ -0,0 +1,21 @@
// vtable call + interface call
interface Z {
fun foo(): Any
}
interface Y {
fun foo(): Int
}
open class A {
fun foo(): Int = 42
}
open class B: A(), Z, Y
fun main(args: Array<String>) {
val z: Z = B()
val y: Y = z as Y
println(z.foo().toString())
println(y.foo().toString())
}
@@ -0,0 +1,30 @@
// non-generic interface, generic impl, vtable call + interface call
open class A<T> {
open var size: T = 56 as T
}
interface C {
var size: Int
}
open class B : C, A<Int>()
fun box(): String {
val b = B()
if (b.size != 56) return "fail 1"
b.size = 55
if (b.size != 55) return "fail 2"
val c: C = b
if (c.size != 55) return "fail 3"
c.size = 57
if (c.size != 57) return "fail 4"
return "OK"
}
fun main(args: Array<String>) {
println(box())
}
@@ -0,0 +1,31 @@
// vtable call + interface call
interface Z {
fun foo(): Any
}
interface Y {
fun foo(): Int
}
open class A {
open fun foo(): Any = "A"
}
open class C : A() {
override fun foo(): Int = 42
}
open class D: C(), Y, Z
fun main(args: Array<String>) {
val d = D()
val y: Y = d
val z: Z = d
val c: C = d
val a: A = d
println(d.foo().toString())
println(y.foo().toString())
println(z.foo().toString())
println(c.foo().toString())
println(a.foo().toString())
}
@@ -0,0 +1,30 @@
// generic interface, non-generic impl, vtable call + interface call
open class A {
open var size: Int = 56
}
interface C<T> {
var size: T
}
open class B : C<Int>, A()
fun box(): String {
val b = B()
if (b.size != 56) return "fail 1"
b.size = 55
if (b.size != 55) return "fail 2"
val c: C<Int> = b
if (c.size != 55) return "fail 3"
c.size = 57
if (c.size != 57) return "fail 4"
return "OK"
}
fun main(args: Array<String>) {
println(box())
}
@@ -0,0 +1,30 @@
// generic interface, non-generic impl, non-virtual call + interface call
open class A {
var size: Int = 56
}
interface C<T> {
var size: T
}
class B : C<Int>, A()
fun box(): String {
val b = B()
if (b.size != 56) return "fail 1"
b.size = 55
if (b.size != 55) return "fail 2"
val c: C<Int> = b
if (c.size != 55) return "fail 3"
c.size = 57
if (c.size != 57) return "fail 4"
return "OK"
}
fun main(args: Array<String>) {
println(box())
}
@@ -0,0 +1,27 @@
// abstract class vtable call
abstract class A {
abstract fun foo(): String
}
abstract class B : A()
class Z : B() {
override fun foo() = "Z"
}
fun box(): String {
val z = Z()
val b: B = z
val a: A = z
return when {
z.foo() != "Z" -> "Fail #1"
b.foo() != "Z" -> "Fail #2"
a.foo() != "Z" -> "Fail #3"
else -> "OK"
}
}
fun main(args: Array<String>) {
println(box())
}