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,13 @@
// WITH_STDLIB
// CHECK_BYTECODE_LISTING
enum class E {
OK, NOT_OK
}
operator fun E.getValue(thisRef: Any?, property: Any?): String =
if (this == E.OK && thisRef == null) "OK" else "Failed"
val s: String by E.OK
fun box(): String = s
@@ -0,0 +1,22 @@
@kotlin.Metadata
public final class DelegateToEnumKt {
// source: 'delegateToEnum.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final static @org.jetbrains.annotations.NotNull field s$delegate: E
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.NotNull p0: E, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.Nullable p2: java.lang.Object): java.lang.String
}
@kotlin.Metadata
public final enum class E {
// source: 'delegateToEnum.kt'
private synthetic final static field $VALUES: E[]
public final enum static field NOT_OK: E
public final enum static field OK: 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[]
}
@@ -0,0 +1,17 @@
// WITH_STDLIB
// CHECK_BYTECODE_LISTING
enum class E {
OK, NOT_OK
}
class C {
val s: String by E.OK
}
val c = C()
operator fun E.getValue(thisRef: Any?, property: Any?): String =
if (this == E.OK && thisRef == c) "OK" else "Failed"
fun box(): String = c.s
@@ -0,0 +1,31 @@
@kotlin.Metadata
public final class C {
// source: 'delegateToEnumInAClass.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final @org.jetbrains.annotations.NotNull field s$delegate: E
static method <clinit>(): void
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getS(): java.lang.String
}
@kotlin.Metadata
public final class DelegateToEnumInAClassKt {
// source: 'delegateToEnumInAClass.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.NotNull p0: E, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.Nullable p2: java.lang.Object): java.lang.String
}
@kotlin.Metadata
public final enum class E {
// source: 'delegateToEnumInAClass.kt'
private synthetic final static field $VALUES: E[]
public final enum static field NOT_OK: E
public final enum static field OK: 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[]
}
@@ -0,0 +1,32 @@
@kotlin.Metadata
public final class C {
// source: 'delegateToEnumInAClass.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
static method <clinit>(): void
public method <init>(): void
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 DelegateToEnumInAClassKt {
// source: 'delegateToEnumInAClass.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.NotNull p0: E, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.Nullable p2: java.lang.Object): java.lang.String
}
@kotlin.Metadata
public final enum class E {
// source: 'delegateToEnumInAClass.kt'
private synthetic final static field $VALUES: E[]
public final enum static field NOT_OK: E
public final enum static field OK: 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[]
}
@@ -0,0 +1,23 @@
@kotlin.Metadata
public final class DelegateToEnumKt {
// source: 'delegateToEnum.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.NotNull p0: E, @org.jetbrains.annotations.Nullable p1: java.lang.Object, @org.jetbrains.annotations.Nullable p2: java.lang.Object): java.lang.String
}
@kotlin.Metadata
public final enum class E {
// source: 'delegateToEnum.kt'
private synthetic final static field $VALUES: E[]
public final enum static field NOT_OK: E
public final enum static field OK: 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[]
}
@@ -0,0 +1,25 @@
// WITH_STDLIB
// CHECK_BYTECODE_LISTING
// IGNORE_BACKEND: JS_IR
import kotlin.reflect.KProperty
import kotlin.test.assertEquals
object Store {
private val map = mutableMapOf<Pair<Any?, KProperty<*>>, String?>()
operator fun getValue(thisRef: Any?, property: KProperty<*>): String? = map[thisRef to property]
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String?) {
map[thisRef to property] = value
}
}
object O {
var s: String? by Store
}
fun box(): String? {
O.s = "OK"
return O.s
}
@@ -0,0 +1,28 @@
@kotlin.Metadata
public final class DelegateToSingletonKt {
// source: 'delegateToSingleton.kt'
public final static @org.jetbrains.annotations.Nullable method box(): java.lang.String
}
@kotlin.Metadata
public final class O {
// source: 'delegateToSingleton.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
public final static @org.jetbrains.annotations.NotNull field INSTANCE: O
private final static @org.jetbrains.annotations.Nullable field s$delegate: Store
static method <clinit>(): void
private method <init>(): void
public final @org.jetbrains.annotations.Nullable method getS(): java.lang.String
public final method setS(@org.jetbrains.annotations.Nullable p0: java.lang.String): void
}
@kotlin.Metadata
public final class Store {
// source: 'delegateToSingleton.kt'
public final static @org.jetbrains.annotations.NotNull field INSTANCE: Store
private final static field map: java.util.Map
static method <clinit>(): void
private method <init>(): void
public final @org.jetbrains.annotations.Nullable method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.reflect.KProperty): java.lang.String
public final method setValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.reflect.KProperty, @org.jetbrains.annotations.Nullable p2: java.lang.String): void
}
@@ -0,0 +1,28 @@
@kotlin.Metadata
public final class DelegateToSingletonKt {
// source: 'delegateToSingleton.kt'
public final static @org.jetbrains.annotations.Nullable method box(): java.lang.String
}
@kotlin.Metadata
public final class O {
// source: 'delegateToSingleton.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
public final static @org.jetbrains.annotations.NotNull field INSTANCE: O
static method <clinit>(): void
private method <init>(): void
private static method getS$delegate(p0: O): java.lang.Object
public final @org.jetbrains.annotations.Nullable method getS(): java.lang.String
public final method setS(@org.jetbrains.annotations.Nullable p0: java.lang.String): void
}
@kotlin.Metadata
public final class Store {
// source: 'delegateToSingleton.kt'
public final static @org.jetbrains.annotations.NotNull field INSTANCE: Store
private final static @org.jetbrains.annotations.NotNull field map: java.util.Map
static method <clinit>(): void
private method <init>(): void
public final @org.jetbrains.annotations.Nullable method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.reflect.KProperty): java.lang.String
public final method setValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.reflect.KProperty, @org.jetbrains.annotations.Nullable p2: java.lang.String): void
}
@@ -0,0 +1,15 @@
// WITH_STDLIB
// CHECK_BYTECODE_LISTING
object O {
object P
init {
throw IllegalStateException("O should not be initialized")
}
}
operator fun O.P.getValue(thisRef: Any?, property: Any?) = if (thisRef == null) "OK" else "Failed"
val result by O.P
fun box(): String = result
@@ -0,0 +1,28 @@
@kotlin.Metadata
public final class NoInitializationOfOuterClassKt {
// source: 'noInitializationOfOuterClass.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final static @org.jetbrains.annotations.NotNull field result$delegate: O$P
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
public final static @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.NotNull p0: O$P, @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$P {
// source: 'noInitializationOfOuterClass.kt'
public final static @org.jetbrains.annotations.NotNull field INSTANCE: O$P
static method <clinit>(): void
private method <init>(): void
public final inner class O$P
}
@kotlin.Metadata
public final class O {
// source: 'noInitializationOfOuterClass.kt'
public final static @org.jetbrains.annotations.NotNull field INSTANCE: O
static method <clinit>(): void
private method <init>(): void
public final inner class O$P
}
@@ -0,0 +1,28 @@
@kotlin.Metadata
public final class NoInitializationOfOuterClassKt {
// source: 'noInitializationOfOuterClass.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 getResult$delegate(): java.lang.Object
public final static @org.jetbrains.annotations.NotNull method getResult(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.NotNull p0: O$P, @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$P {
// source: 'noInitializationOfOuterClass.kt'
public final static @org.jetbrains.annotations.NotNull field INSTANCE: O$P
static method <clinit>(): void
private method <init>(): void
public final inner class O$P
}
@kotlin.Metadata
public final class O {
// source: 'noInitializationOfOuterClass.kt'
public final static @org.jetbrains.annotations.NotNull field INSTANCE: O
static method <clinit>(): void
private method <init>(): void
public final inner class O$P
}
@@ -0,0 +1,23 @@
// WITH_STDLIB
// CHECK_BYTECODE_LISTING
var initialized = false
object O {
init {
initialized = true
}
operator fun getValue(x: Any?, y: Any?): String {
throw RuntimeException()
}
}
class C {
val s: String by O
}
fun box(): String {
val c = C()
return if (initialized) "OK" else "FAILURE"
}
@@ -0,0 +1,27 @@
@kotlin.Metadata
public final class C {
// source: 'withSideEffects.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final @org.jetbrains.annotations.NotNull field s$delegate: O
static method <clinit>(): void
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getS(): java.lang.String
}
@kotlin.Metadata
public final class O {
// source: 'withSideEffects.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 getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.String
}
@kotlin.Metadata
public final class WithSideEffectsKt {
// source: 'withSideEffects.kt'
private static field initialized: boolean
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static method getInitialized(): boolean
public final static method setInitialized(p0: boolean): void
}
@@ -0,0 +1,19 @@
// WITH_STDLIB
// CHECK_BYTECODE_LISTING
var initialized = false
object O {
init {
initialized = true
}
operator fun getValue(x: Any?, y: Any?): String {
throw RuntimeException()
}
}
val s: String by O
fun box(): String = if (initialized) "OK" else "FAILURE"
@@ -0,0 +1,21 @@
@kotlin.Metadata
public final class O {
// source: 'withSideEffectsFromFileClass.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 getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.String
}
@kotlin.Metadata
public final class WithSideEffectsFromFileClassKt {
// source: 'withSideEffectsFromFileClass.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private static field initialized: boolean
private final static @org.jetbrains.annotations.NotNull field s$delegate: O
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static method getInitialized(): boolean
public final static @org.jetbrains.annotations.NotNull method getS(): java.lang.String
public final static method setInitialized(p0: boolean): void
}
@@ -0,0 +1,21 @@
@kotlin.Metadata
public final class O {
// source: 'withSideEffectsFromFileClass.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 getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.String
}
@kotlin.Metadata
public final class WithSideEffectsFromFileClassKt {
// source: 'withSideEffectsFromFileClass.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private static field initialized: boolean
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static method getInitialized(): boolean
private static method getS$delegate(): java.lang.Object
public final static @org.jetbrains.annotations.NotNull method getS(): java.lang.String
public final static method setInitialized(p0: boolean): void
}
@@ -0,0 +1,22 @@
// WITH_STDLIB
// CHECK_BYTECODE_LISTING
var initialized = false
enum class E {
X;
companion object {
init {
initialized = true
}
}
}
operator fun Any?.getValue(x: Any?, y: Any?): String {
throw RuntimeException()
}
val result by E.X
fun box() = if (initialized) "OK" else "FAILURE"
@@ -0,0 +1,34 @@
@kotlin.Metadata
public final class E$Companion {
// source: 'withSideEffectsToEnum.kt'
private method <init>(): void
public synthetic method <init>(p0: kotlin.jvm.internal.DefaultConstructorMarker): void
public final inner class E$Companion
}
@kotlin.Metadata
public final enum class E {
// source: 'withSideEffectsToEnum.kt'
private synthetic final static field $VALUES: E[]
public final static @org.jetbrains.annotations.NotNull field Companion: E$Companion
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[]
public final inner class E$Companion
}
@kotlin.Metadata
public final class WithSideEffectsToEnumKt {
// source: 'withSideEffectsToEnum.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private static field initialized: boolean
private final static @org.jetbrains.annotations.NotNull field result$delegate: E
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static method getInitialized(): boolean
public final static @org.jetbrains.annotations.NotNull method getResult(): 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
public final static method setInitialized(p0: boolean): void
}
@@ -0,0 +1,35 @@
@kotlin.Metadata
public final class E$Companion {
// source: 'withSideEffectsToEnum.kt'
private method <init>(): void
public synthetic method <init>(p0: kotlin.jvm.internal.DefaultConstructorMarker): void
public final inner class E$Companion
}
@kotlin.Metadata
public final enum class E {
// source: 'withSideEffectsToEnum.kt'
private synthetic final static field $VALUES: E[]
public final static @org.jetbrains.annotations.NotNull field Companion: E$Companion
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[]
public final inner class E$Companion
}
@kotlin.Metadata
public final class WithSideEffectsToEnumKt {
// source: 'withSideEffectsToEnum.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private static field initialized: boolean
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static method getInitialized(): boolean
private static method getResult$delegate(): java.lang.Object
public final static @org.jetbrains.annotations.NotNull method getResult(): 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
public final static method setInitialized(p0: boolean): void
}
@@ -0,0 +1,28 @@
@kotlin.Metadata
public final class C {
// source: 'withSideEffects.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
static method <clinit>(): void
public method <init>(): void
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 O {
// source: 'withSideEffects.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 getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.String
}
@kotlin.Metadata
public final class WithSideEffectsKt {
// source: 'withSideEffects.kt'
private static field initialized: boolean
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static method getInitialized(): boolean
public final static method setInitialized(p0: boolean): void
}