From 6cc293a0c5d61384354c54d3cc9764c15231c773 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 28 Mar 2019 14:16:04 +0100 Subject: [PATCH] JVM IR: record FIELD_FOR_PROPERTY for property delegates Delegated properties now have their $delegate fields recorded in the metadata (in `ClassCodegen.generateField`). This part of metadata is used by `KPropertyN.getDelegate` functions, so almost all tests on getDelegate are now unmuted --- .../generators/DelegatedPropertyGenerator.kt | 14 +++++++++++--- .../getDelegate/booleanPropertyNameStartsWithIs.kt | 1 - .../getDelegate/boundExtensionProperty.kt | 1 - .../properties/getDelegate/boundMemberProperty.kt | 1 - .../properties/getDelegate/extensionProperty.kt | 1 - .../properties/getDelegate/getExtensionDelegate.kt | 1 - .../getDelegate/kPropertyForDelegatedProperty.kt | 1 - .../getDelegate/memberExtensionProperty.kt | 1 - .../properties/getDelegate/memberProperty.kt | 1 - .../getDelegate/nameClashClassAndCompanion.kt | 1 - .../properties/getDelegate/noSetAccessibleTrue.kt | 4 +--- .../getDelegate/overrideDelegatedByDelegated.kt | 1 - .../properties/getDelegate/topLevelProperty.kt | 1 - .../ir/semantics/IrJsCodegenBoxTestGenerated.java | 5 ----- .../test/semantics/JsCodegenBoxTestGenerated.java | 5 ----- 15 files changed, 12 insertions(+), 27 deletions(-) diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DelegatedPropertyGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DelegatedPropertyGenerator.kt index db4c4dfe0b4..35b4d4337ad 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DelegatedPropertyGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DelegatedPropertyGenerator.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.ir.builders.irBlockBody import org.jetbrains.kotlin.ir.builders.irGet import org.jetbrains.kotlin.ir.builders.irReturn import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl import org.jetbrains.kotlin.ir.descriptors.IrLocalDelegatedPropertyDelegateDescriptor import org.jetbrains.kotlin.ir.descriptors.IrLocalDelegatedPropertyDelegateDescriptorImpl import org.jetbrains.kotlin.ir.descriptors.IrPropertyDelegateDescriptor @@ -122,10 +123,17 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D val delegateType = getDelegatedPropertyDelegateType(propertyDescriptor, ktDelegate) val delegateDescriptor = createPropertyDelegateDescriptor(propertyDescriptor, delegateType, kPropertyType) + val startOffset = ktDelegate.startOffsetSkippingComments + val endOffset = ktDelegate.endOffset + val origin = IrDeclarationOrigin.DELEGATE + val type = delegateDescriptor.type.toIrType() return context.symbolTable.declareField( - ktDelegate.startOffsetSkippingComments, ktDelegate.endOffset, IrDeclarationOrigin.DELEGATE, - delegateDescriptor, delegateDescriptor.type.toIrType() - ).also { irDelegate -> + startOffset, endOffset, origin, delegateDescriptor, type + ) { + IrFieldImpl(startOffset, endOffset, origin, it, type).apply { + metadata = MetadataSource.Property(propertyDescriptor) + } + }.also { irDelegate -> irDelegate.initializer = generateInitializerBodyForPropertyDelegate( propertyDescriptor, kPropertyType, ktDelegate, irDelegate.symbol diff --git a/compiler/testData/codegen/box/reflection/properties/getDelegate/booleanPropertyNameStartsWithIs.kt b/compiler/testData/codegen/box/reflection/properties/getDelegate/booleanPropertyNameStartsWithIs.kt index 54347b3c7bd..bd50b053c4b 100644 --- a/compiler/testData/codegen/box/reflection/properties/getDelegate/booleanPropertyNameStartsWithIs.kt +++ b/compiler/testData/codegen/box/reflection/properties/getDelegate/booleanPropertyNameStartsWithIs.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/codegen/box/reflection/properties/getDelegate/boundExtensionProperty.kt b/compiler/testData/codegen/box/reflection/properties/getDelegate/boundExtensionProperty.kt index 88177e4fc43..ce58b02ff28 100644 --- a/compiler/testData/codegen/box/reflection/properties/getDelegate/boundExtensionProperty.kt +++ b/compiler/testData/codegen/box/reflection/properties/getDelegate/boundExtensionProperty.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/codegen/box/reflection/properties/getDelegate/boundMemberProperty.kt b/compiler/testData/codegen/box/reflection/properties/getDelegate/boundMemberProperty.kt index 3b6a0298ce5..9e8b6dbbc18 100644 --- a/compiler/testData/codegen/box/reflection/properties/getDelegate/boundMemberProperty.kt +++ b/compiler/testData/codegen/box/reflection/properties/getDelegate/boundMemberProperty.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/codegen/box/reflection/properties/getDelegate/extensionProperty.kt b/compiler/testData/codegen/box/reflection/properties/getDelegate/extensionProperty.kt index 8a4ea814a47..7289f71d279 100644 --- a/compiler/testData/codegen/box/reflection/properties/getDelegate/extensionProperty.kt +++ b/compiler/testData/codegen/box/reflection/properties/getDelegate/extensionProperty.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/codegen/box/reflection/properties/getDelegate/getExtensionDelegate.kt b/compiler/testData/codegen/box/reflection/properties/getDelegate/getExtensionDelegate.kt index fa457393183..82f8e2b3c04 100644 --- a/compiler/testData/codegen/box/reflection/properties/getDelegate/getExtensionDelegate.kt +++ b/compiler/testData/codegen/box/reflection/properties/getDelegate/getExtensionDelegate.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/codegen/box/reflection/properties/getDelegate/kPropertyForDelegatedProperty.kt b/compiler/testData/codegen/box/reflection/properties/getDelegate/kPropertyForDelegatedProperty.kt index 2295be4edee..812fb5c1c1f 100644 --- a/compiler/testData/codegen/box/reflection/properties/getDelegate/kPropertyForDelegatedProperty.kt +++ b/compiler/testData/codegen/box/reflection/properties/getDelegate/kPropertyForDelegatedProperty.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/codegen/box/reflection/properties/getDelegate/memberExtensionProperty.kt b/compiler/testData/codegen/box/reflection/properties/getDelegate/memberExtensionProperty.kt index f080d575de0..704f8f5c741 100644 --- a/compiler/testData/codegen/box/reflection/properties/getDelegate/memberExtensionProperty.kt +++ b/compiler/testData/codegen/box/reflection/properties/getDelegate/memberExtensionProperty.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/codegen/box/reflection/properties/getDelegate/memberProperty.kt b/compiler/testData/codegen/box/reflection/properties/getDelegate/memberProperty.kt index ccf7751822c..c00d4580c2f 100644 --- a/compiler/testData/codegen/box/reflection/properties/getDelegate/memberProperty.kt +++ b/compiler/testData/codegen/box/reflection/properties/getDelegate/memberProperty.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/codegen/box/reflection/properties/getDelegate/nameClashClassAndCompanion.kt b/compiler/testData/codegen/box/reflection/properties/getDelegate/nameClashClassAndCompanion.kt index 912c4d26267..e6b948f9615 100644 --- a/compiler/testData/codegen/box/reflection/properties/getDelegate/nameClashClassAndCompanion.kt +++ b/compiler/testData/codegen/box/reflection/properties/getDelegate/nameClashClassAndCompanion.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/codegen/box/reflection/properties/getDelegate/noSetAccessibleTrue.kt b/compiler/testData/codegen/box/reflection/properties/getDelegate/noSetAccessibleTrue.kt index 5efbe4e067c..9b7a170c2c0 100644 --- a/compiler/testData/codegen/box/reflection/properties/getDelegate/noSetAccessibleTrue.kt +++ b/compiler/testData/codegen/box/reflection/properties/getDelegate/noSetAccessibleTrue.kt @@ -1,6 +1,4 @@ -// IGNORE_BACKEND: JVM_IR -// IGNORE_BACKEND: JS_IR -// IGNORE_BACKEND: JS, NATIVE +// TARGET_BACKEND: JVM // WITH_REFLECT import kotlin.reflect.KProperty diff --git a/compiler/testData/codegen/box/reflection/properties/getDelegate/overrideDelegatedByDelegated.kt b/compiler/testData/codegen/box/reflection/properties/getDelegate/overrideDelegatedByDelegated.kt index 56f7d1ea823..f263ec2a738 100644 --- a/compiler/testData/codegen/box/reflection/properties/getDelegate/overrideDelegatedByDelegated.kt +++ b/compiler/testData/codegen/box/reflection/properties/getDelegate/overrideDelegatedByDelegated.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/codegen/box/reflection/properties/getDelegate/topLevelProperty.kt b/compiler/testData/codegen/box/reflection/properties/getDelegate/topLevelProperty.kt index e507a96394a..140a97f9e23 100644 --- a/compiler/testData/codegen/box/reflection/properties/getDelegate/topLevelProperty.kt +++ b/compiler/testData/codegen/box/reflection/properties/getDelegate/topLevelProperty.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 8caf811a11f..2c16aadc58e 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -16585,11 +16585,6 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { public void testAllFilesPresentInGetDelegate() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/reflection/properties/getDelegate"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true); } - - @TestMetadata("noSetAccessibleTrue.kt") - public void testNoSetAccessibleTrue() throws Exception { - runTest("compiler/testData/codegen/box/reflection/properties/getDelegate/noSetAccessibleTrue.kt"); - } } @TestMetadata("compiler/testData/codegen/box/reflection/properties/jvmField") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 8184d29b9ee..d7bb42f85d1 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -17730,11 +17730,6 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { public void testAllFilesPresentInGetDelegate() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/reflection/properties/getDelegate"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); } - - @TestMetadata("noSetAccessibleTrue.kt") - public void testNoSetAccessibleTrue() throws Exception { - runTest("compiler/testData/codegen/box/reflection/properties/getDelegate/noSetAccessibleTrue.kt"); - } } @TestMetadata("compiler/testData/codegen/box/reflection/properties/jvmField")