diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/utils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/utils.kt index 5b6215d1895..ee719ee84b3 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/utils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/utils.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.backend.konan.descriptors import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.serialization.deserialization.descriptors.* +import org.jetbrains.kotlin.serialization.KonanLinkData import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.FqName @@ -45,11 +46,11 @@ fun ClassDescriptor?.signature2Descriptor(methodName: Name, signature:Array { // TODO: Here's what is going on here: // The existence of a backing field for a property is only described in the IR, - // but not in the property descriptor. - // That works, while we process the IR, but not for deserialized descriptors. + // but not in the PropertyDescriptor. // - // So to have something in deserialized descriptors, - // while we still see the IR, we mark the property with an annotation. - // - // We could apply the annotation during IR rewite, but we still are not - // that far in the rewriting infrastructure. So we postpone - // the annotation until the serializer. + // We mark serialized properties with a Konan protobuf extension bit, + // so it is present in DeserializedPropertyDescriptor. // // In this function we check the presence of the backing filed - // two ways: first we check IR, then we check the annotation. + // two ways: first we check IR, then we check the protobuf extension. val irClass = context.ir.moduleIndexForCodegen.classes[classDescriptor] val fields = if (irClass != null) { @@ -130,7 +126,7 @@ private fun ContextUtils.getDeclaredFields(classDescriptor: ClassDescriptor): Li } else { val properties = classDescriptor.unsubstitutedMemberScope. getContributedDescriptors(). - filterIsInstance() + filterIsInstance() properties.mapNotNull { it.backingField } } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanLinkData.proto b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanLinkData.proto index 1da90e59156..e35f8afcc23 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanLinkData.proto +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanLinkData.proto @@ -29,15 +29,16 @@ extend Constructor { extend Function { repeated Annotation function_annotation = 170; - optional InlineIrBody inline_ir_body = 174; + optional InlineIrBody inline_ir_body = 171; } extend Property { repeated Annotation property_annotation = 170; - optional bool used_as_variable = 173; - optional Annotation.Argument.Value compile_time_value = 174; - optional InlineIrBody inline_getter_ir_body = 175; - optional InlineIrBody inline_setter_ir_body = 176; + optional bool has_backing_field = 171; + optional bool used_as_variable = 172; + optional Annotation.Argument.Value compile_time_value = 173; + optional InlineIrBody inline_getter_ir_body = 174; + optional InlineIrBody inline_setter_ir_body = 175; } extend EnumEntry { diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanSerializerExtension.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanSerializerExtension.kt index aad10bb273f..df03bb7dc28 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanSerializerExtension.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanSerializerExtension.kt @@ -34,7 +34,9 @@ internal class KonanSerializerExtension(val context: Context, val util: KonanSer override fun shouldUseTypeTable(): Boolean = true override fun serializeType(type: KotlinType, proto: ProtoBuf.Type.Builder) { - + // TODO: For debugging purpose we store the textual + // representation of serialized types. + // To be removed for release 1.0. proto.setExtension(KonanLinkData.typeText, type.toString()) super.serializeType(type, proto) @@ -68,26 +70,16 @@ internal class KonanSerializerExtension(val context: Context, val util: KonanSer super.serializeFunction(descriptor, proto) } - private val backingFieldClass = - context.builtIns.getKonanInternalClass("HasBackingField").getDefaultType() - - private val backingFieldAnnotation = AnnotationDescriptorImpl( - backingFieldClass, emptyMap(), SourceElement.NO_SOURCE) - override fun serializeProperty(descriptor: PropertyDescriptor, proto: ProtoBuf.Property.Builder) { val variable = originalVariables[descriptor] if (variable != null) { proto.setExtension(KonanLinkData.usedAsVariable, true) } + proto.setExtension(KonanLinkData.hasBackingField, + context.ir.propertiesWithBackingFields.contains(descriptor)) + super.serializeProperty(descriptor, proto) - - if (context.ir.propertiesWithBackingFields.contains(descriptor)) { - proto.addExtension(KonanLinkData.propertyAnnotation, - annotationSerializer.serializeAnnotation(backingFieldAnnotation)) - - proto.flags = proto.flags or Flags.HAS_ANNOTATIONS.toFlags(true) - } } override fun addFunctionIR(proto: ProtoBuf.Function.Builder, serializedIR: String) diff --git a/runtime/src/main/kotlin/konan/internal/Annotations.kt b/runtime/src/main/kotlin/konan/internal/Annotations.kt index b45e99c4adb..874ac4f2978 100644 --- a/runtime/src/main/kotlin/konan/internal/Annotations.kt +++ b/runtime/src/main/kotlin/konan/internal/Annotations.kt @@ -28,10 +28,6 @@ package konan.internal //@Retention(AnnotationRetention.SOURCE) annotation class ExportForCppRuntime(val name: String = "") -// This one is used internally to mark the presence of a backing field -// in the absence of IR. -annotation class HasBackingField - /** * This annotation denotes that the element is intrinsic and its usages require special handling in compiler. */ @@ -44,4 +40,4 @@ annotation class Intrinsic */ @Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.CLASS) @Retention(AnnotationRetention.BINARY) -annotation class ExportForCompiler \ No newline at end of file +annotation class ExportForCompiler