[FIR] optimize direct allocation of empty ConeTypeProjection arrays

On the snapshot from KTIJ-26260 empty ConeTypeProjection arrays take about 10mb
This commit is contained in:
Ilya Kirillov
2023-08-17 16:10:28 +02:00
committed by Space Team
parent 04d330edae
commit bdfc68468f
19 changed files with 35 additions and 24 deletions
@@ -572,7 +572,7 @@ internal class StubBasedFirMemberDeserializer(
withPsiEntry("declaration", declaration)
}
val enumType = ConeClassLikeTypeImpl(symbol.toLookupTag(), emptyArray(), false)
val enumType = ConeClassLikeTypeImpl(symbol.toLookupTag(), ConeTypeProjection.EMPTY_ARRAY, false)
val enumEntry = buildEnumEntry {
source = KtRealPsiSourceElement(declaration)
this.moduleData = c.moduleData
@@ -14,7 +14,7 @@ sealed class ConeIntegerLiteralType(
abstract val possibleTypes: Collection<ConeClassLikeType>
abstract val supertypes: List<ConeClassLikeType>
final override val typeArguments: Array<out ConeTypeProjection> = emptyArray()
final override val typeArguments: Array<out ConeTypeProjection> get() = EMPTY_ARRAY
final override val attributes: ConeAttributes get() = ConeAttributes.Empty
abstract fun getApproximatedType(expectedType: ConeKotlinType? = null): ConeClassLikeType
@@ -16,7 +16,7 @@ class ConeTypeVariableType(
override val lookupTag: ConeTypeVariableTypeConstructor,
override val attributes: ConeAttributes = ConeAttributes.Empty,
) : ConeLookupTagBasedType() {
override val typeArguments: Array<out ConeTypeProjection> get() = emptyArray()
override val typeArguments: Array<out ConeTypeProjection> get() = EMPTY_ARRAY
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ConeTypeVariableType) return false
@@ -65,7 +65,7 @@ sealed class ConeStubType(val constructor: ConeStubTypeConstructor, override val
ConeSimpleKotlinType() {
override val typeArguments: Array<out ConeTypeProjection>
get() = emptyArray()
get() = EMPTY_ARRAY
override val attributes: ConeAttributes
get() = ConeAttributes.Empty
@@ -144,7 +144,7 @@ data class ConeCapturedType(
)
override val typeArguments: Array<out ConeTypeProjection>
get() = emptyArray()
get() = EMPTY_ARRAY
override fun equals(other: Any?): Boolean {
if (this === other) return true
@@ -220,7 +220,7 @@ class ConeIntersectionType(
val alternativeType: ConeKotlinType? = null,
) : ConeSimpleKotlinType(), IntersectionTypeConstructorMarker {
override val typeArguments: Array<out ConeTypeProjection>
get() = emptyArray()
get() = EMPTY_ARRAY
override val nullability: ConeNullability
get() = ConeNullability.NOT_NULL
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProviderInternals
import org.jetbrains.kotlin.fir.scopes.FirKotlinScopeProvider
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.types.ConeTypeProjection
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.fir.types.constructClassType
import org.jetbrains.kotlin.fir.types.toLookupTag
@@ -125,7 +126,7 @@ class NativeForwardDeclarationsSymbolProvider(
NativeStandardInteropNames.ExperimentalForeignApi
)
type = annotationClassId.toLookupTag()
.constructClassType(typeArguments = emptyArray(), isNullable = false)
.constructClassType(typeArguments = ConeTypeProjection.EMPTY_ARRAY, isNullable = false)
}
argumentMapping = FirEmptyAnnotationArgumentMapping
}
@@ -187,7 +187,7 @@ abstract class AbstractAnnotationDeserializer(
val classId = nameResolver.getClassId(proto.id)
return buildAnnotation {
annotationTypeRef = buildResolvedTypeRef {
type = classId.toLookupTag().constructClassType(emptyArray(), isNullable = false)
type = classId.toLookupTag().constructClassType(ConeTypeProjection.EMPTY_ARRAY, isNullable = false)
}
session.lazyDeclarationResolver.disableLazyResolveContractChecksInside {
this.argumentMapping = createArgumentMapping(proto, classId, nameResolver)
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirEnumEntrySymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.ConeTypeProjection
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.fir.types.coneTypeSafe
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
@@ -168,7 +169,7 @@ fun deserializeClassToSymbol(
classProto.enumEntryList.mapNotNull { enumEntryProto ->
val enumEntryName = nameResolver.getName(enumEntryProto.name)
val enumType = ConeClassLikeTypeImpl(symbol.toLookupTag(), emptyArray(), false)
val enumType = ConeClassLikeTypeImpl(symbol.toLookupTag(), ConeTypeProjection.EMPTY_ARRAY, false)
val property = buildEnumEntry {
this.moduleData = moduleData
this.origin = FirDeclarationOrigin.Library
@@ -265,7 +266,7 @@ fun FirRegularClassBuilder.addCloneForArrayIfNeeded(classId: ClassId, dispatchRe
superTypeRefs += buildResolvedTypeRef {
type = ConeClassLikeTypeImpl(
StandardClassIds.Cloneable.toLookupTag(),
typeArguments = emptyArray(),
typeArguments = ConeTypeProjection.EMPTY_ARRAY,
isNullable = false
)
}
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.references.builder.buildErrorNamedReference
import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference
import org.jetbrains.kotlin.fir.resolve.providers.getClassDeclaredPropertySymbols
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
import org.jetbrains.kotlin.fir.types.ConeTypeProjection
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.fir.types.toLookupTag
@@ -45,7 +46,7 @@ fun FirEnumEntryDeserializedAccessExpression.toQualifiedPropertyAccessExpression
typeRef = buildResolvedTypeRef {
type = ConeClassLikeTypeImpl(
enumClassId.toLookupTag(), emptyArray(), isNullable = false
enumClassId.toLookupTag(), ConeTypeProjection.EMPTY_ARRAY, isNullable = false
)
}
}
@@ -49,7 +49,7 @@ import org.jetbrains.org.objectweb.asm.Type
class FirJvmTypeMapper(val session: FirSession) : FirSessionComponent {
companion object {
val NON_EXISTENT_ID = ClassId.topLevel(StandardNames.NON_EXISTENT_CLASS)
private val typeForNonExistentClass = NON_EXISTENT_ID.toLookupTag().constructClassType(emptyArray(), isNullable = false)
private val typeForNonExistentClass = NON_EXISTENT_ID.toLookupTag().constructClassType(ConeTypeProjection.EMPTY_ARRAY, isNullable = false)
}
fun mapType(
@@ -217,7 +217,7 @@ private fun JavaClassifierType.toConeKotlinTypeForFlexibleBound(
else -> lowerBound?.typeArguments
}
lookupTag.constructClassType(mappedTypeArguments ?: emptyArray(), isNullable = lowerBound != null, attributes)
lookupTag.constructClassType(mappedTypeArguments ?: ConeTypeProjection.EMPTY_ARRAY, isNullable = lowerBound != null, attributes)
}
is JavaTypeParameter -> {
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.builder.FirRegularClassBuilder
import org.jetbrains.kotlin.fir.deserialization.FirConstDeserializer
import org.jetbrains.kotlin.fir.deserialization.FirDeserializationExtension
import org.jetbrains.kotlin.fir.types.ConeTypeProjection
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.fir.types.toLookupTag
@@ -43,7 +44,7 @@ class FirJvmDeserializationExtension(session: FirSession) : FirDeserializationEx
superTypeRefs += buildResolvedTypeRef {
type = ConeClassLikeTypeImpl(
JAVA_IO_SERIALIZABLE.toLookupTag(),
typeArguments = emptyArray(),
typeArguments = ConeTypeProjection.EMPTY_ARRAY,
isNullable = false
)
}
@@ -106,7 +106,7 @@ private fun mapTypeAliasArguments(
useSiteSession: FirSession,
): ConeKotlinType {
if (typeAlias.typeParameters.isNotEmpty() && abbreviatedType.typeArguments.isEmpty()) {
return resultingType.lookupTag.constructClassType(emptyArray(), resultingType.isNullable)
return resultingType.lookupTag.constructClassType(ConeTypeProjection.EMPTY_ARRAY, resultingType.isNullable)
}
val typeAliasMap = typeAlias.typeParameters.map { it.symbol }.zip(abbreviatedType.typeArguments).toMap()
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.fir.scopes.FirScopeProvider
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.ConeTypeProjection
import org.jetbrains.kotlin.fir.types.FirTypeProjection
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.types.FirUserTypeRef
@@ -787,7 +788,7 @@ class LightTreeRawFirDeclarationBuilder(
delegatedSelfTypeRef = buildResolvedTypeRef {
type = ConeClassLikeTypeImpl(
this@buildAnonymousObject.symbol.toLookupTag(),
emptyArray(),
ConeTypeProjection.EMPTY_ARRAY,
isNullable = false
)
}.also { registerSelfType(it) },
@@ -104,7 +104,7 @@ fun ConstantValueKind<*>.expectedConeType(session: FirSession): ConeKotlinType {
fun constructLiteralType(classId: ClassId, isNullable: Boolean = false): ConeKotlinType {
val symbol = session.symbolProvider.getClassLikeSymbolByClassId(classId)
?: return ConeErrorType(ConeSimpleDiagnostic("Missing stdlib class: $classId", DiagnosticKind.MissingStdlibClass))
return symbol.toLookupTag().constructClassType(emptyArray(), isNullable)
return symbol.toLookupTag().constructClassType(ConeTypeProjection.EMPTY_ARRAY, isNullable)
}
return when (this) {
ConstantValueKind.Null -> session.builtinTypes.nullableNothingType.type
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.fir.expressions.builder.buildEmptyExpressionBlock
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol
import org.jetbrains.kotlin.fir.types.ConeTypeProjection
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.fir.types.toLookupTag
@@ -50,7 +51,11 @@ fun FirRegularClassBuilder.generateValuesFunction(
type = ConeClassLikeTypeImpl(
StandardClassIds.Array.toLookupTag(),
arrayOf(
ConeClassLikeTypeImpl(this@generateValuesFunction.symbol.toLookupTag(), emptyArray(), isNullable = false)
ConeClassLikeTypeImpl(
this@generateValuesFunction.symbol.toLookupTag(),
ConeTypeProjection.EMPTY_ARRAY,
isNullable = false
)
),
isNullable = false
)
@@ -145,7 +150,7 @@ fun FirRegularClassBuilder.generateEntriesGetter(
type = ConeClassLikeTypeImpl(
StandardClassIds.EnumEntries.toLookupTag(),
arrayOf(
ConeClassLikeTypeImpl(this@generateEntriesGetter.symbol.toLookupTag(), emptyArray(), isNullable = false)
ConeClassLikeTypeImpl(this@generateEntriesGetter.symbol.toLookupTag(), ConeTypeProjection.EMPTY_ARRAY, isNullable = false)
),
isNullable = false
)
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.utils.classId
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.ConeTypeProjection
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.fir.types.toLookupTag
import org.jetbrains.kotlin.name.ClassId
@@ -29,7 +30,7 @@ object StandardTypes {
}
private fun ClassId.createType(isNullable: Boolean = false): ConeClassLikeType =
ConeClassLikeTypeImpl(this.toLookupTag(), emptyArray(), isNullable)
ConeClassLikeTypeImpl(this.toLookupTag(), ConeTypeProjection.EMPTY_ARRAY, isNullable)
fun ConeClassLikeType.isDouble(): Boolean = lookupTag.classId == StandardClassIds.Double
fun ConeClassLikeType.isFloat(): Boolean = lookupTag.classId == StandardClassIds.Float
@@ -84,7 +84,7 @@ class ConeIntegerLiteralConstantTypeImpl(
}
private fun createType(classId: ClassId): ConeClassLikeType {
return ConeClassLikeTypeImpl(classId.toLookupTag(), emptyArray(), false)
return ConeClassLikeTypeImpl(classId.toLookupTag(), EMPTY_ARRAY, false)
}
private val INT_RANGE = Int.MIN_VALUE.toLong()..Int.MAX_VALUE.toLong()
@@ -147,7 +147,7 @@ private object ConeIntegerLiteralTypeExtensions {
}
fun createClassLikeType(classId: ClassId): ConeClassLikeType {
return ConeClassLikeTypeImpl(classId.toLookupTag(), emptyArray(), false)
return ConeClassLikeTypeImpl(classId.toLookupTag(), ConeTypeProjection.EMPTY_ARRAY, false)
}
fun ConeIntegerLiteralType.getApproximatedTypeImpl(expectedType: ConeKotlinType?): ConeClassLikeType {
@@ -43,7 +43,7 @@ class FirNumberSignAttributeExtension(session: FirSession) : FirTypeAttributeExt
annotationTypeRef = buildResolvedTypeRef {
type = ConeClassLikeTypeImpl(
classId.toLookupTag(),
emptyArray(),
ConeTypeProjection.EMPTY_ARRAY,
isNullable = false
)
}
@@ -78,7 +78,7 @@ object FirParcelizeClassChecker : FirClassChecker() {
val superType = superTypeRef.coneType
val parcelableType = ConeClassLikeTypeImpl(
PARCELABLE_ID.toLookupTag(),
emptyArray(),
ConeTypeProjection.EMPTY_ARRAY,
isNullable = false
)
if (superType.isSubtypeOf(parcelableType, context.session)) {