Files
kotlin-fork/compiler/testData/codegen/bytecodeText/companion/inlineFunctionCompanionPropertyAccess.kt
T
Mads Ager c922484758 [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.
2020-12-11 06:24:55 +01:00

30 lines
774 B
Kotlin
Vendored

class A {
companion object {
val s = "OK"
var v = "NOT OK"
}
inline fun f(): String = s
inline fun g() {
v = "OK"
}
}
// One direct `A.s` access in the accessibility bridge `access$getS$cp`.
// 1 GETSTATIC A.s
// One direct `A.v` set in the accessibility bridge `access$setV$cp`.
// One direct `A.v` set in `A.<clinit>`
// 2 PUTSTATIC A.v
// One call to the getter/setter on the companion object from f and one from g.
// 1 INVOKEVIRTUAL A\$Companion.getS
// 1 INVOKEVIRTUAL A\$Companion.setV
// One call to the accessibility bridge `access$setV$cp` from Companion.setV.
// 1 INVOKESTATIC A.access\$setV\$cp
// One call to the accessibility bridge `access$getS$cp` from Companion.getS.
// 1 INVOKESTATIC A.access\$getS\$cp