JVM_IR: optimize out redundant delegated property receiver fields
Now this:
class C {
val x = something
val y by x::property
}
is *exactly* the same as this:
class C {
val x = something
val y get() = x.property
}
(plus a `getY$delegate` method)
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
// WITH_RUNTIME
|
||||
var result = "Fail"
|
||||
|
||||
object O {
|
||||
val z = 42
|
||||
init { result = "OK" }
|
||||
}
|
||||
|
||||
class A {
|
||||
val x by O::z
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
A()
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_RUNTIME
|
||||
val String.foo: String
|
||||
get() = this
|
||||
|
||||
abstract class A {
|
||||
abstract val x: String
|
||||
|
||||
val y by x::foo
|
||||
}
|
||||
|
||||
var storage = "OK"
|
||||
|
||||
class B : A() {
|
||||
override var x: String
|
||||
get() = storage
|
||||
set(value) { storage = value }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b = B()
|
||||
b.x = "fail"
|
||||
return b.y
|
||||
}
|
||||
+1
@@ -33,6 +33,7 @@ fun local() {
|
||||
// Optimized all to direct accesses, with `$delegate` methods generating reflected references on demand:
|
||||
// 0 extends kotlin/jvm/internal/MutablePropertyReference[0-2]Impl
|
||||
// 0 private final( static)? Lkotlin/reflect/KMutableProperty[0-2]; [xyz]m?\$delegate
|
||||
// 2 private final( static)? LC; [xyz]m?\$receiver
|
||||
// 0 LOCALVARIABLE [xyz]m? Lkotlin/reflect/KMutableProperty[0-2];
|
||||
// 12 static get[XYZ]m?\$delegate
|
||||
|
||||
|
||||
Reference in New Issue
Block a user