KT-23397 Optimize out field for property delegate when it's safe (JVM)

This commit is contained in:
Pavel Mikhailovskii
2022-06-03 16:54:12 +02:00
committed by teamcity
parent 9ee0268197
commit 65b2cee913
83 changed files with 3015 additions and 19 deletions
@@ -0,0 +1,26 @@
// CHECK_BYTECODE_LISTING
class A {
val b = B()
}
class B {
val c = C()
}
class C {
val d = D()
}
class D {
val e = 1
}
val a = A()
operator fun Int.getValue(thisRef: Any?, property: Any?) =
if (this == 1 && thisRef == null) "OK" else "Failed"
val x by a.b.c.d.e
fun box() = x
@@ -0,0 +1,44 @@
@kotlin.Metadata
public final class A {
// source: 'chain.kt'
private final @org.jetbrains.annotations.NotNull field b: B
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getB(): B
}
@kotlin.Metadata
public final class B {
// source: 'chain.kt'
private final @org.jetbrains.annotations.NotNull field c: C
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getC(): C
}
@kotlin.Metadata
public final class C {
// source: 'chain.kt'
private final @org.jetbrains.annotations.NotNull field d: D
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getD(): D
}
@kotlin.Metadata
public final class ChainKt {
// source: 'chain.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final static @org.jetbrains.annotations.NotNull field a: A
private final static field x$delegate: int
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getA(): A
public final static @org.jetbrains.annotations.NotNull method getValue(p0: int, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.Nullable p2: java.lang.Object): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getX(): java.lang.String
}
@kotlin.Metadata
public final class D {
// source: 'chain.kt'
private final field e: int
public method <init>(): void
public final method getE(): int
}
@@ -0,0 +1,44 @@
@kotlin.Metadata
public final class A {
// source: 'chain.kt'
private final @org.jetbrains.annotations.NotNull field b: B
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getB(): B
}
@kotlin.Metadata
public final class B {
// source: 'chain.kt'
private final @org.jetbrains.annotations.NotNull field c: C
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getC(): C
}
@kotlin.Metadata
public final class C {
// source: 'chain.kt'
private final @org.jetbrains.annotations.NotNull field d: D
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getD(): D
}
@kotlin.Metadata
public final class ChainKt {
// source: 'chain.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final static @org.jetbrains.annotations.NotNull field a: A
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getA(): A
public final static @org.jetbrains.annotations.NotNull method getValue(p0: int, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.Nullable p2: java.lang.Object): java.lang.String
private static method getX$delegate(): java.lang.Object
public final static @org.jetbrains.annotations.NotNull method getX(): java.lang.String
}
@kotlin.Metadata
public final class D {
// source: 'chain.kt'
private final field e: int
public method <init>(): void
public final method getE(): int
}
@@ -0,0 +1,14 @@
// CHECK_BYTECODE_LISTING
class C {
val impl = 123
val s: String by impl
}
val c = C()
operator fun Any?.getValue(thisRef: Any?, property: Any?) =
if (this == 123 && thisRef == c) "OK" else "Failed"
fun box() = c.s
@@ -0,0 +1,21 @@
@kotlin.Metadata
public final class C {
// source: 'delegateToFinalInstanceProperty.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final field impl: int
private final field s$delegate: int
static method <clinit>(): void
public method <init>(): void
public final method getImpl(): int
public final @org.jetbrains.annotations.NotNull method getS(): java.lang.String
}
@kotlin.Metadata
public final class DelegateToFinalInstancePropertyKt {
// source: 'delegateToFinalInstanceProperty.kt'
private final static @org.jetbrains.annotations.NotNull field c: C
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getC(): C
public final static @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.Nullable p2: java.lang.Object): java.lang.String
}
@@ -0,0 +1,21 @@
@kotlin.Metadata
public final class C {
// source: 'delegateToFinalInstanceProperty.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final field impl: int
static method <clinit>(): void
public method <init>(): void
public final method getImpl(): int
private static method getS$delegate(p0: C): java.lang.Object
public final @org.jetbrains.annotations.NotNull method getS(): java.lang.String
}
@kotlin.Metadata
public final class DelegateToFinalInstancePropertyKt {
// source: 'delegateToFinalInstanceProperty.kt'
private final static @org.jetbrains.annotations.NotNull field c: C
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getC(): C
public final static @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.Nullable p2: java.lang.Object): java.lang.String
}
@@ -0,0 +1,12 @@
// CHECK_BYTECODE_LISTING
object O {
val impl = 123
}
operator fun Any?.getValue(thisRef: Any?, property: Any?) =
if (this == 123 && thisRef == null) "OK" else "Failed"
val s: String by O.impl
fun box() = s
@@ -0,0 +1,20 @@
@kotlin.Metadata
public final class DelegateToFinalObjectPropertyKt {
// source: 'delegateToFinalObjectProperty.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final static field s$delegate: int
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getS(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.Nullable p2: java.lang.Object): java.lang.String
}
@kotlin.Metadata
public final class O {
// source: 'delegateToFinalObjectProperty.kt'
public final static @org.jetbrains.annotations.NotNull field INSTANCE: O
private final static field impl: int
static method <clinit>(): void
private method <init>(): void
public final method getImpl(): int
}
@@ -0,0 +1,20 @@
@kotlin.Metadata
public final class DelegateToFinalObjectPropertyKt {
// source: 'delegateToFinalObjectProperty.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
private static method getS$delegate(): java.lang.Object
public final static @org.jetbrains.annotations.NotNull method getS(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.Nullable p2: java.lang.Object): java.lang.String
}
@kotlin.Metadata
public final class O {
// source: 'delegateToFinalObjectProperty.kt'
public final static @org.jetbrains.annotations.NotNull field INSTANCE: O
private final static field impl: int
static method <clinit>(): void
private method <init>(): void
public final method getImpl(): int
}
@@ -0,0 +1,10 @@
// CHECK_BYTECODE_LISTING
val impl = 123
operator fun Any?.getValue(thisRef: Any?, property: Any?) =
if (this == 123 && thisRef == null) "OK" else "Failed"
val s: String by impl
fun box() = s
@@ -0,0 +1,12 @@
@kotlin.Metadata
public final class DelegateToFinalPropertyKt {
// source: 'delegateToFinalProperty.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final static field impl: int
private final static field s$delegate: int
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static method getImpl(): int
public final static @org.jetbrains.annotations.NotNull method getS(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.Nullable p2: java.lang.Object): java.lang.String
}
@@ -0,0 +1,12 @@
@kotlin.Metadata
public final class DelegateToFinalPropertyKt {
// source: 'delegateToFinalProperty.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final static field impl: int
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static method getImpl(): int
private static method getS$delegate(): java.lang.Object
public final static @org.jetbrains.annotations.NotNull method getS(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.Nullable p2: java.lang.Object): java.lang.String
}
@@ -0,0 +1,12 @@
// CHECK_BYTECODE_LISTING
//FILE file1.kt
val impl = 123
//FILE file2.kt
operator fun Any?.getValue(thisRef: Any?, property: Any?) =
if (this == 123 && thisRef == null) "OK" else "Failed"
val s: String by impl
fun box() = s
@@ -0,0 +1,12 @@
@kotlin.Metadata
public final class FinalPropertyInAnotherFileKt {
// source: 'finalPropertyInAnotherFile.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final static field impl: int
private final static field s$delegate: int
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static method getImpl(): int
public final static @org.jetbrains.annotations.NotNull method getS(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.Nullable p2: java.lang.Object): java.lang.String
}
@@ -0,0 +1,12 @@
@kotlin.Metadata
public final class FinalPropertyInAnotherFileKt {
// source: 'finalPropertyInAnotherFile.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final static field impl: int
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static method getImpl(): int
private static method getS$delegate(): java.lang.Object
public final static @org.jetbrains.annotations.NotNull method getS(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.Nullable p2: java.lang.Object): java.lang.String
}
@@ -0,0 +1,18 @@
// FILE: 1.kt
var result = "Fail"
val unused by c
fun box(): String = result
// FILE: 2.kt
class C {
init {
result = "OK"
}
}
operator fun C.getValue(x: Any?, y: Any?): String = throw IllegalStateException()
val c = C()
@@ -0,0 +1,18 @@
// CHECK_BYTECODE_LISTING
import O.d
enum class E { X }
object O {
val E.d: Delegate get() = Delegate()
}
class Delegate {
operator fun getValue(thisRef: Any?, property: Any?) =
if (thisRef == null) "OK" else "Failed"
}
val result by E.X.d
fun box(): String = result
@@ -0,0 +1,36 @@
@kotlin.Metadata
public final class Delegate {
// source: 'memberExtensionPropertyAndImportFromObject.kt'
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.String
}
@kotlin.Metadata
public final enum class E {
// source: 'memberExtensionPropertyAndImportFromObject.kt'
private synthetic final static field $VALUES: E[]
public final enum static field X: E
static method <clinit>(): void
private method <init>(p0: java.lang.String, p1: int): void
public static method valueOf(p0: java.lang.String): E
public static method values(): E[]
}
@kotlin.Metadata
public final class MemberExtensionPropertyAndImportFromObjectKt {
// source: 'memberExtensionPropertyAndImportFromObject.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final static @org.jetbrains.annotations.NotNull field result$delegate: Delegate
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getResult(): java.lang.String
}
@kotlin.Metadata
public final class O {
// source: 'memberExtensionPropertyAndImportFromObject.kt'
public final static @org.jetbrains.annotations.NotNull field INSTANCE: O
static method <clinit>(): void
private method <init>(): void
public final @org.jetbrains.annotations.NotNull method getD(@org.jetbrains.annotations.NotNull p0: E): Delegate
}
@@ -0,0 +1,37 @@
@kotlin.Metadata
public final class Delegate {
// source: 'memberExtensionPropertyAndImportFromObject.kt'
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.String
}
@kotlin.Metadata
public final enum class E {
// source: 'memberExtensionPropertyAndImportFromObject.kt'
private synthetic final static field $VALUES: E[]
public final enum static field X: E
private synthetic final static method $values(): E[]
static method <clinit>(): void
private method <init>(p0: java.lang.String, p1: int): void
public static method valueOf(p0: java.lang.String): E
public static method values(): E[]
}
@kotlin.Metadata
public final class MemberExtensionPropertyAndImportFromObjectKt {
// source: 'memberExtensionPropertyAndImportFromObject.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final static @org.jetbrains.annotations.NotNull field result$delegate: Delegate
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getResult(): java.lang.String
}
@kotlin.Metadata
public final class O {
// source: 'memberExtensionPropertyAndImportFromObject.kt'
public final static @org.jetbrains.annotations.NotNull field INSTANCE: O
static method <clinit>(): void
private method <init>(): void
public final @org.jetbrains.annotations.NotNull method getD(@org.jetbrains.annotations.NotNull p0: E): Delegate
}
@@ -0,0 +1,17 @@
// CHECK_BYTECODE_LISTING
enum class E { X }
object O {
val E.d: Delegate get() = Delegate()
}
class Delegate {
operator fun getValue(thisRef: Any?, property: Any?) =
if (thisRef == null) "OK" else "Failed"
}
fun box(): String = with(O) {
val result by E.X.d
result
}
@@ -0,0 +1,34 @@
@kotlin.Metadata
public final class Delegate {
// source: 'memberExtensionPropertyAndLocalDelegatedProperty.kt'
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.String
}
@kotlin.Metadata
public final enum class E {
// source: 'memberExtensionPropertyAndLocalDelegatedProperty.kt'
private synthetic final static field $VALUES: E[]
public final enum static field X: E
static method <clinit>(): void
private method <init>(p0: java.lang.String, p1: int): void
public static method valueOf(p0: java.lang.String): E
public static method values(): E[]
}
@kotlin.Metadata
public final class MemberExtensionPropertyAndLocalDelegatedPropertyKt {
// source: 'memberExtensionPropertyAndLocalDelegatedProperty.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
}
@kotlin.Metadata
public final class O {
// source: 'memberExtensionPropertyAndLocalDelegatedProperty.kt'
public final static @org.jetbrains.annotations.NotNull field INSTANCE: O
static method <clinit>(): void
private method <init>(): void
public final @org.jetbrains.annotations.NotNull method getD(@org.jetbrains.annotations.NotNull p0: E): Delegate
}
@@ -0,0 +1,36 @@
@kotlin.Metadata
public final class Delegate {
// source: 'memberExtensionPropertyAndLocalDelegatedProperty.kt'
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.String
}
@kotlin.Metadata
public final enum class E {
// source: 'memberExtensionPropertyAndLocalDelegatedProperty.kt'
private synthetic final static field $VALUES: E[]
public final enum static field X: E
private synthetic final static method $values(): E[]
static method <clinit>(): void
private method <init>(p0: java.lang.String, p1: int): void
public static method valueOf(p0: java.lang.String): E
public static method values(): E[]
}
@kotlin.Metadata
public final class MemberExtensionPropertyAndLocalDelegatedPropertyKt {
// source: 'memberExtensionPropertyAndLocalDelegatedProperty.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
static method <clinit>(): void
private final static method box$lambda-1$lambda-0(p0: Delegate): java.lang.String
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
}
@kotlin.Metadata
public final class O {
// source: 'memberExtensionPropertyAndLocalDelegatedProperty.kt'
public final static @org.jetbrains.annotations.NotNull field INSTANCE: O
static method <clinit>(): void
private method <init>(): void
public final @org.jetbrains.annotations.NotNull method getD(@org.jetbrains.annotations.NotNull p0: E): Delegate
}
@@ -0,0 +1,14 @@
// TARGET_BACKEND: JVM
// CHECK_BYTECODE_LISTING
// MODULE: lib
// FILE: file1.kt
val impl = 123
// MODULE: main(lib)
// FILE: file2.kt
operator fun Any?.getValue(thisRef: Any?, property: Any?) = "OK"
val s: String by impl
fun box() = s
@@ -0,0 +1,19 @@
Module: lib
@kotlin.Metadata
public final class File1Kt {
// source: 'file1.kt'
private final static field impl: int
static method <clinit>(): void
public final static method getImpl(): int
}
Module: main
@kotlin.Metadata
public final class File2Kt {
// source: 'file2.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final static field s$delegate: int
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getS(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.Nullable p2: java.lang.Object): java.lang.String
}