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