From 82b6fdf97e955e939209aae1de54cac03e80d434 Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Wed, 30 Mar 2022 12:13:13 +0300 Subject: [PATCH] FIR: Serialize type attributes for non-type-ref types, too --- .../fir/serialization/FirElementSerializer.kt | 71 ++++++++++--------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/compiler/fir/fir-serialization/src/org/jetbrains/kotlin/fir/serialization/FirElementSerializer.kt b/compiler/fir/fir-serialization/src/org/jetbrains/kotlin/fir/serialization/FirElementSerializer.kt index f4804dcc036..103d46d71e3 100644 --- a/compiler/fir/fir-serialization/src/org/jetbrains/kotlin/fir/serialization/FirElementSerializer.kt +++ b/compiler/fir/fir-serialization/src/org/jetbrains/kotlin/fir/serialization/FirElementSerializer.kt @@ -622,39 +622,7 @@ class FirElementSerializer private constructor( fun typeId(type: ConeKotlinType): Int = typeTable[typeProto(type)] private fun typeProto(typeRef: FirTypeRef, toSuper: Boolean = false): ProtoBuf.Type.Builder { - val coneType = typeRef.coneType - return typeProto(coneType, toSuper, correspondingTypeRef = typeRef).also { typeProto -> - val compilerAttributes = mutableListOf>() - val extensionAttributes = mutableListOf>() - for (attribute in coneType.attributes) { - when { - attribute is CustomAnnotationTypeAttribute -> continue - attribute.key in CompilerConeAttributes.classIdByCompilerAttributeKey -> compilerAttributes += attribute - else -> extensionAttributes += attribute - } - } - - for (attribute in compilerAttributes) { - val annotation = buildAnnotation { - annotationTypeRef = buildResolvedTypeRef { - type = ConeClassLikeTypeImpl( - ConeClassLikeLookupTagImpl(CompilerConeAttributes.classIdByCompilerAttributeKey.getValue(attribute.key)), - emptyArray(), - isNullable = false - ) - } - argumentMapping = FirEmptyAnnotationArgumentMapping - } - extension.serializeTypeAnnotation(annotation, typeProto) - } - - for (attributeExtension in session.extensionService.typeAttributeExtensions) { - for (attribute in extensionAttributes) { - val annotation = attributeExtension.convertAttributeToAnnotation(attribute) ?: continue - extension.serializeTypeAnnotation(annotation, typeProto) - } - } - } + return typeProto(typeRef.coneType, toSuper, correspondingTypeRef = typeRef) } private fun typeProto( @@ -739,8 +707,24 @@ class FirElementSerializer private constructor( builder.nullable = type.isMarkedNullable } - for (annotation in type.attributes.customAnnotations) { - extension.serializeTypeAnnotation(annotation, builder) + val extensionAttributes = mutableListOf>() + for (attribute in type.attributes) { + when { + attribute is CustomAnnotationTypeAttribute -> + for (annotation in attribute.annotations) { + extension.serializeTypeAnnotation(annotation, builder) + } + attribute.key in CompilerConeAttributes.classIdByCompilerAttributeKey -> + serializeCompilerDefinedTypeAttribute(builder, attribute) + else -> extensionAttributes += attribute + } + } + + for (attributeExtension in session.extensionService.typeAttributeExtensions) { + for (attribute in extensionAttributes) { + val annotation = attributeExtension.convertAttributeToAnnotation(attribute) ?: continue + extension.serializeTypeAnnotation(annotation, builder) + } } // TODO: abbreviated type @@ -756,6 +740,23 @@ class FirElementSerializer private constructor( return builder } + private fun serializeCompilerDefinedTypeAttribute( + builder: ProtoBuf.Type.Builder, + attribute: ConeAttribute<*> + ) { + val annotation = buildAnnotation { + annotationTypeRef = buildResolvedTypeRef { + this.type = ConeClassLikeTypeImpl( + ConeClassLikeLookupTagImpl(CompilerConeAttributes.classIdByCompilerAttributeKey.getValue(attribute.key)), + emptyArray(), + isNullable = false + ) + } + argumentMapping = FirEmptyAnnotationArgumentMapping + } + extension.serializeTypeAnnotation(annotation, builder) + } + private fun serializeAnnotationFromAttribute( existingAnnotations: List?, classId: ClassId,