FIR: support custom annotation-based type attributes
This commit is contained in:
compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantReturnUnitTypeChecker.fir.txt
Vendored
+1
-1
@@ -22,7 +22,7 @@ FILE: RedundantReturnUnitTypeChecker.kt
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final fun too(): @R|kotlin/Annotation|() R|kotlin/Unit| {
|
||||
public final fun too(): @R|kotlin/Annotation|() R|@R|kotlin/Annotation|() kotlin/Unit| {
|
||||
}
|
||||
|
||||
public final fun foo(): R|kotlin/Unit| {
|
||||
|
||||
Vendored
+1
-1
@@ -19,7 +19,7 @@ FILE: delegateTypeMismatch.kt
|
||||
public get(): R|kotlin/Boolean|
|
||||
|
||||
private final fun <T> property(initialValue: R|T|): R|kotlin/properties/ReadWriteProperty<A, T>| {
|
||||
^property Q|kotlin/properties/Delegates|.R|kotlin/properties/Delegates.vetoable|<R|T|>(R|<local>/initialValue|, <L> = vetoable@fun <anonymous>(_: R|kotlin/reflect/KProperty<*>|, _: R|T|, _: R|T|): R|kotlin/Boolean| <kind=UNKNOWN> {
|
||||
^property Q|kotlin/properties/Delegates|.R|kotlin/properties/Delegates.vetoable|<R|T|>(R|<local>/initialValue|, <L> = vetoable@fun <anonymous>(_: R|@R|kotlin/ParameterName|(name = String(property)) kotlin/reflect/KProperty<*>|, _: R|T|, _: R|T|): R|kotlin/Boolean| <kind=UNKNOWN> {
|
||||
^ when () {
|
||||
this@R|/A|.R|/A.isLocked| -> {
|
||||
throw R|java/lang/IllegalStateException.IllegalStateException|(String(Cannot modify readonly DescriptorRendererOptions))
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
|
||||
object StandardClassIds {
|
||||
|
||||
private val BASE_KOTLIN_PACKAGE = FqName("kotlin")
|
||||
val BASE_KOTLIN_PACKAGE = FqName("kotlin")
|
||||
val BASE_REFLECT_PACKAGE = BASE_KOTLIN_PACKAGE.child(Name.identifier("reflect"))
|
||||
private fun String.baseId() = ClassId(BASE_KOTLIN_PACKAGE, Name.identifier(this))
|
||||
private fun ClassId.unsignedId() = ClassId(BASE_KOTLIN_PACKAGE, Name.identifier("U" + shortClassName.identifier))
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.fir.backend
|
||||
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.classId
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
||||
@@ -100,6 +101,10 @@ class Fir2IrTypeConverter(
|
||||
typeAnnotations += it
|
||||
}
|
||||
}
|
||||
for (attributeAnnotation in attributes.customAnnotations) {
|
||||
if (annotations.any { it.classId == attributeAnnotation.classId }) continue
|
||||
typeAnnotations += callGenerator.convertToIrConstructorCall(attributeAnnotation) as? IrConstructorCall ?: continue
|
||||
}
|
||||
IrSimpleTypeImpl(
|
||||
irSymbol, !typeContext.definitelyNotNull && this.isMarkedNullable,
|
||||
fullyExpandedType(session).typeArguments.map { it.toIrTypeArgument(typeContext) },
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.types
|
||||
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.render
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
class CustomAnnotationTypeAttribute(val annotations: List<FirAnnotationCall>) : ConeAttribute<CustomAnnotationTypeAttribute>() {
|
||||
override fun union(other: CustomAnnotationTypeAttribute?): CustomAnnotationTypeAttribute? = null
|
||||
|
||||
override fun intersect(other: CustomAnnotationTypeAttribute?): CustomAnnotationTypeAttribute? = null
|
||||
|
||||
override fun isSubtypeOf(other: CustomAnnotationTypeAttribute?): Boolean = true
|
||||
|
||||
override fun toString(): String = annotations.joinToString(separator = " ") { it.render() }
|
||||
|
||||
override val key: KClass<out CustomAnnotationTypeAttribute>
|
||||
get() = CustomAnnotationTypeAttribute::class
|
||||
}
|
||||
|
||||
private val ConeAttributes.custom: CustomAnnotationTypeAttribute? by ConeAttributes.attributeAccessor<CustomAnnotationTypeAttribute>()
|
||||
|
||||
val ConeAttributes.customAnnotations: List<FirAnnotationCall> get() = custom?.annotations.orEmpty()
|
||||
@@ -95,6 +95,7 @@ fun List<FirAnnotationCall>.computeTypeAttributes(
|
||||
): ConeAttributes {
|
||||
if (this.isEmpty()) return ConeAttributes.Empty
|
||||
val attributes = mutableListOf<ConeAttribute<*>>()
|
||||
val customAnnotations = mutableListOf<FirAnnotationCall>()
|
||||
for (annotation in this) {
|
||||
val type = annotation.annotationTypeRef.coneTypeSafe<ConeClassLikeType>() ?: continue
|
||||
when (val classId = type.lookupTag.classId) {
|
||||
@@ -102,9 +103,18 @@ fun List<FirAnnotationCall>.computeTypeAttributes(
|
||||
CompilerConeAttributes.NoInfer.ANNOTATION_CLASS_ID -> attributes += CompilerConeAttributes.NoInfer
|
||||
CompilerConeAttributes.ExtensionFunctionType.ANNOTATION_CLASS_ID -> attributes += CompilerConeAttributes.ExtensionFunctionType
|
||||
CompilerConeAttributes.UnsafeVariance.ANNOTATION_CLASS_ID -> attributes += CompilerConeAttributes.UnsafeVariance
|
||||
else -> additionalProcessor.invoke(attributes, classId)
|
||||
else -> {
|
||||
if (classId.startsWith(StandardClassIds.BASE_KOTLIN_PACKAGE.shortName())) {
|
||||
// The check ^ is intended to leave only annotations which may be important for BE
|
||||
customAnnotations += annotation
|
||||
}
|
||||
additionalProcessor.invoke(attributes, classId)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (customAnnotations.isNotEmpty()) {
|
||||
attributes += CustomAnnotationTypeAttribute(customAnnotations)
|
||||
}
|
||||
return ConeAttributes.create(attributes)
|
||||
}
|
||||
|
||||
|
||||
compiler/testData/codegen/box/javaInterop/generics/covariantOverrideWithDeclarationSiteProjection.kt
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
+4
-4
@@ -1,10 +1,10 @@
|
||||
public abstract interface LoadIterableWithNullability<T : R|ft<kotlin/Any, kotlin/Any?>!|> : R|kotlin/Any| {
|
||||
@R|org/jetbrains/annotations/NotNull|() @R|kotlin/annotations/jvm/Mutable|() public abstract fun getIterable(): R|@EnhancedNullability kotlin/collections/MutableIterable<ft<@FlexibleNullability T, T?>!>|
|
||||
@R|org/jetbrains/annotations/NotNull|() @R|kotlin/annotations/jvm/Mutable|() public abstract fun getIterable(): R|@EnhancedNullability @R|kotlin/annotations/jvm/Mutable|() kotlin/collections/MutableIterable<ft<@FlexibleNullability T, T?>!>|
|
||||
|
||||
public abstract fun setIterable(@R|kotlin/annotations/jvm/Mutable|() @R|org/jetbrains/annotations/NotNull|() Iterable: R|@EnhancedNullability kotlin/collections/MutableIterable<ft<@FlexibleNullability T, T?>!>|): R|kotlin/Unit|
|
||||
public abstract fun setIterable(@R|kotlin/annotations/jvm/Mutable|() @R|org/jetbrains/annotations/NotNull|() Iterable: R|@EnhancedNullability @R|kotlin/annotations/jvm/Mutable|() kotlin/collections/MutableIterable<ft<@FlexibleNullability T, T?>!>|): R|kotlin/Unit|
|
||||
|
||||
@R|org/jetbrains/annotations/NotNull|() @R|kotlin/annotations/jvm/ReadOnly|() public abstract fun getReadOnlyIterable(): R|@EnhancedNullability kotlin/collections/Iterable<ft<@FlexibleNullability T, T?>!>|
|
||||
@R|org/jetbrains/annotations/NotNull|() @R|kotlin/annotations/jvm/ReadOnly|() public abstract fun getReadOnlyIterable(): R|@EnhancedNullability @R|kotlin/annotations/jvm/ReadOnly|() kotlin/collections/Iterable<ft<@FlexibleNullability T, T?>!>|
|
||||
|
||||
public abstract fun setReadOnlyIterable(@R|kotlin/annotations/jvm/ReadOnly|() @R|org/jetbrains/annotations/NotNull|() Iterable: R|@EnhancedNullability kotlin/collections/Iterable<ft<@FlexibleNullability T, T?>!>|): R|kotlin/Unit|
|
||||
public abstract fun setReadOnlyIterable(@R|kotlin/annotations/jvm/ReadOnly|() @R|org/jetbrains/annotations/NotNull|() Iterable: R|@EnhancedNullability @R|kotlin/annotations/jvm/ReadOnly|() kotlin/collections/Iterable<ft<@FlexibleNullability T, T?>!>|): R|kotlin/Unit|
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user