JVM_IR KT-45431 don't optimize out $$delegatedProperties in companion
Corresponding delegates are initialized in the host class, using '$$delegatedProperties'. TODO figure out proper code generation scheme for delegated properties in companions (KT-45580)
This commit is contained in:
committed by
TeamCityServer
parent
f6baabd98e
commit
73d4fa65ea
+6
@@ -12774,6 +12774,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt45431.kt")
|
||||
public void testKt45431() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt45431.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt6722.kt")
|
||||
public void testKt6722() throws Exception {
|
||||
|
||||
+5
-2
@@ -133,7 +133,10 @@ class ClassCodegen private constructor(
|
||||
irClass.functions.find { it.name.asString() == "<clinit>" }?.let { generateMethod(it, smap, delegatedPropertyOptimizer) }
|
||||
// 3. Now we have all the fields (`$$delegatedProperties` might be redundant if all reads were optimized out):
|
||||
for (field in irClass.fields) {
|
||||
if (field !== delegatedProperties || delegatedPropertyOptimizer?.needsDelegatedProperties == true) {
|
||||
if (field !== delegatedProperties ||
|
||||
delegatedPropertyOptimizer?.needsDelegatedProperties == true ||
|
||||
irClass.isCompanion
|
||||
) {
|
||||
generateField(field)
|
||||
}
|
||||
}
|
||||
@@ -326,7 +329,7 @@ class ClassCodegen private constructor(
|
||||
val (node, smap) = generateMethodNode(method)
|
||||
if (delegatedPropertyOptimizer != null) {
|
||||
delegatedPropertyOptimizer.transform(node)
|
||||
if (method.name.asString() == "<clinit>") {
|
||||
if (method.name.asString() == "<clinit>" && !irClass.isCompanion) {
|
||||
delegatedPropertyOptimizer.transformClassInitializer(node)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class DP {
|
||||
operator fun provideDelegate(t: Any?, kp: KProperty<*>) =
|
||||
lazy { "OK" }
|
||||
}
|
||||
|
||||
class H {
|
||||
companion object {
|
||||
val property: String by DP()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = H.property
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class DP {
|
||||
operator fun provideDelegate(t: Any?, kp: KProperty<*>) =
|
||||
lazy { "OK" }
|
||||
}
|
||||
|
||||
class H1 {
|
||||
companion object {
|
||||
val property: String by DP()
|
||||
}
|
||||
}
|
||||
|
||||
class H2 {
|
||||
companion object {
|
||||
val property: String by lazy { "OK" }
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
@kotlin.Metadata
|
||||
final class DP$provideDelegate$1 {
|
||||
// source: 'delegatedPropertiesInCompanionObject.kt'
|
||||
enclosing method DP.provideDelegate(Ljava/lang/Object;Lkotlin/reflect/KProperty;)Lkotlin/Lazy;
|
||||
public final static field INSTANCE: DP$provideDelegate$1
|
||||
inner (anonymous) class DP$provideDelegate$1
|
||||
static method <clinit>(): void
|
||||
method <init>(): void
|
||||
public synthetic bridge method invoke(): java.lang.Object
|
||||
public final @org.jetbrains.annotations.NotNull method invoke(): java.lang.String
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class DP {
|
||||
// source: 'delegatedPropertiesInCompanionObject.kt'
|
||||
inner (anonymous) class DP$provideDelegate$1
|
||||
public method <init>(): void
|
||||
public final @org.jetbrains.annotations.NotNull method provideDelegate(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.reflect.KProperty): kotlin.Lazy
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class H1$Companion {
|
||||
// source: 'delegatedPropertiesInCompanionObject.kt'
|
||||
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
|
||||
static method <clinit>(): void
|
||||
private method <init>(): void
|
||||
public synthetic method <init>(p0: kotlin.jvm.internal.DefaultConstructorMarker): void
|
||||
public final @org.jetbrains.annotations.NotNull method getProperty(): java.lang.String
|
||||
public final inner class H1$Companion
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class H1 {
|
||||
// source: 'delegatedPropertiesInCompanionObject.kt'
|
||||
public final static @org.jetbrains.annotations.NotNull field Companion: H1$Companion
|
||||
private final static @org.jetbrains.annotations.NotNull field property$delegate: kotlin.Lazy
|
||||
static method <clinit>(): void
|
||||
public method <init>(): void
|
||||
public synthetic final static method access$getProperty$cp(): kotlin.Lazy
|
||||
public final inner class H1$Companion
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
final class H2$Companion$property$2 {
|
||||
// source: 'delegatedPropertiesInCompanionObject.kt'
|
||||
enclosing class H2
|
||||
public final static field INSTANCE: H2$Companion$property$2
|
||||
inner (anonymous) class H2$Companion$property$2
|
||||
static method <clinit>(): void
|
||||
method <init>(): void
|
||||
public synthetic bridge method invoke(): java.lang.Object
|
||||
public final @org.jetbrains.annotations.NotNull method invoke(): java.lang.String
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class H2$Companion {
|
||||
// source: 'delegatedPropertiesInCompanionObject.kt'
|
||||
private method <init>(): void
|
||||
public synthetic method <init>(p0: kotlin.jvm.internal.DefaultConstructorMarker): void
|
||||
public final @org.jetbrains.annotations.NotNull method getProperty(): java.lang.String
|
||||
public final inner class H2$Companion
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class H2 {
|
||||
// source: 'delegatedPropertiesInCompanionObject.kt'
|
||||
public final static @org.jetbrains.annotations.NotNull field Companion: H2$Companion
|
||||
private final static @org.jetbrains.annotations.NotNull field property$delegate: kotlin.Lazy
|
||||
inner (anonymous) class H2$Companion$property$2
|
||||
static method <clinit>(): void
|
||||
public method <init>(): void
|
||||
public synthetic final static method access$getProperty$cp(): kotlin.Lazy
|
||||
public final inner class H2$Companion
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
@kotlin.Metadata
|
||||
final class DP$provideDelegate$1 {
|
||||
// source: 'delegatedPropertiesInCompanionObject.kt'
|
||||
enclosing method DP.provideDelegate(Ljava/lang/Object;Lkotlin/reflect/KProperty;)Lkotlin/Lazy;
|
||||
public final static field INSTANCE: DP$provideDelegate$1
|
||||
inner (anonymous) class DP$provideDelegate$1
|
||||
static method <clinit>(): void
|
||||
method <init>(): void
|
||||
public synthetic bridge method invoke(): java.lang.Object
|
||||
public final @org.jetbrains.annotations.NotNull method invoke(): java.lang.String
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class DP {
|
||||
// source: 'delegatedPropertiesInCompanionObject.kt'
|
||||
inner (anonymous) class DP$provideDelegate$1
|
||||
public method <init>(): void
|
||||
public final @org.jetbrains.annotations.NotNull method provideDelegate(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.reflect.KProperty): kotlin.Lazy
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class H1$Companion {
|
||||
// source: 'delegatedPropertiesInCompanionObject.kt'
|
||||
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
|
||||
static method <clinit>(): void
|
||||
private method <init>(): void
|
||||
public synthetic method <init>(p0: kotlin.jvm.internal.DefaultConstructorMarker): void
|
||||
public final @org.jetbrains.annotations.NotNull method getProperty(): java.lang.String
|
||||
public final inner class H1$Companion
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class H1 {
|
||||
// source: 'delegatedPropertiesInCompanionObject.kt'
|
||||
public final static @org.jetbrains.annotations.NotNull field Companion: H1$Companion
|
||||
private final static @org.jetbrains.annotations.NotNull field property$delegate: kotlin.Lazy
|
||||
static method <clinit>(): void
|
||||
public method <init>(): void
|
||||
public synthetic final static method access$getProperty$delegate$cp(): kotlin.Lazy
|
||||
public final inner class H1$Companion
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
final class H2$Companion$property$2 {
|
||||
// source: 'delegatedPropertiesInCompanionObject.kt'
|
||||
enclosing method H2.<clinit>()V
|
||||
public final static field INSTANCE: H2$Companion$property$2
|
||||
inner (anonymous) class H2$Companion$property$2
|
||||
static method <clinit>(): void
|
||||
method <init>(): void
|
||||
public synthetic bridge method invoke(): java.lang.Object
|
||||
public final @org.jetbrains.annotations.NotNull method invoke(): java.lang.String
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class H2$Companion {
|
||||
// source: 'delegatedPropertiesInCompanionObject.kt'
|
||||
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
|
||||
static method <clinit>(): void
|
||||
private method <init>(): void
|
||||
public synthetic method <init>(p0: kotlin.jvm.internal.DefaultConstructorMarker): void
|
||||
public final @org.jetbrains.annotations.NotNull method getProperty(): java.lang.String
|
||||
public final inner class H2$Companion
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class H2 {
|
||||
// source: 'delegatedPropertiesInCompanionObject.kt'
|
||||
public final static @org.jetbrains.annotations.NotNull field Companion: H2$Companion
|
||||
private final static @org.jetbrains.annotations.NotNull field property$delegate: kotlin.Lazy
|
||||
inner (anonymous) class H2$Companion$property$2
|
||||
static method <clinit>(): void
|
||||
public method <init>(): void
|
||||
public synthetic final static method access$getProperty$delegate$cp(): kotlin.Lazy
|
||||
public final inner class H2$Companion
|
||||
}
|
||||
+6
@@ -12774,6 +12774,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt45431.kt")
|
||||
public void testKt45431() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt45431.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt6722.kt")
|
||||
public void testKt6722() throws Exception {
|
||||
|
||||
+6
@@ -12774,6 +12774,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt45431.kt")
|
||||
public void testKt45431() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt45431.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt6722.kt")
|
||||
public void testKt6722() throws Exception {
|
||||
|
||||
+5
@@ -80,6 +80,11 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/defaultImpls.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegatedPropertiesInCompanionObject.kt")
|
||||
public void testDelegatedPropertiesInCompanionObject() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/delegatedPropertiesInCompanionObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegationToJavaInterfaceWithWildcardType.kt")
|
||||
public void testDelegationToJavaInterfaceWithWildcardType() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/delegationToJavaInterfaceWithWildcardType.kt");
|
||||
|
||||
+5
@@ -10411,6 +10411,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt45431.kt")
|
||||
public void testKt45431() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt45431.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt6722.kt")
|
||||
public void testKt6722() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt6722.kt");
|
||||
|
||||
+5
@@ -80,6 +80,11 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes
|
||||
runTest("compiler/testData/codegen/bytecodeListing/defaultImpls.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegatedPropertiesInCompanionObject.kt")
|
||||
public void testDelegatedPropertiesInCompanionObject() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/delegatedPropertiesInCompanionObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegationToJavaInterfaceWithWildcardType.kt")
|
||||
public void testDelegationToJavaInterfaceWithWildcardType() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/delegationToJavaInterfaceWithWildcardType.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -9294,6 +9294,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt45431.kt")
|
||||
public void testKt45431() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt45431.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt6722.kt")
|
||||
public void testKt6722() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt6722.kt");
|
||||
|
||||
Generated
+5
@@ -8751,6 +8751,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt45431.kt")
|
||||
public void testKt45431() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt45431.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt6722.kt")
|
||||
public void testKt6722() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt6722.kt");
|
||||
|
||||
Generated
+5
@@ -8751,6 +8751,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt4138.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt45431.kt")
|
||||
public void testKt45431() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt45431.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt6722.kt")
|
||||
public void testKt6722() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/kt6722.kt");
|
||||
|
||||
Reference in New Issue
Block a user