[Commonizer] Rename Commonizer IR (CIR) entities

This commit is contained in:
Dmitriy Dolovov
2019-09-26 18:33:54 +07:00
parent 2bc0a3c9c0
commit 310166443a
57 changed files with 636 additions and 636 deletions
@@ -20,8 +20,8 @@ import org.jetbrains.kotlin.utils.addIfNotNull
internal class DeclarationsBuilderVisitor(
private val storageManager: StorageManager,
private val collector: (Target, Collection<ModuleDescriptor>) -> Unit
) : NodeVisitor<List<DeclarationDescriptor?>, List<DeclarationDescriptor?>> {
override fun visitRootNode(node: RootNode, data: List<DeclarationDescriptor?>): List<DeclarationDescriptor?> {
) : CirNodeVisitor<List<DeclarationDescriptor?>, List<DeclarationDescriptor?>> {
override fun visitRootNode(node: CirRootNode, data: List<DeclarationDescriptor?>): List<DeclarationDescriptor?> {
val allTargets = (node.target + node.common()!!).map { it.target }
val modulesByTargets = HashMap<Target, MutableList<ModuleDescriptorImpl>>()
@@ -49,7 +49,7 @@ internal class DeclarationsBuilderVisitor(
return noReturningDeclarations()
}
override fun visitModuleNode(node: ModuleNode, data: List<DeclarationDescriptor?>): List<ModuleDescriptorImpl?> {
override fun visitModuleNode(node: CirModuleNode, data: List<DeclarationDescriptor?>): List<ModuleDescriptorImpl?> {
// build module descriptors:
val moduleDescriptorsGroup = CommonizedGroup<ModuleDescriptorImpl>(node.dimension)
node.buildDescriptors(moduleDescriptorsGroup, storageManager)
@@ -70,7 +70,7 @@ internal class DeclarationsBuilderVisitor(
return moduleDescriptors
}
override fun visitPackageNode(node: PackageNode, data: List<DeclarationDescriptor?>): List<PackageFragmentDescriptor?> {
override fun visitPackageNode(node: CirPackageNode, data: List<DeclarationDescriptor?>): List<PackageFragmentDescriptor?> {
val containingDeclarations = data.asListContaining<ModuleDescriptorImpl>()
// build package fragments:
@@ -101,21 +101,21 @@ internal class DeclarationsBuilderVisitor(
return packageFragments
}
override fun visitPropertyNode(node: PropertyNode, data: List<DeclarationDescriptor?>): List<PropertyDescriptor?> {
override fun visitPropertyNode(node: CirPropertyNode, data: List<DeclarationDescriptor?>): List<PropertyDescriptor?> {
val propertyDescriptorsGroup = CommonizedGroup<PropertyDescriptor>(node.dimension)
node.buildDescriptors(propertyDescriptorsGroup, data, storageManager)
return propertyDescriptorsGroup.toList()
}
override fun visitFunctionNode(node: FunctionNode, data: List<DeclarationDescriptor?>): List<DeclarationDescriptor?> {
override fun visitFunctionNode(node: CirFunctionNode, data: List<DeclarationDescriptor?>): List<DeclarationDescriptor?> {
val functionDescriptorsGroup = CommonizedGroup<SimpleFunctionDescriptor>(node.dimension)
node.buildDescriptors(functionDescriptorsGroup, data)
return functionDescriptorsGroup.toList()
}
override fun visitClassNode(node: ClassNode, data: List<DeclarationDescriptor?>): List<DeclarationDescriptor?> {
override fun visitClassNode(node: CirClassNode, data: List<DeclarationDescriptor?>): List<DeclarationDescriptor?> {
val classesGroup = CommonizedGroup<ClassifierDescriptorWithTypeParameters>(node.dimension)
node.buildDescriptors(classesGroup, data, storageManager)
val classes = classesGroup.toList().asListContaining<CommonizedClassDescriptor>()
@@ -149,7 +149,7 @@ internal class DeclarationsBuilderVisitor(
return classes
}
override fun visitClassConstructorNode(node: ClassConstructorNode, data: List<DeclarationDescriptor?>): List<DeclarationDescriptor?> {
override fun visitClassConstructorNode(node: CirClassConstructorNode, data: List<DeclarationDescriptor?>): List<DeclarationDescriptor?> {
val containingDeclarations = data.asListContaining<ClassDescriptor>()
val constructorsGroup = CommonizedGroup<ClassConstructorDescriptor>(node.dimension)
@@ -158,7 +158,7 @@ internal class DeclarationsBuilderVisitor(
return constructorsGroup.toList()
}
override fun visitTypeAliasNode(node: TypeAliasNode, data: List<DeclarationDescriptor?>): List<DeclarationDescriptor?> {
override fun visitTypeAliasNode(node: CirTypeAliasNode, data: List<DeclarationDescriptor?>): List<DeclarationDescriptor?> {
val typeAliasesGroup = CommonizedGroup<ClassifierDescriptorWithTypeParameters>(node.dimension)
node.buildDescriptors(typeAliasesGroup, data, storageManager)
val typeAliases = typeAliasesGroup.toList()
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.*
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.indexOfCommon
import org.jetbrains.kotlin.storage.StorageManager
internal fun ClassNode.buildDescriptors(
internal fun CirClassNode.buildDescriptors(
output: CommonizedGroup<ClassifierDescriptorWithTypeParameters>,
containingDeclarations: List<DeclarationDescriptor?>,
storageManager: StorageManager
@@ -26,7 +26,7 @@ internal fun ClassNode.buildDescriptors(
commonClass?.buildDescriptor(output, indexOfCommon, containingDeclarations, storageManager, isExpect = true)
}
internal fun ClassDeclaration.buildDescriptor(
internal fun CirClass.buildDescriptor(
output: CommonizedGroup<in ClassifierDescriptorWithTypeParameters>,
index: Int,
containingDeclarations: List<DeclarationDescriptor?>,
@@ -60,7 +60,7 @@ internal fun ClassDeclaration.buildDescriptor(
output[index] = classDescriptor
}
internal fun ClassConstructorNode.buildDescriptors(
internal fun CirClassConstructorNode.buildDescriptors(
output: CommonizedGroup<ClassConstructorDescriptor>,
containingDeclarations: List<ClassDescriptor?>
) {
@@ -74,7 +74,7 @@ internal fun ClassConstructorNode.buildDescriptors(
commonConstructor?.buildDescriptor(output, indexOfCommon, containingDeclarations, isExpect = true)
}
private fun ClassConstructor.buildDescriptor(
private fun CirClassConstructor.buildDescriptor(
output: CommonizedGroup<ClassConstructorDescriptor>,
index: Int,
containingDeclarations: List<ClassDescriptor?>,
@@ -10,12 +10,12 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.descriptors.commonizer.CommonizedGroup
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.Function
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.FunctionNode
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.impl.SimpleFunctionDescriptorImpl
internal fun FunctionNode.buildDescriptors(
internal fun CirFunctionNode.buildDescriptors(
output: CommonizedGroup<SimpleFunctionDescriptor>,
containingDeclarations: List<DeclarationDescriptor?>
) {
@@ -29,7 +29,7 @@ internal fun FunctionNode.buildDescriptors(
commonFunction?.buildDescriptor(output, indexOfCommon, containingDeclarations, isExpect = markAsExpectAndActual)
}
private fun Function.buildDescriptor(
private fun CirFunction.buildDescriptor(
output: CommonizedGroup<SimpleFunctionDescriptor>,
index: Int,
containingDeclarations: List<DeclarationDescriptor?>,
@@ -6,13 +6,13 @@
package org.jetbrains.kotlin.descriptors.commonizer.builder
import org.jetbrains.kotlin.descriptors.commonizer.CommonizedGroup
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.Module
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ModuleNode
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.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.storage.StorageManager
internal fun ModuleNode.buildDescriptors(
internal fun CirModuleNode.buildDescriptors(
output: CommonizedGroup<ModuleDescriptorImpl>,
storageManager: StorageManager
) {
@@ -23,7 +23,7 @@ internal fun ModuleNode.buildDescriptors(
common()?.buildDescriptor(output, indexOfCommon, storageManager)
}
private fun Module.buildDescriptor(
private fun CirModule.buildDescriptor(
output: CommonizedGroup<ModuleDescriptorImpl>,
index: Int,
storageManager: StorageManager
@@ -7,15 +7,15 @@ package org.jetbrains.kotlin.descriptors.commonizer.builder
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.commonizer.CommonizedGroup
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.Package
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.PackageNode
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.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.scopes.MemberScope
internal fun PackageNode.buildDescriptors(
internal fun CirPackageNode.buildDescriptors(
output: CommonizedGroup<CommonizedPackageFragmentDescriptor>,
modules: List<ModuleDescriptorImpl?>
) {
@@ -26,7 +26,7 @@ internal fun PackageNode.buildDescriptors(
common()?.buildDescriptor(output, indexOfCommon, modules)
}
private fun Package.buildDescriptor(
private fun CirPackage.buildDescriptor(
output: CommonizedGroup<CommonizedPackageFragmentDescriptor>,
index: Int,
modules: List<ModuleDescriptorImpl?>
@@ -10,15 +10,15 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.descriptors.commonizer.CommonizedGroup
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.Property
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.PropertyNode
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.impl.FieldDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
import org.jetbrains.kotlin.resolve.DescriptorFactory
import org.jetbrains.kotlin.storage.StorageManager
internal fun PropertyNode.buildDescriptors(
internal fun CirPropertyNode.buildDescriptors(
output: CommonizedGroup<PropertyDescriptor>,
containingDeclarations: List<DeclarationDescriptor?>,
storageManager: StorageManager
@@ -33,7 +33,7 @@ internal fun PropertyNode.buildDescriptors(
commonProperty?.buildDescriptor(output, indexOfCommon, containingDeclarations, storageManager, isExpect = markAsExpectAndActual)
}
private fun Property.buildDescriptor(
private fun CirProperty.buildDescriptor(
output: CommonizedGroup<PropertyDescriptor>,
index: Int,
containingDeclarations: List<DeclarationDescriptor?>,
@@ -8,18 +8,18 @@ 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.CommonizedGroup
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ClassDeclaration
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.TypeAlias
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.TypeAliasNode
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.storage.StorageManager
internal fun TypeAliasNode.buildDescriptors(
internal fun CirTypeAliasNode.buildDescriptors(
output: CommonizedGroup<ClassifierDescriptorWithTypeParameters>,
containingDeclarations: List<DeclarationDescriptor?>,
storageManager: StorageManager
) {
val commonClass: ClassDeclaration? = common()
val commonClass: CirClass? = common()
val markAsActual = commonClass != null
target.forEachIndexed { index, typeAlias ->
@@ -29,7 +29,7 @@ internal fun TypeAliasNode.buildDescriptors(
commonClass?.buildDescriptor(output, indexOfCommon, containingDeclarations, storageManager, isExpect = true)
}
private fun TypeAlias.buildDescriptor(
private fun CirTypeAlias.buildDescriptor(
output: CommonizedGroup<ClassifierDescriptorWithTypeParameters>,
index: Int,
containingDeclarations: List<DeclarationDescriptor?>,
@@ -6,15 +6,15 @@
package org.jetbrains.kotlin.descriptors.commonizer.builder
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ExtensionReceiver
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.TypeParameter
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ValueParameter
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirExtensionReceiver
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirTypeParameter
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirValueParameter
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
import org.jetbrains.kotlin.resolve.DescriptorFactory
import org.jetbrains.kotlin.resolve.DescriptorUtils
internal fun List<TypeParameter>.buildDescriptors(
internal fun List<CirTypeParameter>.buildDescriptors(
containingDeclaration: DeclarationDescriptor
): List<TypeParameterDescriptor> {
return mapIndexed { index, param ->
@@ -35,7 +35,7 @@ internal fun List<TypeParameter>.buildDescriptors(
}
}
internal fun List<ValueParameter>.buildDescriptors(
internal fun List<CirValueParameter>.buildDescriptors(
containingDeclaration: CallableDescriptor
) = mapIndexed { index, param ->
ValueParameterDescriptorImpl(
@@ -53,7 +53,7 @@ internal fun List<ValueParameter>.buildDescriptors(
)
}
internal fun ExtensionReceiver.buildExtensionReceiver(
internal fun CirExtensionReceiver.buildExtensionReceiver(
containingDeclaration: CallableDescriptor
) = DescriptorFactory.createExtensionReceiverParameterForCallable(
containingDeclaration,
@@ -8,12 +8,12 @@ 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.ClassifiersCache
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.FunctionOrProperty
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.name.Name
abstract class AbstractFunctionOrPropertyCommonizer<T : FunctionOrProperty>(cache: ClassifiersCache) : AbstractStandardCommonizer<T, T>() {
abstract class AbstractFunctionOrPropertyCommonizer<T : CirFunctionOrProperty>(cache: CirClassifiersCache) : AbstractStandardCommonizer<T, T>() {
protected lateinit var name: Name
protected val modality = ModalityCommonizer.default()
protected val visibility = VisibilityCommonizer.lowering()
@@ -6,12 +6,12 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ClassDeclaration
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ClassifiersCache
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CommonClassDeclaration
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.name.Name
class ClassCommonizer(cache: ClassifiersCache) : AbstractStandardCommonizer<ClassDeclaration, ClassDeclaration>() {
class ClassCommonizer(cache: CirClassifiersCache) : AbstractStandardCommonizer<CirClass, CirClass>() {
private lateinit var name: Name
private lateinit var kind: ClassKind
private val typeParameters = TypeParameterListCommonizer.default(cache)
@@ -21,7 +21,7 @@ class ClassCommonizer(cache: ClassifiersCache) : AbstractStandardCommonizer<Clas
private var isInline = false
private var isCompanion = false
override fun commonizationResult() = CommonClassDeclaration(
override fun commonizationResult() = CirCommonClass(
name = name,
typeParameters = typeParameters.result,
kind = kind,
@@ -32,7 +32,7 @@ class ClassCommonizer(cache: ClassifiersCache) : AbstractStandardCommonizer<Clas
isInner = isInner
)
override fun initialize(first: ClassDeclaration) {
override fun initialize(first: CirClass) {
name = first.name
kind = first.kind
isInner = first.isInner
@@ -40,7 +40,7 @@ class ClassCommonizer(cache: ClassifiersCache) : AbstractStandardCommonizer<Clas
isCompanion = first.isCompanion
}
override fun doCommonizeWith(next: ClassDeclaration) =
override fun doCommonizeWith(next: CirClass) =
kind == next.kind
&& isInner == next.isInner
&& isInline == next.isInline
@@ -7,11 +7,11 @@ package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ClassConstructor
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ClassifiersCache
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CommonClassConstructor
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassConstructor
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassifiersCache
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirCommonClassConstructor
class ClassConstructorCommonizer(cache: ClassifiersCache) : AbstractStandardCommonizer<ClassConstructor, ClassConstructor>() {
class ClassConstructorCommonizer(cache: CirClassifiersCache) : AbstractStandardCommonizer<CirClassConstructor, CirClassConstructor>() {
private var isPrimary = false
private lateinit var kind: CallableMemberDescriptor.Kind
private val visibility = VisibilityCommonizer.equalizing()
@@ -20,7 +20,7 @@ class ClassConstructorCommonizer(cache: ClassifiersCache) : AbstractStandardComm
private var hasStableParameterNames = true
private var hasSynthesizedParameterNames = false
override fun commonizationResult() = CommonClassConstructor(
override fun commonizationResult() = CirCommonClassConstructor(
isPrimary = isPrimary,
kind = kind,
visibility = visibility.result,
@@ -30,12 +30,12 @@ class ClassConstructorCommonizer(cache: ClassifiersCache) : AbstractStandardComm
hasSynthesizedParameterNames = hasSynthesizedParameterNames
)
override fun initialize(first: ClassConstructor) {
override fun initialize(first: CirClassConstructor) {
isPrimary = first.isPrimary
kind = first.kind
}
override fun doCommonizeWith(next: ClassConstructor): Boolean {
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)
&& isPrimary == next.isPrimary
@@ -12,9 +12,9 @@ import org.jetbrains.kotlin.types.KotlinType
import java.lang.IllegalStateException
internal class CommonizationVisitor(
private val root: RootNode
) : NodeVisitor<Unit, Unit> {
override fun visitRootNode(node: RootNode, data: Unit) {
private val root: CirRootNode
) : CirNodeVisitor<Unit, Unit> {
override fun visitRootNode(node: CirRootNode, data: Unit) {
check(node === root)
check(node.common() != null) // root should already be commonized
@@ -23,7 +23,7 @@ internal class CommonizationVisitor(
}
}
override fun visitModuleNode(node: ModuleNode, data: Unit) {
override fun visitModuleNode(node: CirModuleNode, data: Unit) {
node.common() // commonize module
node.packages.forEach { pkg ->
@@ -31,7 +31,7 @@ internal class CommonizationVisitor(
}
}
override fun visitPackageNode(node: PackageNode, data: Unit) {
override fun visitPackageNode(node: CirPackageNode, data: Unit) {
node.common() // commonize package
node.properties.forEach { property ->
@@ -51,16 +51,16 @@ internal class CommonizationVisitor(
}
}
override fun visitPropertyNode(node: PropertyNode, data: Unit) {
override fun visitPropertyNode(node: CirPropertyNode, data: Unit) {
node.common() // commonize property
}
override fun visitFunctionNode(node: FunctionNode, data: Unit) {
override fun visitFunctionNode(node: CirFunctionNode, data: Unit) {
node.common() // commonize function
}
override fun visitClassNode(node: ClassNode, data: Unit) {
val commonClass = node.common() as CommonClassDeclaration? // commonize class
override fun visitClassNode(node: CirClassNode, data: Unit) {
val commonClass = node.common() as CirCommonClass? // commonize class
node.constructors.forEach { constructor ->
constructor.accept(this, Unit)
@@ -107,11 +107,11 @@ internal class CommonizationVisitor(
}
}
override fun visitClassConstructorNode(node: ClassConstructorNode, data: Unit) {
override fun visitClassConstructorNode(node: CirClassConstructorNode, data: Unit) {
node.common() // commonize constructor
}
override fun visitTypeAliasNode(node: TypeAliasNode, data: Unit) {
override fun visitTypeAliasNode(node: CirTypeAliasNode, data: Unit) {
node.common() // commonize type alias
}
}
@@ -5,20 +5,20 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ClassifiersCache
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ExtensionReceiver
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassifiersCache
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirExtensionReceiver
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.UnwrappedType
interface ExtensionReceiverCommonizer : Commonizer<ExtensionReceiver?, UnwrappedType?> {
interface ExtensionReceiverCommonizer : Commonizer<CirExtensionReceiver?, UnwrappedType?> {
companion object {
fun default(cache: ClassifiersCache): ExtensionReceiverCommonizer = DefaultExtensionReceiverCommonizer(cache)
fun default(cache: CirClassifiersCache): ExtensionReceiverCommonizer = DefaultExtensionReceiverCommonizer(cache)
}
}
private class DefaultExtensionReceiverCommonizer(cache: ClassifiersCache) :
private class DefaultExtensionReceiverCommonizer(cache: CirClassifiersCache) :
ExtensionReceiverCommonizer,
AbstractNullableCommonizer<ExtensionReceiver, UnwrappedType, KotlinType, UnwrappedType>(
AbstractNullableCommonizer<CirExtensionReceiver, UnwrappedType, KotlinType, UnwrappedType>(
wrappedCommonizerFactory = { TypeCommonizer.default(cache) },
extractor = { it.type },
builder = { it }
@@ -5,18 +5,18 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ClassifiersCache
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CommonFunction
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ExtensionReceiver.Companion.toReceiverNoAnnotations
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.Function
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.CirExtensionReceiver.Companion.toReceiverNoAnnotations
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirFunction
class FunctionCommonizer(cache: ClassifiersCache) : AbstractFunctionOrPropertyCommonizer<Function>(cache) {
class FunctionCommonizer(cache: CirClassifiersCache) : AbstractFunctionOrPropertyCommonizer<CirFunction>(cache) {
private val modifiers = FunctionModifiersCommonizer.default()
private val valueParameters = ValueParameterListCommonizer.default(cache)
private var hasStableParameterNames = true
private var hasSynthesizedParameterNames = false
override fun commonizationResult() = CommonFunction(
override fun commonizationResult() = CirCommonFunction(
name = name,
modality = modality.result,
visibility = visibility.result,
@@ -30,7 +30,7 @@ class FunctionCommonizer(cache: ClassifiersCache) : AbstractFunctionOrPropertyCo
hasSynthesizedParameterNames = hasSynthesizedParameterNames
)
override fun doCommonizeWith(next: Function): Boolean {
override fun doCommonizeWith(next: CirFunction): Boolean {
val result = super.doCommonizeWith(next)
&& modifiers.commonizeWith(next)
&& valueParameters.commonizeWith(next.valueParameters)
@@ -5,28 +5,28 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.FunctionModifiers
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirFunctionModifiers
interface FunctionModifiersCommonizer : Commonizer<FunctionModifiers, FunctionModifiers> {
interface FunctionModifiersCommonizer : Commonizer<CirFunctionModifiers, CirFunctionModifiers> {
companion object {
fun default(): FunctionModifiersCommonizer = DefaultFunctionModifiersCommonizer()
}
}
private class DefaultFunctionModifiersCommonizer : FunctionModifiersCommonizer {
private var modifiers: FunctionModifiersImpl? = null
private var modifiers: CirFunctionModifiersImpl? = null
private var error = false
override val result: FunctionModifiers
override val result: CirFunctionModifiers
get() = modifiers?.takeIf { !error } ?: throw IllegalCommonizerStateException()
override fun commonizeWith(next: FunctionModifiers): Boolean {
override fun commonizeWith(next: CirFunctionModifiers): Boolean {
if (error)
return false
val modifiers = modifiers
if (modifiers == null)
this.modifiers = FunctionModifiersImpl(next)
this.modifiers = CirFunctionModifiersImpl(next)
else {
if (modifiers.isSuspend != next.isSuspend)
error = true
@@ -42,15 +42,15 @@ private class DefaultFunctionModifiersCommonizer : FunctionModifiersCommonizer {
return !error
}
private data class FunctionModifiersImpl(
private data class CirFunctionModifiersImpl(
override var isOperator: Boolean,
override var isInfix: Boolean,
override var isInline: Boolean,
override var isTailrec: Boolean,
override var isSuspend: Boolean,
override var isExternal: Boolean
) : FunctionModifiers {
constructor(function: FunctionModifiers) : this(
) : CirFunctionModifiers {
constructor(function: CirFunctionModifiers) : this(
function.isOperator,
function.isInfix,
function.isInline,
@@ -7,30 +7,30 @@ package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
import org.jetbrains.kotlin.builtins.konan.KonanBuiltIns
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.Module
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirModule
import org.jetbrains.kotlin.name.Name
interface ModuleCommonizer : Commonizer<Module, Module> {
interface ModuleCommonizer : Commonizer<CirModule, CirModule> {
companion object {
fun default(): ModuleCommonizer = DefaultModuleCommonizer()
}
}
private class DefaultModuleCommonizer : ModuleCommonizer, AbstractStandardCommonizer<Module, Module>() {
private class DefaultModuleCommonizer : ModuleCommonizer, AbstractStandardCommonizer<CirModule, CirModule>() {
private lateinit var name: Name
private var konanBuiltIns: KonanBuiltIns? = null
override fun commonizationResult() = Module(
override fun commonizationResult() = CirModule(
name = name,
builtIns = konanBuiltIns ?: DefaultBuiltIns.Instance
)
override fun initialize(first: Module) {
override fun initialize(first: CirModule) {
name = first.name
konanBuiltIns = first.konanBuiltIns
}
override fun doCommonizeWith(next: Module): Boolean {
override fun doCommonizeWith(next: CirModule): Boolean {
// keep the first met KonanBuiltIns when all targets are Kotlin/Native
// otherwise use DefaultBuiltIns
if (konanBuiltIns != null) {
@@ -40,6 +40,6 @@ private class DefaultModuleCommonizer : ModuleCommonizer, AbstractStandardCommon
return true
}
private inline val Module.konanBuiltIns
private inline val CirModule.konanBuiltIns
get() = builtIns as? KonanBuiltIns
}
@@ -5,16 +5,16 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ClassifiersCache
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CommonProperty
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ExtensionReceiver.Companion.toReceiverNoAnnotations
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.Property
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.CirExtensionReceiver.Companion.toReceiverNoAnnotations
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirProperty
class PropertyCommonizer(cache: ClassifiersCache) : AbstractFunctionOrPropertyCommonizer<Property>(cache) {
class PropertyCommonizer(cache: CirClassifiersCache) : AbstractFunctionOrPropertyCommonizer<CirProperty>(cache) {
private val setter = PropertySetterCommonizer.default()
private var isExternal = true
override fun commonizationResult() = CommonProperty(
override fun commonizationResult() = CirCommonProperty(
name = name,
modality = modality.result,
visibility = visibility.result,
@@ -26,7 +26,7 @@ class PropertyCommonizer(cache: ClassifiersCache) : AbstractFunctionOrPropertyCo
typeParameters = typeParameters.result
)
override fun doCommonizeWith(next: Property): Boolean {
override fun doCommonizeWith(next: CirProperty): Boolean {
when {
next.isConst -> return false // expect property can't be const because expect can't have initializer
next.isLateInit -> return false // expect property can't be lateinit
@@ -6,10 +6,10 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.DeclarationWithVisibility
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.Setter
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirDeclarationWithVisibility
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirSetter
interface PropertySetterCommonizer : Commonizer<Setter?, Setter?> {
interface PropertySetterCommonizer : Commonizer<CirSetter?, CirSetter?> {
companion object {
fun default(): PropertySetterCommonizer = DefaultPropertySetterCommonizer()
}
@@ -17,8 +17,8 @@ interface PropertySetterCommonizer : Commonizer<Setter?, Setter?> {
private class DefaultPropertySetterCommonizer :
PropertySetterCommonizer,
AbstractNullableCommonizer<Setter, Setter, DeclarationWithVisibility, Visibility>(
AbstractNullableCommonizer<CirSetter, CirSetter, CirDeclarationWithVisibility, Visibility>(
wrappedCommonizerFactory = { VisibilityCommonizer.equalizing() },
extractor = { it },
builder = { Setter.createDefaultNoAnnotations(it) }
builder = { CirSetter.createDefaultNoAnnotations(it) }
)
@@ -11,12 +11,12 @@ import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.checker.isClassType
class TypeAliasCommonizer(cache: ClassifiersCache) : AbstractStandardCommonizer<TypeAlias, ClassDeclaration>() {
class TypeAliasCommonizer(cache: CirClassifiersCache) : AbstractStandardCommonizer<CirTypeAlias, CirClass>() {
private lateinit var name: Name
private val underlyingType = TypeCommonizer.default(cache)
private val visibility = VisibilityCommonizer.lowering(allowPrivate = true)
override fun commonizationResult() = CommonClassDeclaration(
override fun commonizationResult() = CirCommonClass(
name = name,
typeParameters = emptyList(),
kind = ClassKind.CLASS,
@@ -27,11 +27,11 @@ class TypeAliasCommonizer(cache: ClassifiersCache) : AbstractStandardCommonizer<
isInner = false
)
override fun initialize(first: TypeAlias) {
override fun initialize(first: CirTypeAlias) {
name = first.name
}
override fun doCommonizeWith(next: TypeAlias) =
override fun doCommonizeWith(next: CirTypeAlias) =
next.typeParameters.isEmpty() // TAs with declared type parameters can't be commonized
&& next.underlyingType.arguments.isEmpty() // TAs with functional types or types with parameters at the right-hand side can't be commonized
&& next.underlyingType.isClassType // right-hand side could have only class
@@ -7,18 +7,18 @@ package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.commonizer.isUnderStandardKotlinPackages
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ClassifiersCache
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.Node
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassifiersCache
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirNode
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.types.*
interface TypeCommonizer : Commonizer<KotlinType, UnwrappedType> {
companion object {
fun default(cache: ClassifiersCache): TypeCommonizer = DefaultTypeCommonizer(cache)
fun default(cache: CirClassifiersCache): TypeCommonizer = DefaultTypeCommonizer(cache)
}
}
private class DefaultTypeCommonizer(private val cache: ClassifiersCache) :
private class DefaultTypeCommonizer(private val cache: CirClassifiersCache) :
TypeCommonizer,
AbstractStandardCommonizer<KotlinType, UnwrappedType>() {
@@ -36,7 +36,7 @@ private class DefaultTypeCommonizer(private val cache: ClassifiersCache) :
/**
* See also [AbstractStrictEqualityTypeChecker].
*/
internal fun areTypesEqual(cache: ClassifiersCache, a: UnwrappedType, b: UnwrappedType): Boolean = when {
internal fun areTypesEqual(cache: CirClassifiersCache, a: UnwrappedType, b: UnwrappedType): Boolean = when {
a === b -> true
a is SimpleType -> (b is SimpleType) && areSimpleTypesEqual(cache, a, b)
a is FlexibleType -> (b is FlexibleType)
@@ -44,7 +44,7 @@ internal fun areTypesEqual(cache: ClassifiersCache, a: UnwrappedType, b: Unwrapp
else -> false
}
private fun areSimpleTypesEqual(cache: ClassifiersCache, a: SimpleType, b: SimpleType): Boolean = areAbbreviatedTypesEqual(
private fun areSimpleTypesEqual(cache: CirClassifiersCache, a: SimpleType, b: SimpleType): Boolean = areAbbreviatedTypesEqual(
cache,
a = a.getAbbreviation() ?: a,
aExpanded = a,
@@ -53,7 +53,7 @@ private fun areSimpleTypesEqual(cache: ClassifiersCache, a: SimpleType, b: Simpl
)
private fun areAbbreviatedTypesEqual(
cache: ClassifiersCache,
cache: CirClassifiersCache,
a: SimpleType,
aExpanded: SimpleType,
b: SimpleType,
@@ -130,7 +130,7 @@ private inline fun SimpleType.nonNullDescriptorExpectedErrorMessage() =
"${TypeCommonizer::class} couldn't obtain non-null descriptor from: $this, ${this::class}"
@Suppress("NOTHING_TO_INLINE")
private inline fun Node<*, *>?.canBeCommonized() =
private inline fun CirNode<*, *>?.canBeCommonized() =
if (this == null) {
// No node means that the class or type alias was not subject for commonization at all, probably it lays
// not in commonized module descriptors but somewhere in their dependencies.
@@ -5,61 +5,61 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ClassifiersCache
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CommonTypeParameter
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.TypeParameter
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.CirTypeParameter
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.UnwrappedType
import org.jetbrains.kotlin.types.Variance
interface TypeParameterCommonizer : Commonizer<TypeParameter, TypeParameter> {
interface TypeParameterCommonizer : Commonizer<CirTypeParameter, CirTypeParameter> {
companion object {
fun default(cache: ClassifiersCache): TypeParameterCommonizer = DefaultTypeParameterCommonizer(cache)
fun default(cache: CirClassifiersCache): TypeParameterCommonizer = DefaultTypeParameterCommonizer(cache)
}
}
private class DefaultTypeParameterCommonizer(cache: ClassifiersCache) :
private class DefaultTypeParameterCommonizer(cache: CirClassifiersCache) :
TypeParameterCommonizer,
AbstractStandardCommonizer<TypeParameter, TypeParameter>() {
AbstractStandardCommonizer<CirTypeParameter, CirTypeParameter>() {
private lateinit var name: Name
private var isReified = false
private lateinit var variance: Variance
private val upperBounds = TypeParameterUpperBoundsCommonizer(cache)
override fun commonizationResult() = CommonTypeParameter(
override fun commonizationResult() = CirCommonTypeParameter(
name = name,
isReified = isReified,
variance = variance,
upperBounds = upperBounds.result
)
override fun initialize(first: TypeParameter) {
override fun initialize(first: CirTypeParameter) {
name = first.name
isReified = first.isReified
variance = first.variance
}
override fun doCommonizeWith(next: TypeParameter) =
override fun doCommonizeWith(next: CirTypeParameter) =
name == next.name
&& isReified == next.isReified
&& variance == next.variance
&& upperBounds.commonizeWith(next.upperBounds)
}
private class TypeParameterUpperBoundsCommonizer(cache: ClassifiersCache) : AbstractListCommonizer<KotlinType, UnwrappedType>(
private class TypeParameterUpperBoundsCommonizer(cache: CirClassifiersCache) : AbstractListCommonizer<KotlinType, UnwrappedType>(
singleElementCommonizerFactory = { TypeCommonizer.default(cache) }
)
interface TypeParameterListCommonizer : Commonizer<List<TypeParameter>, List<TypeParameter>> {
interface TypeParameterListCommonizer : Commonizer<List<CirTypeParameter>, List<CirTypeParameter>> {
companion object {
fun default(cache: ClassifiersCache): TypeParameterListCommonizer = DefaultTypeParameterListCommonizer(cache)
fun default(cache: CirClassifiersCache): TypeParameterListCommonizer = DefaultTypeParameterListCommonizer(cache)
}
}
private class DefaultTypeParameterListCommonizer(cache: ClassifiersCache) :
private class DefaultTypeParameterListCommonizer(cache: CirClassifiersCache) :
TypeParameterListCommonizer,
AbstractListCommonizer<TypeParameter, TypeParameter>(
AbstractListCommonizer<CirTypeParameter, CirTypeParameter>(
singleElementCommonizerFactory = { TypeParameterCommonizer.default(cache) }
)
@@ -5,22 +5,22 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CommonValueParameter
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ValueParameter
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirCommonValueParameter
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirValueParameter
import org.jetbrains.kotlin.descriptors.commonizer.isNull
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ClassifiersCache
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassifiersCache
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.UnwrappedType
interface ValueParameterCommonizer : Commonizer<ValueParameter, ValueParameter> {
interface ValueParameterCommonizer : Commonizer<CirValueParameter, CirValueParameter> {
companion object {
fun default(cache: ClassifiersCache): ValueParameterCommonizer = DefaultValueParameterCommonizer(cache)
fun default(cache: CirClassifiersCache): ValueParameterCommonizer = DefaultValueParameterCommonizer(cache)
}
}
private class DefaultValueParameterCommonizer(cache: ClassifiersCache) :
private class DefaultValueParameterCommonizer(cache: CirClassifiersCache) :
ValueParameterCommonizer,
AbstractStandardCommonizer<ValueParameter, ValueParameter>() {
AbstractStandardCommonizer<CirValueParameter, CirValueParameter>() {
private lateinit var name: Name
private val returnType = TypeCommonizer.default(cache)
@@ -28,7 +28,7 @@ private class DefaultValueParameterCommonizer(cache: ClassifiersCache) :
private var isCrossinline = true
private var isNoinline = true
override fun commonizationResult() = CommonValueParameter(
override fun commonizationResult() = CirCommonValueParameter(
name = name,
returnType = returnType.result,
varargElementType = varargElementType,
@@ -36,14 +36,14 @@ private class DefaultValueParameterCommonizer(cache: ClassifiersCache) :
isNoinline = isNoinline
)
override fun initialize(first: ValueParameter) {
override fun initialize(first: CirValueParameter) {
name = first.name
varargElementType = first.varargElementType
isCrossinline = first.isCrossinline
isNoinline = first.isNoinline
}
override fun doCommonizeWith(next: ValueParameter): Boolean {
override fun doCommonizeWith(next: CirValueParameter): Boolean {
val result = !next.declaresDefaultValue
&& varargElementType.isNull() == next.varargElementType.isNull()
&& name == next.name
@@ -58,14 +58,14 @@ private class DefaultValueParameterCommonizer(cache: ClassifiersCache) :
}
}
interface ValueParameterListCommonizer : Commonizer<List<ValueParameter>, List<ValueParameter>> {
interface ValueParameterListCommonizer : Commonizer<List<CirValueParameter>, List<CirValueParameter>> {
companion object {
fun default(cache: ClassifiersCache): ValueParameterListCommonizer = DefaultValueParameterListCommonizer(cache)
fun default(cache: CirClassifiersCache): ValueParameterListCommonizer = DefaultValueParameterListCommonizer(cache)
}
}
private class DefaultValueParameterListCommonizer(cache: ClassifiersCache) :
private class DefaultValueParameterListCommonizer(cache: CirClassifiersCache) :
ValueParameterListCommonizer,
AbstractListCommonizer<ValueParameter, ValueParameter>(
AbstractListCommonizer<CirValueParameter, CirValueParameter>(
singleElementCommonizerFactory = { ValueParameterCommonizer.default(cache) }
)
@@ -6,11 +6,11 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.DeclarationWithVisibility
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.FunctionOrProperty
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
abstract class VisibilityCommonizer(private val allowPrivate: Boolean) : Commonizer<DeclarationWithVisibility, Visibility> {
abstract class VisibilityCommonizer(private val allowPrivate: Boolean) : Commonizer<CirDeclarationWithVisibility, Visibility> {
companion object {
fun lowering(allowPrivate: Boolean = false): VisibilityCommonizer = LoweringVisibilityCommonizer(allowPrivate)
@@ -22,7 +22,7 @@ abstract class VisibilityCommonizer(private val allowPrivate: Boolean) : Commoni
override val result: Visibility
get() = temp?.takeIf { it != Visibilities.UNKNOWN } ?: throw IllegalCommonizerStateException()
override fun commonizeWith(next: DeclarationWithVisibility): Boolean {
override fun commonizeWith(next: CirDeclarationWithVisibility): Boolean {
if (temp == Visibilities.UNKNOWN)
return false
@@ -37,7 +37,7 @@ abstract class VisibilityCommonizer(private val allowPrivate: Boolean) : Commoni
return temp != Visibilities.UNKNOWN
}
protected abstract fun canBeCommonized(next: DeclarationWithVisibility): Boolean
protected abstract fun canBeCommonized(next: CirDeclarationWithVisibility): Boolean
protected abstract fun getNext(current: Visibility, next: Visibility): Visibility
}
@@ -49,9 +49,9 @@ private class LoweringVisibilityCommonizer(allowPrivate: Boolean) : VisibilityCo
private var atLeastOneVirtualCallableMet = false
private var atLeastTwoVisibilitiesMet = false
override fun canBeCommonized(next: DeclarationWithVisibility): Boolean {
override fun canBeCommonized(next: CirDeclarationWithVisibility): Boolean {
if (!atLeastOneVirtualCallableMet)
atLeastOneVirtualCallableMet = (next as? FunctionOrProperty)?.isVirtual() == true
atLeastOneVirtualCallableMet = (next as? CirFunctionOrProperty)?.isVirtual() == true
return !atLeastOneVirtualCallableMet || !atLeastTwoVisibilitiesMet
}
@@ -74,7 +74,7 @@ private class LoweringVisibilityCommonizer(allowPrivate: Boolean) : VisibilityCo
* Make sure that visibilities of all member descriptors are equal are not private according to [Visibilities.isPrivate].
*/
private class EqualizingVisibilityCommonizer : VisibilityCommonizer(false) {
override fun canBeCommonized(next: DeclarationWithVisibility) = true
override fun canBeCommonized(next: CirDeclarationWithVisibility) = true
override fun getNext(current: Visibility, next: Visibility) =
if (Visibilities.compare(current, next) == 0) current else Visibilities.UNKNOWN
@@ -8,7 +8,7 @@ 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.ClassifiersCache
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
@@ -17,21 +17,21 @@ import org.jetbrains.kotlin.storage.StorageManager
internal fun mergeProperties(
storageManager: StorageManager,
cache: ClassifiersCache,
cache: CirClassifiersCache,
containingDeclarationCommon: NullableLazyValue<*>?,
properties: List<PropertyDescriptor?>
) = buildPropertyNode(storageManager, cache, containingDeclarationCommon, properties)
internal fun mergeFunctions(
storageManager: StorageManager,
cache: ClassifiersCache,
cache: CirClassifiersCache,
containingDeclarationCommon: NullableLazyValue<*>?,
properties: List<SimpleFunctionDescriptor?>
) = buildFunctionNode(storageManager, cache, containingDeclarationCommon, properties)
internal fun mergeClassConstructors(
storageManager: StorageManager,
cache: ClassifiersCache,
cache: CirClassifiersCache,
containingDeclarationCommon: NullableLazyValue<*>?,
constructors: List<ClassConstructorDescriptor?>
) = buildClassConstructorNode(storageManager, cache, containingDeclarationCommon, constructors)
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.commonizer.CommonizedGroupMap
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.*
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.RootNode.ClassifiersCacheImpl
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.name.Name
@@ -20,7 +20,7 @@ internal fun mergeClasses(
cacheRW: ClassifiersCacheImpl,
containingDeclarationCommon: NullableLazyValue<*>?,
classes: List<ClassDescriptor?>
): ClassNode {
): CirClassNode {
val node = buildClassNode(storageManager, cacheRW, containingDeclarationCommon, classes)
val constructorsMap = CommonizedGroupMap<ConstructorApproximationKey, ClassConstructorDescriptor>(classes.size)
@@ -0,0 +1,111 @@
/*
* 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.annotations.Annotations
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.types.KotlinType
import kotlin.LazyThreadSafetyMode.PUBLICATION
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<KotlinType>
}
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<CirTypeParameter>,
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 get() = Annotations.EMPTY
override val isData get() = false
override val isExternal get() = false
override var companion: FqName? = null
override val supertypes: MutableCollection<KotlinType> = ArrayList()
}
data class CirCommonClassConstructor(
override val isPrimary: Boolean,
override val kind: CallableMemberDescriptor.Kind,
override val visibility: Visibility,
override val typeParameters: List<CirTypeParameter>,
override val valueParameters: List<CirValueParameter>,
override val hasStableParameterNames: Boolean,
override val hasSynthesizedParameterNames: Boolean
) : CirClassConstructor {
override val annotations: Annotations get() = Annotations.EMPTY
override val containingClassKind: ClassKind get() = unsupported()
override val containingClassModality: Modality get() = unsupported()
override val containingClassIsData: Boolean get() = unsupported()
}
class CirWrappedClass(private val wrapped: ClassDescriptor) : CirClass {
override val annotations get() = wrapped.annotations
override val name get() = wrapped.name
override val typeParameters by lazy(PUBLICATION) { wrapped.declaredTypeParameters.map(::CirWrappedTypeParameter) }
override val companion by lazy(PUBLICATION) { wrapped.companionObjectDescriptor?.fqNameSafe }
override val kind get() = wrapped.kind
override val modality get() = wrapped.modality
override val visibility get() = wrapped.visibility
override val isCompanion get() = wrapped.isCompanionObject
override val isData get() = wrapped.isData
override val isInline get() = wrapped.isInline
override val isInner get() = wrapped.isInner
override val isExternal get() = wrapped.isExternal
override val supertypes: Collection<KotlinType> get() = wrapped.typeConstructor.supertypes
}
class CirWrappedClassConstructor(private val wrapped: ClassConstructorDescriptor) : CirClassConstructor {
override val isPrimary: Boolean get() = wrapped.isPrimary
override val kind: CallableMemberDescriptor.Kind get() = wrapped.kind
override val containingClassKind: ClassKind get() = wrapped.containingDeclaration.kind
override val containingClassModality: Modality get() = wrapped.containingDeclaration.modality
override val containingClassIsData: Boolean get() = wrapped.containingDeclaration.isData
override val annotations: Annotations get() = wrapped.annotations
override val visibility: Visibility get() = wrapped.visibility
override val typeParameters: List<CirTypeParameter> by lazy(PUBLICATION) { wrapped.typeParameters.map(::CirWrappedTypeParameter) }
override val valueParameters: List<CirValueParameter> by lazy(PUBLICATION) { wrapped.valueParameters.map(::CirWrappedValueParameter) }
override val hasStableParameterNames: Boolean get() = wrapped.hasStableParameterNames()
override val hasSynthesizedParameterNames: Boolean get() = wrapped.hasSynthesizedParameterNames()
}
object CirClassRecursionMarker : CirClass, CirRecursionMarker {
override val companion: FqName? get() = unsupported()
override val kind: ClassKind get() = unsupported()
override val modality: Modality get() = unsupported()
override val isCompanion: Boolean get() = unsupported()
override val isData: Boolean get() = unsupported()
override val isInline: Boolean get() = unsupported()
override val isInner: Boolean get() = unsupported()
override val isExternal: Boolean get() = unsupported()
override val supertypes: Collection<KotlinType> get() = unsupported()
override val annotations: Annotations get() = unsupported()
override val name: Name get() = unsupported()
override val visibility: Visibility get() = unsupported()
override val typeParameters: List<CirTypeParameter> get() = unsupported()
}
@@ -14,44 +14,44 @@ import org.jetbrains.kotlin.name.Name
* An intermediate representation of [DeclarationDescriptor]s for commonization purposes.
*
* The most essential subclasses are:
* - [ClassDeclaration] - represents [ClassDescriptor]
* - [TypeAlias] - [TypeAliasDescriptor]
* - [Function] - [SimpleFunctionDescriptor]
* - [Property] - [PropertyDescriptor]
* - [Package] - union of multiple [PackageFragmentDescriptor]s with the same [FqName] contributed by commonized [ModuleDescriptor]s
* - [Module] - [ModuleDescriptor]
* - [Root] - the root of the whole IR tree
* - [CirClass] - represents [ClassDescriptor]
* - [CirTypeAlias] - [TypeAliasDescriptor]
* - [CirFunction] - [SimpleFunctionDescriptor]
* - [CirProperty] - [PropertyDescriptor]
* - [CirPackage] - union of multiple [PackageFragmentDescriptor]s with the same [FqName] contributed by commonized [ModuleDescriptor]s
* - [CirModule] - [ModuleDescriptor]
* - [CirRoot] - the root of the whole Commonizer IR tree
*/
interface Declaration
interface CirDeclaration
interface AnnotatedDeclaration : Declaration {
interface CirAnnotatedDeclaration : CirDeclaration {
val annotations: Annotations
}
interface NamedDeclaration : Declaration {
interface CirNamedDeclaration : CirDeclaration {
val name: Name
}
interface DeclarationWithVisibility : Declaration {
interface CirDeclarationWithVisibility : CirDeclaration {
val visibility: Visibility
}
interface DeclarationWithModality : Declaration {
interface CirDeclarationWithModality : CirDeclaration {
val modality: Modality
}
interface MaybeCallableMemberOfClass : Declaration {
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
}
interface DeclarationWithTypeParameters : Declaration {
val typeParameters: List<TypeParameter>
interface CirDeclarationWithTypeParameters : CirDeclaration {
val typeParameters: List<CirTypeParameter>
}
/** Indicates presence of recursion in lazy calculations. */
interface RecursionMarker : Declaration
interface CirRecursionMarker : CirDeclaration
@Suppress("unused", "NOTHING_TO_INLINE")
internal inline fun Declaration.unsupported(): Nothing = error("This method should never be called")
internal inline fun CirDeclaration.unsupported(): Nothing = error("This method should never be called")
@@ -0,0 +1,85 @@
/*
* 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.annotations.Annotations
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.UnwrappedType
import kotlin.LazyThreadSafetyMode.PUBLICATION
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<CirValueParameter>
val hasStableParameterNames: Boolean
val hasSynthesizedParameterNames: Boolean
}
interface CirFunction : CirFunctionOrProperty, CirFunctionModifiers, CirCallableMemberWithParameters
data class CirCommonFunction(
override val name: Name,
override val modality: Modality,
override val visibility: Visibility,
override val extensionReceiver: CirExtensionReceiver?,
override val returnType: UnwrappedType,
override val kind: CallableMemberDescriptor.Kind,
private val modifiers: CirFunctionModifiers,
override val valueParameters: List<CirValueParameter>,
override val typeParameters: List<CirTypeParameter>,
override val hasStableParameterNames: Boolean,
override val hasSynthesizedParameterNames: Boolean
) : CirCommonFunctionOrProperty(), CirFunction, CirFunctionModifiers by modifiers
class CirWrappedFunction(wrapped: SimpleFunctionDescriptor) : CirWrappedFunctionOrProperty<SimpleFunctionDescriptor>(wrapped), CirFunction {
override val isOperator get() = wrapped.isOperator
override val isInfix get() = wrapped.isInfix
override val isInline get() = wrapped.isInline
override val isTailrec get() = wrapped.isTailrec
override val isSuspend get() = wrapped.isSuspend
override val valueParameters by lazy(PUBLICATION) { wrapped.valueParameters.map(::CirWrappedValueParameter) }
override val hasStableParameterNames: Boolean get() = wrapped.hasStableParameterNames()
override val hasSynthesizedParameterNames: Boolean get() = wrapped.hasSynthesizedParameterNames()
}
interface CirValueParameter {
val name: Name
val annotations: Annotations
val returnType: UnwrappedType
val varargElementType: UnwrappedType?
val declaresDefaultValue: Boolean
val isCrossinline: Boolean
val isNoinline: Boolean
}
data class CirCommonValueParameter(
override val name: Name,
override val returnType: UnwrappedType,
override val varargElementType: UnwrappedType?,
override val isCrossinline: Boolean,
override val isNoinline: Boolean
) : CirValueParameter {
override val annotations get() = Annotations.EMPTY
override val declaresDefaultValue get() = false
}
data class CirWrappedValueParameter(private val wrapped: ValueParameterDescriptor) : CirValueParameter {
override val name get() = wrapped.name
override val annotations get() = wrapped.annotations
override val returnType by lazy(PUBLICATION) { wrapped.returnType!!.unwrap() }
override val varargElementType by lazy(PUBLICATION) { wrapped.varargElementType?.unwrap() }
override val declaresDefaultValue get() = wrapped.declaresDefaultValue()
override val isCrossinline get() = wrapped.isCrossinline
override val isNoinline get() = wrapped.isNoinline
}
@@ -7,54 +7,54 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ExtensionReceiver.Companion.toReceiver
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirExtensionReceiver.Companion.toReceiver
import org.jetbrains.kotlin.types.UnwrappedType
import kotlin.LazyThreadSafetyMode.PUBLICATION
interface FunctionOrProperty : AnnotatedDeclaration, NamedDeclaration, DeclarationWithTypeParameters, DeclarationWithVisibility, DeclarationWithModality, MaybeCallableMemberOfClass {
interface CirFunctionOrProperty : CirAnnotatedDeclaration, CirNamedDeclaration, CirDeclarationWithTypeParameters, CirDeclarationWithVisibility, CirDeclarationWithModality, CirMaybeCallableMemberOfClass {
val isExternal: Boolean
val extensionReceiver: ExtensionReceiver?
val extensionReceiver: CirExtensionReceiver?
val returnType: UnwrappedType
val kind: CallableMemberDescriptor.Kind
}
abstract class CommonFunctionOrProperty : FunctionOrProperty {
abstract class CirCommonFunctionOrProperty : CirFunctionOrProperty {
final override val annotations get() = Annotations.EMPTY
final override val containingClassKind: ClassKind? get() = unsupported()
final override val containingClassModality: Modality? get() = unsupported()
final override val containingClassIsData: Boolean? get() = unsupported()
}
abstract class TargetFunctionOrProperty<T : CallableMemberDescriptor>(protected val descriptor: T) : FunctionOrProperty {
final override val annotations get() = descriptor.annotations
final override val name get() = descriptor.name
final override val modality get() = descriptor.modality
final override val visibility get() = descriptor.visibility
final override val isExternal get() = descriptor.isExternal
final override val extensionReceiver by lazy(PUBLICATION) { descriptor.extensionReceiverParameter?.toReceiver() }
final override val returnType by lazy(PUBLICATION) { descriptor.returnType!!.unwrap() }
final override val kind get() = descriptor.kind
abstract class CirWrappedFunctionOrProperty<T : CallableMemberDescriptor>(protected val wrapped: T) : CirFunctionOrProperty {
final override val annotations get() = wrapped.annotations
final override val name get() = wrapped.name
final override val modality get() = wrapped.modality
final override val visibility get() = wrapped.visibility
final override val isExternal get() = wrapped.isExternal
final override val extensionReceiver by lazy(PUBLICATION) { wrapped.extensionReceiverParameter?.toReceiver() }
final override val returnType by lazy(PUBLICATION) { wrapped.returnType!!.unwrap() }
final override val kind get() = wrapped.kind
final override val containingClassKind: ClassKind? get() = containingClass?.kind
final override val containingClassModality: Modality? get() = containingClass?.modality
final override val containingClassIsData: Boolean? get() = containingClass?.isData
final override val typeParameters by lazy(PUBLICATION) { descriptor.typeParameters.map(::TargetTypeParameter) }
private val containingClass: ClassDescriptor? get() = descriptor.containingDeclaration as? ClassDescriptor
final override val typeParameters by lazy(PUBLICATION) { wrapped.typeParameters.map(::CirWrappedTypeParameter) }
private val containingClass: ClassDescriptor? get() = wrapped.containingDeclaration as? ClassDescriptor
}
data class ExtensionReceiver(
data class CirExtensionReceiver(
val annotations: Annotations,
val type: UnwrappedType
) {
companion object {
fun UnwrappedType.toReceiverNoAnnotations() = ExtensionReceiver(Annotations.EMPTY, this)
fun ReceiverParameterDescriptor.toReceiver() = ExtensionReceiver(annotations, type.unwrap())
fun UnwrappedType.toReceiverNoAnnotations() = CirExtensionReceiver(Annotations.EMPTY, this)
fun ReceiverParameterDescriptor.toReceiver() = CirExtensionReceiver(annotations, type.unwrap())
}
}
fun FunctionOrProperty.isNonAbstractMemberInInterface() =
fun CirFunctionOrProperty.isNonAbstractMemberInInterface() =
modality != Modality.ABSTRACT && containingClassKind == ClassKind.INTERFACE
fun FunctionOrProperty.isVirtual() =
fun CirFunctionOrProperty.isVirtual() =
visibility != Visibilities.PRIVATE
&& modality != Modality.FINAL
&& !(containingClassModality == Modality.FINAL && containingClassKind != ClassKind.ENUM_CLASS)
@@ -9,6 +9,6 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.name.Name
data class Module(val name: Name, val builtIns: KotlinBuiltIns) : Declaration {
data class CirModule(val name: Name, val builtIns: KotlinBuiltIns) : CirDeclaration {
constructor(descriptor: ModuleDescriptor) : this(descriptor.name, descriptor.builtIns)
}
@@ -0,0 +1,17 @@
/*
* 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
interface CirNodeVisitor<R, T> {
fun visitRootNode(node: CirRootNode, data: T): R
fun visitModuleNode(node: CirModuleNode, data: T): R
fun visitPackageNode(node: CirPackageNode, data: T): R
fun visitPropertyNode(node: CirPropertyNode, data: T): R
fun visitFunctionNode(node: CirFunctionNode, data: T): R
fun visitClassNode(node: CirClassNode, data: T): R
fun visitClassConstructorNode(node: CirClassConstructorNode, data: T): R
fun visitTypeAliasNode(node: CirTypeAliasNode, data: T): R
}
@@ -7,4 +7,4 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir
import org.jetbrains.kotlin.name.FqName
data class Package(val fqName: FqName) : Declaration
data class CirPackage(val fqName: FqName) : CirDeclaration
@@ -9,90 +9,90 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.UnwrappedType
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.Getter.Companion.toGetter
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.Setter.Companion.toSetter
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirGetter.Companion.toGetter
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirSetter.Companion.toSetter
import org.jetbrains.kotlin.resolve.constants.ConstantValue
import kotlin.LazyThreadSafetyMode.PUBLICATION
interface Property : FunctionOrProperty {
interface CirProperty : CirFunctionOrProperty {
val isVar: Boolean
val isLateInit: Boolean
val isConst: Boolean
val isDelegate: Boolean
val getter: Getter?
val setter: Setter?
val getter: CirGetter?
val setter: CirSetter?
val backingFieldAnnotations: Annotations? // null assumes no backing field
val delegateFieldAnnotations: Annotations? // null assumes no backing field
val compileTimeInitializer: ConstantValue<*>?
}
data class CommonProperty(
data class CirCommonProperty(
override val name: Name,
override val modality: Modality,
override val visibility: Visibility,
override val isExternal: Boolean,
override val extensionReceiver: ExtensionReceiver?,
override val extensionReceiver: CirExtensionReceiver?,
override val returnType: UnwrappedType,
override val kind: CallableMemberDescriptor.Kind,
override val setter: Setter?,
override val typeParameters: List<TypeParameter>
) : CommonFunctionOrProperty(), Property {
override val setter: CirSetter?,
override val typeParameters: List<CirTypeParameter>
) : CirCommonFunctionOrProperty(), CirProperty {
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() = Getter.DEFAULT_NO_ANNOTATIONS
override val getter get() = CirGetter.DEFAULT_NO_ANNOTATIONS
override val backingFieldAnnotations: Annotations? get() = null
override val delegateFieldAnnotations: Annotations? get() = null
override val compileTimeInitializer: ConstantValue<*>? get() = null
}
class TargetProperty(descriptor: PropertyDescriptor) : TargetFunctionOrProperty<PropertyDescriptor>(descriptor), Property {
override val isVar get() = descriptor.isVar
override val isLateInit get() = descriptor.isLateInit
override val isConst get() = descriptor.isConst
override val isDelegate get() = @Suppress("DEPRECATION") descriptor.isDelegated
override val getter by lazy(PUBLICATION) { descriptor.getter?.toGetter() }
override val setter by lazy(PUBLICATION) { descriptor.setter?.toSetter() }
override val backingFieldAnnotations get() = descriptor.backingField?.annotations
override val delegateFieldAnnotations get() = descriptor.delegateField?.annotations
override val compileTimeInitializer get() = descriptor.compileTimeInitializer
class CirWrappedProperty(wrapped: PropertyDescriptor) : CirWrappedFunctionOrProperty<PropertyDescriptor>(wrapped), CirProperty {
override val isVar get() = wrapped.isVar
override val isLateInit get() = wrapped.isLateInit
override val isConst get() = wrapped.isConst
override val isDelegate get() = @Suppress("DEPRECATION") wrapped.isDelegated
override val getter by lazy(PUBLICATION) { wrapped.getter?.toGetter() }
override val setter by lazy(PUBLICATION) { wrapped.setter?.toSetter() }
override val backingFieldAnnotations get() = wrapped.backingField?.annotations
override val delegateFieldAnnotations get() = wrapped.delegateField?.annotations
override val compileTimeInitializer get() = wrapped.compileTimeInitializer
}
interface PropertyAccessor {
interface CirPropertyAccessor {
val annotations: Annotations
val isDefault: Boolean
val isExternal: Boolean
val isInline: Boolean
}
data class Getter(
data class CirGetter(
override val annotations: Annotations,
override val isDefault: Boolean,
override val isExternal: Boolean,
override val isInline: Boolean
) : PropertyAccessor {
) : CirPropertyAccessor {
companion object {
val DEFAULT_NO_ANNOTATIONS = Getter(Annotations.EMPTY, isDefault = true, isExternal = false, isInline = false)
val DEFAULT_NO_ANNOTATIONS = CirGetter(Annotations.EMPTY, isDefault = true, isExternal = false, isInline = false)
fun PropertyGetterDescriptor.toGetter() =
if (isDefault && annotations.isEmpty())
DEFAULT_NO_ANNOTATIONS
else
Getter(annotations, isDefault, isExternal, isInline)
CirGetter(annotations, isDefault, isExternal, isInline)
}
}
data class Setter(
data class CirSetter(
override val annotations: Annotations,
val parameterAnnotations: Annotations,
override val visibility: Visibility,
override val isDefault: Boolean,
override val isExternal: Boolean,
override val isInline: Boolean
) : PropertyAccessor, DeclarationWithVisibility {
) : CirPropertyAccessor, CirDeclarationWithVisibility {
companion object {
fun createDefaultNoAnnotations(visibility: Visibility) = Setter(
fun createDefaultNoAnnotations(visibility: Visibility) = CirSetter(
Annotations.EMPTY,
Annotations.EMPTY,
visibility,
@@ -101,7 +101,7 @@ data class Setter(
isInline = false
)
fun PropertySetterDescriptor.toSetter() = Setter(
fun PropertySetterDescriptor.toSetter() = CirSetter(
annotations,
valueParameters.single().annotations,
visibility,
@@ -7,4 +7,4 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir
import org.jetbrains.kotlin.descriptors.commonizer.Target
data class Root(val target: Target) : Declaration
data class CirRoot(val target: Target) : CirDeclaration
@@ -0,0 +1,24 @@
/*
* 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.types.SimpleType
import kotlin.LazyThreadSafetyMode.PUBLICATION
interface CirTypeAlias : CirAnnotatedDeclaration, CirNamedDeclaration, CirDeclarationWithTypeParameters, CirDeclarationWithVisibility {
val underlyingType: SimpleType
val expandedType: SimpleType
}
class CirWrappedTypeAlias(private val wrapped: TypeAliasDescriptor) : CirTypeAlias {
override val annotations get() = wrapped.annotations
override val name get() = wrapped.name
override val typeParameters by lazy(PUBLICATION) { wrapped.declaredTypeParameters.map(::CirWrappedTypeParameter) }
override val visibility get() = wrapped.visibility
override val underlyingType get() = wrapped.underlyingType
override val expandedType get() = wrapped.expandedType
}
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.types.UnwrappedType
import org.jetbrains.kotlin.types.Variance
import kotlin.LazyThreadSafetyMode.PUBLICATION
interface TypeParameter {
interface CirTypeParameter {
val annotations: Annotations
val name: Name
val isReified: Boolean
@@ -20,19 +20,19 @@ interface TypeParameter {
val upperBounds: List<UnwrappedType>
}
data class CommonTypeParameter(
data class CirCommonTypeParameter(
override val name: Name,
override val isReified: Boolean,
override val variance: Variance,
override val upperBounds: List<UnwrappedType>
) : TypeParameter {
) : CirTypeParameter {
override val annotations get() = Annotations.EMPTY
}
data class TargetTypeParameter(private val descriptor: TypeParameterDescriptor) : TypeParameter {
override val annotations get() = descriptor.annotations
override val name get() = descriptor.name
override val isReified get() = descriptor.isReified
override val variance get() = descriptor.variance
override val upperBounds by lazy(PUBLICATION) { descriptor.upperBounds.map { it.unwrap() } }
data class CirWrappedTypeParameter(private val wrapped: TypeParameterDescriptor) : CirTypeParameter {
override val annotations get() = wrapped.annotations
override val name get() = wrapped.name
override val isReified get() = wrapped.isReified
override val variance get() = wrapped.variance
override val upperBounds by lazy(PUBLICATION) { wrapped.upperBounds.map { it.unwrap() } }
}
@@ -1,111 +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.annotations.Annotations
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.types.KotlinType
import kotlin.LazyThreadSafetyMode.PUBLICATION
interface ClassDeclaration : AnnotatedDeclaration, NamedDeclaration, DeclarationWithTypeParameters, DeclarationWithVisibility, DeclarationWithModality {
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<KotlinType>
}
interface ClassConstructor : AnnotatedDeclaration, DeclarationWithTypeParameters, DeclarationWithVisibility, MaybeCallableMemberOfClass, CallableMemberWithParameters {
val isPrimary: Boolean
val kind: CallableMemberDescriptor.Kind
override val containingClassKind: ClassKind
override val containingClassModality: Modality
override val containingClassIsData: Boolean
}
data class CommonClassDeclaration(
override val name: Name,
override val typeParameters: List<TypeParameter>,
override val kind: ClassKind,
override val modality: Modality,
override val visibility: Visibility,
override val isCompanion: Boolean,
override val isInline: Boolean,
override val isInner: Boolean
) : ClassDeclaration {
override val annotations get() = Annotations.EMPTY
override val isData get() = false
override val isExternal get() = false
override var companion: FqName? = null
override val supertypes: MutableCollection<KotlinType> = ArrayList()
}
data class CommonClassConstructor(
override val isPrimary: Boolean,
override val kind: CallableMemberDescriptor.Kind,
override val visibility: Visibility,
override val typeParameters: List<TypeParameter>,
override val valueParameters: List<ValueParameter>,
override val hasStableParameterNames: Boolean,
override val hasSynthesizedParameterNames: Boolean
) : ClassConstructor {
override val annotations: Annotations get() = Annotations.EMPTY
override val containingClassKind: ClassKind get() = unsupported()
override val containingClassModality: Modality get() = unsupported()
override val containingClassIsData: Boolean get() = unsupported()
}
class TargetClassDeclaration(private val descriptor: ClassDescriptor) : ClassDeclaration {
override val annotations get() = descriptor.annotations
override val name get() = descriptor.name
override val typeParameters by lazy(PUBLICATION) { descriptor.declaredTypeParameters.map(::TargetTypeParameter) }
override val companion by lazy(PUBLICATION) { descriptor.companionObjectDescriptor?.fqNameSafe }
override val kind get() = descriptor.kind
override val modality get() = descriptor.modality
override val visibility get() = descriptor.visibility
override val isCompanion get() = descriptor.isCompanionObject
override val isData get() = descriptor.isData
override val isInline get() = descriptor.isInline
override val isInner get() = descriptor.isInner
override val isExternal get() = descriptor.isExternal
override val supertypes: Collection<KotlinType> get() = descriptor.typeConstructor.supertypes
}
class TargetClassConstructor(private val descriptor: ClassConstructorDescriptor) : ClassConstructor {
override val isPrimary: Boolean get() = descriptor.isPrimary
override val kind: CallableMemberDescriptor.Kind get() = descriptor.kind
override val containingClassKind: ClassKind get() = descriptor.containingDeclaration.kind
override val containingClassModality: Modality get() = descriptor.containingDeclaration.modality
override val containingClassIsData: Boolean get() = descriptor.containingDeclaration.isData
override val annotations: Annotations get() = descriptor.annotations
override val visibility: Visibility get() = descriptor.visibility
override val typeParameters: List<TypeParameter> by lazy(PUBLICATION) { descriptor.typeParameters.map(::TargetTypeParameter) }
override val valueParameters: List<ValueParameter> by lazy(PUBLICATION) { descriptor.valueParameters.map(::PlatformValueParameter) }
override val hasStableParameterNames: Boolean get() = descriptor.hasStableParameterNames()
override val hasSynthesizedParameterNames: Boolean get() = descriptor.hasSynthesizedParameterNames()
}
object ClassDeclarationRecursionMarker : ClassDeclaration, RecursionMarker {
override val companion: FqName? get() = unsupported()
override val kind: ClassKind get() = unsupported()
override val modality: Modality get() = unsupported()
override val isCompanion: Boolean get() = unsupported()
override val isData: Boolean get() = unsupported()
override val isInline: Boolean get() = unsupported()
override val isInner: Boolean get() = unsupported()
override val isExternal: Boolean get() = unsupported()
override val supertypes: Collection<KotlinType> get() = unsupported()
override val annotations: Annotations get() = unsupported()
override val name: Name get() = unsupported()
override val visibility: Visibility get() = unsupported()
override val typeParameters: List<TypeParameter> get() = unsupported()
}
@@ -1,85 +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.annotations.Annotations
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.UnwrappedType
import kotlin.LazyThreadSafetyMode.PUBLICATION
interface FunctionModifiers {
val isOperator: Boolean
val isInfix: Boolean
val isInline: Boolean
val isTailrec: Boolean
val isSuspend: Boolean
val isExternal: Boolean
}
interface CallableMemberWithParameters {
val valueParameters: List<ValueParameter>
val hasStableParameterNames: Boolean
val hasSynthesizedParameterNames: Boolean
}
interface Function : FunctionOrProperty, FunctionModifiers, CallableMemberWithParameters
data class CommonFunction(
override val name: Name,
override val modality: Modality,
override val visibility: Visibility,
override val extensionReceiver: ExtensionReceiver?,
override val returnType: UnwrappedType,
override val kind: CallableMemberDescriptor.Kind,
private val modifiers: FunctionModifiers,
override val valueParameters: List<ValueParameter>,
override val typeParameters: List<TypeParameter>,
override val hasStableParameterNames: Boolean,
override val hasSynthesizedParameterNames: Boolean
) : CommonFunctionOrProperty(), Function, FunctionModifiers by modifiers
class TargetFunction(descriptor: SimpleFunctionDescriptor) : TargetFunctionOrProperty<SimpleFunctionDescriptor>(descriptor), Function {
override val isOperator get() = descriptor.isOperator
override val isInfix get() = descriptor.isInfix
override val isInline get() = descriptor.isInline
override val isTailrec get() = descriptor.isTailrec
override val isSuspend get() = descriptor.isSuspend
override val valueParameters by lazy(PUBLICATION) { descriptor.valueParameters.map(::PlatformValueParameter) }
override val hasStableParameterNames: Boolean get() = descriptor.hasStableParameterNames()
override val hasSynthesizedParameterNames: Boolean get() = descriptor.hasSynthesizedParameterNames()
}
interface ValueParameter {
val name: Name
val annotations: Annotations
val returnType: UnwrappedType
val varargElementType: UnwrappedType?
val declaresDefaultValue: Boolean
val isCrossinline: Boolean
val isNoinline: Boolean
}
data class CommonValueParameter(
override val name: Name,
override val returnType: UnwrappedType,
override val varargElementType: UnwrappedType?,
override val isCrossinline: Boolean,
override val isNoinline: Boolean
) : ValueParameter {
override val annotations get() = Annotations.EMPTY
override val declaresDefaultValue get() = false
}
data class PlatformValueParameter(private val descriptor: ValueParameterDescriptor) : ValueParameter {
override val name get() = descriptor.name
override val annotations get() = descriptor.annotations
override val returnType by lazy(PUBLICATION) { descriptor.returnType!!.unwrap() }
override val varargElementType by lazy(PUBLICATION) { descriptor.varargElementType?.unwrap() }
override val declaresDefaultValue get() = descriptor.declaresDefaultValue()
override val isCrossinline get() = descriptor.isCrossinline
override val isNoinline get() = descriptor.isNoinline
}
@@ -1,17 +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
interface NodeVisitor<R, T> {
fun visitRootNode(node: RootNode, data: T): R
fun visitModuleNode(node: ModuleNode, data: T): R
fun visitPackageNode(node: PackageNode, data: T): R
fun visitPropertyNode(node: PropertyNode, data: T): R
fun visitFunctionNode(node: FunctionNode, data: T): R
fun visitClassNode(node: ClassNode, data: T): R
fun visitClassConstructorNode(node: ClassConstructorNode, data: T): R
fun visitTypeAliasNode(node: TypeAliasNode, data: T): R
}
@@ -1,24 +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.types.SimpleType
import kotlin.LazyThreadSafetyMode.PUBLICATION
interface TypeAlias : AnnotatedDeclaration, NamedDeclaration, DeclarationWithTypeParameters, DeclarationWithVisibility {
val underlyingType: SimpleType
val expandedType: SimpleType
}
class TargetTypeAlias(private val descriptor: TypeAliasDescriptor) : TypeAlias {
override val annotations get() = descriptor.annotations
override val name get() = descriptor.name
override val typeParameters by lazy(PUBLICATION) { descriptor.declaredTypeParameters.map(::TargetTypeParameter) }
override val visibility get() = descriptor.visibility
override val underlyingType get() = descriptor.underlyingType
override val expandedType get() = descriptor.expandedType
}
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.descriptors.commonizer.*
import org.jetbrains.kotlin.descriptors.commonizer.CommonizedGroup
import org.jetbrains.kotlin.descriptors.commonizer.core.*
import org.jetbrains.kotlin.descriptors.commonizer.firstNonNull
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.RootNode.ClassifiersCacheImpl
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirRootNode.ClassifiersCacheImpl
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.scopes.MemberScope
@@ -20,64 +20,64 @@ import org.jetbrains.kotlin.storage.StorageManager
internal fun buildRootNode(
storageManager: StorageManager,
targets: List<InputTarget>
): RootNode = RootNode(
target = targets.map { Root(it) },
): CirRootNode = CirRootNode(
target = targets.map { CirRoot(it) },
common = storageManager.createNullableLazyValue {
Root(OutputTarget(targets.toSet()))
CirRoot(OutputTarget(targets.toSet()))
}
)
internal fun buildModuleNode(
storageManager: StorageManager,
modules: List<ModuleDescriptor?>
): ModuleNode = buildNode(
): CirModuleNode = buildNode(
storageManager = storageManager,
descriptors = modules,
targetDeclarationProducer = ::Module,
targetDeclarationProducer = ::CirModule,
commonValueProducer = { commonize(it, ModuleCommonizer.default()) },
recursionMarker = null,
nodeProducer = ::ModuleNode
nodeProducer = ::CirModuleNode
)
internal fun buildPackageNode(
storageManager: StorageManager,
packageFqName: FqName,
packageMemberScopes: List<MemberScope?>
): PackageNode = buildNode(
): CirPackageNode = buildNode(
storageManager = storageManager,
descriptors = packageMemberScopes,
targetDeclarationProducer = { Package(packageFqName) },
commonValueProducer = { Package(packageFqName) },
targetDeclarationProducer = { CirPackage(packageFqName) },
commonValueProducer = { CirPackage(packageFqName) },
recursionMarker = null,
nodeProducer = ::PackageNode
nodeProducer = ::CirPackageNode
)
internal fun buildPropertyNode(
storageManager: StorageManager,
cache: ClassifiersCache,
cache: CirClassifiersCache,
containingDeclarationCommon: NullableLazyValue<*>?,
properties: List<PropertyDescriptor?>
): PropertyNode = buildNode(
): CirPropertyNode = buildNode(
storageManager = storageManager,
descriptors = properties,
targetDeclarationProducer = ::TargetProperty,
targetDeclarationProducer = ::CirWrappedProperty,
commonValueProducer = { commonize(containingDeclarationCommon, it, PropertyCommonizer(cache)) },
recursionMarker = null,
nodeProducer = ::PropertyNode
nodeProducer = ::CirPropertyNode
)
internal fun buildFunctionNode(
storageManager: StorageManager,
cache: ClassifiersCache,
cache: CirClassifiersCache,
containingDeclarationCommon: NullableLazyValue<*>?,
functions: List<SimpleFunctionDescriptor?>
): FunctionNode = buildNode(
): CirFunctionNode = buildNode(
storageManager = storageManager,
descriptors = functions,
targetDeclarationProducer = ::TargetFunction,
targetDeclarationProducer = ::CirWrappedFunction,
commonValueProducer = { commonize(containingDeclarationCommon, it, FunctionCommonizer(cache)) },
recursionMarker = null,
nodeProducer = ::FunctionNode
nodeProducer = ::CirFunctionNode
)
internal fun buildClassNode(
@@ -85,16 +85,16 @@ internal fun buildClassNode(
cacheRW: ClassifiersCacheImpl,
containingDeclarationCommon: NullableLazyValue<*>?,
classes: List<ClassDescriptor?>
): ClassNode {
): CirClassNode {
val fqName = classes.firstNonNull().fqNameSafe
return buildNode(
storageManager = storageManager,
descriptors = classes,
targetDeclarationProducer = ::TargetClassDeclaration,
targetDeclarationProducer = ::CirWrappedClass,
commonValueProducer = { commonize(containingDeclarationCommon, it, ClassCommonizer(cacheRW)) },
recursionMarker = ClassDeclarationRecursionMarker,
nodeProducer = ::ClassNode
recursionMarker = CirClassRecursionMarker,
nodeProducer = ::CirClassNode
).also { node ->
node.fqName = fqName
cacheRW.classes.put(fqName, node)?.let { oldNode ->
@@ -105,32 +105,32 @@ internal fun buildClassNode(
internal fun buildClassConstructorNode(
storageManager: StorageManager,
cache: ClassifiersCache,
cache: CirClassifiersCache,
containingDeclarationCommon: NullableLazyValue<*>?,
constructors: List<ClassConstructorDescriptor?>
): ClassConstructorNode = buildNode(
): CirClassConstructorNode = buildNode(
storageManager = storageManager,
descriptors = constructors,
targetDeclarationProducer = ::TargetClassConstructor,
targetDeclarationProducer = ::CirWrappedClassConstructor,
commonValueProducer = { commonize(containingDeclarationCommon, it, ClassConstructorCommonizer(cache)) },
recursionMarker = null,
nodeProducer = ::ClassConstructorNode
nodeProducer = ::CirClassConstructorNode
)
internal fun buildTypeAliasNode(
storageManager: StorageManager,
cacheRW: ClassifiersCacheImpl,
typeAliases: List<TypeAliasDescriptor?>
): TypeAliasNode {
): CirTypeAliasNode {
val fqName = typeAliases.firstNonNull().fqNameSafe
return buildNode(
storageManager = storageManager,
descriptors = typeAliases,
targetDeclarationProducer = ::TargetTypeAlias,
targetDeclarationProducer = ::CirWrappedTypeAlias,
commonValueProducer = { commonize(it, TypeAliasCommonizer(cacheRW)) },
recursionMarker = ClassDeclarationRecursionMarker,
nodeProducer = ::TypeAliasNode
recursionMarker = CirClassRecursionMarker,
nodeProducer = ::CirTypeAliasNode
).also { node ->
node.fqName = fqName
cacheRW.typeAliases.put(fqName, node)?.let { oldNode ->
@@ -139,7 +139,7 @@ internal fun buildTypeAliasNode(
}
}
private fun <D : Any, T : Declaration, R : Declaration, N : Node<T, R>> buildNode(
private fun <D : Any, T : CirDeclaration, R : CirDeclaration, N : CirNode<T, R>> buildNode(
storageManager: StorageManager,
descriptors: List<D?>,
targetDeclarationProducer: (D) -> T,
@@ -8,108 +8,108 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.storage.NullableLazyValue
interface Node<T : Declaration, R : Declaration> {
interface CirNode<T : CirDeclaration, R : CirDeclaration> {
val target: List<T?>
val common: NullableLazyValue<R>
fun <R, T> accept(visitor: NodeVisitor<R, T>, data: T): R
fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T): R
}
class RootNode(
override val target: List<Root>,
override val common: NullableLazyValue<Root>
) : Node<Root, Root> {
class ClassifiersCacheImpl : ClassifiersCache {
override val classes = HashMap<FqName, ClassNode>()
override val typeAliases = HashMap<FqName, TypeAliasNode>()
class CirRootNode(
override val target: List<CirRoot>,
override val common: NullableLazyValue<CirRoot>
) : CirNode<CirRoot, CirRoot> {
class ClassifiersCacheImpl : CirClassifiersCache {
override val classes = HashMap<FqName, CirClassNode>()
override val typeAliases = HashMap<FqName, CirTypeAliasNode>()
}
val modules: MutableList<ModuleNode> = ArrayList()
val modules: MutableList<CirModuleNode> = ArrayList()
val cache = ClassifiersCacheImpl()
override fun <R, T> accept(visitor: NodeVisitor<R, T>, data: T): R =
override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T): R =
visitor.visitRootNode(this, data)
}
class ModuleNode(
override val target: List<Module?>,
override val common: NullableLazyValue<Module>
) : Node<Module, Module> {
val packages: MutableList<PackageNode> = ArrayList()
class CirModuleNode(
override val target: List<CirModule?>,
override val common: NullableLazyValue<CirModule>
) : CirNode<CirModule, CirModule> {
val packages: MutableList<CirPackageNode> = ArrayList()
override fun <R, T> accept(visitor: NodeVisitor<R, T>, data: T) =
override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T) =
visitor.visitModuleNode(this, data)
}
class PackageNode(
override val target: List<Package?>,
override val common: NullableLazyValue<Package>
) : Node<Package, Package> {
val properties: MutableList<PropertyNode> = ArrayList()
val functions: MutableList<FunctionNode> = ArrayList()
val classes: MutableList<ClassNode> = ArrayList()
val typeAliases: MutableList<TypeAliasNode> = ArrayList()
class CirPackageNode(
override val target: List<CirPackage?>,
override val common: NullableLazyValue<CirPackage>
) : CirNode<CirPackage, CirPackage> {
val properties: MutableList<CirPropertyNode> = ArrayList()
val functions: MutableList<CirFunctionNode> = ArrayList()
val classes: MutableList<CirClassNode> = ArrayList()
val typeAliases: MutableList<CirTypeAliasNode> = ArrayList()
override fun <R, T> accept(visitor: NodeVisitor<R, T>, data: T) =
override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T) =
visitor.visitPackageNode(this, data)
}
class PropertyNode(
override val target: List<Property?>,
override val common: NullableLazyValue<Property>
) : Node<Property, Property> {
override fun <R, T> accept(visitor: NodeVisitor<R, T>, data: T) =
class CirPropertyNode(
override val target: List<CirProperty?>,
override val common: NullableLazyValue<CirProperty>
) : CirNode<CirProperty, CirProperty> {
override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T) =
visitor.visitPropertyNode(this, data)
}
class FunctionNode(
override val target: List<Function?>,
override val common: NullableLazyValue<Function>
) : Node<Function, Function> {
override fun <R, T> accept(visitor: NodeVisitor<R, T>, data: T) =
class CirFunctionNode(
override val target: List<CirFunction?>,
override val common: NullableLazyValue<CirFunction>
) : CirNode<CirFunction, CirFunction> {
override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T) =
visitor.visitFunctionNode(this, data)
}
class ClassNode(
override val target: List<ClassDeclaration?>,
override val common: NullableLazyValue<ClassDeclaration>
) : Node<ClassDeclaration, ClassDeclaration> {
class CirClassNode(
override val target: List<CirClass?>,
override val common: NullableLazyValue<CirClass>
) : CirNode<CirClass, CirClass> {
lateinit var fqName: FqName
val constructors: MutableList<ClassConstructorNode> = ArrayList()
val properties: MutableList<PropertyNode> = ArrayList()
val functions: MutableList<FunctionNode> = ArrayList()
val classes: MutableList<ClassNode> = ArrayList()
val constructors: MutableList<CirClassConstructorNode> = ArrayList()
val properties: MutableList<CirPropertyNode> = ArrayList()
val functions: MutableList<CirFunctionNode> = ArrayList()
val classes: MutableList<CirClassNode> = ArrayList()
override fun <R, T> accept(visitor: NodeVisitor<R, T>, data: T): R =
override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T): R =
visitor.visitClassNode(this, data)
}
class ClassConstructorNode(
override val target: List<ClassConstructor?>,
override val common: NullableLazyValue<ClassConstructor>
) : Node<ClassConstructor, ClassConstructor> {
override fun <R, T> accept(visitor: NodeVisitor<R, T>, data: T): R =
class CirClassConstructorNode(
override val target: List<CirClassConstructor?>,
override val common: NullableLazyValue<CirClassConstructor>
) : CirNode<CirClassConstructor, CirClassConstructor> {
override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T): R =
visitor.visitClassConstructorNode(this, data)
}
class TypeAliasNode(
override val target: List<TypeAlias?>,
override val common: NullableLazyValue<ClassDeclaration>
) : Node<TypeAlias, ClassDeclaration> {
class CirTypeAliasNode(
override val target: List<CirTypeAlias?>,
override val common: NullableLazyValue<CirClass>
) : CirNode<CirTypeAlias, CirClass> {
lateinit var fqName: FqName
override fun <R, T> accept(visitor: NodeVisitor<R, T>, data: T): R =
override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T): R =
visitor.visitTypeAliasNode(this, data)
}
interface ClassifiersCache {
val classes: Map<FqName, ClassNode>
val typeAliases: Map<FqName, TypeAliasNode>
interface CirClassifiersCache {
val classes: Map<FqName, CirClassNode>
val typeAliases: Map<FqName, CirTypeAliasNode>
}
internal inline val Node<*, *>.indexOfCommon: Int
internal inline val CirNode<*, *>.indexOfCommon: Int
get() = target.size
internal inline val Node<*, *>.dimension: Int
internal inline val CirNode<*, *>.dimension: Int
get() = target.size + 1
@@ -7,8 +7,8 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.commonizer.CommonizedGroupMap
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ModuleNode
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.RootNode
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.toList
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
@@ -20,9 +20,9 @@ import org.jetbrains.kotlin.utils.alwaysTrue
internal fun mergeModules(
storageManager: StorageManager,
cacheRW: RootNode.ClassifiersCacheImpl,
cacheRW: CirRootNode.ClassifiersCacheImpl,
modules: List<ModuleDescriptor?>
): ModuleNode {
): CirModuleNode {
val node = buildModuleNode(storageManager, modules)
val packageMemberScopesMap = CommonizedGroupMap<FqName, MemberScope>(modules.size)
@@ -10,8 +10,8 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
import org.jetbrains.kotlin.descriptors.commonizer.CommonizedGroupMap
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.PackageNode
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.RootNode
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.name.FqName
import org.jetbrains.kotlin.name.Name
@@ -20,10 +20,10 @@ import org.jetbrains.kotlin.storage.StorageManager
internal fun mergePackages(
storageManager: StorageManager,
cacheRW: RootNode.ClassifiersCacheImpl,
cacheRW: CirRootNode.ClassifiersCacheImpl,
packageFqName: FqName,
packageMemberScopes: List<MemberScope?>
): PackageNode {
): CirPackageNode {
val node = buildPackageNode(storageManager, packageFqName, packageMemberScopes)
val propertiesMap = CommonizedGroupMap<PropertyApproximationKey, PropertyDescriptor>(packageMemberScopes.size)
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.commonizer.CommonizedGroupMap
import org.jetbrains.kotlin.descriptors.commonizer.InputTarget
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.RootNode
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirRootNode
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.buildRootNode
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.storage.StorageManager
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.storage.StorageManager
internal fun mergeRoots(
storageManager: StorageManager,
modulesByTargets: List<Pair<InputTarget, Collection<ModuleDescriptor>>>
): RootNode {
): CirRootNode {
val node = buildRootNode(storageManager, modulesByTargets.map { it.first })
val modulesMap = CommonizedGroupMap<Name, ModuleDescriptor>(modulesByTargets.size)
@@ -7,12 +7,12 @@ package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ExtensionReceiver
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirExtensionReceiver
import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType
import org.jetbrains.kotlin.types.UnwrappedType
import org.junit.Test
class DefaultExtensionReceiverCommonizerTest : AbstractCommonizerTest<ExtensionReceiver?, UnwrappedType?>() {
class DefaultExtensionReceiverCommonizerTest : AbstractCommonizerTest<CirExtensionReceiver?, UnwrappedType?>() {
@Test
fun nullReceiver() = doTestSuccess(
@@ -54,7 +54,7 @@ class DefaultExtensionReceiverCommonizerTest : AbstractCommonizerTest<ExtensionR
override fun createCommonizer() = ExtensionReceiverCommonizer.default(EMPTY_CLASSIFIERS_CACHE)
}
private fun mockExtensionReceiver(typeFqName: String) = ExtensionReceiver(
private fun mockExtensionReceiver(typeFqName: String) = CirExtensionReceiver(
annotations = Annotations.EMPTY,
type = mockClassType(typeFqName).unwrap()
)
@@ -5,11 +5,11 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.commonizer.core.TestFunctionModifiers.Companion.areEqual
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.FunctionModifiers
import org.jetbrains.kotlin.descriptors.commonizer.core.CirTestFunctionModifiers.Companion.areEqual
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirFunctionModifiers
import org.junit.Test
class DefaultFunctionModifiersCommonizerTest : AbstractCommonizerTest<FunctionModifiers, FunctionModifiers>() {
class DefaultFunctionModifiersCommonizerTest : AbstractCommonizerTest<CirFunctionModifiers, CirFunctionModifiers>() {
@Test
fun allDefault() = doTestSuccess(
@@ -162,21 +162,21 @@ class DefaultFunctionModifiersCommonizerTest : AbstractCommonizerTest<FunctionMo
)
override fun createCommonizer() = FunctionModifiersCommonizer.default()
override fun isEqual(a: FunctionModifiers?, b: FunctionModifiers?) = (a === b) || (a != null && b != null && areEqual(a, b))
override fun isEqual(a: CirFunctionModifiers?, b: CirFunctionModifiers?) = (a === b) || (a != null && b != null && areEqual(a, b))
}
private typealias mockFunctionModifiers = TestFunctionModifiers
private typealias mockFunctionModifiers = CirTestFunctionModifiers
private data class TestFunctionModifiers(
private data class CirTestFunctionModifiers(
override val isOperator: Boolean = false,
override val isInfix: Boolean = false,
override val isInline: Boolean = false,
override val isTailrec: Boolean = false,
override val isSuspend: Boolean = false,
override val isExternal: Boolean = false
) : FunctionModifiers {
) : CirFunctionModifiers {
companion object {
fun areEqual(a: FunctionModifiers, b: FunctionModifiers) =
fun areEqual(a: CirFunctionModifiers, b: CirFunctionModifiers) =
a.isOperator == b.isOperator && a.isInfix == b.isInfix && a.isInline == b.isInline
&& a.isTailrec == b.isTailrec && a.isSuspend == b.isSuspend && a.isExternal == b.isExternal
}
@@ -9,12 +9,12 @@ import org.jetbrains.kotlin.builtins.DefaultBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltIns
import org.jetbrains.kotlin.builtins.konan.KonanBuiltIns
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.Module
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirModule
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.junit.Test
class DefaultModuleCommonizerTest : AbstractCommonizerTest<Module, Module>() {
class DefaultModuleCommonizerTest : AbstractCommonizerTest<CirModule, CirModule>() {
@Test
fun allAreNative() = doTestSuccess(
@@ -66,7 +66,7 @@ class DefaultModuleCommonizerTest : AbstractCommonizerTest<Module, Module>() {
override fun createCommonizer() = ModuleCommonizer.default()
override fun isEqual(a: Module?, b: Module?) =
override fun isEqual(a: CirModule?, b: CirModule?) =
(a === b) || (a != null && b != null && a.name == b.name && a.builtIns::class.java.name == b.builtIns::class.java.name)
private companion object {
@@ -74,6 +74,6 @@ class DefaultModuleCommonizerTest : AbstractCommonizerTest<Module, Module>() {
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() = Module(Name.identifier("fakeModule"), this)
fun KotlinBuiltIns.toMock() = CirModule(Name.identifier("fakeModule"), this)
}
}
@@ -7,10 +7,10 @@ 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.Setter
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirSetter
import org.junit.Test
class DefaultPropertySetterCommonizerTest : AbstractCommonizerTest<Setter?, Setter?>() {
class DefaultPropertySetterCommonizerTest : AbstractCommonizerTest<CirSetter?, CirSetter?>() {
@Test
fun absentOnly() = super.doTestSuccess(null, null, null, null)
@@ -56,13 +56,13 @@ class DefaultPropertySetterCommonizerTest : AbstractCommonizerTest<Setter?, Sett
private fun doTestSuccess(expected: Visibility?, vararg variants: Visibility?) =
super.doTestSuccess(
expected?.let { Setter.createDefaultNoAnnotations(expected) },
*variants.map { it?.let(Setter.Companion::createDefaultNoAnnotations) }.toTypedArray()
expected?.let { CirSetter.createDefaultNoAnnotations(expected) },
*variants.map { it?.let(CirSetter.Companion::createDefaultNoAnnotations) }.toTypedArray()
)
private fun doTestFailure(vararg variants: Visibility?) =
super.doTestFailure(
*variants.map { it?.let(Setter.Companion::createDefaultNoAnnotations) }.toTypedArray()
*variants.map { it?.let(CirSetter.Companion::createDefaultNoAnnotations) }.toTypedArray()
)
override fun createCommonizer() = PropertySetterCommonizer.default()
@@ -8,7 +8,7 @@ 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.CommonizedGroupMap
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.RootNode.ClassifiersCacheImpl
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.utils.mockClassType
@@ -6,14 +6,14 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CommonTypeParameter
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.TypeParameter
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirCommonTypeParameter
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
import org.junit.Test
class DefaultTypeParameterCommonizerTest : AbstractCommonizerTest<TypeParameter, TypeParameter>() {
class DefaultTypeParameterCommonizerTest : AbstractCommonizerTest<CirTypeParameter, CirTypeParameter>() {
override fun createCommonizer() = TypeParameterCommonizer.default(EMPTY_CLASSIFIERS_CACHE)
@Test
@@ -87,7 +87,7 @@ class DefaultTypeParameterCommonizerTest : AbstractCommonizerTest<TypeParameter,
isReified: Boolean = false,
variance: Variance = Variance.INVARIANT,
upperBounds: List<String> = listOf("kotlin.Any")
) = CommonTypeParameter(
) = CirCommonTypeParameter(
name = Name.identifier(name),
isReified = isReified,
variance = variance,
@@ -6,10 +6,10 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.TypeParameter
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirTypeParameter
import org.junit.Test
class DefaultTypeParameterListCommonizerTest : AbstractCommonizerTest<List<TypeParameter>, List<TypeParameter>>() {
class DefaultTypeParameterListCommonizerTest : AbstractCommonizerTest<List<CirTypeParameter>, List<CirTypeParameter>>() {
@Test
fun emptyValueParameters() = doTestSuccess(
@@ -111,7 +111,7 @@ class DefaultTypeParameterListCommonizerTest : AbstractCommonizerTest<List<TypeP
override fun createCommonizer() = TypeParameterListCommonizer.default(EMPTY_CLASSIFIERS_CACHE)
private companion object {
fun mockTypeParams(vararg params: Pair<String, String>): List<TypeParameter> {
fun mockTypeParams(vararg params: Pair<String, String>): List<CirTypeParameter> {
check(params.isNotEmpty())
return params.map { (name, returnTypeFqName) ->
DefaultTypeParameterCommonizerTest.mockTypeParam(
@@ -7,15 +7,15 @@ package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE
import org.jetbrains.kotlin.descriptors.commonizer.core.TestValueParameter.Companion.areEqual
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ClassifiersCache
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ValueParameter
import org.jetbrains.kotlin.descriptors.commonizer.core.CirTestValueParameter.Companion.areEqual
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirClassifiersCache
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirValueParameter
import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.UnwrappedType
import org.junit.Test
class DefaultValueParameterCommonizerTest : AbstractCommonizerTest<ValueParameter, ValueParameter>() {
class DefaultValueParameterCommonizerTest : AbstractCommonizerTest<CirValueParameter, CirValueParameter>() {
@Test
fun sameReturnType1() = doTestSuccess(
@@ -141,7 +141,7 @@ class DefaultValueParameterCommonizerTest : AbstractCommonizerTest<ValueParamete
override fun createCommonizer() = ValueParameterCommonizer.default(EMPTY_CLASSIFIERS_CACHE)
override fun isEqual(a: ValueParameter?, b: ValueParameter?) =
override fun isEqual(a: CirValueParameter?, b: CirValueParameter?) =
(a === b) || (a != null && b != null && areEqual(EMPTY_CLASSIFIERS_CACHE, a, b))
internal companion object {
@@ -152,10 +152,10 @@ class DefaultValueParameterCommonizerTest : AbstractCommonizerTest<ValueParamete
isCrossinline: Boolean = false,
isNoinline: Boolean = false,
declaresDefaultValue: Boolean = false
): ValueParameter {
): CirValueParameter {
val returnType = mockClassType(returnTypeFqName).unwrap()
return TestValueParameter(
return CirTestValueParameter(
name = Name.identifier(name),
annotations = Annotations.EMPTY,
returnType = returnType,
@@ -168,7 +168,7 @@ class DefaultValueParameterCommonizerTest : AbstractCommonizerTest<ValueParamete
}
}
internal data class TestValueParameter(
internal data class CirTestValueParameter(
override val name: Name,
override val annotations: Annotations,
override val returnType: UnwrappedType,
@@ -176,9 +176,9 @@ internal data class TestValueParameter(
override val declaresDefaultValue: Boolean,
override val isCrossinline: Boolean,
override val isNoinline: Boolean
) : ValueParameter {
) : CirValueParameter {
companion object {
fun areEqual(cache: ClassifiersCache, a: ValueParameter, b: ValueParameter): Boolean {
fun areEqual(cache: CirClassifiersCache, a: CirValueParameter, b: CirValueParameter): Boolean {
if (a.name != b.name
|| !areTypesEqual(cache, a.returnType, b.returnType)
|| a.declaresDefaultValue != b.declaresDefaultValue
@@ -6,11 +6,11 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE
import org.jetbrains.kotlin.descriptors.commonizer.core.TestValueParameter.Companion.areEqual
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.ValueParameter
import org.jetbrains.kotlin.descriptors.commonizer.core.CirTestValueParameter.Companion.areEqual
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirValueParameter
import org.junit.Test
class DefaultValueParameterListCommonizerTest : AbstractCommonizerTest<List<ValueParameter>, List<ValueParameter>>() {
class DefaultValueParameterListCommonizerTest : AbstractCommonizerTest<List<CirValueParameter>, List<CirValueParameter>>() {
@Test
fun emptyValueParameters() = doTestSuccess(
@@ -166,7 +166,7 @@ class DefaultValueParameterListCommonizerTest : AbstractCommonizerTest<List<Valu
override fun createCommonizer() = ValueParameterListCommonizer.default(EMPTY_CLASSIFIERS_CACHE)
override fun isEqual(a: List<ValueParameter>?, b: List<ValueParameter>?): Boolean {
override fun isEqual(a: List<CirValueParameter>?, b: List<CirValueParameter>?): Boolean {
if (a === b)
return true
else if (a == null || b == null || a.size != b.size)
@@ -181,7 +181,7 @@ class DefaultValueParameterListCommonizerTest : AbstractCommonizerTest<List<Valu
}
private companion object {
fun mockValueParams(vararg params: Pair<String, String>): List<ValueParameter> {
fun mockValueParams(vararg params: Pair<String, String>): List<CirValueParameter> {
check(params.isNotEmpty())
return params.map { (name, returnTypeFqName) ->
DefaultValueParameterCommonizerTest.mockValueParam(
@@ -7,10 +7,10 @@ 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.DeclarationWithVisibility
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirDeclarationWithVisibility
import org.junit.Test
class EqualizingVisibilityCommonizerTest : AbstractCommonizerTest<DeclarationWithVisibility, Visibility>() {
class EqualizingVisibilityCommonizerTest : AbstractCommonizerTest<CirDeclarationWithVisibility, Visibility>() {
@Test
fun publicOnly() = doTestSuccess(PUBLIC, PUBLIC.toMock(), PUBLIC.toMock(), PUBLIC.toMock())
@@ -42,6 +42,6 @@ class EqualizingVisibilityCommonizerTest : AbstractCommonizerTest<DeclarationWit
override fun createCommonizer() = VisibilityCommonizer.equalizing()
}
private fun Visibility.toMock() = object : DeclarationWithVisibility {
private fun Visibility.toMock() = object : CirDeclarationWithVisibility {
override val visibility: Visibility = this@toMock
}
@@ -16,7 +16,7 @@ import org.junit.Test
abstract class LoweringVisibilityCommonizerTest(
private val allowPrivate: Boolean,
private val areMembersVirtual: Boolean
) : AbstractCommonizerTest<DeclarationWithVisibility, Visibility>() {
) : AbstractCommonizerTest<CirDeclarationWithVisibility, Visibility>() {
@Test
fun publicOnly() = doTestSuccess(PUBLIC, PUBLIC.toMock(), PUBLIC.toMock(), PUBLIC.toMock())
@@ -32,19 +32,19 @@ abstract class LoweringVisibilityCommonizerTest(
final override fun createCommonizer() = VisibilityCommonizer.lowering(allowPrivate = allowPrivate)
protected fun Visibility.toMock() = object : FunctionOrProperty {
protected fun Visibility.toMock() = object : CirFunctionOrProperty {
override val visibility: Visibility = this@toMock
override val modality: Modality get() = if (areMembersVirtual) Modality.OPEN else Modality.FINAL
override val containingClassModality: Modality? get() = if (areMembersVirtual) Modality.OPEN else null
override val containingClassKind: ClassKind? get() = if (areMembersVirtual) ClassKind.CLASS else null
override val isExternal: Boolean get() = unsupported()
override val extensionReceiver: ExtensionReceiver? get() = unsupported()
override val extensionReceiver: CirExtensionReceiver? get() = unsupported()
override val returnType: UnwrappedType get() = unsupported()
override val kind: CallableMemberDescriptor.Kind get() = unsupported()
override val annotations: Annotations get() = unsupported()
override val name: Name get() = unsupported()
override val containingClassIsData: Boolean? get() = unsupported()
override val typeParameters: List<TypeParameter> get() = unsupported()
override val typeParameters: List<CirTypeParameter> get() = unsupported()
}
class PrivateMembers : LoweringVisibilityCommonizerTest(true, false) {
@@ -104,7 +104,7 @@ private fun createPackageFragmentForClassifier(classifierFqName: FqName): Packag
override fun toString() = "package $name"
}
internal val EMPTY_CLASSIFIERS_CACHE = object : ClassifiersCache {
override val classes: Map<FqName, ClassNode> get() = emptyMap()
override val typeAliases: Map<FqName, TypeAliasNode> get() = emptyMap()
internal val EMPTY_CLASSIFIERS_CACHE = object : CirClassifiersCache {
override val classes: Map<FqName, CirClassNode> get() = emptyMap()
override val typeAliases: Map<FqName, CirTypeAliasNode> get() = emptyMap()
}