[JVM_IR] Use direct field access to backing fields on current class.

The current backend uses direct field access to the backing field
instead of calling the companion object accessor, which calls
an accessibility bridge, which then gets the field for code such as:

```
class A {
  companion object {
    val s: String = "OK"
  }

  // f uses direct access to the A.s backing field.
  fun f() = s
}
```

This change does the same for the IR backend.
This commit is contained in:
Mads Ager
2020-11-25 14:36:40 +01:00
committed by max-kammerer
parent 1d14926444
commit c922484758
19 changed files with 524 additions and 6 deletions
@@ -0,0 +1,46 @@
import kotlin.reflect.KProperty
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): String = "OK"
}
class Delegate2 {
var value: String = "NOT OK"
operator fun getValue(t: Any?, p: KProperty<*>): String = value
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) {
this.value = value
}
}
class A {
companion object {
val s: String by Delegate()
var s2: String by Delegate2()
var s3: String by Delegate2()
}
fun f() = s
inline fun g() = s
fun set2() {
s2 = "OK"
}
fun get2() = s2
inline fun set3() {
s3 = "OK"
}
inline fun get3() = s3
}
fun box(): String {
val a = A()
if (a.f() != "OK") return "FAIL0"
if (a.g() != "OK") return "FAIL0"
a.set2()
if (a.get2() != "OK") return "FAIL0"
a.set3()
return a.get3()
}
@@ -0,0 +1,19 @@
class A {
companion object {
val s = "OK"
var v = "NOT OK"
}
inline fun f(): String = s
inline fun g() {
v = "OK"
}
}
fun box(): String {
val a = A()
if (a.f() != "OK") return "FAIL0"
a.g()
return A.v
}