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:
Alexander Udalov
2018-03-21 17:22:13 +01:00
parent 7bac9b62c7
commit 965e3ebab2
25 changed files with 231 additions and 53 deletions
@@ -0,0 +1,17 @@
// ALLOW_AST_ACCESS
// NO_CHECK_SOURCE_VS_BINARY
package test
@Target(AnnotationTarget.TYPE_PARAMETER, AnnotationTarget.TYPEALIAS, AnnotationTarget.TYPE)
@Retention(AnnotationRetention.SOURCE)
annotation class A
class TypeParameterAnnotation {
fun <@A T> foo(x: T) {}
}
@A
typealias TypeAliasAnnotation<X> = List<X>
fun typeAnnotation(): @A Unit {}
@@ -0,0 +1,13 @@
package test
public fun typeAnnotation(): kotlin.Unit
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE_PARAMETER, AnnotationTarget.TYPEALIAS, AnnotationTarget.TYPE}) @kotlin.annotation.Retention(value = AnnotationRetention.SOURCE) public final annotation class A : kotlin.Annotation {
/*primary*/ public constructor A()
}
public final class TypeParameterAnnotation {
/*primary*/ public constructor TypeParameterAnnotation()
public final fun </*0*/ T> foo(/*0*/ x: T): kotlin.Unit
}
public typealias TypeAliasAnnotation</*0*/ X> = kotlin.collections.List<X>