[FIR] Store abbreviated type in deserialized declarations as attribute

#KT-58542 Fixed
This commit is contained in:
Kirill Rakhman
2023-08-22 18:38:39 +02:00
committed by Space Team
parent 8e72f60996
commit 5b4409e34c
34 changed files with 251 additions and 89 deletions
@@ -62,6 +62,9 @@ open class ConeTypeRenderer {
}
fun render(type: ConeKotlinType) {
type.abbreviatedType?.let {
return render(it)
}
if (type !is ConeFlexibleType && type !is ConeDefinitelyNotNullType) {
// We don't render attributes for flexible/definitely not null types here,
// because bounds duplicate these attributes often
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2023 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 kotlin.reflect.KClass
class AbbreviatedTypeAttribute(
val coneType: ConeKotlinType
): ConeAttribute<AbbreviatedTypeAttribute>() {
override fun union(other: AbbreviatedTypeAttribute?): AbbreviatedTypeAttribute? = null
override fun intersect(other: AbbreviatedTypeAttribute?): AbbreviatedTypeAttribute? = null
override fun add(other: AbbreviatedTypeAttribute?): AbbreviatedTypeAttribute? = null
override fun isSubtypeOf(other: AbbreviatedTypeAttribute?): Boolean = true
override fun toString(): String = "{${coneType.renderForDebugging()}=}"
override val key: KClass<out AbbreviatedTypeAttribute>
get() = AbbreviatedTypeAttribute::class
}
val ConeAttributes.abbreviatedType: AbbreviatedTypeAttribute? by ConeAttributes.attributeAccessor<AbbreviatedTypeAttribute>()
val ConeKotlinType.abbreviatedType: ConeKotlinType?
get() = attributes.abbreviatedType?.coneType
@@ -110,6 +110,15 @@ class ConeAttributes private constructor(attributes: List<ConeAttribute<*>>) : A
return create(attributes)
}
fun replace(oldAttribute: ConeAttribute<*>, newAttribute: ConeAttribute<*>): ConeAttributes {
return create(buildList {
arrayMap.mapNotNullTo(this) { attr ->
attr.takeUnless { it == oldAttribute }
}
add(newAttribute)
})
}
private inline fun perform(other: ConeAttributes, op: ConeAttribute<*>.(ConeAttribute<*>?) -> ConeAttribute<*>?): ConeAttributes {
if (this.isEmpty() && other.isEmpty()) return this
val attributes = mutableListOf<ConeAttribute<*>>()