Do not serialize SOURCE-retained annotations
Also, fix the value of "hasAnnotations" flag to reflect if there are any _non-source_ annotations on a declaration. Unfortunately, after this change IncrementalJsCompilerRunnerTestGenerated$PureKotlin.testAnnotations starts to fail because of the following problem. The problem is that annotations on property accessors are not serialized yet on JS (see KT-14529), yet property proto message has setterFlags field which has the hasAnnotations flag. Upon the full rebuild of the code in that test, we correctly write hasAnnotations = true, but annotations themselves are not serialized. After an incremental build, we deserialize property setter descriptor, observe its Annotations object which happens to be an instance of NonEmptyDeserializedAnnotationsWithPossibleTargets. Now, because annotations itself are not serialized, that Annotations object has no annotations, yet its isEmpty always returns false (see the code). Everything worked correctly before the change because in DescriptorSerializer.hasAnnotations, we used Annotations.isEmpty and the result was the same in the full rebuild and in the incremental scenario. But now we're actually loading annotations, to determine their retention, and that's why the setterFlags are becoming different here and the test fails #KT-23360 Fixed
This commit is contained in:
@@ -23,7 +23,13 @@ interface Annotated {
|
||||
}
|
||||
|
||||
interface Annotations : Iterable<AnnotationDescriptor> {
|
||||
|
||||
/**
|
||||
* @return `true` iff there are no "direct" annotations applicable to this declaration. Note that even if [isEmpty] is `true`,
|
||||
* there may be use-site-targeted annotations applicable to the declaration!
|
||||
*
|
||||
* @see getUseSiteTargetedAnnotations
|
||||
* @see getAllAnnotations
|
||||
*/
|
||||
fun isEmpty(): Boolean
|
||||
|
||||
fun findAnnotation(fqName: FqName): AnnotationDescriptor? = firstOrNull { it.fqName == fqName }
|
||||
@@ -32,7 +38,9 @@ interface Annotations : Iterable<AnnotationDescriptor> {
|
||||
|
||||
fun getUseSiteTargetedAnnotations(): List<AnnotationWithTarget>
|
||||
|
||||
// Returns both targeted and annotations without target. Annotation order is preserved.
|
||||
/**
|
||||
* @return both targeted and annotations without target. Annotation order is preserved.
|
||||
*/
|
||||
fun getAllAnnotations(): List<AnnotationWithTarget>
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -218,6 +218,18 @@ fun Annotated.getAnnotationRetention(): KotlinRetention? {
|
||||
return KotlinRetention.valueOf(retentionArgumentValue.enumEntryName.asString())
|
||||
}
|
||||
|
||||
val Annotated.nonSourceAnnotations: List<AnnotationDescriptor>
|
||||
get() = annotations.filterOutSourceAnnotations()
|
||||
|
||||
fun Iterable<AnnotationDescriptor>.filterOutSourceAnnotations(): List<AnnotationDescriptor> =
|
||||
filterNot(AnnotationDescriptor::isSourceAnnotation)
|
||||
|
||||
val AnnotationDescriptor.isSourceAnnotation: Boolean
|
||||
get() {
|
||||
val classDescriptor = annotationClass
|
||||
return classDescriptor == null || classDescriptor.getAnnotationRetention() == KotlinRetention.SOURCE
|
||||
}
|
||||
|
||||
val DeclarationDescriptor.parentsWithSelf: Sequence<DeclarationDescriptor>
|
||||
get() = generateSequence(this, { it.containingDeclaration })
|
||||
|
||||
|
||||
Reference in New Issue
Block a user