diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeAttributes.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeAttributes.kt index 57eafdfa361..1e5698af96d 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeAttributes.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeAttributes.kt @@ -6,9 +6,7 @@ package org.jetbrains.kotlin.fir.types import org.jetbrains.kotlin.fir.utils.AttributeArrayOwner -import org.jetbrains.kotlin.fir.utils.Protected import org.jetbrains.kotlin.fir.utils.TypeRegistry -import org.jetbrains.kotlin.fir.utils.isEmpty import org.jetbrains.kotlin.types.model.AnnotationMarker import org.jetbrains.kotlin.utils.addIfNotNull import kotlin.properties.ReadOnlyProperty @@ -24,7 +22,6 @@ abstract class ConeAttribute> : AnnotationMarker { abstract val key: KClass } -@OptIn(Protected::class) class ConeAttributes private constructor(attributes: List>) : AttributeArrayOwner, ConeAttribute<*>>(), Iterable> { @@ -85,16 +82,12 @@ class ConeAttributes private constructor(attributes: List>) : A } fun remove(attribute: ConeAttribute<*>): ConeAttributes { - if (arrayMap.isEmpty()) return this + if (isEmpty()) return this val attributes = arrayMap.filter { it != attribute } if (attributes.size == arrayMap.size) return this return create(attributes) } - override fun iterator(): Iterator> { - return arrayMap.iterator() - } - private inline fun perform(other: ConeAttributes, op: ConeAttribute<*>.(ConeAttribute<*>?) -> ConeAttribute<*>?): ConeAttributes { if (this.isEmpty() && other.isEmpty()) return this val attributes = mutableListOf>() @@ -109,8 +102,4 @@ class ConeAttributes private constructor(attributes: List>) : A override val typeRegistry: TypeRegistry, ConeAttribute<*>> get() = Companion - - private fun isEmpty(): Boolean { - return arrayMap.isEmpty() - } } diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/utils/ArrayMap.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/utils/ArrayMap.kt index a66f9366b01..3632ac3ca38 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/utils/ArrayMap.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/utils/ArrayMap.kt @@ -14,9 +14,6 @@ sealed class ArrayMap : Iterable { abstract fun copy(): ArrayMap } -fun ArrayMap<*>.isEmpty(): Boolean = size == 0 -fun ArrayMap<*>.isNotEmpty(): Boolean = size != 0 - internal object EmptyArrayMap : ArrayMap() { override val size: Int get() = 0 diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/utils/ArrayMapOwner.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/utils/ArrayMapOwner.kt index 724004b3361..56da4459eb9 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/utils/ArrayMapOwner.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/utils/ArrayMapOwner.kt @@ -14,10 +14,8 @@ import kotlin.reflect.KProperty @RequiresOptIn annotation class Protected -@OptIn(Protected::class) -abstract class AbstractArrayMapOwner { - @Protected - abstract val arrayMap: ArrayMap +abstract class AbstractArrayMapOwner : Iterable { + protected abstract val arrayMap: ArrayMap protected abstract val typeRegistry: TypeRegistry abstract class AbstractArrayMapAccessor( @@ -31,6 +29,14 @@ abstract class AbstractArrayMapOwner { } protected abstract fun registerComponent(tClass: KClass, value: V) + + final override fun iterator(): Iterator = arrayMap.iterator() + + fun isEmpty(): Boolean = arrayMap.size == 0 + + fun isNotEmpty(): Boolean = arrayMap.size != 0 + + operator fun get(index: Int): V? = arrayMap[index] } class ArrayMapAccessor( diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/utils/AttributeArrayOwner.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/utils/AttributeArrayOwner.kt index a7bee7edba9..2c9530ae228 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/utils/AttributeArrayOwner.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/utils/AttributeArrayOwner.kt @@ -16,7 +16,6 @@ import kotlin.reflect.KClass * Note that you can remove attributes from [AttributeArrayOwner] despite * from components in [ComponentArrayOwner] */ -@OptIn(Protected::class) abstract class AttributeArrayOwner protected constructor( arrayMap: ArrayMap ) : AbstractArrayMapOwner() { diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/utils/ComponentArrayOwner.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/utils/ComponentArrayOwner.kt index e2610ed1d01..26e33286940 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/utils/ComponentArrayOwner.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/utils/ComponentArrayOwner.kt @@ -11,7 +11,6 @@ import kotlin.reflect.KClass * [ComponentArrayOwner] based on [ArrayMap] with flexible size and should be used for * storing services in entities with limited number of instances, like FirSession */ -@OptIn(Protected::class) abstract class ComponentArrayOwner : AbstractArrayMapOwner() { final override val arrayMap: ArrayMap = ArrayMapImpl() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/FirExtensionService.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/FirExtensionService.kt index 79c100dbba4..4623d75ba95 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/FirExtensionService.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/FirExtensionService.kt @@ -10,7 +10,6 @@ import org.jetbrains.kotlin.fir.FirSessionComponent import org.jetbrains.kotlin.fir.NoMutableState import org.jetbrains.kotlin.fir.utils.ArrayMapAccessor import org.jetbrains.kotlin.fir.utils.ComponentArrayOwner -import org.jetbrains.kotlin.fir.utils.Protected import org.jetbrains.kotlin.fir.utils.TypeRegistry import kotlin.reflect.KClass @@ -50,7 +49,6 @@ class FirExtensionService(val session: FirSession) : ComponentArrayOwner { return arrayMap.flatten() } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt index f45a4fd5617..9f6c818b92f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt @@ -377,7 +377,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty override fun KotlinTypeMarker.getAnnotations(): List { require(this is ConeKotlinType) - return attributes.arrayMap.toList() + return attributes.toList() } override fun SimpleTypeMarker.isStubType(): Boolean { diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt index 2b4eadcef93..c47c168da62 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt @@ -24,7 +24,6 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol import org.jetbrains.kotlin.fir.types.* -import org.jetbrains.kotlin.fir.utils.isNotEmpty import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.types.Variance @@ -413,7 +412,7 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM } private fun FirDeclaration.renderDeclarationAttributesIfNeeded() { - if (mode.renderDeclarationAttributes && attributes.arrayMap.isNotEmpty()) { + if (mode.renderDeclarationAttributes && attributes.isNotEmpty()) { val attributes = getAttributesWithValues().mapNotNull { (klass, value) -> value?.let { klass.simpleName to value.renderAsDeclarationAttributeValue() } }.joinToString { (name, value) -> "$name=$value" } @@ -427,10 +426,9 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM } } - private fun FirDeclaration.getAttributesWithValues(): List, Any?>> { val attributesMap = FirDeclarationDataRegistry.allValuesThreadUnsafeForRendering() - return attributesMap.entries.sortedBy { it.key.simpleName }.map { (klass, index) -> klass to attributes.arrayMap[index] } + return attributesMap.entries.sortedBy { it.key.simpleName }.map { (klass, index) -> klass to attributes[index] } } private fun Any.renderAsDeclarationAttributeValue() = when (this) {