diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/DescriptorUtils.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/DescriptorUtils.kt index 1f913064518..a314109c26d 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/DescriptorUtils.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/DescriptorUtils.kt @@ -26,12 +26,23 @@ import org.jetbrains.kotlin.types.TypeProjectionImpl import org.jetbrains.kotlin.types.TypeSubstitutor import org.jetbrains.kotlin.types.replace +val String.synthesizedName: Name get() = Name.identifier(this.synthesizedString) + +val String.synthesizedString: String get() = "\$$this" + +val DeclarationDescriptor.propertyIfAccessor: DeclarationDescriptor + get() = if (this is PropertyAccessorDescriptor) + this.correspondingProperty + else this + val CallableDescriptor.isSuspend: Boolean get() = this is FunctionDescriptor && isSuspend /** * @return naturally-ordered list of all parameters available inside the function body. */ +// Used in Kotlin/Native +@Suppress("unused") val CallableDescriptor.allParameters: List get() = if (this is ConstructorDescriptor) { listOf(this.constructedClass.thisAsReceiverParameter) + explicitParameters @@ -59,58 +70,17 @@ val CallableDescriptor.explicitParameters: List return result } -fun KotlinType.replace(types: List) = this.replace(types.map(::TypeProjectionImpl)) - +// Used in Kotlin/Native +@Suppress("unused") fun FunctionDescriptor.substitute(vararg types: KotlinType): FunctionDescriptor { val typeSubstitutor = TypeSubstitutor.create( - typeParameters - .withIndex() - .associateBy({ it.value.typeConstructor }, { TypeProjectionImpl(types[it.index]) }) - ) - return substitute(typeSubstitutor)!! -} - -fun FunctionDescriptor.substitute(typeArguments: Map): FunctionDescriptor { - val typeSubstitutor = TypeSubstitutor.create( - typeParameters.associateBy({ it.typeConstructor }, { TypeProjectionImpl(typeArguments[it]!!) }) - ) - return substitute(typeSubstitutor)!! -} - -fun ClassDescriptor.getFunction(name: String, types: List): FunctionDescriptor { - val typeSubstitutor = TypeSubstitutor.create( - declaredTypeParameters - .withIndex() - .associateBy({ it.value.typeConstructor }, { TypeProjectionImpl(types[it.index]) }) - ) - return unsubstitutedMemberScope - .getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BACKEND).single().substitute(typeSubstitutor)!! -} - -fun ClassDescriptor.getStaticFunction(name: String, types: List): FunctionDescriptor { - val typeSubstitutor = TypeSubstitutor.create( - declaredTypeParameters + typeParameters .withIndex() .associateBy({ it.value.typeConstructor }, { TypeProjectionImpl(types[it.index]) }) ) - return staticScope - .getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BACKEND).single().substitute(typeSubstitutor)!! + return substitute(typeSubstitutor)!! } -fun ClassDescriptor.getProperty(name: String, types: List): PropertyDescriptor { - val typeSubstitutor = TypeSubstitutor.create( - declaredTypeParameters - .withIndex() - .associateBy({ it.value.typeConstructor }, { TypeProjectionImpl(types[it.index]) }) - ) - return unsubstitutedMemberScope - .getContributedVariables( - Name.identifier(name), - NoLookupLocation.FROM_BACKEND - ).single().substitute(typeSubstitutor) as PropertyDescriptor -} - - val KotlinType.isFunctionOrKFunctionType: Boolean get() { val kind = constructor.declarationDescriptor?.getFunctionalClassKind() diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/KnownDescriptors.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/KnownDescriptors.kt deleted file mode 100644 index dc1a6802481..00000000000 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/KnownDescriptors.kt +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright 2000-2018 JetBrains s.r.o. 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.backend.common.descriptors - -import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.descriptors.impl.LazyClassReceiverParameterDescriptor -import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl -import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe -import org.jetbrains.kotlin.resolve.scopes.MemberScope -import org.jetbrains.kotlin.storage.LockBasedStorageManager -import org.jetbrains.kotlin.types.* - -open class KnownPackageFragmentDescriptor(moduleDescriptor: ModuleDescriptor, fqName: FqName) : - PackageFragmentDescriptorImpl(moduleDescriptor, fqName) { - override fun getMemberScope(): MemberScope = MemberScope.Empty -} - -open class KnownClassDescriptor( - private val name: Name, - private val containingDeclaration: DeclarationDescriptor, - private val sourceElement: SourceElement, - private val kind: ClassKind, - private val modality: Modality, - private val visibility: Visibility, - override val annotations: Annotations -) : ClassDescriptor { - init { - assert(modality != Modality.SEALED) { "Implement getSealedSubclasses() for this class: ${this::class.java}" } - } - - private lateinit var typeConstructor: TypeConstructor - private lateinit var supertypes: List - private lateinit var defaultType: SimpleType - private lateinit var declaredTypeParameters: List - - private val thisAsReceiverParameter = LazyClassReceiverParameterDescriptor(this) - - fun initialize(declaredTypeParameters: List, supertypes: List) { - this.declaredTypeParameters = declaredTypeParameters - this.supertypes = supertypes - this.typeConstructor = ClassTypeConstructorImpl(this, declaredTypeParameters, supertypes, LockBasedStorageManager.NO_LOCKS) - this.defaultType = TypeUtils.makeUnsubstitutedType(this, unsubstitutedMemberScope) - } - - companion object { - fun createClass( - name: Name, - containingDeclaration: DeclarationDescriptor, - supertypes: List, - modality: Modality = Modality.FINAL, - visibility: Visibility = Visibilities.PUBLIC, - annotations: Annotations = Annotations.EMPTY - ) = - KnownClassDescriptor( - name, containingDeclaration, - SourceElement.NO_SOURCE, ClassKind.CLASS, - modality, visibility, - annotations - ).apply { - initialize(emptyList(), supertypes) - } - - private inline fun createClassWithTypeParameters( - name: Name, - containingDeclaration: DeclarationDescriptor, - supertypes: List, - modality: Modality = Modality.FINAL, - visibility: Visibility = Visibilities.PUBLIC, - annotations: Annotations = Annotations.EMPTY, - createTypeParameters: (ClassDescriptor) -> List - ) = - KnownClassDescriptor( - name, containingDeclaration, - SourceElement.NO_SOURCE, ClassKind.CLASS, - modality, visibility, - annotations - ).apply { - initialize(createTypeParameters(this), supertypes) - } - - fun createClassWithTypeParameters( - name: Name, - containingDeclaration: DeclarationDescriptor, - supertypes: List, - typeParameterNames: List, - modality: Modality = Modality.FINAL, - visibility: Visibility = Visibilities.PUBLIC, - annotations: Annotations = Annotations.EMPTY - ) = - createClassWithTypeParameters(name, containingDeclaration, supertypes, modality, visibility, annotations) { classDescriptor -> - typeParameterNames.mapIndexed { index, name -> - TypeParameterDescriptorImpl.createWithDefaultBound( - classDescriptor, Annotations.EMPTY, true, Variance.INVARIANT, name, index - ) - } - } - } - - override fun getCompanionObjectDescriptor(): ClassDescriptor? = null - override fun getConstructors(): Collection = emptyList() - override fun getContainingDeclaration(): DeclarationDescriptor = containingDeclaration - override fun getDeclaredTypeParameters(): List = declaredTypeParameters - override fun getKind(): ClassKind = kind - override fun getSealedSubclasses(): Collection = emptyList() - - override fun getMemberScope(typeArguments: MutableList): MemberScope = MemberScope.Empty - override fun getMemberScope(typeSubstitution: TypeSubstitution): MemberScope = MemberScope.Empty - override fun getStaticScope(): MemberScope = MemberScope.Empty - override fun getUnsubstitutedInnerClassesScope(): MemberScope = MemberScope.Empty - override fun getUnsubstitutedMemberScope(): MemberScope = MemberScope.Empty - - override fun getUnsubstitutedPrimaryConstructor(): ClassConstructorDescriptor? = null - - override fun substitute(substitutor: TypeSubstitutor): ClassDescriptor = error("Class $this can't be substituted") - - override fun getThisAsReceiverParameter(): ReceiverParameterDescriptor = thisAsReceiverParameter - - override fun getModality(): Modality = modality - override fun getOriginal(): ClassDescriptor = this - override fun getName(): Name = name - override fun getVisibility(): Visibility = visibility - override fun getSource(): SourceElement = sourceElement - override fun getTypeConstructor(): TypeConstructor = typeConstructor - override fun getDefaultType(): SimpleType = defaultType - - override fun isCompanionObject(): Boolean = false - override fun isData(): Boolean = false - override fun isInline(): Boolean = false - override fun isInner(): Boolean = false - override fun isExpect(): Boolean = false - override fun isActual(): Boolean = false - override fun isExternal(): Boolean = false - - override fun accept(visitor: DeclarationDescriptorVisitor, data: D): R { - return visitor.visitClassDescriptor(this, data) - } - - override fun acceptVoid(visitor: DeclarationDescriptorVisitor) { - visitor.visitClassDescriptor(this, null) - } - - override fun toString(): String = - "KnownClassDescriptor($fqNameUnsafe)" -} diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/utils.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/utils.kt deleted file mode 100644 index c5f6c04ac56..00000000000 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/utils.kt +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.backend.common.descriptors - -import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.incremental.components.NoLookupLocation -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor -import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor -import org.jetbrains.kotlin.types.KotlinType - -fun ClassDescriptor?.getter2Descriptor(methodName: Name) = this?.let { - this.unsubstitutedMemberScope.getContributedDescriptors { true } - .firstOrNull { - it.name == methodName - }?.let { - return@let (it as? PropertyDescriptor)?.getter - } -} - -fun ClassDescriptor?.signature2Descriptor(methodName: Name, signature: Array = emptyArray()) = this?.let { - this - .unsubstitutedMemberScope - .getContributedFunctions(methodName, NoLookupLocation.FROM_BACKEND) - .firstOrNull { - return@firstOrNull it.valueParameters.size == signature.size - && (signature.isEmpty() || it.valueParameters.any { p -> - val index = it.valueParameters.indexOf(p) - return@any p.type == signature[index] - }) - } -} - -val String.synthesizedName get() = Name.identifier(this.synthesizedString) - -val String.synthesizedString get() = "\$$this" - -val DeclarationDescriptor.propertyIfAccessor - get() = if (this is PropertyAccessorDescriptor) - this.correspondingProperty - else this - -val CallableMemberDescriptor.propertyIfAccessor - get() = if (this is PropertyAccessorDescriptor) - this.correspondingProperty - else this - -val FunctionDescriptor.deserializedPropertyIfAccessor: DeserializedCallableMemberDescriptor - get() { - val member = this.propertyIfAccessor - if (member is DeserializedCallableMemberDescriptor) - return member - else - error("Unexpected deserializable callable descriptor") - } - -val CallableMemberDescriptor.isDeserializableCallable - get () = (this.propertyIfAccessor is DeserializedCallableMemberDescriptor) \ No newline at end of file diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt index 5b945837931..6353912a563 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt @@ -7,7 +7,6 @@ package org.jetbrains.kotlin.ir.backend.js import org.jetbrains.kotlin.backend.common.CommonBackendContext import org.jetbrains.kotlin.backend.common.atMostOne -import org.jetbrains.kotlin.backend.common.descriptors.KnownPackageFragmentDescriptor import org.jetbrains.kotlin.backend.common.ir.Ir import org.jetbrains.kotlin.backend.common.ir.Symbols import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig @@ -17,6 +16,7 @@ import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor +import org.jetbrains.kotlin.descriptors.impl.EmptyPackageFragmentDescriptor import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.ir.IrElement @@ -59,7 +59,7 @@ class JsIrBackendContext( val packageLevelJsModules = mutableListOf() val declarationLevelJsModules = mutableListOf() - val internalPackageFragmentDescriptor = KnownPackageFragmentDescriptor(builtIns.builtInsModule, FqName("kotlin.js.internal")) + val internalPackageFragmentDescriptor = EmptyPackageFragmentDescriptor(builtIns.builtInsModule, FqName("kotlin.js.internal")) val implicitDeclarationFile by lazy { IrFileImpl(object : SourceManager.FileEntry { override val name = "" diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/DefaultImplsClassDescriptor.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/DefaultImplsClassDescriptor.kt deleted file mode 100644 index c5c7df3057a..00000000000 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/DefaultImplsClassDescriptor.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.backend.jvm.descriptors - -import org.jetbrains.kotlin.backend.common.descriptors.KnownClassDescriptor -import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.resolve.descriptorUtil.module - -interface DefaultImplsClassDescriptor : ClassDescriptor { - val correspondingInterface: ClassDescriptor -} - -class DefaultImplsClassDescriptorImpl( - name: Name, - override val correspondingInterface: ClassDescriptor, - sourceElement: SourceElement -) : DefaultImplsClassDescriptor, KnownClassDescriptor( - name, - correspondingInterface, - sourceElement, - ClassKind.CLASS, - Modality.FINAL, - Visibilities.PUBLIC, - Annotations.EMPTY -) { - init { - initialize(emptyList(), listOf(correspondingInterface.module.builtIns.anyType)) - } - - override fun isExternal() = false -} \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltIns.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltIns.kt index e5a8e5cf20a..710cec1dd41 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltIns.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltIns.kt @@ -127,7 +127,6 @@ class IrBuiltIns( val collectionClass = builtIns.collection.toIrSymbol() - val arrayType = builtIns.array.toIrType(symbolTable = symbolTable) val arrayClass = builtIns.array.toIrSymbol() val throwableType = builtIns.throwable.defaultType.toIrType() diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypes.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypes.kt index 8472eee91aa..863b34b7f5d 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypes.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypes.kt @@ -107,11 +107,6 @@ private fun makeKotlinType( return classifier.descriptor.defaultType.replace(newArguments = kotlinTypeArguments).makeNullableAsSpecified(hasQuestionMark) } -fun ClassifierDescriptor.toIrType(hasQuestionMark: Boolean = false, symbolTable: SymbolTable? = null): IrType { - val symbol = getSymbol(symbolTable) - return IrSimpleTypeImpl(defaultType, symbol, hasQuestionMark, listOf(), listOf()) -} - val IrTypeParameter.defaultType: IrType get() = IrSimpleTypeImpl( symbol, @@ -155,4 +150,4 @@ private fun ClassifierDescriptor.getSymbol(symbolTable: SymbolTable?): IrClassif is ClassDescriptor -> symbolTable?.referenceClass(this) ?: IrClassSymbolImpl(this) is TypeParameterDescriptor -> symbolTable?.referenceTypeParameter(this) ?: IrTypeParameterSymbolImpl(this) else -> TODO() -} \ No newline at end of file +}