JVM IR: minor, sort ElementType fields as in the old backend

In the old backend, targets are generated in the order of their
declaration in the ElementType enum, see AnnotationCodegen.java:306
(EnumSet guarantees such iteration ordering).

This has no effect other than reducing non-essential differences when
comparing ABI of JVM vs JVM_IR.
This commit is contained in:
Alexander Udalov
2020-10-09 17:17:34 +02:00
parent 1daeebcdd3
commit e399b4cd12
2 changed files with 7 additions and 7 deletions
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.ir.util.isAnnotationClass
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import java.lang.annotation.ElementType
internal val additionalClassAnnotationPhase = makeIrFilePhase(
::AdditionalClassAnnotationLowering,
@@ -192,7 +193,9 @@ private class AdditionalClassAnnotationLowering(private val context: JvmBackendC
?: throw AssertionError("No annotation target map for JVM target $jvmTarget")
val targets = irClass.applicableTargetSet() ?: return
val javaTargets = targets.mapNotNull { annotationTargetMap[it] }.toSet()
val javaTargets = targets.mapNotNullTo(HashSet()) { annotationTargetMap[it] }.sortedBy {
ElementType.valueOf(it.symbol.owner.name.asString())
}
val vararg = IrVarargImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
@@ -11,12 +11,9 @@ public annotation class TestAnn
fun box(): String {
val testAnnClass = TestAnn::class.java
val targetAnn = testAnnClass.getAnnotation(java.lang.annotation.Target::class.java)
val targets = targetAnn.value
if (targets.size != 2) {
return targets.toList().toString()
}
if (targets.toSet() != setOf(java.lang.annotation.ElementType.FIELD, java.lang.annotation.ElementType.METHOD)) {
return targets.toList().toString()
val targets = targetAnn.value.toList()
if (targets != listOf(java.lang.annotation.ElementType.FIELD, java.lang.annotation.ElementType.METHOD)) {
return targets.toString()
}
return "OK"
}