[Commonizer] Refactor CIR to avoid strong refs on descriptors

This is necessary to reduce memory consumption in commonizer while
processing sets of massive libraries.
Ex: ios_x64 (127 libraries) vs ios_arm64 (127 libraries).
This commit is contained in:
Dmitriy Dolovov
2020-02-13 18:51:48 +07:00
parent a0b0f72edf
commit 11e0f427ac
18 changed files with 236 additions and 193 deletions
@@ -39,7 +39,7 @@ internal fun List<CirTypeParameter>.buildDescriptorsAndTypeParameterResolver(
targetComponents = targetComponents,
typeParameterResolver = typeParameterResolver,
containingDeclaration = containingDeclaration,
annotations = param.annotations,
annotations = param.annotations.buildDescriptors(targetComponents),
name = param.name,
variance = param.variance,
isReified = param.isReified,
@@ -61,7 +61,7 @@ internal fun List<CirValueParameter>.buildDescriptors(
containingDeclaration,
null,
index,
param.annotations,
param.annotations.buildDescriptors(targetComponents),
param.name,
param.returnType.buildType(targetComponents, typeParameterResolver),
param.declaresDefaultValue,
@@ -80,7 +80,7 @@ private fun CirProperty.buildDescriptor(
val getterDescriptor = getter?.let { getter ->
DescriptorFactory.createGetter(
propertyDescriptor,
getter.annotations,
getter.annotations.buildDescriptors(targetComponents),
getter.isDefault,
getter.isExternal,
getter.isInline
@@ -92,8 +92,8 @@ private fun CirProperty.buildDescriptor(
val setterDescriptor = setter?.let { setter ->
DescriptorFactory.createSetter(
propertyDescriptor,
setter.annotations,
setter.parameterAnnotations,
setter.annotations.buildDescriptors(targetComponents),
setter.parameterAnnotations.buildDescriptors(targetComponents),
setter.isDefault,
setter.isExternal,
setter.isInline,
@@ -102,8 +102,13 @@ private fun CirProperty.buildDescriptor(
)
}
val backingField = backingFieldAnnotations?.let { FieldDescriptorImpl(it, propertyDescriptor) }
val delegateField = delegateFieldAnnotations?.let { FieldDescriptorImpl(it, propertyDescriptor) }
val backingField = backingFieldAnnotations?.let { annotations ->
FieldDescriptorImpl(annotations.buildDescriptors(targetComponents), propertyDescriptor)
}
val delegateField = delegateFieldAnnotations?.let { annotations ->
FieldDescriptorImpl(annotations.buildDescriptors(targetComponents), propertyDescriptor)
}
propertyDescriptor.initialize(
getterDescriptor,
@@ -8,9 +8,37 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.constants.ConstantValue
import org.jetbrains.kotlin.resolve.constants.*
class CirAnnotation(private val wrapped: AnnotationDescriptor) {
val fqName: FqName get() = wrapped.fqName ?: error("Annotation with no FQ name: ${wrapped::class.java}, $wrapped")
val allValueArguments: Map<Name, ConstantValue<*>> get() = wrapped.allValueArguments
class CirAnnotation(original: AnnotationDescriptor) {
val fqName: FqName = original.fqName ?: error("Annotation with no FQ name: ${original::class.java}, $original")
val allValueArguments: Map<Name, ConstantValue<*>> = original.allValueArguments
init {
allValueArguments.forEach { (name, constantValue) ->
checkSupportedInCommonization(constantValue) { "${original::class.java}, $original[$name]" }
}
}
}
internal fun checkSupportedInCommonization(constantValue: ConstantValue<*>, location: () -> String) {
@Suppress("TrailingComma")
return when (constantValue) {
is StringValue,
is IntegerValueConstant<*>,
is UnsignedValueConstant<*>,
is BooleanValue,
is NullValue,
is DoubleValue,
is FloatValue,
is EnumValue -> {
// OK
}
is ArrayValue -> {
constantValue.value.forEachIndexed { index, innerConstantValue ->
checkSupportedInCommonization(innerConstantValue) { "${location()}[$index]" }
}
}
else -> error("Unsupported const value type: ${constantValue::class.java}, $constantValue at ${location()}")
}
}
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import kotlin.LazyThreadSafetyMode.PUBLICATION
interface CirClass : CirAnnotatedDeclaration, CirNamedDeclaration, CirDeclarationWithTypeParameters, CirDeclarationWithVisibility, CirDeclarationWithModality {
val companion: FqName? // null means no companion object
@@ -62,39 +61,37 @@ data class CirCommonClassConstructor(
override val containingClassIsData get() = unsupported()
}
class CirWrappedClass(private val wrapped: ClassDescriptor) : CirClass {
override val annotations by lazy(PUBLICATION) { wrapped.annotations.map(::CirAnnotation) }
override val name get() = wrapped.name
override val typeParameters by lazy(PUBLICATION) { wrapped.declaredTypeParameters.map(::CirWrappedTypeParameter) }
override val companion by lazy(PUBLICATION) { wrapped.companionObjectDescriptor?.fqNameSafe }
override val kind get() = wrapped.kind
override val modality get() = wrapped.modality
override val visibility get() = wrapped.visibility
override val isCompanion get() = wrapped.isCompanionObject
override val isData get() = wrapped.isData
override val isInline get() = wrapped.isInline
override val isInner get() = wrapped.isInner
override val isExternal get() = wrapped.isExternal
override val supertypes by lazy(PUBLICATION) { wrapped.typeConstructor.supertypes.map(CirType.Companion::create) }
class CirClassImpl(original: ClassDescriptor) : CirClass {
override val annotations = original.annotations.map(::CirAnnotation)
override val name = original.name
override val typeParameters = original.declaredTypeParameters.map(::CirTypeParameterImpl)
override val companion = original.companionObjectDescriptor?.fqNameSafe
override val kind = original.kind
override val modality = original.modality
override val visibility = original.visibility
override val isCompanion = original.isCompanionObject
override val isData = original.isData
override val isInline = original.isInline
override val isInner = original.isInner
override val isExternal = original.isExternal
override val supertypes = original.typeConstructor.supertypes.map(CirType.Companion::create)
}
class CirWrappedClassConstructor(private val wrapped: ClassConstructorDescriptor) : CirClassConstructor {
override val isPrimary get() = wrapped.isPrimary
override val kind get() = wrapped.kind
override val containingClassKind get() = wrapped.containingDeclaration.kind
override val containingClassModality get() = wrapped.containingDeclaration.modality
override val containingClassIsData get() = wrapped.containingDeclaration.isData
override val annotations by lazy(PUBLICATION) { wrapped.annotations.map(::CirAnnotation) }
override val visibility get() = wrapped.visibility
override val typeParameters by lazy(PUBLICATION) {
wrapped.typeParameters.mapNotNull { typeParameter ->
// save only type parameters that are contributed by the constructor itself
typeParameter.takeIf { it.containingDeclaration == wrapped }?.let(::CirWrappedTypeParameter)
}
class CirClassConstructorImpl(original: ClassConstructorDescriptor) : CirClassConstructor {
override val isPrimary = original.isPrimary
override val kind = original.kind
override val containingClassKind = original.containingDeclaration.kind
override val containingClassModality = original.containingDeclaration.modality
override val containingClassIsData = original.containingDeclaration.isData
override val annotations = original.annotations.map(::CirAnnotation)
override val visibility = original.visibility
override val typeParameters = original.typeParameters.mapNotNull { typeParameter ->
// save only type parameters that are contributed by the constructor itself
typeParameter.takeIf { it.containingDeclaration == original }?.let(::CirTypeParameterImpl)
}
override val valueParameters by lazy(PUBLICATION) { wrapped.valueParameters.map(::CirWrappedValueParameter) }
override val hasStableParameterNames get() = wrapped.hasStableParameterNames()
override val hasSynthesizedParameterNames get() = wrapped.hasSynthesizedParameterNames()
override val valueParameters = original.valueParameters.map(::CirValueParameterImpl)
override val hasStableParameterNames = original.hasStableParameterNames()
override val hasSynthesizedParameterNames = original.hasSynthesizedParameterNames()
}
object CirClassRecursionMarker : CirClass, CirRecursionMarker {
@@ -6,9 +6,7 @@
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.Name
import kotlin.LazyThreadSafetyMode.PUBLICATION
interface CirFunctionModifiers {
val isOperator: Boolean
@@ -41,20 +39,20 @@ data class CirCommonFunction(
override val hasSynthesizedParameterNames: Boolean
) : CirCommonFunctionOrProperty(), CirFunction, CirFunctionModifiers by modifiers
class CirWrappedFunction(wrapped: SimpleFunctionDescriptor) : CirWrappedFunctionOrProperty<SimpleFunctionDescriptor>(wrapped), CirFunction {
override val isOperator get() = wrapped.isOperator
override val isInfix get() = wrapped.isInfix
override val isInline get() = wrapped.isInline
override val isTailrec get() = wrapped.isTailrec
override val isSuspend get() = wrapped.isSuspend
override val valueParameters by lazy(PUBLICATION) { wrapped.valueParameters.map(::CirWrappedValueParameter) }
override val hasStableParameterNames get() = wrapped.hasStableParameterNames()
override val hasSynthesizedParameterNames get() = wrapped.hasSynthesizedParameterNames()
class CirFunctionImpl(original: SimpleFunctionDescriptor) : CirFunctionOrPropertyImpl<SimpleFunctionDescriptor>(original), CirFunction {
override val isOperator = original.isOperator
override val isInfix = original.isInfix
override val isInline = original.isInline
override val isTailrec = original.isTailrec
override val isSuspend = original.isSuspend
override val valueParameters = original.valueParameters.map(::CirValueParameterImpl)
override val hasStableParameterNames = original.hasStableParameterNames()
override val hasSynthesizedParameterNames = original.hasSynthesizedParameterNames()
}
interface CirValueParameter {
val name: Name
val annotations: Annotations
val annotations: List<CirAnnotation>
val returnType: CirType
val varargElementType: CirType?
val declaresDefaultValue: Boolean
@@ -69,16 +67,16 @@ data class CirCommonValueParameter(
override val isCrossinline: Boolean,
override val isNoinline: Boolean
) : CirValueParameter {
override val annotations get() = Annotations.EMPTY
override val annotations: List<CirAnnotation> get() = emptyList()
override val declaresDefaultValue get() = false
}
data class CirWrappedValueParameter(private val wrapped: ValueParameterDescriptor) : CirValueParameter {
override val name get() = wrapped.name
override val annotations get() = wrapped.annotations
override val returnType by lazy(PUBLICATION) { CirType.create(wrapped.returnType!!) }
override val varargElementType by lazy(PUBLICATION) { wrapped.varargElementType?.let(CirType.Companion::create) }
override val declaresDefaultValue get() = wrapped.declaresDefaultValue()
override val isCrossinline get() = wrapped.isCrossinline
override val isNoinline get() = wrapped.isNoinline
class CirValueParameterImpl(original: ValueParameterDescriptor) : CirValueParameter {
override val name = original.name
override val annotations = original.annotations.map(::CirAnnotation)
override val returnType = CirType.create(original.returnType!!)
override val varargElementType = original.varargElementType?.let(CirType.Companion::create)
override val declaresDefaultValue = original.declaresDefaultValue()
override val isCrossinline = original.isCrossinline
override val isNoinline = original.isNoinline
}
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirExtensionReceiver.Companion.toReceiver
import kotlin.LazyThreadSafetyMode.PUBLICATION
interface CirFunctionOrProperty : CirAnnotatedDeclaration, CirNamedDeclaration, CirDeclarationWithTypeParameters, CirDeclarationWithVisibility, CirDeclarationWithModality, CirMaybeCallableMemberOfClass {
val isExternal: Boolean
@@ -23,20 +22,26 @@ abstract class CirCommonFunctionOrProperty : CirFunctionOrProperty {
final override val containingClassIsData: Boolean? get() = unsupported()
}
abstract class CirWrappedFunctionOrProperty<T : CallableMemberDescriptor>(protected val wrapped: T) : CirFunctionOrProperty {
final override val annotations by lazy(PUBLICATION) { wrapped.annotations.map(::CirAnnotation) }
final override val name get() = wrapped.name
final override val modality get() = wrapped.modality
final override val visibility get() = wrapped.visibility
final override val isExternal get() = wrapped.isExternal
final override val extensionReceiver by lazy(PUBLICATION) { wrapped.extensionReceiverParameter?.toReceiver() }
final override val returnType by lazy(PUBLICATION) { CirType.create(wrapped.returnType!!) }
final override val kind get() = wrapped.kind
final override val containingClassKind: ClassKind? get() = containingClass?.kind
final override val containingClassModality: Modality? get() = containingClass?.modality
final override val containingClassIsData: Boolean? get() = containingClass?.isData
final override val typeParameters by lazy(PUBLICATION) { wrapped.typeParameters.map(::CirWrappedTypeParameter) }
private val containingClass: ClassDescriptor? get() = wrapped.containingDeclaration as? ClassDescriptor
abstract class CirFunctionOrPropertyImpl<T : CallableMemberDescriptor>(original: T) : CirFunctionOrProperty {
final override val annotations = original.annotations.map(::CirAnnotation)
final override val name = original.name
final override val modality = original.modality
final override val visibility = original.visibility
final override val isExternal = original.isExternal
final override val extensionReceiver = original.extensionReceiverParameter?.toReceiver()
final override val returnType = CirType.create(original.returnType!!)
final override val kind = original.kind
final override val containingClassKind: ClassKind?
final override val containingClassModality: Modality?
final override val containingClassIsData: Boolean?
final override val typeParameters = original.typeParameters.map(::CirTypeParameterImpl)
init {
val containingClass = original.containingDeclaration as? ClassDescriptor
containingClassKind = containingClass?.kind
containingClassModality = containingClass?.modality
containingClassIsData = containingClass?.isData
}
}
data class CirExtensionReceiver(
@@ -10,5 +10,5 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.name.Name
data class CirModule(val name: Name, val builtIns: KotlinBuiltIns) : CirDeclaration {
constructor(descriptor: ModuleDescriptor) : this(descriptor.name, descriptor.builtIns)
constructor(descriptor: ModuleDescriptor) : this(descriptor.name, descriptor.builtIns) // TODO: strong ref
}
@@ -6,12 +6,10 @@
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirGetter.Companion.toGetter
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirSetter.Companion.toSetter
import org.jetbrains.kotlin.resolve.constants.ConstantValue
import kotlin.LazyThreadSafetyMode.PUBLICATION
interface CirProperty : CirFunctionOrProperty {
val isVar: Boolean
@@ -20,8 +18,8 @@ interface CirProperty : CirFunctionOrProperty {
val isDelegate: Boolean
val getter: CirGetter?
val setter: CirSetter?
val backingFieldAnnotations: Annotations? // null assumes no backing field
val delegateFieldAnnotations: Annotations? // null assumes no backing field
val backingFieldAnnotations: List<CirAnnotation>? // null assumes no backing field
val delegateFieldAnnotations: List<CirAnnotation>? // null assumes no backing field
val compileTimeInitializer: ConstantValue<*>?
}
@@ -41,50 +39,56 @@ data class CirCommonProperty(
override val isConst get() = false
override val isDelegate get() = false
override val getter get() = CirGetter.DEFAULT_NO_ANNOTATIONS
override val backingFieldAnnotations: Annotations? get() = null
override val delegateFieldAnnotations: Annotations? get() = null
override val backingFieldAnnotations: List<CirAnnotation>? get() = null
override val delegateFieldAnnotations: List<CirAnnotation>? get() = null
override val compileTimeInitializer: ConstantValue<*>? get() = null
}
class CirWrappedProperty(wrapped: PropertyDescriptor) : CirWrappedFunctionOrProperty<PropertyDescriptor>(wrapped), CirProperty {
override val isVar get() = wrapped.isVar
override val isLateInit get() = wrapped.isLateInit
override val isConst get() = wrapped.isConst
override val isDelegate get() = @Suppress("DEPRECATION") wrapped.isDelegated
override val getter by lazy(PUBLICATION) { wrapped.getter?.toGetter() }
override val setter by lazy(PUBLICATION) { wrapped.setter?.toSetter() }
override val backingFieldAnnotations get() = wrapped.backingField?.annotations
override val delegateFieldAnnotations get() = wrapped.delegateField?.annotations
override val compileTimeInitializer get() = wrapped.compileTimeInitializer
class CirPropertyImpl(original: PropertyDescriptor) : CirFunctionOrPropertyImpl<PropertyDescriptor>(original), CirProperty {
override val isVar = original.isVar
override val isLateInit = original.isLateInit
override val isConst = original.isConst
override val isDelegate = @Suppress("DEPRECATION") original.isDelegated
override val getter = original.getter?.toGetter()
override val setter = original.setter?.toSetter()
override val backingFieldAnnotations = original.backingField?.annotations?.map(::CirAnnotation)
override val delegateFieldAnnotations = original.delegateField?.annotations?.map(::CirAnnotation)
override val compileTimeInitializer = original.compileTimeInitializer
init {
compileTimeInitializer?.let { compileTimeInitializer ->
checkSupportedInCommonization(compileTimeInitializer) { "${original::class.java}, $original" }
}
}
}
interface CirPropertyAccessor {
val annotations: Annotations
val annotations: List<CirAnnotation>
val isDefault: Boolean
val isExternal: Boolean
val isInline: Boolean
}
data class CirGetter(
override val annotations: Annotations,
override val annotations: List<CirAnnotation>,
override val isDefault: Boolean,
override val isExternal: Boolean,
override val isInline: Boolean
) : CirPropertyAccessor {
companion object {
val DEFAULT_NO_ANNOTATIONS = CirGetter(Annotations.EMPTY, isDefault = true, isExternal = false, isInline = false)
val DEFAULT_NO_ANNOTATIONS = CirGetter(emptyList(), isDefault = true, isExternal = false, isInline = false)
fun PropertyGetterDescriptor.toGetter() =
if (isDefault && annotations.isEmpty())
DEFAULT_NO_ANNOTATIONS
else
CirGetter(annotations, isDefault, isExternal, isInline)
CirGetter(annotations.map(::CirAnnotation), isDefault, isExternal, isInline)
}
}
data class CirSetter(
override val annotations: Annotations,
val parameterAnnotations: Annotations,
override val annotations: List<CirAnnotation>,
val parameterAnnotations: List<CirAnnotation>,
override val visibility: Visibility,
override val isDefault: Boolean,
override val isExternal: Boolean,
@@ -92,8 +96,8 @@ data class CirSetter(
) : CirPropertyAccessor, CirDeclarationWithVisibility {
companion object {
fun createDefaultNoAnnotations(visibility: Visibility) = CirSetter(
Annotations.EMPTY,
Annotations.EMPTY,
emptyList(),
emptyList(),
visibility,
isDefault = visibility == Visibilities.PUBLIC,
isExternal = false,
@@ -101,8 +105,8 @@ data class CirSetter(
)
fun PropertySetterDescriptor.toSetter() = CirSetter(
annotations,
valueParameters.single().annotations,
annotations.map(::CirAnnotation),
valueParameters.single().annotations.map(::CirAnnotation),
visibility,
isDefault,
isExternal,
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.descriptors.commonizer.utils.fqName
import org.jetbrains.kotlin.descriptors.commonizer.utils.fqNameWithTypeParameters
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.types.*
import kotlin.LazyThreadSafetyMode.PUBLICATION
sealed class CirType {
companion object {
@@ -36,25 +35,35 @@ sealed class CirType {
* This is necessary to properly compare types for type aliases, where abbreviation type represents the type alias itself while
* expanded type represents right-hand side declaration that should be processed separately.
*
* There is no difference between [abbreviation] and [expanded] for types representing classes and type parameters.
* There is no difference between "abbreviation" and "expanded" for types representing classes and type parameters.
*/
class CirSimpleType(private val wrapped: SimpleType) : CirType() {
val annotations by lazy(PUBLICATION) { abbreviation.annotations.map(::CirAnnotation) }
val kind = CirSimpleTypeKind.determineKind(abbreviation.declarationDescriptor)
val fqName by lazy(PUBLICATION) { abbreviation.fqName }
val arguments by lazy(PUBLICATION) { abbreviation.arguments.map(::CirTypeProjection) }
val isMarkedNullable get() = abbreviation.isMarkedNullable
val isDefinitelyNotNullType get() = abbreviation.isDefinitelyNotNullType
val expandedTypeConstructorId by lazy(PUBLICATION) { CirTypeConstructorId(expanded) }
class CirSimpleType(original: SimpleType) : CirType() {
val annotations: List<CirAnnotation>
val kind: CirSimpleTypeKind
val fqName: FqName
val arguments: List<CirTypeProjection>
val isMarkedNullable: Boolean
val isDefinitelyNotNullType: Boolean
val expandedTypeConstructorId: CirTypeConstructorId
init {
val abbreviation = (original as? AbbreviatedType)?.abbreviation ?: original
val expanded = (original as? AbbreviatedType)?.expandedType ?: original
annotations = abbreviation.annotations.map(::CirAnnotation)
kind = CirSimpleTypeKind.determineKind(abbreviation.declarationDescriptor)
fqName = abbreviation.fqName
arguments = abbreviation.arguments.map(::CirTypeProjection)
isMarkedNullable = abbreviation.isMarkedNullable
isDefinitelyNotNullType = abbreviation.isDefinitelyNotNullType
expandedTypeConstructorId = CirTypeConstructorId(expanded)
}
inline val isClassOrTypeAlias get() = (kind == CLASS || kind == TYPE_ALIAS)
val fqNameWithTypeParameters by lazy(PUBLICATION) { wrapped.fqNameWithTypeParameters }
val fqNameWithTypeParameters = original.fqNameWithTypeParameters
override fun equals(other: Any?) = wrapped == (other as? CirSimpleType)?.wrapped
override fun hashCode() = wrapped.hashCode()
private inline val abbreviation: SimpleType get() = (wrapped as? AbbreviatedType)?.abbreviation ?: wrapped
private inline val expanded: SimpleType get() = (wrapped as? AbbreviatedType)?.expandedType ?: wrapped
override fun equals(other: Any?) = fqNameWithTypeParameters == (other as? CirSimpleType)?.fqNameWithTypeParameters
override fun hashCode() = fqNameWithTypeParameters.hashCode()
}
enum class CirSimpleTypeKind {
@@ -79,10 +88,10 @@ data class CirTypeConstructorId(val fqName: FqName, val numberOfTypeParameters:
constructor(type: SimpleType) : this(type.fqName, type.constructor.parameters.size)
}
class CirTypeProjection(private val wrapped: TypeProjection) {
val projectionKind get() = wrapped.projectionKind
val isStarProjection get() = wrapped.isStarProjection
val type by lazy(PUBLICATION) { CirType.create(wrapped.type) }
class CirTypeProjection(original: TypeProjection) {
val projectionKind = original.projectionKind
val isStarProjection = original.isStarProjection
val type = CirType.create(original.type)
}
data class CirFlexibleType(val lowerBound: CirSimpleType, val upperBound: CirSimpleType) : CirType()
@@ -6,18 +6,17 @@
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
import kotlin.LazyThreadSafetyMode.PUBLICATION
interface CirTypeAlias : CirAnnotatedDeclaration, CirNamedDeclaration, CirDeclarationWithTypeParameters, CirDeclarationWithVisibility {
val underlyingType: CirSimpleType
val expandedType: CirSimpleType
}
class CirWrappedTypeAlias(private val wrapped: TypeAliasDescriptor) : CirTypeAlias {
override val annotations by lazy(PUBLICATION) { wrapped.annotations.map(::CirAnnotation) }
override val name get() = wrapped.name
override val typeParameters by lazy(PUBLICATION) { wrapped.declaredTypeParameters.map(::CirWrappedTypeParameter) }
override val visibility get() = wrapped.visibility
override val underlyingType by lazy(PUBLICATION) { CirSimpleType(wrapped.underlyingType) }
override val expandedType by lazy(PUBLICATION) { CirSimpleType(wrapped.expandedType) }
class CirTypeAliasImpl(original: TypeAliasDescriptor) : CirTypeAlias {
override val annotations = original.annotations.map(::CirAnnotation)
override val name = original.name
override val typeParameters = original.declaredTypeParameters.map(::CirTypeParameterImpl)
override val visibility = original.visibility
override val underlyingType = CirSimpleType(original.underlyingType)
override val expandedType = CirSimpleType(original.expandedType)
}
@@ -6,13 +6,11 @@
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.Variance
import kotlin.LazyThreadSafetyMode.PUBLICATION
interface CirTypeParameter {
val annotations: Annotations
val annotations: List<CirAnnotation>
val name: Name
val isReified: Boolean
val variance: Variance
@@ -25,13 +23,13 @@ data class CirCommonTypeParameter(
override val variance: Variance,
override val upperBounds: List<CirType>
) : CirTypeParameter {
override val annotations get() = Annotations.EMPTY
override val annotations: List<CirAnnotation> get() = emptyList()
}
data class CirWrappedTypeParameter(private val wrapped: TypeParameterDescriptor) : CirTypeParameter {
override val annotations get() = wrapped.annotations
override val name get() = wrapped.name
override val isReified get() = wrapped.isReified
override val variance get() = wrapped.variance
override val upperBounds by lazy(PUBLICATION) { wrapped.upperBounds.map(CirType.Companion::create) }
class CirTypeParameterImpl(original: TypeParameterDescriptor) : CirTypeParameter {
override val annotations = original.annotations.map(::CirAnnotation)
override val name = original.name
override val isReified = original.isReified
override val variance = original.variance
override val upperBounds = original.upperBounds.map(CirType.Companion::create)
}
@@ -66,7 +66,7 @@ internal fun buildPropertyNode(
): CirPropertyNode = buildNode(
storageManager = storageManager,
descriptors = properties,
targetDeclarationProducer = ::CirWrappedProperty,
targetDeclarationProducer = ::CirPropertyImpl,
commonValueProducer = { commonize(containingDeclarationCommon, it, PropertyCommonizer(cache)) },
recursionMarker = null,
nodeProducer = ::CirPropertyNode
@@ -80,7 +80,7 @@ internal fun buildFunctionNode(
): CirFunctionNode = buildNode(
storageManager = storageManager,
descriptors = functions,
targetDeclarationProducer = ::CirWrappedFunction,
targetDeclarationProducer = ::CirFunctionImpl,
commonValueProducer = { commonize(containingDeclarationCommon, it, FunctionCommonizer(cache)) },
recursionMarker = null,
nodeProducer = ::CirFunctionNode
@@ -94,7 +94,7 @@ internal fun buildClassNode(
): CirClassNode = buildNode(
storageManager = storageManager,
descriptors = classes,
targetDeclarationProducer = ::CirWrappedClass,
targetDeclarationProducer = ::CirClassImpl,
commonValueProducer = { commonize(containingDeclarationCommon, it, ClassCommonizer(cacheRW)) },
recursionMarker = CirClassRecursionMarker,
nodeProducer = ::CirClassNode
@@ -113,7 +113,7 @@ internal fun buildClassConstructorNode(
): CirClassConstructorNode = buildNode(
storageManager = storageManager,
descriptors = constructors,
targetDeclarationProducer = ::CirWrappedClassConstructor,
targetDeclarationProducer = ::CirClassConstructorImpl,
commonValueProducer = { commonize(containingDeclarationCommon, it, ClassConstructorCommonizer(cache)) },
recursionMarker = null,
nodeProducer = ::CirClassConstructorNode
@@ -126,7 +126,7 @@ internal fun buildTypeAliasNode(
): CirTypeAliasNode = buildNode(
storageManager = storageManager,
descriptors = typeAliases,
targetDeclarationProducer = ::CirWrappedTypeAlias,
targetDeclarationProducer = ::CirTypeAliasImpl,
commonValueProducer = { commonize(it, TypeAliasCommonizer(cacheRW)) },
recursionMarker = CirClassRecursionMarker,
nodeProducer = ::CirTypeAliasNode
@@ -1,8 +1,8 @@
expect annotation class CommonAnnotationForAnnotationClassesOnly(text: String) { val text: String }
expect annotation class CommonAnnotation(text: String) { val text: String }
expect annotation class CommonOuterAnnotation(inner: CommonInnerAnnotation) { val inner: CommonInnerAnnotation }
expect annotation class CommonInnerAnnotation(text: String) { val text: String }
//expect annotation class CommonOuterAnnotation(inner: CommonInnerAnnotation) { val inner: CommonInnerAnnotation }
//expect annotation class CommonInnerAnnotation(text: String) { val text: String }
expect var propertyWithoutBackingField: Double
expect val propertyWithBackingField: Double
@@ -15,4 +15,4 @@ expect fun <Q : Number> Q.function2(): Q
expect class AnnotatedClass(value: String) { val value: String }
expect class AnnotatedTypeAlias
expect object ObjectWithNestedAnnotations
//expect object ObjectWithNestedAnnotations
@@ -16,13 +16,13 @@ annotation class JsAnnotationForAnnotationClassesOnly(val text: String)
@CommonAnnotationForAnnotationClassesOnly("annotation-class")
annotation class JsAnnotation(val text: String)
@Target(AnnotationTarget.CLASS)
actual annotation class CommonOuterAnnotation(actual val inner: CommonInnerAnnotation)
actual annotation class CommonInnerAnnotation(actual val text: String)
//@Target(AnnotationTarget.CLASS)
//actual annotation class CommonOuterAnnotation(actual val inner: CommonInnerAnnotation)
//actual annotation class CommonInnerAnnotation(actual val text: String)
@Target(AnnotationTarget.CLASS)
annotation class JsOuterAnnotation(val inner: JsInnerAnnotation)
annotation class JsInnerAnnotation(val text: String)
//@Target(AnnotationTarget.CLASS)
//annotation class JsOuterAnnotation(val inner: JsInnerAnnotation)
//annotation class JsInnerAnnotation(val text: String)
@JsAnnotation("property")
@CommonAnnotation("property")
@@ -57,6 +57,6 @@ actual class AnnotatedClass @JsAnnotation("constructor") @CommonAnnotation("cons
@CommonAnnotation("type-alias")
actual typealias AnnotatedTypeAlias = AnnotatedClass
@JsOuterAnnotation(inner = JsInnerAnnotation("nested-annotations"))
@CommonOuterAnnotation(inner = CommonInnerAnnotation("nested-annotations"))
actual object ObjectWithNestedAnnotations
//@JsOuterAnnotation(inner = JsInnerAnnotation("nested-annotations"))
//@CommonOuterAnnotation(inner = CommonInnerAnnotation("nested-annotations"))
//actual object ObjectWithNestedAnnotations
@@ -16,13 +16,13 @@ annotation class JvmAnnotationForAnnotationClassesOnly(val text: String)
@CommonAnnotationForAnnotationClassesOnly("annotation-class")
annotation class JvmAnnotation(val text: String)
@Target(AnnotationTarget.CLASS)
actual annotation class CommonOuterAnnotation(actual val inner: CommonInnerAnnotation)
actual annotation class CommonInnerAnnotation(actual val text: String)
@Target(AnnotationTarget.CLASS)
annotation class JvmOuterAnnotation(val inner: JvmInnerAnnotation)
annotation class JvmInnerAnnotation(val text: String)
//@Target(AnnotationTarget.CLASS)
//actual annotation class CommonOuterAnnotation(actual val inner: CommonInnerAnnotation)
//actual annotation class CommonInnerAnnotation(actual val text: String)
//
//@Target(AnnotationTarget.CLASS)
//annotation class JvmOuterAnnotation(val inner: JvmInnerAnnotation)
//annotation class JvmInnerAnnotation(val text: String)
@JvmAnnotation("property")
@CommonAnnotation("property")
@@ -57,6 +57,6 @@ actual class AnnotatedClass @JvmAnnotation("constructor") @CommonAnnotation("con
@CommonAnnotation("type-alias")
actual typealias AnnotatedTypeAlias = AnnotatedClass
@JvmOuterAnnotation(inner = JvmInnerAnnotation("nested-annotations"))
@CommonOuterAnnotation(inner = CommonInnerAnnotation("nested-annotations"))
actual object ObjectWithNestedAnnotations
//@JvmOuterAnnotation(inner = JvmInnerAnnotation("nested-annotations"))
//@CommonOuterAnnotation(inner = CommonInnerAnnotation("nested-annotations"))
//actual object ObjectWithNestedAnnotations
@@ -16,13 +16,13 @@ annotation class JsAnnotationForAnnotationClassesOnly(val text: String)
@CommonAnnotationForAnnotationClassesOnly("annotation-class")
annotation class JsAnnotation(val text: String)
@Target(AnnotationTarget.CLASS)
annotation class CommonOuterAnnotation(val inner: CommonInnerAnnotation)
annotation class CommonInnerAnnotation(val text: String)
@Target(AnnotationTarget.CLASS)
annotation class JsOuterAnnotation(val inner: JsInnerAnnotation)
annotation class JsInnerAnnotation(val text: String)
//@Target(AnnotationTarget.CLASS)
//annotation class CommonOuterAnnotation(val inner: CommonInnerAnnotation)
//annotation class CommonInnerAnnotation(val text: String)
//
//@Target(AnnotationTarget.CLASS)
//annotation class JsOuterAnnotation(val inner: JsInnerAnnotation)
//annotation class JsInnerAnnotation(val text: String)
@JsAnnotation("property")
@CommonAnnotation("property")
@@ -57,6 +57,6 @@ class AnnotatedClass @JsAnnotation("constructor") @CommonAnnotation("constructor
@CommonAnnotation("type-alias")
typealias AnnotatedTypeAlias = AnnotatedClass
@JsOuterAnnotation(inner = JsInnerAnnotation("nested-annotations"))
@CommonOuterAnnotation(inner = CommonInnerAnnotation("nested-annotations"))
object ObjectWithNestedAnnotations
//@JsOuterAnnotation(inner = JsInnerAnnotation("nested-annotations"))
//@CommonOuterAnnotation(inner = CommonInnerAnnotation("nested-annotations"))
//object ObjectWithNestedAnnotations
@@ -16,13 +16,13 @@ annotation class JvmAnnotationForAnnotationClassesOnly(val text: String)
@CommonAnnotationForAnnotationClassesOnly("annotation-class")
annotation class JvmAnnotation(val text: String)
@Target(AnnotationTarget.CLASS)
annotation class CommonOuterAnnotation(val inner: CommonInnerAnnotation)
annotation class CommonInnerAnnotation(val text: String)
@Target(AnnotationTarget.CLASS)
annotation class JvmOuterAnnotation(val inner: JvmInnerAnnotation)
annotation class JvmInnerAnnotation(val text: String)
//@Target(AnnotationTarget.CLASS)
//annotation class CommonOuterAnnotation(val inner: CommonInnerAnnotation)
//annotation class CommonInnerAnnotation(val text: String)
//
//@Target(AnnotationTarget.CLASS)
//annotation class JvmOuterAnnotation(val inner: JvmInnerAnnotation)
//annotation class JvmInnerAnnotation(val text: String)
@JvmAnnotation("property")
@CommonAnnotation("property")
@@ -57,6 +57,6 @@ class AnnotatedClass @JvmAnnotation("constructor") @CommonAnnotation("constructo
@CommonAnnotation("type-alias")
typealias AnnotatedTypeAlias = AnnotatedClass
@JvmOuterAnnotation(inner = JvmInnerAnnotation("nested-annotations"))
@CommonOuterAnnotation(inner = CommonInnerAnnotation("nested-annotations"))
object ObjectWithNestedAnnotations
//@JvmOuterAnnotation(inner = JvmInnerAnnotation("nested-annotations"))
//@CommonOuterAnnotation(inner = CommonInnerAnnotation("nested-annotations"))
//object ObjectWithNestedAnnotations
@@ -5,9 +5,9 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE
import org.jetbrains.kotlin.descriptors.commonizer.core.CirTestValueParameter.Companion.areEqual
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirAnnotation
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassifiersCache
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirType
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirValueParameter
@@ -157,7 +157,7 @@ class DefaultValueParameterCommonizerTest : AbstractCommonizerTest<CirValueParam
return CirTestValueParameter(
name = Name.identifier(name),
annotations = Annotations.EMPTY,
annotations = emptyList(),
returnType = returnType,
varargElementType = returnType.takeIf { hasVarargElementType }, // the vararg type itself does not matter here, only it's presence matters
isCrossinline = isCrossinline,
@@ -170,7 +170,7 @@ class DefaultValueParameterCommonizerTest : AbstractCommonizerTest<CirValueParam
internal data class CirTestValueParameter(
override val name: Name,
override val annotations: Annotations,
override val annotations: List<CirAnnotation>,
override val returnType: CirType,
override val varargElementType: CirType?,
override val declaresDefaultValue: Boolean,