diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedAnnotationDescriptor.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedAnnotationDescriptor.kt index 536e4f0f7c6..aacb3cdc1e3 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedAnnotationDescriptor.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedAnnotationDescriptor.kt @@ -9,7 +9,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassKind.ANNOTATION_CLASS import org.jetbrains.kotlin.descriptors.SourceElement import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation import org.jetbrains.kotlin.descriptors.commonizer.utils.concat import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.constants.AnnotationValue diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedClassDescriptor.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedClassDescriptor.kt index 740774e6f1a..2a38f3e82f0 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedClassDescriptor.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedClassDescriptor.kt @@ -7,13 +7,13 @@ package org.jetbrains.kotlin.descriptors.commonizer.builder import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirType -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirTypeParameter +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorBase import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.resolve.DescriptorFactory.* +import org.jetbrains.kotlin.resolve.DescriptorFactory.createPrimaryConstructorForObject import org.jetbrains.kotlin.resolve.descriptorUtil.computeSealedSubclasses import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.scopes.MemberScope diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedTypeParameterDescriptor.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedTypeParameterDescriptor.kt index 88c9d3c7cd4..1ca2df9e0e3 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedTypeParameterDescriptor.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedTypeParameterDescriptor.kt @@ -9,7 +9,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.SourceElement import org.jetbrains.kotlin.descriptors.SupertypeLoopChecker import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.KotlinType diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/DeclarationsBuilderVisitor1.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/DeclarationsBuilderVisitor1.kt index 9510e455167..0baae510f23 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/DeclarationsBuilderVisitor1.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/DeclarationsBuilderVisitor1.kt @@ -12,7 +12,7 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor import org.jetbrains.kotlin.descriptors.commonizer.Target import org.jetbrains.kotlin.descriptors.commonizer.builder.CommonizedMemberScope.Companion.plusAssign import org.jetbrains.kotlin.descriptors.commonizer.builder.CommonizedPackageFragmentProvider.Companion.plusAssign -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.* +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.* import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl import org.jetbrains.kotlin.utils.addIfNotNull diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/DeclarationsBuilderVisitor2.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/DeclarationsBuilderVisitor2.kt index b2eefda0012..7e131ef62b2 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/DeclarationsBuilderVisitor2.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/DeclarationsBuilderVisitor2.kt @@ -10,7 +10,7 @@ import org.jetbrains.kotlin.descriptors.commonizer.builder.CommonizedMemberScope import org.jetbrains.kotlin.descriptors.commonizer.builder.DeclarationsBuilderVisitor1.Companion.asListContaining import org.jetbrains.kotlin.descriptors.commonizer.builder.DeclarationsBuilderVisitor1.Companion.noContainingDeclarations import org.jetbrains.kotlin.descriptors.commonizer.builder.DeclarationsBuilderVisitor1.Companion.noReturningDeclarations -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.* +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.* import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/builderUtils.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/builderUtils.kt index a61efe9be9a..305be20113a 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/builderUtils.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/builderUtils.kt @@ -7,8 +7,9 @@ package org.jetbrains.kotlin.descriptors.commonizer.builder import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.* -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirSimpleTypeKind.Companion.areCompatible +import org.jetbrains.kotlin.descriptors.commonizer.cir.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirSimpleTypeKind.Companion.areCompatible +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.cirSimpleTypeKind import org.jetbrains.kotlin.descriptors.commonizer.utils.isUnderStandardKotlinPackages import org.jetbrains.kotlin.descriptors.commonizer.utils.resolveClassOrTypeAliasByFqName import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl @@ -160,7 +161,7 @@ internal fun findClassOrTypeAlias( } private fun checkClassifier(classifier: ClassifierDescriptor, kind: CirSimpleTypeKind, strict: Boolean) { - val classifierKind = CirSimpleTypeKind.determineKind(classifier) + val classifierKind = classifier.cirSimpleTypeKind if (strict) { check(kind == classifierKind) { diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/classDescriptors.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/classDescriptors.kt index d8ed51d75f1..048c1b7e0a3 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/classDescriptors.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/classDescriptors.kt @@ -9,7 +9,11 @@ import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClassConstructor +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassConstructorNode +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassNode +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.indexOfCommon import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup import org.jetbrains.kotlin.name.FqName diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/context.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/context.kt index 4cb5d1b5af9..cee2ff4b995 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/context.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/context.kt @@ -9,9 +9,9 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.commonizer.StatsCollector import org.jetbrains.kotlin.descriptors.commonizer.Target -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirRootNode -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.dimension -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.indexOfCommon +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirRootNode +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.dimension +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.indexOfCommon import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroupMap import org.jetbrains.kotlin.descriptors.commonizer.utils.createKotlinNativeForwardDeclarationsModule diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/functionDescriptors.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/functionDescriptors.kt index 64145610824..4bd753bb187 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/functionDescriptors.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/functionDescriptors.kt @@ -9,9 +9,9 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor import org.jetbrains.kotlin.descriptors.SourceElement -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirFunction -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirFunctionNode -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.indexOfCommon +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirFunction +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirFunctionNode +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.indexOfCommon import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl @@ -52,12 +52,12 @@ private fun CirFunction.buildDescriptor( SourceElement.NO_SOURCE ) - functionDescriptor.isOperator = isOperator - functionDescriptor.isInfix = isInfix - functionDescriptor.isInline = isInline - functionDescriptor.isTailrec = isTailrec - functionDescriptor.isSuspend = isSuspend - functionDescriptor.isExternal = isExternal + functionDescriptor.isOperator = modifiers.isOperator + functionDescriptor.isInfix = modifiers.isInfix + functionDescriptor.isInline = modifiers.isInline + functionDescriptor.isTailrec = modifiers.isTailrec + functionDescriptor.isSuspend = modifiers.isSuspend + functionDescriptor.isExternal = modifiers.isExternal functionDescriptor.isExpect = isExpect functionDescriptor.isActual = isActual diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/moduleDescriptors.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/moduleDescriptors.kt index c94ecd256e0..bb0a65e6a51 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/moduleDescriptors.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/moduleDescriptors.kt @@ -5,9 +5,9 @@ package org.jetbrains.kotlin.descriptors.commonizer.builder -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirModule -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirModuleNode -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.indexOfCommon +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirModule +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirModuleNode +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.indexOfCommon import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/packageFragments.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/packageFragments.kt index 625aab9257d..37c769e69ba 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/packageFragments.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/packageFragments.kt @@ -6,9 +6,9 @@ package org.jetbrains.kotlin.descriptors.commonizer.builder import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirPackage -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirPackageNode -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.indexOfCommon +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackage +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirPackageNode +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.indexOfCommon import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/propertyDescriptors.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/propertyDescriptors.kt index f6aa370ce27..5c85348c1f1 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/propertyDescriptors.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/propertyDescriptors.kt @@ -9,9 +9,9 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.SourceElement -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirProperty -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirPropertyNode -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.indexOfCommon +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirProperty +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirPropertyNode +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.indexOfCommon import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup import org.jetbrains.kotlin.descriptors.impl.FieldDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/typeAliasDescriptors.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/typeAliasDescriptors.kt index cf6e8db27ef..d721c13b148 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/typeAliasDescriptors.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/typeAliasDescriptors.kt @@ -7,10 +7,10 @@ package org.jetbrains.kotlin.descriptors.commonizer.builder import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClass -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirTypeAlias -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirTypeAliasNode -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.indexOfCommon +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeAlias +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirTypeAliasNode +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.indexOfCommon import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup import org.jetbrains.kotlin.name.FqName diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirAnnotation.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirAnnotation.kt new file mode 100644 index 00000000000..daa58875c44 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirAnnotation.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.constants.ConstantValue + +interface CirAnnotation { + val fqName: FqName + val constantValueArguments: Map> + val annotationValueArguments: Map +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirClass.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirClass.kt new file mode 100644 index 00000000000..276d7687c02 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirClass.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +import org.jetbrains.kotlin.descriptors.ClassKind +import org.jetbrains.kotlin.name.FqName + +interface CirClass : + CirAnnotatedDeclaration, + CirNamedDeclaration, + CirDeclarationWithTypeParameters, + CirDeclarationWithVisibility, + CirDeclarationWithModality { + + val kind: ClassKind + var companion: FqName? // null means no companion object + val isCompanion: Boolean + val isData: Boolean + val isInline: Boolean + val isInner: Boolean + val isExternal: Boolean + val supertypes: MutableCollection +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirClassConstructor.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirClassConstructor.kt new file mode 100644 index 00000000000..291a9a175db --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirClassConstructor.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor + +interface CirClassConstructor : + CirAnnotatedDeclaration, + CirDeclarationWithTypeParameters, + CirDeclarationWithVisibility, + CirMaybeCallableMemberOfClass, + CirCallableMemberWithParameters { + + val isPrimary: Boolean + val kind: CallableMemberDescriptor.Kind + override val containingClassDetails: CirContainingClassDetails // non-nullable +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirContainingClassDetails.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirContainingClassDetails.kt new file mode 100644 index 00000000000..f3057efbd98 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirContainingClassDetails.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +import org.jetbrains.kotlin.descriptors.ClassKind +import org.jetbrains.kotlin.descriptors.Modality + +// TODO: inline? +data class CirContainingClassDetails( + val kind: ClassKind, + val modality: Modality, + val isData: Boolean +) { + companion object { + val DOES_NOT_MATTER = CirContainingClassDetails( + kind = ClassKind.CLASS, + modality = Modality.FINAL, + isData = false + ) + } +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirDeclaration.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirDeclaration.kt similarity index 74% rename from native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirDeclaration.kt rename to native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirDeclaration.kt index ff28ba15f7d..01df59134b6 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirDeclaration.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirDeclaration.kt @@ -1,9 +1,9 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir +package org.jetbrains.kotlin.descriptors.commonizer.cir import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.name.FqName @@ -40,17 +40,18 @@ interface CirDeclarationWithModality : CirDeclaration { } interface CirMaybeCallableMemberOfClass : CirDeclaration { - val containingClassKind: ClassKind? // null assumes no containing class - val containingClassModality: Modality? // null assumes no containing class - val containingClassIsData: Boolean? // null assumes no containing class + val containingClassDetails: CirContainingClassDetails? // null assumes no containing class } interface CirDeclarationWithTypeParameters : CirDeclaration { val typeParameters: List } +interface CirCallableMemberWithParameters { + val valueParameters: List + val hasStableParameterNames: Boolean + val hasSynthesizedParameterNames: Boolean +} + /** Indicates presence of recursion in lazy calculations. */ interface CirRecursionMarker : CirDeclaration - -@Suppress("unused", "NOTHING_TO_INLINE") -internal inline fun CirDeclaration.unsupported(): Nothing = error("This method should never be called") diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirExtensionReceiver.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirExtensionReceiver.kt new file mode 100644 index 00000000000..932f8e7f208 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirExtensionReceiver.kt @@ -0,0 +1,11 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +interface CirExtensionReceiver { + val annotations: List + val type: CirType +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirFunction.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirFunction.kt new file mode 100644 index 00000000000..b6d9e34ee65 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirFunction.kt @@ -0,0 +1,10 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +interface CirFunction : CirFunctionOrProperty, CirCallableMemberWithParameters { + val modifiers: CirFunctionModifiers +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirFunctionModifiers.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirFunctionModifiers.kt new file mode 100644 index 00000000000..09dfffcf067 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirFunctionModifiers.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +// TODO: inline? +data class CirFunctionModifiers( + var isOperator: Boolean, + var isInfix: Boolean, + var isInline: Boolean, + var isTailrec: Boolean, + var isSuspend: Boolean, + var isExternal: Boolean +) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirFunctionOrProperty.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirFunctionOrProperty.kt new file mode 100644 index 00000000000..8e1a8c0fc26 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirFunctionOrProperty.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor +import org.jetbrains.kotlin.descriptors.ClassKind +import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.descriptors.Visibilities + +interface CirFunctionOrProperty : + CirAnnotatedDeclaration, + CirNamedDeclaration, + CirDeclarationWithTypeParameters, + CirDeclarationWithVisibility, + CirDeclarationWithModality, + CirMaybeCallableMemberOfClass { + + val isExternal: Boolean + val extensionReceiver: CirExtensionReceiver? + val returnType: CirType + val kind: CallableMemberDescriptor.Kind +} + +fun CirFunctionOrProperty.isNonAbstractMemberInInterface(): Boolean = + modality != Modality.ABSTRACT && containingClassDetails?.kind == ClassKind.INTERFACE + +fun CirFunctionOrProperty.isVirtual(): Boolean = + visibility != Visibilities.PRIVATE + && modality != Modality.FINAL + && !(containingClassDetails?.modality == Modality.FINAL && containingClassDetails?.kind != ClassKind.ENUM_CLASS) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirModule.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirModule.kt new file mode 100644 index 00000000000..2ed3f1596d4 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirModule.kt @@ -0,0 +1,8 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +interface CirModule : CirNamedDeclaration diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirPackage.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirPackage.kt new file mode 100644 index 00000000000..6be2f17f77c --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirPackage.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +import org.jetbrains.kotlin.name.FqName + +interface CirPackage : CirDeclaration { + val fqName: FqName +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirProperty.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirProperty.kt new file mode 100644 index 00000000000..1473dc044ce --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirProperty.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +import org.jetbrains.kotlin.resolve.constants.ConstantValue + +interface CirProperty : CirFunctionOrProperty { + val isVar: Boolean + val isLateInit: Boolean + val isConst: Boolean + val isDelegate: Boolean + val getter: CirPropertyGetter? + val setter: CirPropertySetter? + val backingFieldAnnotations: List? // null assumes no backing field + val delegateFieldAnnotations: List? // null assumes no backing field + val compileTimeInitializer: ConstantValue<*>? +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirPropertyAccessor.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirPropertyAccessor.kt new file mode 100644 index 00000000000..f272ff46164 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirPropertyAccessor.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +interface CirPropertyAccessor { + val annotations: List + val isDefault: Boolean + val isExternal: Boolean + val isInline: Boolean +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirPropertyGetter.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirPropertyGetter.kt new file mode 100644 index 00000000000..3577a25f027 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirPropertyGetter.kt @@ -0,0 +1,8 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +interface CirPropertyGetter : CirPropertyAccessor diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirPropertySetter.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirPropertySetter.kt new file mode 100644 index 00000000000..5ded1fc2e6a --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirPropertySetter.kt @@ -0,0 +1,10 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +interface CirPropertySetter : CirPropertyAccessor, CirDeclarationWithVisibility { + val parameterAnnotations: List +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirRoot.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirRoot.kt new file mode 100644 index 00000000000..676db84a1f1 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirRoot.kt @@ -0,0 +1,15 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +import org.jetbrains.kotlin.descriptors.commonizer.BuiltInsProvider +import org.jetbrains.kotlin.descriptors.commonizer.Target + +interface CirRoot : CirDeclaration { + val target: Target + val builtInsClass: String + val builtInsProvider: BuiltInsProvider +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirType.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirType.kt new file mode 100644 index 00000000000..0ed028d6a8a --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirType.kt @@ -0,0 +1,62 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirSimpleTypeKind.CLASS +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirSimpleTypeKind.TYPE_ALIAS +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.types.AbbreviatedType +import org.jetbrains.kotlin.types.Variance + +sealed class CirType + +/** + * All attributes except for [expandedTypeConstructorId] are read from the abbreviation type: [AbbreviatedType.abbreviation]. + * And [expandedTypeConstructorId] is read from the expanded type: [AbbreviatedType.expandedType]. + * + * 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. + * For details, see [CirTypeFactory]. + * + * Note: Annotations at simple types are not preserved. After commonization all annotations assigned to types will be lost. + */ +abstract class CirSimpleType : CirType() { + abstract val kind: CirSimpleTypeKind + abstract val fqName: FqName + abstract val arguments: List + abstract val isMarkedNullable: Boolean + abstract val isDefinitelyNotNullType: Boolean + abstract val expandedTypeConstructorId: CirTypeConstructorId + abstract val fqNameWithTypeParameters: String + + inline val isClassOrTypeAlias: Boolean get() = (kind == CLASS || kind == TYPE_ALIAS) +} + +enum class CirSimpleTypeKind { + CLASS, + TYPE_ALIAS, + TYPE_PARAMETER; + + companion object { + fun areCompatible(expect: CirSimpleTypeKind, actual: CirSimpleTypeKind): Boolean = + expect == actual || (expect == CLASS && actual == TYPE_ALIAS) + } +} + +data class CirTypeConstructorId(val fqName: FqName, val numberOfTypeParameters: Int) + +data class CirTypeProjection(val projectionKind: Variance, val isStarProjection: Boolean, val type: CirType) + +data class CirFlexibleType(val lowerBound: CirSimpleType, val upperBound: CirSimpleType) : CirType() + +val CirType.fqNameWithTypeParameters: String + get() = when (this) { + is CirSimpleType -> fqNameWithTypeParameters + is CirFlexibleType -> lowerBound.fqNameWithTypeParameters + } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirTypeAlias.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirTypeAlias.kt new file mode 100644 index 00000000000..84c7700f753 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirTypeAlias.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +interface CirTypeAlias : + CirAnnotatedDeclaration, + CirNamedDeclaration, + CirDeclarationWithTypeParameters, + CirDeclarationWithVisibility { + + val underlyingType: CirSimpleType + val expandedType: CirSimpleType +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirTypeParameter.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirTypeParameter.kt new file mode 100644 index 00000000000..5b7ea15197f --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirTypeParameter.kt @@ -0,0 +1,17 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.types.Variance + +interface CirTypeParameter { + val annotations: List + val name: Name + val isReified: Boolean + val variance: Variance + val upperBounds: List +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirValueParameter.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirValueParameter.kt new file mode 100644 index 00000000000..7c73eb536c5 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/CirValueParameter.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir + +import org.jetbrains.kotlin.name.Name + +interface CirValueParameter { + val annotations: List + val name: Name + val returnType: CirType + val varargElementType: CirType? + val declaresDefaultValue: Boolean + val isCrossinline: Boolean + val isNoinline: Boolean +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirAnnotationFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirAnnotationFactory.kt new file mode 100644 index 00000000000..85c132ffbad --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirAnnotationFactory.kt @@ -0,0 +1,66 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.factory + +import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirAnnotationImpl +import org.jetbrains.kotlin.descriptors.commonizer.utils.Interner +import org.jetbrains.kotlin.descriptors.commonizer.utils.checkConstantSupportedInCommonization +import org.jetbrains.kotlin.descriptors.commonizer.utils.intern +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.constants.AnnotationValue +import org.jetbrains.kotlin.resolve.constants.ConstantValue + +object CirAnnotationFactory { + private val interner = Interner() + + fun create(source: AnnotationDescriptor): CirAnnotation { + val fqName: FqName = source.fqName?.intern() ?: error("Annotation with no FQ name: ${source::class.java}, $source") + + val allValueArguments: Map> = source.allValueArguments + if (allValueArguments.isEmpty()) + return create(fqName = fqName, constantValueArguments = emptyMap(), annotationValueArguments = emptyMap()) + + val constantValueArguments: MutableMap> = HashMap() + val annotationValueArguments: MutableMap = HashMap() + + allValueArguments.forEach { (name, constantValue) -> + checkConstantSupportedInCommonization( + constantValue = constantValue, + constantName = name, + owner = source, + allowAnnotationValues = true + ) + + if (constantValue is AnnotationValue) + annotationValueArguments[name.intern()] = create(source = constantValue.value) + else + constantValueArguments[name.intern()] = constantValue + } + + return create( + fqName = fqName, + constantValueArguments = constantValueArguments, + annotationValueArguments = annotationValueArguments + ) + } + + fun create( + fqName: FqName, + constantValueArguments: Map>, + annotationValueArguments: Map + ): CirAnnotation { + return interner.intern( + CirAnnotationImpl( + fqName = fqName, + constantValueArguments = constantValueArguments, + annotationValueArguments = annotationValueArguments + ) + ) + } +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirClassConstructorFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirClassConstructorFactory.kt new file mode 100644 index 00000000000..7e57d2166fc --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirClassConstructorFactory.kt @@ -0,0 +1,63 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.factory + +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor +import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.descriptors.commonizer.cir.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirClassConstructorImpl + +object CirClassConstructorFactory { + fun create(source: ClassConstructorDescriptor): CirClassConstructor { + val containingClass: ClassDescriptor = source.containingDeclaration + + return create( + annotations = source.annotations.map(CirAnnotationFactory::create), + typeParameters = source.typeParameters.mapNotNull { typeParameter -> + // save only type parameters that are contributed by the constructor itself + typeParameter.takeIf { it.containingDeclaration == source }?.let(CirTypeParameterFactory::create) + }, + visibility = source.visibility, + containingClassDetails = CirContainingClassDetails( + kind = containingClass.kind, + modality = containingClass.modality, + isData = containingClass.isData + ), + valueParameters = source.valueParameters.map(CirValueParameterFactory::create), + hasStableParameterNames = source.hasStableParameterNames(), + hasSynthesizedParameterNames = source.hasSynthesizedParameterNames(), + isPrimary = source.isPrimary, + kind = source.kind + ) + } + + @Suppress("NOTHING_TO_INLINE") + inline fun create( + annotations: List, + typeParameters: List, + visibility: Visibility, + containingClassDetails: CirContainingClassDetails, + valueParameters: List, + hasStableParameterNames: Boolean, + hasSynthesizedParameterNames: Boolean, + isPrimary: Boolean, + kind: CallableMemberDescriptor.Kind + ): CirClassConstructor { + return CirClassConstructorImpl( + annotations = annotations, + typeParameters = typeParameters, + visibility = visibility, + containingClassDetails = containingClassDetails, + valueParameters = valueParameters, + hasStableParameterNames = hasStableParameterNames, + hasSynthesizedParameterNames = hasSynthesizedParameterNames, + isPrimary = isPrimary, + kind = kind + ) + } +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirClassFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirClassFactory.kt new file mode 100644 index 00000000000..cd0b9496cad --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirClassFactory.kt @@ -0,0 +1,71 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.factory + +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.ClassKind +import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter +import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirClassImpl +import org.jetbrains.kotlin.descriptors.commonizer.utils.intern +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe + +object CirClassFactory { + fun create(source: ClassDescriptor): CirClass = create( + annotations = source.annotations.map(CirAnnotationFactory::create), + name = source.name.intern(), + typeParameters = source.declaredTypeParameters.map(CirTypeParameterFactory::create), + visibility = source.visibility, + modality = source.modality, + kind = source.kind, + companion = source.companionObjectDescriptor?.fqNameSafe?.intern(), + isCompanion = source.isCompanionObject, + isData = source.isData, + isInline = source.isInline, + isInner = source.isInner, + isExternal = source.isExternal, + supertypes = source.typeConstructor.supertypes.mapTo(mutableListOf()) { CirTypeFactory.create(it) } + ) + + @Suppress("NOTHING_TO_INLINE") + inline fun create( + annotations: List, + name: Name, + typeParameters: List, + visibility: Visibility, + modality: Modality, + kind: ClassKind, + companion: FqName?, + isCompanion: Boolean, + isData: Boolean, + isInline: Boolean, + isInner: Boolean, + isExternal: Boolean, + supertypes: MutableCollection + ): CirClass { + return CirClassImpl( + annotations = annotations, + name = name, + typeParameters = typeParameters, + visibility = visibility, + modality = modality, + kind = kind, + companion = companion, + isCompanion = isCompanion, + isData = isData, + isInline = isInline, + isInner = isInner, + isExternal = isExternal, + supertypes = supertypes + ) + } +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirExtensionReceiverFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirExtensionReceiverFactory.kt new file mode 100644 index 00000000000..2fe81210572 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirExtensionReceiverFactory.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.factory + +import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirExtensionReceiver +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirExtensionReceiverImpl + +object CirExtensionReceiverFactory { + fun create(source: ReceiverParameterDescriptor): CirExtensionReceiver = create( + annotations = source.annotations.map(CirAnnotationFactory::create), + type = CirTypeFactory.create(source.type) + ) + + @Suppress("NOTHING_TO_INLINE") + inline fun create( + annotations: List, + type: CirType + ): CirExtensionReceiver { + return CirExtensionReceiverImpl( + annotations = annotations, + type = type + ) + } +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirFunctionFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirFunctionFactory.kt new file mode 100644 index 00000000000..db84429cdb0 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirFunctionFactory.kt @@ -0,0 +1,84 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.factory + +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirFunctionImpl +import org.jetbrains.kotlin.descriptors.commonizer.utils.intern +import org.jetbrains.kotlin.name.Name + +object CirFunctionFactory { + fun create(source: SimpleFunctionDescriptor): CirFunction { + val containingClass: ClassDescriptor? = source.containingDeclaration as? ClassDescriptor + + return create( + annotations = source.annotations.map(CirAnnotationFactory::create), + name = source.name.intern(), + typeParameters = source.typeParameters.map(CirTypeParameterFactory::create), + visibility = source.visibility, + modality = source.modality, + containingClassDetails = containingClass?.let { + CirContainingClassDetails( + kind = it.kind, + modality = it.modality, + isData = it.isData + ) + }, + valueParameters = source.valueParameters.map(CirValueParameterFactory::create), + hasStableParameterNames = source.hasStableParameterNames(), + hasSynthesizedParameterNames = source.hasSynthesizedParameterNames(), + isExternal = source.isExternal, + extensionReceiver = source.extensionReceiverParameter?.let(CirExtensionReceiverFactory::create), + returnType = CirTypeFactory.create(source.returnType!!), + kind = source.kind, + // TODO: inline? + modifiers = CirFunctionModifiers( + isOperator = source.isOperator, + isInfix = source.isInfix, + isInline = source.isInline, + isTailrec = source.isTailrec, + isSuspend = source.isSuspend, + isExternal = source.isExternal + ) + ) + } + + @Suppress("NOTHING_TO_INLINE") + inline fun create( + annotations: List, + name: Name, + typeParameters: List, + visibility: Visibility, + modality: Modality, + containingClassDetails: CirContainingClassDetails?, + valueParameters: List, + hasStableParameterNames: Boolean, + hasSynthesizedParameterNames: Boolean, + isExternal: Boolean, + extensionReceiver: CirExtensionReceiver?, + returnType: CirType, + kind: CallableMemberDescriptor.Kind, + modifiers: CirFunctionModifiers + ): CirFunction { + return CirFunctionImpl( + annotations = annotations, + name = name, + typeParameters = typeParameters, + visibility = visibility, + modality = modality, + containingClassDetails = containingClassDetails, + valueParameters = valueParameters, + hasStableParameterNames = hasStableParameterNames, + hasSynthesizedParameterNames = hasSynthesizedParameterNames, + isExternal = isExternal, + extensionReceiver = extensionReceiver, + returnType = returnType, + kind = kind, + modifiers = modifiers + ) + } +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirModuleFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirModuleFactory.kt new file mode 100644 index 00000000000..da0e8d6ca31 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirModuleFactory.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.factory + +import org.jetbrains.kotlin.descriptors.ModuleDescriptor +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirModule +import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirModuleImpl +import org.jetbrains.kotlin.descriptors.commonizer.utils.intern +import org.jetbrains.kotlin.name.Name + +object CirModuleFactory { + fun create(source: ModuleDescriptor): CirModule = create(source.name.intern()) + + fun create(name: Name) = CirModuleImpl(name) +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPackageFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPackageFactory.kt new file mode 100644 index 00000000000..daa68a42a41 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPackageFactory.kt @@ -0,0 +1,15 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.factory + +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackage +import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirPackageImpl +import org.jetbrains.kotlin.descriptors.commonizer.utils.intern +import org.jetbrains.kotlin.name.FqName + +object CirPackageFactory { + fun create(fqName: FqName): CirPackage = CirPackageImpl(fqName) +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPropertyFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPropertyFactory.kt new file mode 100644 index 00000000000..6d4f212c8b8 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPropertyFactory.kt @@ -0,0 +1,102 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.factory + +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirPropertyImpl +import org.jetbrains.kotlin.descriptors.commonizer.utils.checkConstantSupportedInCommonization +import org.jetbrains.kotlin.descriptors.commonizer.utils.intern +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.constants.ConstantValue + +object CirPropertyFactory { + fun create(source: PropertyDescriptor): CirProperty { + val compileTimeInitializer: ConstantValue<*>? = source.compileTimeInitializer + if (compileTimeInitializer != null) { + checkConstantSupportedInCommonization( + constantValue = compileTimeInitializer, + owner = source, + allowAnnotationValues = false + ) + } + + val containingClass: ClassDescriptor? = source.containingDeclaration as? ClassDescriptor + + return create( + annotations = source.annotations.map(CirAnnotationFactory::create), + name = source.name.intern(), + typeParameters = source.typeParameters.map(CirTypeParameterFactory::create), + visibility = source.visibility, + modality = source.modality, + containingClassDetails = containingClass?.let { + CirContainingClassDetails( + kind = it.kind, + modality = it.modality, + isData = it.isData + ) + }, + isExternal = source.isExternal, + extensionReceiver = source.extensionReceiverParameter?.let(CirExtensionReceiverFactory::create), + returnType = CirTypeFactory.create(source.returnType!!), + kind = source.kind, + isVar = source.isVar, + isLateInit = source.isLateInit, + isConst = source.isConst, + isDelegate = @Suppress("DEPRECATION") source.isDelegated, + getter = source.getter?.let(CirPropertyGetterFactory::create), + setter = source.setter?.let(CirPropertySetterFactory::create), + backingFieldAnnotations = source.backingField?.annotations?.map(CirAnnotationFactory::create), + delegateFieldAnnotations = source.delegateField?.annotations?.map(CirAnnotationFactory::create), + compileTimeInitializer = source.compileTimeInitializer + ) + } + + @Suppress("NOTHING_TO_INLINE") + inline fun create( + annotations: List, + name: Name, + typeParameters: List, + visibility: Visibility, + modality: Modality, + containingClassDetails: CirContainingClassDetails?, + isExternal: Boolean, + extensionReceiver: CirExtensionReceiver?, + returnType: CirType, + kind: CallableMemberDescriptor.Kind, + isVar: Boolean, + isLateInit: Boolean, + isConst: Boolean, + isDelegate: Boolean, + getter: CirPropertyGetter?, + setter: CirPropertySetter?, + backingFieldAnnotations: List?, + delegateFieldAnnotations: List?, + compileTimeInitializer: ConstantValue<*>? + ): CirProperty { + return CirPropertyImpl( + annotations = annotations, + name = name, + typeParameters = typeParameters, + visibility = visibility, + modality = modality, + containingClassDetails = containingClassDetails, + isExternal = isExternal, + extensionReceiver = extensionReceiver, + returnType = returnType, + kind = kind, + isVar = isVar, + isLateInit = isLateInit, + isConst = isConst, + isDelegate = isDelegate, + getter = getter, + setter = setter, + backingFieldAnnotations = backingFieldAnnotations, + delegateFieldAnnotations = delegateFieldAnnotations, + compileTimeInitializer = compileTimeInitializer + ) + } +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPropertyGetterFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPropertyGetterFactory.kt new file mode 100644 index 00000000000..e373cbe504e --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPropertyGetterFactory.kt @@ -0,0 +1,52 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.factory + +import org.jetbrains.kotlin.descriptors.PropertyGetterDescriptor +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPropertyGetter +import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirPropertyGetterImpl +import org.jetbrains.kotlin.descriptors.commonizer.utils.Interner + +object CirPropertyGetterFactory { + private val interner = Interner() + + // speed optimization + val DEFAULT_NO_ANNOTATIONS: CirPropertyGetter = create( + annotations = emptyList(), + isDefault = true, + isExternal = false, + isInline = false + ) + + fun create(source: PropertyGetterDescriptor): CirPropertyGetter { + return if (source.isDefault && source.annotations.isEmpty()) + DEFAULT_NO_ANNOTATIONS + else + create( + annotations = source.annotations.map(CirAnnotationFactory::create), + isDefault = source.isDefault, + isExternal = source.isExternal, + isInline = source.isInline + ) + } + + fun create( + annotations: List, + isDefault: Boolean, + isExternal: Boolean, + isInline: Boolean + ): CirPropertyGetter { + return interner.intern( + CirPropertyGetterImpl( + annotations = annotations, + isDefault = isDefault, + isExternal = isExternal, + isInline = isInline + ) + ) + } +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPropertySetterFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPropertySetterFactory.kt new file mode 100644 index 00000000000..574d905a42f --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirPropertySetterFactory.kt @@ -0,0 +1,57 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.factory + +import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor +import org.jetbrains.kotlin.descriptors.Visibilities +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPropertySetter +import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirPropertySetterImpl +import org.jetbrains.kotlin.descriptors.commonizer.utils.Interner + +object CirPropertySetterFactory { + private val interner = Interner() + + fun create(source: PropertySetterDescriptor): CirPropertySetter = create( + annotations = source.annotations.map(CirAnnotationFactory::create), + parameterAnnotations = source.valueParameters[0].annotations.map(CirAnnotationFactory::create), + visibility = source.visibility, + isDefault = source.isDefault, + isExternal = source.isExternal, + isInline = source.isInline + ) + + fun create( + annotations: List, + parameterAnnotations: List, + visibility: Visibility, + isDefault: Boolean, + isExternal: Boolean, + isInline: Boolean + ): CirPropertySetter { + return interner.intern( + CirPropertySetterImpl( + annotations = annotations, + parameterAnnotations = parameterAnnotations, + visibility = visibility, + isDefault = isDefault, + isExternal = isExternal, + isInline = isInline + ) + ) + } + + @Suppress("NOTHING_TO_INLINE") + inline fun createDefaultNoAnnotations(visibility: Visibility): CirPropertySetter = create( + annotations = emptyList(), + parameterAnnotations = emptyList(), + visibility = visibility, + isDefault = visibility == Visibilities.PUBLIC, + isExternal = false, + isInline = false + ) +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirRootFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirRootFactory.kt new file mode 100644 index 00000000000..86359646495 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirRootFactory.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.factory + +import org.jetbrains.kotlin.builtins.konan.KonanBuiltIns +import org.jetbrains.kotlin.descriptors.commonizer.BuiltInsProvider +import org.jetbrains.kotlin.descriptors.commonizer.InputTarget +import org.jetbrains.kotlin.descriptors.commonizer.Target +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirRoot +import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirRootImpl + +object CirRootFactory { + fun create( + target: Target, + builtInsClass: String, + builtInsProvider: BuiltInsProvider + ): CirRoot { + if (target is InputTarget) { + check((target.konanTarget != null) == (builtInsClass == KonanBuiltIns::class.java.name)) + } + + return CirRootImpl( + target = target, + builtInsClass = builtInsClass, + builtInsProvider = builtInsProvider + ) + } +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeAliasFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeAliasFactory.kt new file mode 100644 index 00000000000..2fb851486fc --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeAliasFactory.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.factory + +import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeAlias +import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirTypeAliasImpl +import org.jetbrains.kotlin.descriptors.commonizer.utils.intern + +object CirTypeAliasFactory { + fun create(source: TypeAliasDescriptor): CirTypeAlias { + return CirTypeAliasImpl( + annotations = source.annotations.map(CirAnnotationFactory::create), + name = source.name.intern(), + typeParameters = source.declaredTypeParameters.map(CirTypeParameterFactory::create), + visibility = source.visibility, + underlyingType = CirTypeFactory.create(source.underlyingType), + expandedType = CirTypeFactory.create(source.expandedType) + ) + } +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeFactory.kt new file mode 100644 index 00000000000..8b38a65f46c --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeFactory.kt @@ -0,0 +1,64 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.factory + +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.ClassifierDescriptor +import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor +import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor +import org.jetbrains.kotlin.descriptors.commonizer.cir.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirSimpleTypeKind.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirSimpleTypeImpl +import org.jetbrains.kotlin.descriptors.commonizer.utils.Interner +import org.jetbrains.kotlin.descriptors.commonizer.utils.declarationDescriptor +import org.jetbrains.kotlin.descriptors.commonizer.utils.fqNameInterned +import org.jetbrains.kotlin.descriptors.commonizer.utils.fqNameWithTypeParameters +import org.jetbrains.kotlin.types.* + +object CirTypeFactory { + private val interner = Interner() + + fun create(source: KotlinType): CirType = source.unwrap().run { + when (this) { + is SimpleType -> create(this) + is FlexibleType -> CirFlexibleType(create(lowerBound), create(upperBound)) + } + } + + fun create(source: SimpleType): CirSimpleType { + val abbreviation: SimpleType = (source as? AbbreviatedType)?.abbreviation ?: source + val expanded: SimpleType = (source as? AbbreviatedType)?.expandedType ?: source + + val simpleType = CirSimpleTypeImpl( + kind = abbreviation.declarationDescriptor.cirSimpleTypeKind, + fqName = abbreviation.fqNameInterned, + arguments = abbreviation.arguments.map { projection -> + CirTypeProjection( + projectionKind = projection.projectionKind, + isStarProjection = projection.isStarProjection, + type = create(projection.type) + ) + }, + isMarkedNullable = abbreviation.isMarkedNullable, + isDefinitelyNotNullType = abbreviation.isDefinitelyNotNullType, + expandedTypeConstructorId = CirTypeConstructorId( + fqName = expanded.fqNameInterned, + numberOfTypeParameters = expanded.constructor.parameters.size + ), + fqNameWithTypeParameters = source.fqNameWithTypeParameters + ) + + return interner.intern(simpleType) + } +} + +val ClassifierDescriptor.cirSimpleTypeKind: CirSimpleTypeKind + get() = when (this) { + is ClassDescriptor -> CLASS + is TypeAliasDescriptor -> TYPE_ALIAS + is TypeParameterDescriptor -> TYPE_PARAMETER + else -> error("Unexpected classifier descriptor type: ${this::class.java}, $this") + } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeParameterFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeParameterFactory.kt new file mode 100644 index 00000000000..a0cb0db9d7d --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirTypeParameterFactory.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.factory + +import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter +import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirTypeParameterImpl +import org.jetbrains.kotlin.descriptors.commonizer.utils.intern +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.types.Variance + +object CirTypeParameterFactory { + fun create(source: TypeParameterDescriptor): CirTypeParameter = create( + annotations = source.annotations.map(CirAnnotationFactory::create), + name = source.name.intern(), + isReified = source.isReified, + variance = source.variance, + upperBounds = source.upperBounds.map(CirTypeFactory::create) + ) + + @Suppress("NOTHING_TO_INLINE") + inline fun create( + annotations: List, + name: Name, + isReified: Boolean, + variance: Variance, + upperBounds: List + ): CirTypeParameter { + return CirTypeParameterImpl( + annotations = annotations, + name = name, + isReified = isReified, + variance = variance, + upperBounds = upperBounds + ) + } +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirValueParameterFactory.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirValueParameterFactory.kt new file mode 100644 index 00000000000..b3a8835ff7b --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/factory/CirValueParameterFactory.kt @@ -0,0 +1,51 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.factory + +import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirValueParameter +import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirValueParameterImpl +import org.jetbrains.kotlin.descriptors.commonizer.utils.Interner +import org.jetbrains.kotlin.descriptors.commonizer.utils.intern +import org.jetbrains.kotlin.name.Name + +object CirValueParameterFactory { + private val interner = Interner() + + fun create(source: ValueParameterDescriptor): CirValueParameter = create( + annotations = source.annotations.map(CirAnnotationFactory::create), + name = source.name.intern(), + returnType = CirTypeFactory.create(source.returnType!!), + varargElementType = source.varargElementType?.let(CirTypeFactory::create), + declaresDefaultValue = source.declaresDefaultValue(), + isCrossinline = source.isCrossinline, + isNoinline = source.isNoinline + ) + + fun create( + annotations: List, + name: Name, + returnType: CirType, + varargElementType: CirType?, + declaresDefaultValue: Boolean, + isCrossinline: Boolean, + isNoinline: Boolean + ): CirValueParameter { + return interner.intern( + CirValueParameterImpl( + annotations = annotations, + name = name, + returnType = returnType, + varargElementType = varargElementType, + declaresDefaultValue = declaresDefaultValue, + isCrossinline = isCrossinline, + isNoinline = isNoinline + ) + ) + } +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirAnnotationImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirAnnotationImpl.kt new file mode 100644 index 00000000000..6565164b389 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirAnnotationImpl.kt @@ -0,0 +1,44 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.utils.appendHashCode +import org.jetbrains.kotlin.descriptors.commonizer.utils.hashCode +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.constants.ConstantValue + +data class CirAnnotationImpl( + override val fqName: FqName, + override val constantValueArguments: Map>, + override val annotationValueArguments: Map +) : CirAnnotation { + // See also org.jetbrains.kotlin.types.KotlinType.cachedHashCode + private var cachedHashCode = 0 + + private fun computeHashCode() = hashCode(fqName) + .appendHashCode(constantValueArguments) + .appendHashCode(annotationValueArguments) + + override fun hashCode(): Int { + var currentHashCode = cachedHashCode + if (currentHashCode != 0) return currentHashCode + + currentHashCode = computeHashCode() + cachedHashCode = currentHashCode + return currentHashCode + } + + override fun equals(other: Any?): Boolean { + if (other === this) return true + + return other is CirAnnotation + && fqName == other.fqName + && constantValueArguments == other.constantValueArguments + && annotationValueArguments == other.annotationValueArguments + } +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirClassConstructorImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirClassConstructorImpl.kt new file mode 100644 index 00000000000..149582fdf9c --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirClassConstructorImpl.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.descriptors.commonizer.cir.* + +data class CirClassConstructorImpl( + override val annotations: List, + override val typeParameters: List, + override val visibility: Visibility, + override val containingClassDetails: CirContainingClassDetails, + override val valueParameters: List, + override val hasStableParameterNames: Boolean, + override val hasSynthesizedParameterNames: Boolean, + override val isPrimary: Boolean, + override val kind: CallableMemberDescriptor.Kind +) : CirClassConstructor diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirClassImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirClassImpl.kt new file mode 100644 index 00000000000..831f098c4ec --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirClassImpl.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.ClassKind +import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name + +data class CirClassImpl( + override val annotations: List, + override val name: Name, + override val typeParameters: List, + override val visibility: Visibility, + override val modality: Modality, + override val kind: ClassKind, + override var companion: FqName?, + override val isCompanion: Boolean, + override val isData: Boolean, + override val isInline: Boolean, + override val isInner: Boolean, + override val isExternal: Boolean, + override val supertypes: MutableCollection +) : CirClass diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirDeclarationImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirDeclarationImpl.kt new file mode 100644 index 00000000000..4d436795730 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirDeclarationImpl.kt @@ -0,0 +1,11 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirDeclaration + +@Suppress("unused", "NOTHING_TO_INLINE") +internal inline fun CirDeclaration.unsupported(): Nothing = error("This method should never be called") diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirExtensionReceiverImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirExtensionReceiverImpl.kt new file mode 100644 index 00000000000..1459d4c7c79 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirExtensionReceiverImpl.kt @@ -0,0 +1,15 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirExtensionReceiver +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType + +data class CirExtensionReceiverImpl( + override val annotations: List, + override val type: CirType +) : CirExtensionReceiver diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirFunctionImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirFunctionImpl.kt new file mode 100644 index 00000000000..f23a36c84b5 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirFunctionImpl.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor +import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.descriptors.commonizer.cir.* +import org.jetbrains.kotlin.name.Name + +data class CirFunctionImpl( + override val annotations: List, + override val name: Name, + override val typeParameters: List, + override val visibility: Visibility, + override val modality: Modality, + override val containingClassDetails: CirContainingClassDetails?, + override val valueParameters: List, + override val hasStableParameterNames: Boolean, + override val hasSynthesizedParameterNames: Boolean, + override val isExternal: Boolean, + override val extensionReceiver: CirExtensionReceiver?, + override val returnType: CirType, + override val kind: CallableMemberDescriptor.Kind, + override val modifiers: CirFunctionModifiers +) : CirFunction diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirModuleImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirModuleImpl.kt new file mode 100644 index 00000000000..b9a2655f571 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirModuleImpl.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirModule +import org.jetbrains.kotlin.name.Name + +data class CirModuleImpl( + override val name: Name +) : CirModule diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPackageImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPackageImpl.kt new file mode 100644 index 00000000000..d3c285ca65b --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPackageImpl.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackage +import org.jetbrains.kotlin.name.FqName + +data class CirPackageImpl( + override val fqName: FqName +) : CirPackage diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPropertyGetterImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPropertyGetterImpl.kt new file mode 100644 index 00000000000..03dd2ff885f --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPropertyGetterImpl.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPropertyGetter + +data class CirPropertyGetterImpl( + override val annotations: List, + override val isDefault: Boolean, + override val isExternal: Boolean, + override val isInline: Boolean +) : CirPropertyGetter diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPropertyImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPropertyImpl.kt new file mode 100644 index 00000000000..67ae0c945ca --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPropertyImpl.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor +import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.descriptors.commonizer.cir.* +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.constants.ConstantValue + +data class CirPropertyImpl( + override val annotations: List, + override val name: Name, + override val typeParameters: List, + override val visibility: Visibility, + override val modality: Modality, + override val containingClassDetails: CirContainingClassDetails?, + override val isExternal: Boolean, + override val extensionReceiver: CirExtensionReceiver?, + override val returnType: CirType, + override val kind: CallableMemberDescriptor.Kind, + override val isVar: Boolean, + override val isLateInit: Boolean, + override val isConst: Boolean, + override val isDelegate: Boolean, + override val getter: CirPropertyGetter?, + override val setter: CirPropertySetter?, + override val backingFieldAnnotations: List?, + override val delegateFieldAnnotations: List?, + override val compileTimeInitializer: ConstantValue<*>? +) : CirProperty diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPropertySetterImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPropertySetterImpl.kt new file mode 100644 index 00000000000..6feb94c2b27 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirPropertySetterImpl.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPropertySetter + +data class CirPropertySetterImpl( + override val annotations: List, + override val parameterAnnotations: List, + override val visibility: Visibility, + override val isDefault: Boolean, + override val isExternal: Boolean, + override val isInline: Boolean +) : CirPropertySetter diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirRootImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirRootImpl.kt new file mode 100644 index 00000000000..d72b085d4cc --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirRootImpl.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.commonizer.BuiltInsProvider +import org.jetbrains.kotlin.descriptors.commonizer.Target +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirRoot + +data class CirRootImpl( + override val target: Target, + override val builtInsClass: String, + override val builtInsProvider: BuiltInsProvider +) : CirRoot diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirSimpleTypeImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirSimpleTypeImpl.kt new file mode 100644 index 00000000000..b7946fee69d --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirSimpleTypeImpl.kt @@ -0,0 +1,56 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirSimpleType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirSimpleTypeKind +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeConstructorId +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeProjection +import org.jetbrains.kotlin.descriptors.commonizer.utils.appendHashCode +import org.jetbrains.kotlin.descriptors.commonizer.utils.hashCode +import org.jetbrains.kotlin.name.FqName + +data class CirSimpleTypeImpl( + override val kind: CirSimpleTypeKind, + override val fqName: FqName, + override val arguments: List, + override val isMarkedNullable: Boolean, + override val isDefinitelyNotNullType: Boolean, + override val expandedTypeConstructorId: CirTypeConstructorId, + override val fqNameWithTypeParameters: String +) : CirSimpleType() { + // See also org.jetbrains.kotlin.types.KotlinType.cachedHashCode + private var cachedHashCode = 0 + + private fun computeHashCode() = hashCode(kind) + .appendHashCode(fqName) + .appendHashCode(arguments) + .appendHashCode(isMarkedNullable) + .appendHashCode(isDefinitelyNotNullType) + .appendHashCode(fqNameWithTypeParameters) + + override fun hashCode(): Int { + var currentHashCode = cachedHashCode + if (currentHashCode != 0) return currentHashCode + + currentHashCode = computeHashCode() + cachedHashCode = currentHashCode + return currentHashCode + } + + override fun equals(other: Any?) = when { + other === this -> true + other is CirSimpleType -> { + isMarkedNullable == other.isMarkedNullable + && fqName == other.fqName + && kind == other.kind + && arguments == other.arguments + && fqNameWithTypeParameters == other.fqNameWithTypeParameters + && isDefinitelyNotNullType == other.isDefinitelyNotNullType + } + else -> false + } +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeAliasImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeAliasImpl.kt new file mode 100644 index 00000000000..7a3fb2e4aeb --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeAliasImpl.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirSimpleType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeAlias +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter +import org.jetbrains.kotlin.name.Name + +data class CirTypeAliasImpl( + override val annotations: List, + override val name: Name, + override val typeParameters: List, + override val visibility: Visibility, + override val underlyingType: CirSimpleType, + override val expandedType: CirSimpleType +) : CirTypeAlias diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeParameterImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeParameterImpl.kt new file mode 100644 index 00000000000..28f6d9669f9 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirTypeParameterImpl.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.types.Variance + +data class CirTypeParameterImpl( + override val annotations: List, + override val name: Name, + override val isReified: Boolean, + override val variance: Variance, + override val upperBounds: List +) : CirTypeParameter diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirValueParameterImpl.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirValueParameterImpl.kt new file mode 100644 index 00000000000..16ce4761aa1 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/CirValueParameterImpl.kt @@ -0,0 +1,57 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirValueParameter +import org.jetbrains.kotlin.descriptors.commonizer.utils.appendHashCode +import org.jetbrains.kotlin.descriptors.commonizer.utils.hashCode +import org.jetbrains.kotlin.name.Name + +data class CirValueParameterImpl( + override val annotations: List, + override val name: Name, + override val returnType: CirType, + override val varargElementType: CirType?, + override val declaresDefaultValue: Boolean, + override val isCrossinline: Boolean, + override val isNoinline: Boolean +) : CirValueParameter { + // See also org.jetbrains.kotlin.types.KotlinType.cachedHashCode + private var cachedHashCode = 0 + + private fun computeHashCode() = hashCode(name) + .appendHashCode(annotations) + .appendHashCode(returnType) + .appendHashCode(varargElementType) + .appendHashCode(declaresDefaultValue) + .appendHashCode(isCrossinline) + .appendHashCode(isNoinline) + + override fun hashCode(): Int { + var currentHashCode = cachedHashCode + if (currentHashCode != 0) return currentHashCode + + currentHashCode = computeHashCode() + cachedHashCode = currentHashCode + return currentHashCode + } + + override fun equals(other: Any?): Boolean = when { + other === this -> true + other is CirValueParameterImpl -> { + name == other.name + && returnType == other.returnType + && annotations == other.annotations + && varargElementType == other.varargElementType + && declaresDefaultValue == other.declaresDefaultValue + && isCrossinline == other.isCrossinline + && isNoinline == other.isNoinline + } + else -> false + } +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/RecursionMarkers.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/RecursionMarkers.kt new file mode 100644 index 00000000000..d847810da16 --- /dev/null +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/cir/impl/RecursionMarkers.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.descriptors.commonizer.cir.impl + +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirRecursionMarker +import org.jetbrains.kotlin.name.FqName + +object CirClassRecursionMarker : CirClass, CirRecursionMarker { + override val annotations get() = unsupported() + override val name get() = unsupported() + override val typeParameters get() = unsupported() + override val visibility get() = unsupported() + override val modality get() = unsupported() + override val kind get() = unsupported() + override var companion: FqName? + get() = unsupported() + set(_) = unsupported() + override val isCompanion get() = unsupported() + override val isData get() = unsupported() + override val isInline get() = unsupported() + override val isInner get() = unsupported() + override val isExternal get() = unsupported() + override val supertypes get() = unsupported() +} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractFunctionOrPropertyCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractFunctionOrPropertyCommonizer.kt index fba1c8b8525..1c53eadbf0a 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractFunctionOrPropertyCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractFunctionOrPropertyCommonizer.kt @@ -8,9 +8,9 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.DELEGATION import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.SYNTHESIZED -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassifiersCache -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirFunctionOrProperty -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.isNonAbstractMemberInInterface +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirFunctionOrProperty +import org.jetbrains.kotlin.descriptors.commonizer.cir.isNonAbstractMemberInInterface +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassifiersCache import org.jetbrains.kotlin.name.Name abstract class AbstractFunctionOrPropertyCommonizer( @@ -32,7 +32,7 @@ abstract class AbstractFunctionOrPropertyCommonizer( override fun doCommonizeWith(next: T): Boolean = !next.isNonAbstractMemberInInterface() // non-abstract callable members declared in interface can't be commonized && next.kind != DELEGATION // delegated members should not be commonized - && (next.kind != SYNTHESIZED || next.containingClassIsData != true) // synthesized members of data classes should not be commonized + && (next.kind != SYNTHESIZED || next.containingClassDetails?.isData != true) // synthesized members of data classes should not be commonized && kind == next.kind && modality.commonizeWith(next.modality) && visibility.commonizeWith(next) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractListCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractListCommonizer.kt index c0af356144d..fb9df4da730 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractListCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractListCommonizer.kt @@ -5,7 +5,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType /** * Unlike [Commonizer] which commonizes only single elements, this [AbstractListCommonizer] commonizes lists of elements using diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AnnotationsCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AnnotationsCommonizer.kt index 740b92049b9..34532a00e92 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AnnotationsCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/AnnotationsCommonizer.kt @@ -5,8 +5,9 @@ package org.jetbrains.kotlin.descriptors.commonizer.core +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirAnnotationFactory import org.jetbrains.kotlin.descriptors.commonizer.core.AnnotationsCommonizer.Companion.FALLBACK_MESSAGE -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirAnnotation import org.jetbrains.kotlin.descriptors.commonizer.utils.DEPRECATED_ANNOTATION_FQN import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName @@ -68,7 +69,7 @@ private class DeprecatedAnnotationCommonizer : Commonizer): CirAnnotation = - CirAnnotation.create( + CirAnnotationFactory.create( fqName = REPLACE_WITH_FQN, constantValueArguments = mapOf( PROPERTY_NAME_EXPRESSION to StringValue(expression), diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ClassCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ClassCommonizer.kt index 6bc1f07eb65..bb9078c06a3 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ClassCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ClassCommonizer.kt @@ -6,9 +6,9 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import org.jetbrains.kotlin.descriptors.ClassKind -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClass -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassifiersCache -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirCommonClass +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirClassFactory +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassifiersCache import org.jetbrains.kotlin.name.Name class ClassCommonizer(cache: CirClassifiersCache) : AbstractStandardCommonizer() { @@ -21,15 +21,20 @@ class ClassCommonizer(cache: CirClassifiersCache) : AbstractStandardCommonizer() { private var isPrimary = false @@ -20,14 +21,16 @@ class ClassConstructorCommonizer(cache: CirClassifiersCache) : AbstractStandardC private var hasStableParameterNames = true private var hasSynthesizedParameterNames = false - override fun commonizationResult() = CirCommonClassConstructor( - isPrimary = isPrimary, - kind = kind, - visibility = visibility.result, + override fun commonizationResult() = CirClassConstructorFactory.create( + annotations = emptyList(), typeParameters = typeParameters.result, + visibility = visibility.result, + containingClassDetails = CirContainingClassDetails.DOES_NOT_MATTER, valueParameters = valueParameters.result, hasStableParameterNames = hasStableParameterNames, - hasSynthesizedParameterNames = hasSynthesizedParameterNames + hasSynthesizedParameterNames = hasSynthesizedParameterNames, + isPrimary = isPrimary, + kind = kind ) override fun initialize(first: CirClassConstructor) { @@ -36,8 +39,8 @@ class ClassConstructorCommonizer(cache: CirClassifiersCache) : AbstractStandardC } override fun doCommonizeWith(next: CirClassConstructor): Boolean { - val result = !next.containingClassKind.isSingleton // don't commonize constructors for objects and enum entries - && next.containingClassModality != Modality.SEALED // don't commonize constructors for sealed classes (not not their subclasses) + val result = !next.containingClassDetails.kind.isSingleton // don't commonize constructors for objects and enum entries + && next.containingClassDetails.modality != Modality.SEALED // don't commonize constructors for sealed classes (not not their subclasses) && isPrimary == next.isPrimary && kind == next.kind && visibility.commonizeWith(next) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/CommonizationVisitor.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/CommonizationVisitor.kt index c1b5b0955f5..e4180e56f22 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/CommonizationVisitor.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/CommonizationVisitor.kt @@ -5,7 +5,9 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.cir.fqNameWithTypeParameters +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.* import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroupMap internal class CommonizationVisitor( @@ -57,7 +59,7 @@ internal class CommonizationVisitor( } override fun visitClassNode(node: CirClassNode, data: Unit) { - val commonClass = node.common() as CirCommonClass? // commonize class + val commonClass = node.common() // commonized class node.constructors.forEach { constructor -> constructor.accept(this, Unit) @@ -99,7 +101,7 @@ internal class CommonizationVisitor( for ((_, supertypesGroup) in supertypesMap) { val commonSupertype = commonize(supertypesGroup.toList(), TypeCommonizer(root.cache)) if (commonSupertype != null) - commonClass.supertypes += commonSupertype + commonClass.supertypes.add(commonSupertype) } } } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ExtensionReceiverCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ExtensionReceiverCommonizer.kt index 906e65123c1..ba96bda8776 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ExtensionReceiverCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ExtensionReceiverCommonizer.kt @@ -5,14 +5,19 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassifiersCache -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirExtensionReceiver -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirType -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirExtensionReceiver.Companion.toReceiverNoAnnotations +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirExtensionReceiver +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirExtensionReceiverFactory +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassifiersCache class ExtensionReceiverCommonizer(cache: CirClassifiersCache) : AbstractNullableCommonizer( wrappedCommonizerFactory = { TypeCommonizer(cache) }, extractor = { it.type }, - builder = { it.toReceiverNoAnnotations() } + builder = { receiverType -> + CirExtensionReceiverFactory.create( + annotations = emptyList(), + type = receiverType + ) + } ) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/FunctionCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/FunctionCommonizer.kt index 3295b48ed40..a95c1f71b10 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/FunctionCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/FunctionCommonizer.kt @@ -5,9 +5,9 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassifiersCache -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirCommonFunction -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirFunction +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirFunction +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirFunctionFactory +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassifiersCache class FunctionCommonizer(cache: CirClassifiersCache) : AbstractFunctionOrPropertyCommonizer(cache) { private val annotations = AnnotationsCommonizer() @@ -16,25 +16,27 @@ class FunctionCommonizer(cache: CirClassifiersCache) : AbstractFunctionOrPropert private var hasStableParameterNames = true private var hasSynthesizedParameterNames = false - override fun commonizationResult() = CirCommonFunction( + override fun commonizationResult() = CirFunctionFactory.create( annotations = annotations.result, name = name, - modality = modality.result, + typeParameters = typeParameters.result, visibility = visibility.result, + modality = modality.result, + containingClassDetails = null, + valueParameters = valueParameters.result, + hasStableParameterNames = hasStableParameterNames, + hasSynthesizedParameterNames = hasSynthesizedParameterNames, + isExternal = false, extensionReceiver = extensionReceiver.result, returnType = returnType.result, kind = kind, - modifiers = modifiers.result, - valueParameters = valueParameters.result, - typeParameters = typeParameters.result, - hasStableParameterNames = hasStableParameterNames, - hasSynthesizedParameterNames = hasSynthesizedParameterNames + modifiers = modifiers.result ) override fun doCommonizeWith(next: CirFunction): Boolean { val result = super.doCommonizeWith(next) && annotations.commonizeWith(next.annotations) - && modifiers.commonizeWith(next) + && modifiers.commonizeWith(next.modifiers) && valueParameters.commonizeWith(next.valueParameters) if (result) { diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/FunctionModifiersCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/FunctionModifiersCommonizer.kt index 11cda827265..11e065f0323 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/FunctionModifiersCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/FunctionModifiersCommonizer.kt @@ -5,10 +5,10 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirFunctionModifiers +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirFunctionModifiers class FunctionModifiersCommonizer : Commonizer { - private var modifiers: CirFunctionModifiersImpl? = null + private var modifiers: CirFunctionModifiers? = null private var error = false override val result: CirFunctionModifiers @@ -20,7 +20,7 @@ class FunctionModifiersCommonizer : Commonizer() { private lateinit var name: Name - override fun commonizationResult() = CirModule(name = name) + override fun commonizationResult() = CirModuleFactory.create(name = name) override fun initialize(first: CirModule) { name = first.name diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/PropertyCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/PropertyCommonizer.kt index 8d8d5979564..91d063a6df9 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/PropertyCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/PropertyCommonizer.kt @@ -5,25 +5,40 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassifiersCache -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirCommonProperty -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirProperty +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirProperty +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirPropertyFactory +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirPropertyGetterFactory +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassifiersCache class PropertyCommonizer(cache: CirClassifiersCache) : AbstractFunctionOrPropertyCommonizer(cache) { private val setter = PropertySetterCommonizer() private var isExternal = true - override fun commonizationResult() = CirCommonProperty( - name = name, - modality = modality.result, - visibility = visibility.result, - isExternal = isExternal, - extensionReceiver = extensionReceiver.result, - returnType = returnType.result, - kind = kind, - setter = setter.result, - typeParameters = typeParameters.result - ) + override fun commonizationResult(): CirProperty { + val setter = setter.result + + return CirPropertyFactory.create( + annotations = emptyList(), + name = name, + typeParameters = typeParameters.result, + visibility = visibility.result, + modality = modality.result, + containingClassDetails = null, + isExternal = isExternal, + extensionReceiver = extensionReceiver.result, + returnType = returnType.result, + kind = kind, + isVar = setter != null, + isLateInit = false, + isConst = false, + isDelegate = false, + getter = CirPropertyGetterFactory.DEFAULT_NO_ANNOTATIONS, + setter = setter, + backingFieldAnnotations = null, + delegateFieldAnnotations = null, + compileTimeInitializer = null + ) + } override fun doCommonizeWith(next: CirProperty): Boolean { when { diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/PropertySetterCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/PropertySetterCommonizer.kt index 06dba876fa0..73394f1da3d 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/PropertySetterCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/PropertySetterCommonizer.kt @@ -6,11 +6,12 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import org.jetbrains.kotlin.descriptors.Visibility -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirDeclarationWithVisibility -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirSetter +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirDeclarationWithVisibility +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPropertySetter +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirPropertySetterFactory -class PropertySetterCommonizer : AbstractNullableCommonizer( +class PropertySetterCommonizer : AbstractNullableCommonizer( wrappedCommonizerFactory = { VisibilityCommonizer.equalizing() }, extractor = { it }, - builder = { CirSetter.createDefaultNoAnnotations(it) } + builder = CirPropertySetterFactory::createDefaultNoAnnotations ) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/RootCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/RootCommonizer.kt index 58e17cc9681..1f5f2ab4e76 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/RootCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/RootCommonizer.kt @@ -10,13 +10,14 @@ import org.jetbrains.kotlin.builtins.konan.KonanBuiltIns import org.jetbrains.kotlin.descriptors.commonizer.BuiltInsProvider import org.jetbrains.kotlin.descriptors.commonizer.InputTarget import org.jetbrains.kotlin.descriptors.commonizer.OutputTarget -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirRoot +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirRoot +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirRootFactory class RootCommonizer : AbstractStandardCommonizer() { private val inputTargets = mutableSetOf() private var konanBuiltInsProvider: BuiltInsProvider? = null - override fun commonizationResult() = CirRoot( + override fun commonizationResult() = CirRootFactory.create( target = OutputTarget(inputTargets), builtInsClass = if (konanBuiltInsProvider != null) KonanBuiltIns::class.java.name else DefaultBuiltIns::class.java.name, builtInsProvider = konanBuiltInsProvider ?: BuiltInsProvider.wrap(DefaultBuiltIns.Instance) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeAliasCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeAliasCommonizer.kt index d294350f12d..7f94ac98ee1 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeAliasCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeAliasCommonizer.kt @@ -7,7 +7,11 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.Modality -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirSimpleTypeKind +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeAlias +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirClassFactory +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassifiersCache import org.jetbrains.kotlin.name.Name class TypeAliasCommonizer(cache: CirClassifiersCache) : AbstractStandardCommonizer() { @@ -15,15 +19,20 @@ class TypeAliasCommonizer(cache: CirClassifiersCache) : AbstractStandardCommoniz private val underlyingType = TypeCommonizer(cache) private val visibility = VisibilityCommonizer.lowering(allowPrivate = true) - override fun commonizationResult() = CirCommonClass( + override fun commonizationResult() = CirClassFactory.create( + annotations = emptyList(), name = name, typeParameters = emptyList(), - kind = ClassKind.CLASS, - modality = Modality.FINAL, visibility = visibility.result, + modality = Modality.FINAL, + kind = ClassKind.CLASS, + companion = null, isCompanion = false, + isData = false, isInline = false, - isInner = false + isInner = false, + isExternal = false, + supertypes = mutableListOf() ) override fun initialize(first: CirTypeAlias) { diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeCommonizer.kt index 0153cd4207d..1378ce7f581 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeCommonizer.kt @@ -5,7 +5,12 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirFlexibleType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirSimpleType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirSimpleTypeKind +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassifiersCache +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirNode import org.jetbrains.kotlin.descriptors.commonizer.utils.isUnderStandardKotlinPackages import org.jetbrains.kotlin.types.AbstractStrictEqualityTypeChecker @@ -24,6 +29,7 @@ class TypeCommonizer(private val cache: CirClassifiersCache) : AbstractStandardC /** * See also [AbstractStrictEqualityTypeChecker]. */ +@Suppress("IntroduceWhenSubject") internal fun areTypesEqual(cache: CirClassifiersCache, a: CirType, b: CirType): Boolean = when { a is CirSimpleType -> (b is CirSimpleType) && areSimpleTypesEqual(cache, a, b) a is CirFlexibleType -> (b is CirFlexibleType) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterCommonizer.kt index 9ce9b13ced3..545d9f71d58 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterCommonizer.kt @@ -5,10 +5,10 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassifiersCache -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirCommonTypeParameter -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirType -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirTypeParameter +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeParameterFactory +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassifiersCache import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.Variance @@ -18,7 +18,8 @@ class TypeParameterCommonizer(cache: CirClassifiersCache) : AbstractStandardComm private lateinit var variance: Variance private val upperBounds = TypeParameterUpperBoundsCommonizer(cache) - override fun commonizationResult() = CirCommonTypeParameter( + override fun commonizationResult() = CirTypeParameterFactory.create( + annotations = emptyList(), name = name, isReified = isReified, variance = variance, diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterListCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterListCommonizer.kt index 087a8ca6d03..b4807a76611 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterListCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterListCommonizer.kt @@ -5,8 +5,8 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassifiersCache -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirTypeParameter +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassifiersCache class TypeParameterListCommonizer(cache: CirClassifiersCache) : AbstractListCommonizer( singleElementCommonizerFactory = { TypeParameterCommonizer(cache) } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterCommonizer.kt index 27edb6993b6..dec0dfc1053 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterCommonizer.kt @@ -5,10 +5,10 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassifiersCache -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirCommonValueParameter -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirType -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirValueParameter +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirValueParameter +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirValueParameterFactory +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassifiersCache import org.jetbrains.kotlin.descriptors.commonizer.utils.isNull import org.jetbrains.kotlin.name.Name @@ -19,10 +19,12 @@ class ValueParameterCommonizer(cache: CirClassifiersCache) : AbstractStandardCom private var isCrossinline = true private var isNoinline = true - override fun commonizationResult() = CirCommonValueParameter( + override fun commonizationResult() = CirValueParameterFactory.create( + annotations = emptyList(), name = name, returnType = returnType.result, varargElementType = varargElementType, + declaresDefaultValue = false, isCrossinline = isCrossinline, isNoinline = isNoinline ) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterListCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterListCommonizer.kt index 97e0041867e..635ddad9f44 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterListCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterListCommonizer.kt @@ -5,8 +5,8 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassifiersCache -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirValueParameter +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirValueParameter +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassifiersCache class ValueParameterListCommonizer(cache: CirClassifiersCache) : AbstractListCommonizer( singleElementCommonizerFactory = { ValueParameterCommonizer(cache) } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/VisibilityCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/VisibilityCommonizer.kt index 464c7743a99..c8992018e45 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/VisibilityCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/core/VisibilityCommonizer.kt @@ -5,10 +5,11 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirDeclarationWithVisibility -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirFunctionOrProperty -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.isVirtual +import org.jetbrains.kotlin.descriptors.Visibilities +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirDeclarationWithVisibility +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirFunctionOrProperty +import org.jetbrains.kotlin.descriptors.commonizer.cir.isVirtual abstract class VisibilityCommonizer(private val allowPrivate: Boolean) : Commonizer { diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirNodeVisitor.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirNodeVisitor.kt similarity index 83% rename from native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirNodeVisitor.kt rename to native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirNodeVisitor.kt index afa0d3a3b88..c2386fe660c 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirNodeVisitor.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirNodeVisitor.kt @@ -1,9 +1,9 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir +package org.jetbrains.kotlin.descriptors.commonizer.mergedtree interface CirNodeVisitor { fun visitRootNode(node: CirRootNode, data: T): R diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/callableMembers.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/callableMembers.kt index 9226bf5cba1..31e6362aae9 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/callableMembers.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/callableMembers.kt @@ -8,10 +8,6 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassifiersCache -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.buildClassConstructorNode -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.buildFunctionNode -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.buildPropertyNode import org.jetbrains.kotlin.storage.NullableLazyValue import org.jetbrains.kotlin.storage.StorageManager diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/classifiers.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/classifiers.kt index 0fe482841a6..3e5d71d5241 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/classifiers.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/classifiers.kt @@ -6,10 +6,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassNode -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirRootNode.ClassifiersCacheImpl -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.buildClassNode -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.buildTypeAliasNode +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirRootNode.ClassifiersCacheImpl import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroupMap import org.jetbrains.kotlin.descriptors.commonizer.utils.intern import org.jetbrains.kotlin.name.Name diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirAnnotation.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirAnnotation.kt deleted file mode 100644 index 0cc6ddc2ca3..00000000000 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirAnnotation.kt +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir - -import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor -import org.jetbrains.kotlin.descriptors.commonizer.utils.* -import org.jetbrains.kotlin.descriptors.commonizer.utils.checkConstantSupportedInCommonization -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.resolve.constants.* - -class CirAnnotation private constructor( - val fqName: FqName, - val constantValueArguments: Map>, - val annotationValueArguments: Map -) { - // See also org.jetbrains.kotlin.types.KotlinType.cachedHashCode - private var cachedHashCode = 0 - - private fun computeHashCode() = hashCode(fqName) - .appendHashCode(constantValueArguments) - .appendHashCode(annotationValueArguments) - - override fun hashCode(): Int { - var currentHashCode = cachedHashCode - if (currentHashCode != 0) return currentHashCode - - currentHashCode = computeHashCode() - cachedHashCode = currentHashCode - return currentHashCode - } - - override fun equals(other: Any?): Boolean { - if (other === this) return true - - return other is CirAnnotation - && fqName == other.fqName - && constantValueArguments == other.constantValueArguments - && annotationValueArguments == other.annotationValueArguments - } - - companion object { - private val interner = Interner() - - fun create(original: AnnotationDescriptor): CirAnnotation { - val fqName: FqName = original.fqName?.intern() ?: error("Annotation with no FQ name: ${original::class.java}, $original") - - val allValueArguments: Map> = original.allValueArguments - if (allValueArguments.isEmpty()) - return create(fqName = fqName, constantValueArguments = emptyMap(), annotationValueArguments = emptyMap()) - - val constantValueArguments: MutableMap> = HashMap() - val annotationValueArguments: MutableMap = HashMap() - - allValueArguments.forEach { (name, constantValue) -> - checkConstantSupportedInCommonization( - constantValue = constantValue, - constantName = name, - owner = original, - allowAnnotationValues = true - ) - - if (constantValue is AnnotationValue) - annotationValueArguments[name.intern()] = create(original = constantValue.value) - else - constantValueArguments[name.intern()] = constantValue - } - - return create( - fqName = fqName, - constantValueArguments = constantValueArguments, - annotationValueArguments = annotationValueArguments - ) - } - - fun create( - fqName: FqName, - constantValueArguments: Map>, - annotationValueArguments: Map - ): CirAnnotation { - return interner.intern( - CirAnnotation( - fqName = fqName, - constantValueArguments = constantValueArguments, - annotationValueArguments = annotationValueArguments - ) - ) - } - } -} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirClass.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirClass.kt deleted file mode 100644 index 563b6dd836e..00000000000 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirClass.kt +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir - -import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe - -interface CirClass : CirAnnotatedDeclaration, CirNamedDeclaration, CirDeclarationWithTypeParameters, CirDeclarationWithVisibility, CirDeclarationWithModality { - val companion: FqName? // null means no companion object - val kind: ClassKind - val isCompanion: Boolean - val isData: Boolean - val isInline: Boolean - val isInner: Boolean - val isExternal: Boolean - val supertypes: Collection -} - -interface CirClassConstructor : CirAnnotatedDeclaration, CirDeclarationWithTypeParameters, CirDeclarationWithVisibility, CirMaybeCallableMemberOfClass, CirCallableMemberWithParameters { - val isPrimary: Boolean - val kind: CallableMemberDescriptor.Kind - override val containingClassKind: ClassKind - override val containingClassModality: Modality - override val containingClassIsData: Boolean -} - -data class CirCommonClass( - override val name: Name, - override val typeParameters: List, - override val kind: ClassKind, - override val modality: Modality, - override val visibility: Visibility, - override val isCompanion: Boolean, - override val isInline: Boolean, - override val isInner: Boolean -) : CirClass { - override val annotations: List get() = emptyList() - override val isData get() = false - override val isExternal get() = false - override var companion: FqName? = null - override val supertypes: MutableCollection = ArrayList() -} - -data class CirCommonClassConstructor( - override val isPrimary: Boolean, - override val kind: CallableMemberDescriptor.Kind, - override val visibility: Visibility, - override val typeParameters: List, - override val valueParameters: List, - override val hasStableParameterNames: Boolean, - override val hasSynthesizedParameterNames: Boolean -) : CirClassConstructor { - override val annotations: List get() = emptyList() - override val containingClassKind get() = unsupported() - override val containingClassModality get() = unsupported() - override val containingClassIsData get() = unsupported() -} - -class CirClassImpl(original: ClassDescriptor) : CirClass { - override val annotations = original.annotations.map(CirAnnotation.Companion::create) - override val name = original.name.intern() - override val typeParameters = original.declaredTypeParameters.map(::CirTypeParameterImpl) - override val companion = original.companionObjectDescriptor?.fqNameSafe?.intern() - 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 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.Companion::create) - 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 = original.valueParameters.map(CirValueParameterImpl.Companion::create) - override val hasStableParameterNames = original.hasStableParameterNames() - override val hasSynthesizedParameterNames = original.hasSynthesizedParameterNames() -} - -object CirClassRecursionMarker : CirClass, CirRecursionMarker { - override val companion get() = unsupported() - override val kind get() = unsupported() - override val modality get() = unsupported() - override val isCompanion get() = unsupported() - override val isData get() = unsupported() - override val isInline get() = unsupported() - override val isInner get() = unsupported() - override val isExternal get() = unsupported() - override val supertypes get() = unsupported() - override val annotations get() = unsupported() - override val name get() = unsupported() - override val visibility get() = unsupported() - override val typeParameters get() = unsupported() -} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirFunction.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirFunction.kt deleted file mode 100644 index d29f4f2e5a2..00000000000 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirFunction.kt +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir - -import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.descriptors.commonizer.utils.Interner -import org.jetbrains.kotlin.descriptors.commonizer.utils.hashCode -import org.jetbrains.kotlin.descriptors.commonizer.utils.appendHashCode -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern -import org.jetbrains.kotlin.name.Name - -interface CirFunctionModifiers { - val isOperator: Boolean - val isInfix: Boolean - val isInline: Boolean - val isTailrec: Boolean - val isSuspend: Boolean - val isExternal: Boolean -} - -interface CirCallableMemberWithParameters { - val valueParameters: List - val hasStableParameterNames: Boolean - val hasSynthesizedParameterNames: Boolean -} - -interface CirFunction : CirFunctionOrProperty, CirFunctionModifiers, CirCallableMemberWithParameters - -data class CirCommonFunction( - override val annotations: List, - override val name: Name, - override val modality: Modality, - override val visibility: Visibility, - override val extensionReceiver: CirExtensionReceiver?, - override val returnType: CirType, - override val kind: CallableMemberDescriptor.Kind, - private val modifiers: CirFunctionModifiers, - override val valueParameters: List, - override val typeParameters: List, - override val hasStableParameterNames: Boolean, - override val hasSynthesizedParameterNames: Boolean -) : CirCommonFunctionOrProperty(), CirFunction, CirFunctionModifiers by modifiers - -class CirFunctionImpl(original: SimpleFunctionDescriptor) : CirFunctionOrPropertyImpl(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.Companion::create) - override val hasStableParameterNames = original.hasStableParameterNames() - override val hasSynthesizedParameterNames = original.hasSynthesizedParameterNames() -} - -interface CirValueParameter { - val name: Name - val annotations: List - val returnType: CirType - val varargElementType: CirType? - val declaresDefaultValue: Boolean - val isCrossinline: Boolean - val isNoinline: Boolean -} - -data class CirCommonValueParameter( - override val name: Name, - override val returnType: CirType, - override val varargElementType: CirType?, - override val isCrossinline: Boolean, - override val isNoinline: Boolean -) : CirValueParameter { - override val annotations: List get() = emptyList() - override val declaresDefaultValue get() = false -} - -class CirValueParameterImpl private constructor(original: ValueParameterDescriptor) : CirValueParameter { - override val name = original.name.intern() - override val annotations = original.annotations.map(CirAnnotation.Companion::create) - 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 - - // See also org.jetbrains.kotlin.types.KotlinType.cachedHashCode - private var cachedHashCode = 0 - - private fun computeHashCode() = hashCode(name) - .appendHashCode(annotations) - .appendHashCode(returnType) - .appendHashCode(varargElementType) - .appendHashCode(declaresDefaultValue) - .appendHashCode(isCrossinline) - .appendHashCode(isNoinline) - - override fun hashCode(): Int { - var currentHashCode = cachedHashCode - if (currentHashCode != 0) return currentHashCode - - currentHashCode = computeHashCode() - cachedHashCode = currentHashCode - return currentHashCode - } - - override fun equals(other: Any?): Boolean = when { - other === this -> true - other is CirValueParameterImpl -> { - name == other.name - && returnType == other.returnType - && annotations == other.annotations - && varargElementType == other.varargElementType - && declaresDefaultValue == other.declaresDefaultValue - && isCrossinline == other.isCrossinline - && isNoinline == other.isNoinline - } - else -> false - } - - companion object { - private val interner = Interner() - - fun create(original: ValueParameterDescriptor): CirValueParameterImpl = interner.intern(CirValueParameterImpl(original)) - } -} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirFunctionOrProperty.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirFunctionOrProperty.kt deleted file mode 100644 index fc3be9c3d68..00000000000 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirFunctionOrProperty.kt +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir - -import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirExtensionReceiver.Companion.toReceiver -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern - -interface CirFunctionOrProperty : CirAnnotatedDeclaration, CirNamedDeclaration, CirDeclarationWithTypeParameters, - CirDeclarationWithVisibility, CirDeclarationWithModality, CirMaybeCallableMemberOfClass { - val isExternal: Boolean - val extensionReceiver: CirExtensionReceiver? - val returnType: CirType - val kind: CallableMemberDescriptor.Kind -} - -abstract class CirCommonFunctionOrProperty : CirFunctionOrProperty { - final override val containingClassKind: ClassKind? get() = unsupported() - final override val containingClassModality: Modality? get() = unsupported() - final override val containingClassIsData: Boolean? get() = unsupported() -} - -abstract class CirFunctionOrPropertyImpl(original: T) : CirFunctionOrProperty { - final override val annotations = original.annotations.map(CirAnnotation.Companion::create) - final override val name = original.name.intern() - 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( - val annotations: List, - val type: CirType -) { - companion object { - fun CirType.toReceiverNoAnnotations() = CirExtensionReceiver(annotations = emptyList(), type = this) - - fun ReceiverParameterDescriptor.toReceiver() = CirExtensionReceiver( - annotations = annotations.map(CirAnnotation.Companion::create), - type = CirType.create(type) - ) - } -} - -fun CirFunctionOrProperty.isNonAbstractMemberInInterface() = - modality != Modality.ABSTRACT && containingClassKind == ClassKind.INTERFACE - -fun CirFunctionOrProperty.isVirtual() = - visibility != Visibilities.PRIVATE - && modality != Modality.FINAL - && !(containingClassModality == Modality.FINAL && containingClassKind != ClassKind.ENUM_CLASS) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirModule.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirModule.kt deleted file mode 100644 index a4bc2f2dc6e..00000000000 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirModule.kt +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir - -import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern -import org.jetbrains.kotlin.name.Name - -data class CirModule(val name: Name) : CirDeclaration { - constructor(descriptor: ModuleDescriptor) : this(descriptor.name.intern()) -} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirPackage.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirPackage.kt deleted file mode 100644 index 48f15499a36..00000000000 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirPackage.kt +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir - -import org.jetbrains.kotlin.name.FqName - -data class CirPackage(val fqName: FqName) : CirDeclaration diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirProperty.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirProperty.kt deleted file mode 100644 index c8e32ecd252..00000000000 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirProperty.kt +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir - -import org.jetbrains.kotlin.descriptors.* -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.descriptors.commonizer.utils.Interner -import org.jetbrains.kotlin.descriptors.commonizer.utils.checkConstantSupportedInCommonization -import org.jetbrains.kotlin.resolve.constants.ConstantValue - -interface CirProperty : CirFunctionOrProperty { - val isVar: Boolean - val isLateInit: Boolean - val isConst: Boolean - val isDelegate: Boolean - val getter: CirGetter? - val setter: CirSetter? - val backingFieldAnnotations: List? // null assumes no backing field - val delegateFieldAnnotations: List? // null assumes no backing field - val compileTimeInitializer: ConstantValue<*>? -} - -data class CirCommonProperty( - override val name: Name, - override val modality: Modality, - override val visibility: Visibility, - override val isExternal: Boolean, - override val extensionReceiver: CirExtensionReceiver?, - override val returnType: CirType, - override val kind: CallableMemberDescriptor.Kind, - override val setter: CirSetter?, - override val typeParameters: List -) : CirCommonFunctionOrProperty(), CirProperty { - override val annotations: List get() = emptyList() - override val isVar get() = setter != null - override val isLateInit get() = false - override val isConst get() = false - override val isDelegate get() = false - override val getter get() = CirGetter.DEFAULT_NO_ANNOTATIONS - override val backingFieldAnnotations: List? get() = null - override val delegateFieldAnnotations: List? get() = null - override val compileTimeInitializer: ConstantValue<*>? get() = null -} - -class CirPropertyImpl(original: PropertyDescriptor) : CirFunctionOrPropertyImpl(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.Companion::create) - override val delegateFieldAnnotations = original.delegateField?.annotations?.map(CirAnnotation.Companion::create) - override val compileTimeInitializer = original.compileTimeInitializer - - init { - compileTimeInitializer?.let { compileTimeInitializer -> - checkConstantSupportedInCommonization( - constantValue = compileTimeInitializer, - owner = original, - allowAnnotationValues = false - ) - } - } -} - -interface CirPropertyAccessor { - val annotations: List - val isDefault: Boolean - val isExternal: Boolean - val isInline: Boolean -} - -@Suppress("DataClassPrivateConstructor") -data class CirGetter private constructor( - override val annotations: List, - override val isDefault: Boolean, - override val isExternal: Boolean, - override val isInline: Boolean -) : CirPropertyAccessor { - companion object { - private val interner = Interner() - - val DEFAULT_NO_ANNOTATIONS = interner.intern( - CirGetter( - annotations = emptyList(), - isDefault = true, - isExternal = false, - isInline = false - ) - ) - - fun PropertyGetterDescriptor.toGetter() = - if (isDefault && annotations.isEmpty()) - DEFAULT_NO_ANNOTATIONS - else - interner.intern( - CirGetter( - annotations = annotations.map(CirAnnotation.Companion::create), - isDefault = isDefault, - isExternal = isExternal, - isInline = isInline - ) - ) - } -} - -@Suppress("DataClassPrivateConstructor") -data class CirSetter private constructor( - override val annotations: List, - val parameterAnnotations: List, - override val visibility: Visibility, - override val isDefault: Boolean, - override val isExternal: Boolean, - override val isInline: Boolean -) : CirPropertyAccessor, CirDeclarationWithVisibility { - companion object { - private val interner = Interner() - - fun createDefaultNoAnnotations(visibility: Visibility) = interner.intern( - CirSetter( - annotations = emptyList(), - parameterAnnotations = emptyList(), - visibility = visibility, - isDefault = visibility == Visibilities.PUBLIC, - isExternal = false, - isInline = false - ) - ) - - fun PropertySetterDescriptor.toSetter() = interner.intern( - CirSetter( - annotations = annotations.map(CirAnnotation.Companion::create), - parameterAnnotations = valueParameters.single().annotations.map(CirAnnotation.Companion::create), - visibility = visibility, - isDefault = isDefault, - isExternal = isExternal, - isInline = isInline - ) - ) - } -} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirRoot.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirRoot.kt deleted file mode 100644 index b0f27fbdb70..00000000000 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirRoot.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir - -import org.jetbrains.kotlin.builtins.konan.KonanBuiltIns -import org.jetbrains.kotlin.descriptors.commonizer.BuiltInsProvider -import org.jetbrains.kotlin.descriptors.commonizer.InputTarget -import org.jetbrains.kotlin.descriptors.commonizer.Target - -data class CirRoot( - val target: Target, - val builtInsClass: String, - val builtInsProvider: BuiltInsProvider -) : CirDeclaration { - init { - if (target is InputTarget) { - check((target.konanTarget != null) == (builtInsClass == KonanBuiltIns::class.java.name)) - } - } -} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirType.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirType.kt deleted file mode 100644 index 124f1aeb8ee..00000000000 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirType.kt +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir - -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.ClassifierDescriptor -import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor -import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirSimpleTypeKind.CLASS -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirSimpleTypeKind.TYPE_ALIAS -import org.jetbrains.kotlin.descriptors.commonizer.utils.* -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.types.* - -sealed class CirType { - companion object { - fun create(type: KotlinType): CirType = type.unwrap().run { - when (this) { - is SimpleType -> CirSimpleType.create(this) - is FlexibleType -> CirFlexibleType(CirSimpleType.create(lowerBound), CirSimpleType.create(upperBound)) - } - } - } -} - -/** - * All attributes except for [expandedTypeConstructorId] are read from the abbreviation type: [AbbreviatedType.abbreviation]. - * And [expandedTypeConstructorId] is read from the expanded type: [AbbreviatedType.expandedType]. - * - * 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. - * - * Note: Annotations at simple types are not preserved. After commonization all annotations assigned to types will be lost. - */ -class CirSimpleType private constructor(original: SimpleType) : CirType() { - val kind: CirSimpleTypeKind - val fqName: FqName - val arguments: List - val isMarkedNullable: Boolean - val isDefinitelyNotNullType: Boolean - val expandedTypeConstructorId: CirTypeConstructorId - - init { - val abbreviation = (original as? AbbreviatedType)?.abbreviation ?: original - val expanded = (original as? AbbreviatedType)?.expandedType ?: original - - kind = CirSimpleTypeKind.determineKind(abbreviation.declarationDescriptor) - fqName = abbreviation.fqNameInterned - 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 = original.fqNameWithTypeParameters - - override fun equals(other: Any?) = when { - other === this -> true - other is CirSimpleType -> { - isMarkedNullable == other.isMarkedNullable - && fqName == other.fqName - && kind == other.kind - && arguments == other.arguments - && fqNameWithTypeParameters == other.fqNameWithTypeParameters - && isDefinitelyNotNullType == other.isDefinitelyNotNullType - } - else -> false - } - - // See also org.jetbrains.kotlin.types.KotlinType.cachedHashCode - private var cachedHashCode = 0 - - private fun computeHashCode() = hashCode(kind) - .appendHashCode(fqName) - .appendHashCode(arguments) - .appendHashCode(isMarkedNullable) - .appendHashCode(isDefinitelyNotNullType) - .appendHashCode(fqNameWithTypeParameters) - - override fun hashCode(): Int { - var currentHashCode = cachedHashCode - if (currentHashCode != 0) return currentHashCode - - currentHashCode = computeHashCode() - cachedHashCode = currentHashCode - return currentHashCode - } - - companion object { - private val interner = Interner() - - fun create(original: SimpleType): CirSimpleType = interner.intern(CirSimpleType(original)) - } -} - -enum class CirSimpleTypeKind { - CLASS, - TYPE_ALIAS, - TYPE_PARAMETER; - - companion object { - fun determineKind(classifier: ClassifierDescriptor) = when (classifier) { - is ClassDescriptor -> CLASS - is TypeAliasDescriptor -> TYPE_ALIAS - is TypeParameterDescriptor -> TYPE_PARAMETER - else -> error("Unexpected classifier descriptor type: ${classifier::class.java}, $classifier") - } - - fun areCompatible(expect: CirSimpleTypeKind, actual: CirSimpleTypeKind) = - expect == actual || (expect == CLASS && actual == TYPE_ALIAS) - } -} - -data class CirTypeConstructorId(val fqName: FqName, val numberOfTypeParameters: Int) { - constructor(type: SimpleType) : this(type.fqNameInterned, type.constructor.parameters.size) -} - -data class CirTypeProjection(val projectionKind: Variance, val isStarProjection: Boolean, val type: CirType) { - constructor(original: TypeProjection) : this(original.projectionKind, original.isStarProjection, CirType.create(original.type)) -} - -data class CirFlexibleType(val lowerBound: CirSimpleType, val upperBound: CirSimpleType) : CirType() - -val CirType.fqNameWithTypeParameters: String - get() = when (this) { - is CirSimpleType -> fqNameWithTypeParameters - is CirFlexibleType -> lowerBound.fqNameWithTypeParameters - } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirTypeAlias.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirTypeAlias.kt deleted file mode 100644 index c08f7e9c3b3..00000000000 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirTypeAlias.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir - -import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern - -interface CirTypeAlias : CirAnnotatedDeclaration, CirNamedDeclaration, CirDeclarationWithTypeParameters, CirDeclarationWithVisibility { - val underlyingType: CirSimpleType - val expandedType: CirSimpleType -} - -class CirTypeAliasImpl(original: TypeAliasDescriptor) : CirTypeAlias { - override val annotations = original.annotations.map(CirAnnotation.Companion::create) - override val name = original.name.intern() - override val typeParameters = original.declaredTypeParameters.map(::CirTypeParameterImpl) - override val visibility = original.visibility - override val underlyingType = CirSimpleType.create(original.underlyingType) - override val expandedType = CirSimpleType.create(original.expandedType) -} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirTypeParameter.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirTypeParameter.kt deleted file mode 100644 index e8018a8c0d2..00000000000 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirTypeParameter.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir - -import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor -import org.jetbrains.kotlin.descriptors.commonizer.utils.intern -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.types.Variance - -interface CirTypeParameter { - val annotations: List - val name: Name - val isReified: Boolean - val variance: Variance - val upperBounds: List -} - -data class CirCommonTypeParameter( - override val name: Name, - override val isReified: Boolean, - override val variance: Variance, - override val upperBounds: List -) : CirTypeParameter { - override val annotations: List get() = emptyList() -} - -class CirTypeParameterImpl(original: TypeParameterDescriptor) : CirTypeParameter { - override val annotations = original.annotations.map(CirAnnotation.Companion::create) - override val name = original.name.intern() - override val isReified = original.isReified - override val variance = original.variance - override val upperBounds = original.upperBounds.map(CirType.Companion::create) -} diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/memberScopes.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/memberScopes.kt index 97848bb385b..736f3ab150a 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/memberScopes.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/memberScopes.kt @@ -8,10 +8,6 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.commonizer.core.Commonizer import org.jetbrains.kotlin.descriptors.commonizer.utils.* -import org.jetbrains.kotlin.descriptors.commonizer.utils.fqNameWithTypeParameters -import org.jetbrains.kotlin.descriptors.commonizer.utils.isBlacklistedDarwinFunction -import org.jetbrains.kotlin.descriptors.commonizer.utils.isDeprecatedTopLevelFunction -import org.jetbrains.kotlin.descriptors.commonizer.utils.isKniBridgeFunction import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.scopes.MemberScope diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/modules.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/modules.kt index 53a1811fdca..97800266a47 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/modules.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/modules.kt @@ -7,9 +7,6 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree import org.jetbrains.kotlin.backend.common.serialization.metadata.impl.ExportedForwardDeclarationsPackageFragmentDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirModuleNode -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirRootNode -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.buildModuleNode import org.jetbrains.kotlin.descriptors.commonizer.utils.* import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.scopes.ChainedMemberScope diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/nodeBuilders.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/nodeBuilders.kt similarity index 86% rename from native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/nodeBuilders.kt rename to native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/nodeBuilders.kt index 2e3d42e91ef..dacb89521f5 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/nodeBuilders.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/nodeBuilders.kt @@ -1,14 +1,17 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir +package org.jetbrains.kotlin.descriptors.commonizer.mergedtree import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.commonizer.TargetProvider +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirDeclaration +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.* +import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirClassRecursionMarker import org.jetbrains.kotlin.descriptors.commonizer.core.* -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirRootNode.ClassifiersCacheImpl +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirRootNode.ClassifiersCacheImpl import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup import org.jetbrains.kotlin.descriptors.commonizer.utils.firstNonNull import org.jetbrains.kotlin.descriptors.commonizer.utils.intern @@ -25,7 +28,7 @@ internal fun buildRootNode( ): CirRootNode = buildNode( storageManager = storageManager, descriptors = targetProviders, - targetDeclarationProducer = { CirRoot(it.target, it.builtInsClass.name, it.builtInsProvider) }, + targetDeclarationProducer = { CirRootFactory.create(it.target, it.builtInsClass.name, it.builtInsProvider) }, commonValueProducer = { commonize(it, RootCommonizer()) }, recursionMarker = null, nodeProducer = ::CirRootNode @@ -37,7 +40,7 @@ internal fun buildModuleNode( ): CirModuleNode = buildNode( storageManager = storageManager, descriptors = modules, - targetDeclarationProducer = ::CirModule, + targetDeclarationProducer = CirModuleFactory::create, commonValueProducer = { commonize(it, ModuleCommonizer()) }, recursionMarker = null, nodeProducer = ::CirModuleNode @@ -51,8 +54,8 @@ internal fun buildPackageNode( ): CirPackageNode = buildNode( storageManager = storageManager, descriptors = packageMemberScopes, - targetDeclarationProducer = { CirPackage(packageFqName) }, - commonValueProducer = { CirPackage(packageFqName) }, + targetDeclarationProducer = { CirPackageFactory.create(packageFqName) }, + commonValueProducer = { CirPackageFactory.create(packageFqName) }, recursionMarker = null, nodeProducer = ::CirPackageNode ).also { node -> @@ -68,7 +71,7 @@ internal fun buildPropertyNode( ): CirPropertyNode = buildNode( storageManager = storageManager, descriptors = properties, - targetDeclarationProducer = ::CirPropertyImpl, + targetDeclarationProducer = CirPropertyFactory::create, commonValueProducer = { commonize(containingDeclarationCommon, it, PropertyCommonizer(cache)) }, recursionMarker = null, nodeProducer = ::CirPropertyNode @@ -82,7 +85,7 @@ internal fun buildFunctionNode( ): CirFunctionNode = buildNode( storageManager = storageManager, descriptors = functions, - targetDeclarationProducer = ::CirFunctionImpl, + targetDeclarationProducer = CirFunctionFactory::create, commonValueProducer = { commonize(containingDeclarationCommon, it, FunctionCommonizer(cache)) }, recursionMarker = null, nodeProducer = ::CirFunctionNode @@ -96,7 +99,7 @@ internal fun buildClassNode( ): CirClassNode = buildNode( storageManager = storageManager, descriptors = classes, - targetDeclarationProducer = ::CirClassImpl, + targetDeclarationProducer = CirClassFactory::create, commonValueProducer = { commonize(containingDeclarationCommon, it, ClassCommonizer(cacheRW)) }, recursionMarker = CirClassRecursionMarker, nodeProducer = ::CirClassNode @@ -115,7 +118,7 @@ internal fun buildClassConstructorNode( ): CirClassConstructorNode = buildNode( storageManager = storageManager, descriptors = constructors, - targetDeclarationProducer = ::CirClassConstructorImpl, + targetDeclarationProducer = CirClassConstructorFactory::create, commonValueProducer = { commonize(containingDeclarationCommon, it, ClassConstructorCommonizer(cache)) }, recursionMarker = null, nodeProducer = ::CirClassConstructorNode @@ -128,7 +131,7 @@ internal fun buildTypeAliasNode( ): CirTypeAliasNode = buildNode( storageManager = storageManager, descriptors = typeAliases, - targetDeclarationProducer = ::CirTypeAliasImpl, + targetDeclarationProducer = CirTypeAliasFactory::create, commonValueProducer = { commonize(it, TypeAliasCommonizer(cacheRW)) }, recursionMarker = CirClassRecursionMarker, nodeProducer = ::CirTypeAliasNode diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/nodes.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/nodes.kt similarity index 96% rename from native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/nodes.kt rename to native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/nodes.kt index 3be4a94046b..843ba5d2c9c 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/nodes.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/nodes.kt @@ -1,10 +1,11 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir +package org.jetbrains.kotlin.descriptors.commonizer.mergedtree +import org.jetbrains.kotlin.descriptors.commonizer.cir.* import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.storage.NullableLazyValue diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/packages.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/packages.kt index b4aec8a3cd5..44bbddf8c67 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/packages.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/packages.kt @@ -9,9 +9,6 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirPackageNode -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirRootNode -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.buildPackageNode import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroupMap import org.jetbrains.kotlin.descriptors.commonizer.utils.intern import org.jetbrains.kotlin.name.FqName diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/root.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/root.kt index 68572a52cd6..54e697e1ace 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/root.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/root.kt @@ -7,8 +7,6 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.commonizer.TargetProvider -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirRootNode -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.buildRootNode import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroupMap import org.jetbrains.kotlin.descriptors.commonizer.utils.intern import org.jetbrains.kotlin.name.Name diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/type.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/type.kt index 8b215adeab6..a70eeca2ce1 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/type.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/type.kt @@ -13,7 +13,6 @@ import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.types.typeUtil.makeNotNullable -import kotlin.collections.HashSet internal inline val KotlinType.declarationDescriptor: ClassifierDescriptor get() = (constructor.declarationDescriptor ?: error("No declaration descriptor found for $constructor")) diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/CommonizerFacadeTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/CommonizerFacadeTest.kt index decca52b698..71b260b2132 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/CommonizerFacadeTest.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/CommonizerFacadeTest.kt @@ -6,12 +6,12 @@ package org.jetbrains.kotlin.descriptors.commonizer import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import kotlin.test.* -import org.junit.Test import org.jetbrains.kotlin.descriptors.commonizer.AbstractCommonizationFromSourcesTest.Companion.eachModuleAsTarget import org.jetbrains.kotlin.descriptors.commonizer.utils.assertCommonizationPerformed import org.jetbrains.kotlin.descriptors.commonizer.utils.mockEmptyModule +import org.junit.Test import kotlin.contracts.ExperimentalContracts +import kotlin.test.assertEquals @ExperimentalContracts class CommonizerFacadeTest { diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractCommonizerTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractCommonizerTest.kt index 9a690a82a7f..12bccbaa3b3 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractCommonizerTest.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/AbstractCommonizerTest.kt @@ -6,7 +6,9 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import org.junit.Test -import kotlin.test.* +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.fail abstract class AbstractCommonizerTest { diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/AnnotationsCommonizerTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/AnnotationsCommonizerTest.kt index a391dbe4907..dca4bc1104d 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/AnnotationsCommonizerTest.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/AnnotationsCommonizerTest.kt @@ -5,7 +5,8 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirAnnotationFactory import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name @@ -279,17 +280,13 @@ class AnnotationsCommonizerTest : AbstractCommonizerTest, Li ) override fun createCommonizer() = AnnotationsCommonizer() - - override fun isEqual(a: List?, b: List?): Boolean { - return super.isEqual(a, b) - } } private fun mockAnnotation( fqName: String, constantValueArguments: Map> = emptyMap(), annotationValueArguments: Map = emptyMap() -): CirAnnotation = CirAnnotation.create( +): CirAnnotation = CirAnnotationFactory.create( fqName = FqName(fqName), constantValueArguments = constantValueArguments, annotationValueArguments = annotationValueArguments diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/EqualizingVisibilityCommonizerTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/EqualizingVisibilityCommonizerTest.kt index 9c5877bed95..555edcf37f9 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/EqualizingVisibilityCommonizerTest.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/EqualizingVisibilityCommonizerTest.kt @@ -7,7 +7,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import org.jetbrains.kotlin.descriptors.Visibilities.* import org.jetbrains.kotlin.descriptors.Visibility -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirDeclarationWithVisibility +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirDeclarationWithVisibility import org.junit.Test class EqualizingVisibilityCommonizerTest : AbstractCommonizerTest() { diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/ExtensionReceiverCommonizerTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/ExtensionReceiverCommonizerTest.kt index a7990dcd51e..8e5b7222ba9 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/ExtensionReceiverCommonizerTest.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/ExtensionReceiverCommonizerTest.kt @@ -5,9 +5,10 @@ package org.jetbrains.kotlin.descriptors.commonizer.core +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirExtensionReceiver +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirExtensionReceiverFactory +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirExtensionReceiver -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirType import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType import org.junit.Test @@ -51,7 +52,7 @@ class ExtensionReceiverCommonizerTest : AbstractCommonizerTest() { @@ -162,22 +161,20 @@ class FunctionModifiersCommonizerTest : AbstractCommonizerTest() { +class PropertySetterCommonizerTest : AbstractCommonizerTest() { @Test fun absentOnly() = super.doTestSuccess( @@ -88,13 +89,13 @@ class PropertySetterCommonizerTest : AbstractCommonizerTest() { inline val JVM_BUILT_INS get() = JvmBuiltIns(LockBasedStorageManager.NO_LOCKS, JvmBuiltIns.Kind.FROM_CLASS_LOADER) inline val DEFAULT_BUILT_INS get() = DefaultBuiltIns.Instance - fun KotlinBuiltIns.toMock(target: Target) = CirRoot( - target, - this::class.java.name, - BuiltInsProvider.wrap(this) + fun KotlinBuiltIns.toMock(target: Target) = CirRootFactory.create( + target = target, + builtInsClass = this::class.java.name, + builtInsProvider = BuiltInsProvider.wrap(this) ) } } diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeCommonizerTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeCommonizerTest.kt index 02da6cce26c..351b49fe8e9 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeCommonizerTest.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeCommonizerTest.kt @@ -7,10 +7,11 @@ package org.jetbrains.kotlin.descriptors.commonizer.core import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirRootNode.ClassifiersCacheImpl -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirType -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.buildClassNode -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.buildTypeAliasNode +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirRootNode.ClassifiersCacheImpl +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.buildClassNode +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.buildTypeAliasNode import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroupMap import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType import org.jetbrains.kotlin.descriptors.commonizer.utils.mockTAType @@ -412,8 +413,8 @@ class TypeCommonizerTest : AbstractCommonizerTest() { prepareCache(variants) doTestSuccess( - expected = CirType.create(expected), - variants = *variants.map(CirType.Companion::create).toTypedArray() + expected = CirTypeFactory.create(expected), + variants = variants.map(CirTypeFactory::create).toTypedArray() ) } @@ -421,7 +422,7 @@ class TypeCommonizerTest : AbstractCommonizerTest() { prepareCache(variants) doTestFailure( - variants = *variants.map(CirType.Companion::create).toTypedArray(), + variants = variants.map(CirTypeFactory::create).toTypedArray(), shouldFailOnFirstVariant = shouldFailOnFirstVariant ) } diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterCommonizerTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterCommonizerTest.kt index 2308bf1373d..28de2f970bc 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterCommonizerTest.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterCommonizerTest.kt @@ -5,10 +5,10 @@ package org.jetbrains.kotlin.descriptors.commonizer.core +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeParameterFactory import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirCommonTypeParameter -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirType -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirTypeParameter import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.Variance @@ -88,11 +88,12 @@ class TypeParameterCommonizerTest : AbstractCommonizerTest = listOf("kotlin.Any") - ) = CirCommonTypeParameter( + ) = CirTypeParameterFactory.create( + annotations = emptyList(), name = Name.identifier(name), isReified = isReified, variance = variance, - upperBounds = upperBounds.map { CirType.create(mockClassType(it)) } + upperBounds = upperBounds.map { CirTypeFactory.create(mockClassType(it)) } ) } } diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterListCommonizerTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterListCommonizerTest.kt index 69763999e1a..e8efd055a95 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterListCommonizerTest.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/TypeParameterListCommonizerTest.kt @@ -5,8 +5,8 @@ package org.jetbrains.kotlin.descriptors.commonizer.core +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirTypeParameter import org.junit.Test class TypeParameterListCommonizerTest : AbstractCommonizerTest, List>() { diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterCommonizerTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterCommonizerTest.kt index f01a971ef66..71e08906c57 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterCommonizerTest.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/ValueParameterCommonizerTest.kt @@ -5,12 +5,13 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType +import org.jetbrains.kotlin.descriptors.commonizer.cir.CirValueParameter +import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory 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 +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassifiersCache +import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType import org.jetbrains.kotlin.name.Name import org.junit.Test @@ -153,7 +154,7 @@ class ValueParameterCommonizerTest : AbstractCommonizerTest, List>() { diff --git a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/mocks.kt b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/mocks.kt index 3c5b4447182..4870a6bd6d6 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/mocks.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/mocks.kt @@ -10,7 +10,9 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.commonizer.InputTarget import org.jetbrains.kotlin.descriptors.commonizer.builder.* -import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.* +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassNode +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirClassifiersCache +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirTypeAliasNode import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.parentOrNull import org.jetbrains.kotlin.resolve.scopes.MemberScope