[Commonizer] Use compact variants of collections to reduce memory footprint
This commit is contained in:
+3
-2
@@ -8,7 +8,8 @@ package org.jetbrains.kotlin.descriptors.commonizer.builder
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.concat
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactConcat
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMapValues
|
||||
import org.jetbrains.kotlin.resolve.constants.AnnotationValue
|
||||
import org.jetbrains.kotlin.storage.getValue
|
||||
|
||||
@@ -21,7 +22,7 @@ class CommonizedAnnotationDescriptor(
|
||||
}
|
||||
|
||||
override val allValueArguments by targetComponents.storageManager.createLazyValue {
|
||||
cirAnnotation.constantValueArguments concat cirAnnotation.annotationValueArguments.mapValues { (_, nestedCirAnnotation) ->
|
||||
cirAnnotation.constantValueArguments compactConcat cirAnnotation.annotationValueArguments.compactMapValues { (_, nestedCirAnnotation) ->
|
||||
AnnotationValue(CommonizedAnnotationDescriptor(targetComponents, nestedCirAnnotation))
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.descriptors.SupertypeLoopChecker
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||
import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
@@ -40,7 +41,7 @@ class CommonizedTypeParameterDescriptor(
|
||||
return if (cirUpperBounds.isEmpty())
|
||||
listOf(targetComponents.builtIns.defaultBound)
|
||||
else
|
||||
cirUpperBounds.map { it.buildType(targetComponents, typeParameterResolver) }
|
||||
cirUpperBounds.compactMap { it.buildType(targetComponents, typeParameterResolver) }
|
||||
}
|
||||
|
||||
override fun reportSupertypeLoopError(type: KotlinType) =
|
||||
|
||||
+9
-9
@@ -8,6 +8,9 @@ package org.jetbrains.kotlin.descriptors.commonizer.builder
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compact
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMapIndexed
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
@@ -21,7 +24,7 @@ internal fun List<CirTypeParameter>.buildDescriptorsAndTypeParameterResolver(
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
typeParametersIndexOffset: Int = 0
|
||||
): Pair<List<TypeParameterDescriptor>, TypeParameterResolver> {
|
||||
val ownTypeParameters = mutableListOf<TypeParameterDescriptor>()
|
||||
val ownTypeParameters = ArrayList<TypeParameterDescriptor>(size)
|
||||
|
||||
val typeParameterResolver = TypeParameterResolverImpl(
|
||||
ownTypeParameters = ownTypeParameters,
|
||||
@@ -49,7 +52,7 @@ internal fun List<CirValueParameter>.buildDescriptors(
|
||||
targetComponents: TargetDeclarationsBuilderComponents,
|
||||
typeParameterResolver: TypeParameterResolver,
|
||||
containingDeclaration: CallableDescriptor
|
||||
): List<ValueParameterDescriptor> = mapIndexed { index, param ->
|
||||
): List<ValueParameterDescriptor> = compactMapIndexed { index, param ->
|
||||
ValueParameterDescriptorImpl(
|
||||
containingDeclaration,
|
||||
null,
|
||||
@@ -66,10 +69,7 @@ internal fun List<CirValueParameter>.buildDescriptors(
|
||||
}
|
||||
|
||||
internal fun List<CirAnnotation>.buildDescriptors(targetComponents: TargetDeclarationsBuilderComponents): Annotations =
|
||||
if (isEmpty())
|
||||
Annotations.EMPTY
|
||||
else
|
||||
Annotations.create(map { CommonizedAnnotationDescriptor(targetComponents, it) })
|
||||
Annotations.create(compactMap { CommonizedAnnotationDescriptor(targetComponents, it) })
|
||||
|
||||
internal fun CirExtensionReceiver.buildExtensionReceiver(
|
||||
targetComponents: TargetDeclarationsBuilderComponents,
|
||||
@@ -108,7 +108,7 @@ internal fun CirSimpleType.buildType(
|
||||
)
|
||||
is CirTypeAliasType -> {
|
||||
val typeAliasDescriptor = targetComponents.findClassOrTypeAlias(classifierId).checkClassifierType<TypeAliasDescriptor>()
|
||||
val arguments = this.arguments.map { it.buildArgument(targetComponents, typeParameterResolver, expandTypeAliases) }
|
||||
val arguments = this.arguments.compactMap { it.buildArgument(targetComponents, typeParameterResolver, expandTypeAliases) }
|
||||
|
||||
if (expandTypeAliases)
|
||||
buildExpandedType(typeAliasDescriptor, arguments, isMarkedNullable)
|
||||
@@ -152,7 +152,7 @@ private fun CirClassType.collectArguments(
|
||||
expandTypeAliases: Boolean
|
||||
): List<TypeProjection> {
|
||||
return if (outerType == null) {
|
||||
arguments.map { it.buildArgument(targetComponents, typeParameterResolver, expandTypeAliases) }
|
||||
arguments.compactMap { it.buildArgument(targetComponents, typeParameterResolver, expandTypeAliases) }
|
||||
} else {
|
||||
val allTypes = generateSequence(this) { it.outerType }.toList()
|
||||
val arguments = mutableListOf<TypeProjection>()
|
||||
@@ -161,7 +161,7 @@ private fun CirClassType.collectArguments(
|
||||
allTypes[index].arguments.mapTo(arguments) { it.buildArgument(targetComponents, typeParameterResolver, expandTypeAliases) }
|
||||
}
|
||||
|
||||
arguments.toList()
|
||||
arguments.compact()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,5 +16,7 @@ interface CirClass : CirClassifier, CirHasModality {
|
||||
val isInline: Boolean
|
||||
val isInner: Boolean
|
||||
val isExternal: Boolean
|
||||
val supertypes: MutableCollection<CirType>
|
||||
val supertypes: Collection<CirType>
|
||||
|
||||
fun setSupertypes(supertypes: Collection<CirType>)
|
||||
}
|
||||
|
||||
+6
-5
@@ -10,8 +10,9 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClassType
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirAnnotationImpl
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.Interner
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.*
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.checkConstantSupportedInCommonization
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compact
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.intern
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.constants.AnnotationValue
|
||||
@@ -27,8 +28,8 @@ object CirAnnotationFactory {
|
||||
if (allValueArguments.isEmpty())
|
||||
return create(type = type, constantValueArguments = emptyMap(), annotationValueArguments = emptyMap())
|
||||
|
||||
val constantValueArguments: MutableMap<Name, ConstantValue<*>> = THashMap()
|
||||
val annotationValueArguments: MutableMap<Name, CirAnnotation> = THashMap()
|
||||
val constantValueArguments: MutableMap<Name, ConstantValue<*>> = THashMap(allValueArguments.size)
|
||||
val annotationValueArguments: MutableMap<Name, CirAnnotation> = THashMap(allValueArguments.size)
|
||||
|
||||
allValueArguments.forEach { (name, constantValue) ->
|
||||
checkConstantSupportedInCommonization(
|
||||
@@ -46,8 +47,8 @@ object CirAnnotationFactory {
|
||||
|
||||
return create(
|
||||
type = type,
|
||||
constantValueArguments = constantValueArguments,
|
||||
annotationValueArguments = annotationValueArguments
|
||||
constantValueArguments = constantValueArguments.compact(),
|
||||
annotationValueArguments = annotationValueArguments.compact()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -10,6 +10,8 @@ import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirClassConstructorImpl
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMapNotNull
|
||||
|
||||
object CirClassConstructorFactory {
|
||||
fun create(source: ClassConstructorDescriptor): CirClassConstructor {
|
||||
@@ -18,14 +20,14 @@ object CirClassConstructorFactory {
|
||||
}
|
||||
|
||||
return create(
|
||||
annotations = source.annotations.map(CirAnnotationFactory::create),
|
||||
typeParameters = source.typeParameters.mapNotNull { typeParameter ->
|
||||
annotations = source.annotations.compactMap(CirAnnotationFactory::create),
|
||||
typeParameters = source.typeParameters.compactMapNotNull { typeParameter ->
|
||||
// save only type parameters that are contributed by the constructor itself
|
||||
typeParameter.takeIf { it.containingDeclaration == source }?.let(CirTypeParameterFactory::create)
|
||||
},
|
||||
visibility = source.visibility,
|
||||
containingClassDetails = CirContainingClassDetailsFactory.create(source),
|
||||
valueParameters = source.valueParameters.map(CirValueParameterFactory::create),
|
||||
valueParameters = source.valueParameters.compactMap(CirValueParameterFactory::create),
|
||||
hasStableParameterNames = source.hasStableParameterNames(),
|
||||
isPrimary = source.isPrimary
|
||||
)
|
||||
|
||||
+20
-21
@@ -11,17 +11,17 @@ import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirClassImpl
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.intern
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
object CirClassFactory {
|
||||
fun create(source: ClassDescriptor): CirClass = create(
|
||||
annotations = source.annotations.map(CirAnnotationFactory::create),
|
||||
annotations = source.annotations.compactMap(CirAnnotationFactory::create),
|
||||
name = source.name.intern(),
|
||||
typeParameters = source.declaredTypeParameters.map(CirTypeParameterFactory::create),
|
||||
typeParameters = source.declaredTypeParameters.compactMap(CirTypeParameterFactory::create),
|
||||
visibility = source.visibility,
|
||||
modality = source.modality,
|
||||
kind = source.kind,
|
||||
@@ -30,25 +30,25 @@ object CirClassFactory {
|
||||
isData = source.isData,
|
||||
isInline = source.isInline,
|
||||
isInner = source.isInner,
|
||||
isExternal = source.isExternal,
|
||||
supertypes = source.typeConstructor.supertypes.mapTo(mutableListOf()) { CirTypeFactory.create(it) }
|
||||
)
|
||||
isExternal = source.isExternal
|
||||
).apply {
|
||||
setSupertypes(source.typeConstructor.supertypes.compactMap { CirTypeFactory.create(it) })
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun create(
|
||||
annotations: List<CirAnnotation>,
|
||||
name: Name,
|
||||
typeParameters: List<CirTypeParameter>,
|
||||
visibility: DescriptorVisibility,
|
||||
modality: Modality,
|
||||
kind: ClassKind,
|
||||
companion: Name?,
|
||||
isCompanion: Boolean,
|
||||
isData: Boolean,
|
||||
isInline: Boolean,
|
||||
isInner: Boolean,
|
||||
isExternal: Boolean,
|
||||
supertypes: MutableCollection<CirType>
|
||||
annotations: List<CirAnnotation>,
|
||||
name: Name,
|
||||
typeParameters: List<CirTypeParameter>,
|
||||
visibility: DescriptorVisibility,
|
||||
modality: Modality,
|
||||
kind: ClassKind,
|
||||
companion: Name?,
|
||||
isCompanion: Boolean,
|
||||
isData: Boolean,
|
||||
isInline: Boolean,
|
||||
isInner: Boolean,
|
||||
isExternal: Boolean
|
||||
): CirClass {
|
||||
return CirClassImpl(
|
||||
annotations = annotations,
|
||||
@@ -62,8 +62,7 @@ object CirClassFactory {
|
||||
isData = isData,
|
||||
isInline = isInline,
|
||||
isInner = isInner,
|
||||
isExternal = isExternal,
|
||||
supertypes = supertypes
|
||||
isExternal = isExternal
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -10,10 +10,11 @@ import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirExtensionReceiver
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirExtensionReceiverImpl
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||
|
||||
object CirExtensionReceiverFactory {
|
||||
fun create(source: ReceiverParameterDescriptor): CirExtensionReceiver = create(
|
||||
annotations = source.annotations.map(CirAnnotationFactory::create),
|
||||
annotations = source.annotations.compactMap(CirAnnotationFactory::create),
|
||||
type = CirTypeFactory.create(source.type)
|
||||
)
|
||||
|
||||
|
||||
+16
-15
@@ -8,18 +8,19 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.factory
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirFunctionImpl
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.intern
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
object CirFunctionFactory {
|
||||
fun create(source: SimpleFunctionDescriptor): CirFunction = create(
|
||||
annotations = source.annotations.map(CirAnnotationFactory::create),
|
||||
annotations = source.annotations.compactMap(CirAnnotationFactory::create),
|
||||
name = source.name.intern(),
|
||||
typeParameters = source.typeParameters.map(CirTypeParameterFactory::create),
|
||||
typeParameters = source.typeParameters.compactMap(CirTypeParameterFactory::create),
|
||||
visibility = source.visibility,
|
||||
modality = source.modality,
|
||||
containingClassDetails = CirContainingClassDetailsFactory.create(source),
|
||||
valueParameters = source.valueParameters.map(CirValueParameterFactory::create),
|
||||
valueParameters = source.valueParameters.compactMap(CirValueParameterFactory::create),
|
||||
hasStableParameterNames = source.hasStableParameterNames(),
|
||||
extensionReceiver = source.extensionReceiverParameter?.let(CirExtensionReceiverFactory::create),
|
||||
returnType = CirTypeFactory.create(source.returnType!!),
|
||||
@@ -29,18 +30,18 @@ object CirFunctionFactory {
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun create(
|
||||
annotations: List<CirAnnotation>,
|
||||
name: Name,
|
||||
typeParameters: List<CirTypeParameter>,
|
||||
visibility: DescriptorVisibility,
|
||||
modality: Modality,
|
||||
containingClassDetails: CirContainingClassDetails?,
|
||||
valueParameters: List<CirValueParameter>,
|
||||
hasStableParameterNames: Boolean,
|
||||
extensionReceiver: CirExtensionReceiver?,
|
||||
returnType: CirType,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
modifiers: CirFunctionModifiers
|
||||
annotations: List<CirAnnotation>,
|
||||
name: Name,
|
||||
typeParameters: List<CirTypeParameter>,
|
||||
visibility: DescriptorVisibility,
|
||||
modality: Modality,
|
||||
containingClassDetails: CirContainingClassDetails?,
|
||||
valueParameters: List<CirValueParameter>,
|
||||
hasStableParameterNames: Boolean,
|
||||
extensionReceiver: CirExtensionReceiver?,
|
||||
returnType: CirType,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
modifiers: CirFunctionModifiers
|
||||
): CirFunction {
|
||||
return CirFunctionImpl(
|
||||
annotations = annotations,
|
||||
|
||||
+24
-23
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirPropertyImpl
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.checkConstantSupportedInCommonization
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.intern
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
@@ -28,9 +29,9 @@ object CirPropertyFactory {
|
||||
}
|
||||
|
||||
return create(
|
||||
annotations = source.annotations.map(CirAnnotationFactory::create),
|
||||
annotations = source.annotations.compactMap(CirAnnotationFactory::create),
|
||||
name = source.name.intern(),
|
||||
typeParameters = source.typeParameters.map(CirTypeParameterFactory::create),
|
||||
typeParameters = source.typeParameters.compactMap(CirTypeParameterFactory::create),
|
||||
visibility = source.visibility,
|
||||
modality = source.modality,
|
||||
containingClassDetails = CirContainingClassDetailsFactory.create(source),
|
||||
@@ -44,33 +45,33 @@ object CirPropertyFactory {
|
||||
isDelegate = source.isDelegated,
|
||||
getter = source.getter?.let(CirPropertyGetterFactory::create),
|
||||
setter = source.setter?.let(CirPropertySetterFactory::create),
|
||||
backingFieldAnnotations = source.backingField?.annotations?.map(CirAnnotationFactory::create),
|
||||
delegateFieldAnnotations = source.delegateField?.annotations?.map(CirAnnotationFactory::create),
|
||||
backingFieldAnnotations = source.backingField?.annotations?.compactMap(CirAnnotationFactory::create),
|
||||
delegateFieldAnnotations = source.delegateField?.annotations?.compactMap(CirAnnotationFactory::create),
|
||||
compileTimeInitializer = source.compileTimeInitializer
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun create(
|
||||
annotations: List<CirAnnotation>,
|
||||
name: Name,
|
||||
typeParameters: List<CirTypeParameter>,
|
||||
visibility: DescriptorVisibility,
|
||||
modality: Modality,
|
||||
containingClassDetails: CirContainingClassDetails?,
|
||||
isExternal: Boolean,
|
||||
extensionReceiver: CirExtensionReceiver?,
|
||||
returnType: CirType,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
isVar: Boolean,
|
||||
isLateInit: Boolean,
|
||||
isConst: Boolean,
|
||||
isDelegate: Boolean,
|
||||
getter: CirPropertyGetter?,
|
||||
setter: CirPropertySetter?,
|
||||
backingFieldAnnotations: List<CirAnnotation>?,
|
||||
delegateFieldAnnotations: List<CirAnnotation>?,
|
||||
compileTimeInitializer: ConstantValue<*>?
|
||||
annotations: List<CirAnnotation>,
|
||||
name: Name,
|
||||
typeParameters: List<CirTypeParameter>,
|
||||
visibility: DescriptorVisibility,
|
||||
modality: Modality,
|
||||
containingClassDetails: CirContainingClassDetails?,
|
||||
isExternal: Boolean,
|
||||
extensionReceiver: CirExtensionReceiver?,
|
||||
returnType: CirType,
|
||||
kind: CallableMemberDescriptor.Kind,
|
||||
isVar: Boolean,
|
||||
isLateInit: Boolean,
|
||||
isConst: Boolean,
|
||||
isDelegate: Boolean,
|
||||
getter: CirPropertyGetter?,
|
||||
setter: CirPropertySetter?,
|
||||
backingFieldAnnotations: List<CirAnnotation>?,
|
||||
delegateFieldAnnotations: List<CirAnnotation>?,
|
||||
compileTimeInitializer: ConstantValue<*>?
|
||||
): CirProperty {
|
||||
return CirPropertyImpl(
|
||||
annotations = annotations,
|
||||
|
||||
+2
-1
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPropertyGetter
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirPropertyGetterImpl
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.Interner
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||
|
||||
object CirPropertyGetterFactory {
|
||||
private val interner = Interner<CirPropertyGetter>()
|
||||
@@ -27,7 +28,7 @@ object CirPropertyGetterFactory {
|
||||
DEFAULT_NO_ANNOTATIONS
|
||||
else
|
||||
create(
|
||||
annotations = source.annotations.map(CirAnnotationFactory::create),
|
||||
annotations = source.annotations.compactMap(CirAnnotationFactory::create),
|
||||
isDefault = source.isDefault,
|
||||
isExternal = source.isExternal,
|
||||
isInline = source.isInline
|
||||
|
||||
+9
-8
@@ -12,13 +12,14 @@ import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPropertySetter
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirPropertySetterImpl
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.Interner
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||
|
||||
object CirPropertySetterFactory {
|
||||
private val interner = Interner<CirPropertySetter>()
|
||||
|
||||
fun create(source: PropertySetterDescriptor): CirPropertySetter = create(
|
||||
annotations = source.annotations.map(CirAnnotationFactory::create),
|
||||
parameterAnnotations = source.valueParameters[0].annotations.map(CirAnnotationFactory::create),
|
||||
annotations = source.annotations.compactMap(CirAnnotationFactory::create),
|
||||
parameterAnnotations = source.valueParameters[0].annotations.compactMap(CirAnnotationFactory::create),
|
||||
visibility = source.visibility,
|
||||
isDefault = source.isDefault,
|
||||
isExternal = source.isExternal,
|
||||
@@ -26,12 +27,12 @@ object CirPropertySetterFactory {
|
||||
)
|
||||
|
||||
fun create(
|
||||
annotations: List<CirAnnotation>,
|
||||
parameterAnnotations: List<CirAnnotation>,
|
||||
visibility: DescriptorVisibility,
|
||||
isDefault: Boolean,
|
||||
isExternal: Boolean,
|
||||
isInline: Boolean
|
||||
annotations: List<CirAnnotation>,
|
||||
parameterAnnotations: List<CirAnnotation>,
|
||||
visibility: DescriptorVisibility,
|
||||
isDefault: Boolean,
|
||||
isExternal: Boolean,
|
||||
isInline: Boolean
|
||||
): CirPropertySetter {
|
||||
return interner.intern(
|
||||
CirPropertySetterImpl(
|
||||
|
||||
+3
-2
@@ -9,14 +9,15 @@ import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirTypeAliasImpl
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.intern
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
object CirTypeAliasFactory {
|
||||
fun create(source: TypeAliasDescriptor): CirTypeAlias = create(
|
||||
annotations = source.annotations.map(CirAnnotationFactory::create),
|
||||
annotations = source.annotations.compactMap(CirAnnotationFactory::create),
|
||||
name = source.name.intern(),
|
||||
typeParameters = source.declaredTypeParameters.map(CirTypeParameterFactory::create),
|
||||
typeParameters = source.declaredTypeParameters.compactMap(CirTypeParameterFactory::create),
|
||||
visibility = source.visibility,
|
||||
underlyingType = CirTypeFactory.create(source.underlyingType, useAbbreviation = true) as CirClassOrTypeAliasType,
|
||||
expandedType = CirTypeFactory.create(source.expandedType, useAbbreviation = false) as CirClassType
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirClassTypeImpl
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirTypeAliasTypeImpl
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.Interner
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.*
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.declarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.extractExpandedType
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.internedClassId
|
||||
@@ -147,7 +147,7 @@ object CirTypeFactory {
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
private inline fun createArguments(arguments: List<TypeProjection>, useAbbreviation: Boolean): List<CirTypeProjection> =
|
||||
arguments.map { projection ->
|
||||
arguments.compactMap { projection ->
|
||||
if (projection.isStarProjection)
|
||||
CirStarTypeProjection
|
||||
else
|
||||
|
||||
+3
-2
@@ -10,17 +10,18 @@ import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirTypeParameterImpl
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.intern
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
object CirTypeParameterFactory {
|
||||
fun create(source: TypeParameterDescriptor): CirTypeParameter = create(
|
||||
annotations = source.annotations.map(CirAnnotationFactory::create),
|
||||
annotations = source.annotations.compactMap(CirAnnotationFactory::create),
|
||||
name = source.name.intern(),
|
||||
isReified = source.isReified,
|
||||
variance = source.variance,
|
||||
upperBounds = source.upperBounds.map(CirTypeFactory::create)
|
||||
upperBounds = source.upperBounds.compactMap(CirTypeFactory::create)
|
||||
)
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
|
||||
+2
-1
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirValueParameter
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirValueParameterImpl
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.Interner
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.intern
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
@@ -18,7 +19,7 @@ object CirValueParameterFactory {
|
||||
private val interner = Interner<CirValueParameter>()
|
||||
|
||||
fun create(source: ValueParameterDescriptor): CirValueParameter = create(
|
||||
annotations = source.annotations.map(CirAnnotationFactory::create),
|
||||
annotations = source.annotations.compactMap(CirAnnotationFactory::create),
|
||||
name = source.name.intern(),
|
||||
returnType = CirTypeFactory.create(source.returnType!!),
|
||||
varargElementType = source.varargElementType?.let(CirTypeFactory::create),
|
||||
|
||||
+11
-2
@@ -27,5 +27,14 @@ data class CirClassImpl(
|
||||
override val isInline: Boolean,
|
||||
override val isInner: Boolean,
|
||||
override val isExternal: Boolean,
|
||||
override val supertypes: MutableCollection<CirType>
|
||||
) : CirClass
|
||||
) : CirClass {
|
||||
private var _supertypes: Collection<CirType>? = null
|
||||
|
||||
override val supertypes: Collection<CirType>
|
||||
get() = _supertypes.orEmpty()
|
||||
|
||||
override fun setSupertypes(supertypes: Collection<CirType>) {
|
||||
check(_supertypes == null)
|
||||
_supertypes = supertypes
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,4 +8,4 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.impl
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirDeclaration
|
||||
|
||||
@Suppress("unused", "NOTHING_TO_INLINE")
|
||||
internal inline fun CirDeclaration.unsupported(): Nothing = error("This method should never be called")
|
||||
internal inline fun CirDeclaration.unsupported(): Nothing = error("This method should never be called on ${this::class.java}, $this")
|
||||
|
||||
+2
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.impl
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClassifier
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirRecursionMarker
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
object CirClassRecursionMarker : CirClass, CirRecursionMarker {
|
||||
@@ -26,6 +27,7 @@ object CirClassRecursionMarker : CirClass, CirRecursionMarker {
|
||||
override val isInner get() = unsupported()
|
||||
override val isExternal get() = unsupported()
|
||||
override val supertypes get() = unsupported()
|
||||
override fun setSupertypes(supertypes: Collection<CirType>) = unsupported()
|
||||
}
|
||||
|
||||
object CirClassifierRecursionMarker : CirClassifier, CirRecursionMarker {
|
||||
|
||||
+12
-10
@@ -11,6 +11,8 @@ import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirAnnotationFact
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.core.AnnotationsCommonizer.Companion.FALLBACK_MESSAGE
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.DEPRECATED_ANNOTATION_CID
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMapOf
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.intern
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.internedClassId
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -62,18 +64,18 @@ private class DeprecatedAnnotationCommonizer : Commonizer<CirAnnotation, CirAnno
|
||||
|
||||
val constantValueArguments: Map<Name, ConstantValue<*>> = if (level == WARNING) {
|
||||
// don't populate with the default level value
|
||||
mapOf(PROPERTY_NAME_MESSAGE to messageValue)
|
||||
compactMapOf(PROPERTY_NAME_MESSAGE, messageValue)
|
||||
} else
|
||||
hashMapOf(
|
||||
PROPERTY_NAME_MESSAGE to messageValue,
|
||||
PROPERTY_NAME_LEVEL to level.toDeprecationLevelValue()
|
||||
compactMapOf(
|
||||
PROPERTY_NAME_MESSAGE, messageValue,
|
||||
PROPERTY_NAME_LEVEL, level.toDeprecationLevelValue()
|
||||
)
|
||||
|
||||
val annotationValueArguments: Map<Name, CirAnnotation> = if (replaceWithExpression.isEmpty() && replaceWithImports.isEmpty()) {
|
||||
// don't populate with empty (default) ReplaceWith
|
||||
emptyMap()
|
||||
} else
|
||||
mapOf(PROPERTY_NAME_REPLACE_WITH to replaceWithExpression.toReplaceWithValue(replaceWithImports))
|
||||
compactMapOf(PROPERTY_NAME_REPLACE_WITH, replaceWithExpression.toReplaceWithValue(replaceWithImports))
|
||||
|
||||
return CirAnnotationFactory.create(
|
||||
type = DEPRECATED_ANNOTATION_TYPE,
|
||||
@@ -205,7 +207,7 @@ private class DeprecatedAnnotationCommonizer : Commonizer<CirAnnotation, CirAnno
|
||||
val elements: List<ConstantValue<*>> = (this[name] as? ArrayValue)?.value ?: return null
|
||||
if (elements.isEmpty()) return emptyList()
|
||||
|
||||
val result = mutableListOf<String>()
|
||||
val result = ArrayList<String>(elements.size)
|
||||
for (element in elements) {
|
||||
if (element is StringValue) {
|
||||
result += element.value
|
||||
@@ -219,10 +221,10 @@ private class DeprecatedAnnotationCommonizer : Commonizer<CirAnnotation, CirAnno
|
||||
private inline fun createReplaceWithAnnotation(expression: String, imports: List<String>): CirAnnotation =
|
||||
CirAnnotationFactory.create(
|
||||
type = REPLACE_WITH_ANNOTATION_TYPE,
|
||||
constantValueArguments = mapOf(
|
||||
PROPERTY_NAME_EXPRESSION to StringValue(expression),
|
||||
PROPERTY_NAME_IMPORTS to ArrayValue(
|
||||
value = imports.map { StringValue(it) },
|
||||
constantValueArguments = compactMapOf(
|
||||
PROPERTY_NAME_EXPRESSION, StringValue(expression),
|
||||
PROPERTY_NAME_IMPORTS, ArrayValue(
|
||||
value = imports.compactMap { StringValue(it) },
|
||||
computeType = { it.builtIns.getArrayElementType(it.builtIns.stringType) }
|
||||
)
|
||||
),
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirValueParameter
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.core.CallableValueParametersCommonizer.CallableToPatch.Companion.doNothing
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.core.CallableValueParametersCommonizer.CallableToPatch.Companion.patchCallables
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassifiersCache
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMapIndexed
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.intern
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.isObjCInteropCallableAnnotation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -48,7 +49,7 @@ class CallableValueParametersCommonizer(
|
||||
callablesToPatch.forEach { callableToPatch ->
|
||||
val callable = callableToPatch.callable
|
||||
callable.hasStableParameterNames = false
|
||||
callable.valueParameters = callable.valueParameters.mapIndexed { index, valueParameter ->
|
||||
callable.valueParameters = callable.valueParameters.compactMapIndexed { index, valueParameter ->
|
||||
val newName = newNames[index]
|
||||
if (valueParameter.name != newName) {
|
||||
CirValueParameterFactory.create(
|
||||
|
||||
+1
-2
@@ -33,8 +33,7 @@ class ClassCommonizer(cache: CirClassifiersCache) : AbstractStandardCommonizer<C
|
||||
isData = false,
|
||||
isInline = isInline,
|
||||
isInner = isInner,
|
||||
isExternal = false,
|
||||
supertypes = mutableListOf()
|
||||
isExternal = false
|
||||
)
|
||||
|
||||
override fun initialize(first: CirClass) {
|
||||
|
||||
+7
-6
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.*
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMapNotNull
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.internedClassId
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.isUnderStandardKotlinPackages
|
||||
|
||||
@@ -142,11 +143,11 @@ internal class CommonizationVisitor(
|
||||
}
|
||||
|
||||
private fun CirClass.commonizeSupertypes(supertypesMap: Map<CirType, CommonizedGroup<CirType>>?) {
|
||||
supertypesMap ?: return
|
||||
for ((_, supertypesGroup) in supertypesMap) {
|
||||
val commonSupertype = commonize(supertypesGroup, TypeCommonizer(root.cache))
|
||||
if (commonSupertype != null)
|
||||
supertypes.add(commonSupertype)
|
||||
}
|
||||
setSupertypes(
|
||||
if (supertypesMap.isNullOrEmpty())
|
||||
emptyList()
|
||||
else
|
||||
supertypesMap.values.compactMapNotNull { supertypesGroup -> commonize(supertypesGroup, TypeCommonizer(root.cache)) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -138,8 +138,7 @@ private class TypeAliasExpectClassCommonizer : AbstractStandardCommonizer<CirTyp
|
||||
isData = false,
|
||||
isInline = false,
|
||||
isInner = false,
|
||||
isExternal = false,
|
||||
supertypes = mutableListOf()
|
||||
isExternal = false
|
||||
)
|
||||
|
||||
override fun initialize(first: CirTypeAlias) {
|
||||
|
||||
@@ -5,8 +5,15 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.utils
|
||||
|
||||
import com.intellij.util.SmartFMap
|
||||
import gnu.trove.THashMap
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
||||
import java.util.*
|
||||
import java.util.Collections.singletonList
|
||||
import java.util.Collections.singletonMap
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
internal fun <T> Sequence<T>.toList(expectedCapacity: Int): List<T> {
|
||||
val result = ArrayList<T>(expectedCapacity)
|
||||
@@ -14,16 +21,77 @@ internal fun <T> Sequence<T>.toList(expectedCapacity: Int): List<T> {
|
||||
return result
|
||||
}
|
||||
|
||||
internal infix fun <K, V> Map<K, V>.concat(other: Map<K, V>): Map<K, V> =
|
||||
internal infix fun <K, V> Map<K, V>.compactConcat(other: Map<K, V>): Map<K, V> =
|
||||
when {
|
||||
isEmpty() -> other
|
||||
other.isEmpty() -> this
|
||||
else -> THashMap<K, V>(size + other.size, 1F).apply {
|
||||
putAll(this@concat)
|
||||
putAll(other)
|
||||
else -> when (val capacity = size + other.size) {
|
||||
0, 1 -> error("Unreachable code")
|
||||
2, 3 -> SmartFMap.emptyMap<K, V>().plusAll(this).plusAll(other)
|
||||
else -> THashMap<K, V>(capacity).also { it.putAll(this); it.putAll(other) }
|
||||
}
|
||||
}
|
||||
|
||||
internal inline fun <K : Any, V, R> Map<K, V>.compactMapValues(transform: (Map.Entry<K, V>) -> R): Map<K, R> =
|
||||
when (size) {
|
||||
0 -> emptyMap()
|
||||
1 -> with(entries.iterator().next()) { singletonMap(key, transform(this)) }
|
||||
2, 3 -> entries.fold(SmartFMap.emptyMap()) { acc, entry -> acc.plus(entry.key, transform(entry)) }
|
||||
else -> mapValuesTo(THashMap(size), transform)
|
||||
}
|
||||
|
||||
internal inline fun <T, R> Collection<T>.compactMap(transform: (T) -> R): List<R> =
|
||||
when (size) {
|
||||
0 -> emptyList()
|
||||
1 -> singletonList(transform(if (this is List) this[0] else iterator().next()))
|
||||
else -> mapTo(ArrayList(size), transform)
|
||||
}
|
||||
|
||||
internal inline fun <T, reified R : Any> Collection<T>.compactMapNotNull(transform: (T) -> R?): List<R> =
|
||||
if (isEmpty()) emptyList() else mapNotNullTo(ArrayList(size), transform).compact()
|
||||
|
||||
internal inline fun <T, R> Collection<T>.compactMapIndexed(transform: (index: Int, T) -> R): List<R> =
|
||||
when (size) {
|
||||
0 -> emptyList()
|
||||
1 -> singletonList(transform(0, if (this is List) this[0] else iterator().next()))
|
||||
else -> mapIndexedTo(ArrayList(size), transform)
|
||||
}
|
||||
|
||||
internal inline fun <reified T> List<T>.compact(): List<T> =
|
||||
when (size) {
|
||||
0 -> emptyList()
|
||||
1 -> singletonList(this[0])
|
||||
else -> when (this) {
|
||||
is java.util.ArrayList -> {
|
||||
trimToSize()
|
||||
this
|
||||
}
|
||||
else -> {
|
||||
@Suppress("ReplaceJavaStaticMethodWithKotlinAnalog")
|
||||
Arrays.asList(*toTypedArray())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal inline fun <reified R> Annotations.compactMap(transform: (AnnotationDescriptor) -> R): List<R> =
|
||||
if (isEmpty()) emptyList() else map(transform).compact()
|
||||
|
||||
internal fun <K, V> Map<K, V>.compact(): Map<K, V> =
|
||||
when (size) {
|
||||
0 -> emptyMap()
|
||||
1 -> with(entries.iterator().next()) { singletonMap(key, value) }
|
||||
2, 3 -> SmartFMap.emptyMap<K, V>().plusAll(this)
|
||||
else -> THashMap(this)
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
internal inline fun <K : Any, V> compactMapOf(key: K, value: V): Map<K, V> =
|
||||
singletonMap(key, value)
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
internal inline fun <K : Any, V> compactMapOf(key1: K, value1: V, key2: K, value2: V): Map<K, V> =
|
||||
SmartFMap.emptyMap<K, V>().plus(key1, value1).plus(key2, value2)
|
||||
|
||||
internal inline fun <reified T> Iterable<T?>.firstNonNull() = firstIsInstance<T>()
|
||||
|
||||
internal fun Any?.isNull(): Boolean = this == null
|
||||
|
||||
@@ -269,3 +269,10 @@
|
||||
}
|
||||
|
||||
-dontwarn org.jetbrains.kotlin.fir.**
|
||||
|
||||
# used in commonizer
|
||||
-keep class com.intellij.util.SmartFMap {
|
||||
public static ** emptyMap();
|
||||
public ** plus(java.lang.Object, java.lang.Object);
|
||||
public ** plusAll(java.util.Map);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user