diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/MoveBodilessDeclarationsToSeparatePlace.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/MoveBodilessDeclarationsToSeparatePlace.kt index 7471dde6d11..0e9136028d0 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/MoveBodilessDeclarationsToSeparatePlace.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/MoveBodilessDeclarationsToSeparatePlace.kt @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable import org.jetbrains.kotlin.ir.util.isEffectivelyExternal import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid +import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.name.FqName private val BODILESS_BUILTIN_CLASSES = listOf( @@ -55,11 +56,13 @@ private class DescriptorlessIrFileSymbol : IrFileSymbol { private var _owner: IrFile? = null override val owner get() = _owner!! - override var uniqId: UniqId - get() = error("Operation is unsupported") - set(value) { error("Operation is unsupported") } - override val isBound get() = _owner != null + + override val isPublicApi: Boolean + get() = error("Operation is unsupported") + + override val signature: IdSignature + get() = error("Operation is unsupported") } private fun isBuiltInClass(declaration: IrDeclaration): Boolean = diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmBackendContext.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmBackendContext.kt index fd2c894713d..15cc7eb7552 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmBackendContext.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmBackendContext.kt @@ -24,8 +24,8 @@ import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.symbols.impl.IrExternalPackageFragmentSymbolImpl +import org.jetbrains.kotlin.ir.util.IdSignature import org.jetbrains.kotlin.ir.util.SymbolTable -import org.jetbrains.kotlin.ir.util.UniqId import org.jetbrains.kotlin.name.FqName class WasmBackendContext( @@ -90,15 +90,17 @@ class DescriptorlessExternalPackageFragmentSymbol : IrExternalPackageFragmentSym private var _owner: IrExternalPackageFragment? = null override val owner get() = _owner!! - override var uniqId: UniqId - get() = error("Operation is unsupported") - set(value) { error("Operation is unsupported") } - override val isBound get() = _owner != null override fun bind(owner: IrExternalPackageFragment) { _owner = owner } + + override val isPublicApi: Boolean + get() = error("Operation is unsupported") + + override val signature: IdSignature + get() = error("Operation is unsupported") } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrDelegatingSymbol.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrDelegatingSymbol.kt index 6116ce96de8..e2562c8fb65 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrDelegatingSymbol.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrDelegatingSymbol.kt @@ -2,22 +2,24 @@ package org.jetbrains.kotlin.ir.symbols import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.util.UniqId +import org.jetbrains.kotlin.ir.util.IdSignature -abstract class IrDelegatingSymbol, B: IrSymbolOwner, D: DeclarationDescriptor>(var delegate: S) - : IrBindableSymbol { +abstract class IrDelegatingSymbol, B : IrSymbolOwner, D : DeclarationDescriptor>(var delegate: S) : + IrBindableSymbol { override val owner: B get() = delegate.owner override val descriptor: D get() = delegate.descriptor override val isBound: Boolean get() = delegate.isBound - override var uniqId: UniqId - get() = delegate.uniqId - set(value: UniqId) { delegate.uniqId = value } + override val isPublicApi: Boolean + get() = delegate.isPublicApi + + override val signature: IdSignature + get() = delegate.signature override fun bind(owner: B) = delegate.bind(owner) override fun hashCode() = delegate.hashCode() override fun equals(other: Any?): Boolean { if (this === other) return true - if (this === delegate) return true + if (delegate === other) return true return false } } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrSymbol.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrSymbol.kt index 51aae4d9771..970eb9c7860 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrSymbol.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrSymbol.kt @@ -20,8 +20,8 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.IrScript import org.jetbrains.kotlin.ir.expressions.IrReturnableBlock +import org.jetbrains.kotlin.ir.util.IdSignature import org.jetbrains.kotlin.ir.util.IrSymbolVisitor -import org.jetbrains.kotlin.ir.util.UniqId import org.jetbrains.kotlin.types.model.TypeConstructorMarker import org.jetbrains.kotlin.types.model.TypeParameterMarker @@ -30,7 +30,9 @@ interface IrSymbol { val descriptor: DeclarationDescriptor val isBound: Boolean - var uniqId: UniqId + val signature: IdSignature + + val isPublicApi: Boolean fun accept(visitor: IrSymbolVisitor, data: D): R } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrSymbolBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrPrivateSymbolBase.kt similarity index 68% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrSymbolBase.kt rename to compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrPrivateSymbolBase.kt index e343d7a681d..6577b95cfc6 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrSymbolBase.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrPrivateSymbolBase.kt @@ -21,12 +21,12 @@ import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.descriptors.* import org.jetbrains.kotlin.ir.expressions.IrReturnableBlock import org.jetbrains.kotlin.ir.symbols.* -import org.jetbrains.kotlin.ir.util.UniqId +import org.jetbrains.kotlin.ir.util.IdSignature -abstract class IrSymbolBase(override val descriptor: D, override var uniqId: UniqId = UniqId.NONE) : IrSymbol +abstract class IrSymbolBase(override val descriptor: D) : IrSymbol -abstract class IrBindableSymbolBase(descriptor: D, uniqId: UniqId = UniqId.NONE) : - IrBindableSymbol, IrSymbolBase(descriptor, uniqId) { +abstract class IrBindableSymbolBase(descriptor: D) : + IrBindableSymbol, IrSymbolBase(descriptor) { init { assert(isOriginalDescriptor(descriptor)) { @@ -58,6 +58,11 @@ abstract class IrBindableSymbolBase(descriptor, uniqId), +class IrClassSymbolImpl(descriptor: ClassDescriptor) : + IrBindableSymbolBase(descriptor), IrClassSymbol { - constructor(uniqId: UniqId) : this(WrappedClassDescriptor(), uniqId) } -class IrEnumEntrySymbolImpl(descriptor: ClassDescriptor, uniqId: UniqId = UniqId.NONE) : - IrBindableSymbolBase(descriptor, uniqId), +class IrEnumEntrySymbolImpl(descriptor: ClassDescriptor) : + IrBindableSymbolBase(descriptor), IrEnumEntrySymbol { - constructor(uniqId: UniqId) : this(WrappedEnumEntryDescriptor(), uniqId) } -class IrFieldSymbolImpl(descriptor: PropertyDescriptor, uniqId: UniqId = UniqId.NONE) : - IrBindableSymbolBase(descriptor, uniqId), +class IrFieldSymbolImpl(descriptor: PropertyDescriptor) : + IrBindableSymbolBase(descriptor), IrFieldSymbol { - constructor(uniqId: UniqId) : this(WrappedFieldDescriptor(), uniqId) } -class IrTypeParameterSymbolImpl(descriptor: TypeParameterDescriptor, uniqId: UniqId = UniqId.NONE) : - IrBindableSymbolBase(descriptor, uniqId), +class IrTypeParameterSymbolImpl(descriptor: TypeParameterDescriptor) : + IrBindableSymbolBase(descriptor), IrTypeParameterSymbol { - constructor(uniqId: UniqId) : this(WrappedTypeParameterDescriptor(), uniqId) } -class IrValueParameterSymbolImpl(descriptor: ParameterDescriptor, uniqId: UniqId = UniqId.NONE) : - IrBindableSymbolBase(descriptor, uniqId), +class IrValueParameterSymbolImpl(descriptor: ParameterDescriptor) : + IrBindableSymbolBase(descriptor), IrValueParameterSymbol { - constructor(uniqId: UniqId) : this(WrappedValueParameterDescriptor(), uniqId) } -class IrVariableSymbolImpl(descriptor: VariableDescriptor, uniqId: UniqId = UniqId.NONE) : - IrBindableSymbolBase(descriptor, uniqId), +class IrVariableSymbolImpl(descriptor: VariableDescriptor) : + IrBindableSymbolBase(descriptor), IrVariableSymbol { - constructor(uniqId: UniqId) : this(WrappedVariableDescriptor(), uniqId) } -class IrSimpleFunctionSymbolImpl(descriptor: FunctionDescriptor, uniqId: UniqId = UniqId.NONE) : - IrBindableSymbolBase(descriptor, uniqId), +class IrSimpleFunctionSymbolImpl(descriptor: FunctionDescriptor) : + IrBindableSymbolBase(descriptor), IrSimpleFunctionSymbol { - constructor(uniqId: UniqId) : this(WrappedSimpleFunctionDescriptor(), uniqId) } -class IrConstructorSymbolImpl(descriptor: ClassConstructorDescriptor, uniqId: UniqId = UniqId.NONE) : - IrBindableSymbolBase(descriptor, uniqId), +class IrConstructorSymbolImpl(descriptor: ClassConstructorDescriptor) : + IrBindableSymbolBase(descriptor), IrConstructorSymbol { - constructor(uniqId: UniqId) : this(WrappedClassConstructorDescriptor(), uniqId) } class IrReturnableBlockSymbolImpl(descriptor: FunctionDescriptor) : IrBindableSymbolBase(descriptor), IrReturnableBlockSymbol -class IrPropertySymbolImpl(descriptor: PropertyDescriptor, uniqId: UniqId = UniqId.NONE) : - IrBindableSymbolBase(descriptor, uniqId), +class IrPropertySymbolImpl(descriptor: PropertyDescriptor) : + IrBindableSymbolBase(descriptor), IrPropertySymbol { - constructor(uniqId: UniqId) : this(WrappedPropertyDescriptor(), uniqId) } class IrLocalDelegatedPropertySymbolImpl(descriptor: VariableDescriptorWithAccessors) : IrBindableSymbolBase(descriptor), IrLocalDelegatedPropertySymbol -class IrTypeAliasSymbolImpl(descriptor: TypeAliasDescriptor, uniqId: UniqId = UniqId.NONE) : - IrBindableSymbolBase(descriptor, uniqId), +class IrTypeAliasSymbolImpl(descriptor: TypeAliasDescriptor) : + IrBindableSymbolBase(descriptor), IrTypeAliasSymbol { - constructor(uniqId: UniqId) : this(WrappedTypeAliasDescriptor(), uniqId) -} \ No newline at end of file +} + +class IrScriptSymbolImpl(descriptor: ScriptDescriptor) : + IrScriptSymbol, IrBindableSymbolBase(descriptor) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrPublicSymbolBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrPublicSymbolBase.kt new file mode 100644 index 00000000000..90bb1c02a37 --- /dev/null +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrPublicSymbolBase.kt @@ -0,0 +1,78 @@ +/* + * 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.ir.symbols.impl + +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor +import org.jetbrains.kotlin.ir.symbols.* +import org.jetbrains.kotlin.ir.util.IdSignature + +abstract class IrPublicSymbolBase(override val descriptor: D, override val signature: IdSignature) : IrSymbol + +abstract class IrBindablePublicSymbolBase(descriptor: D, sig: IdSignature) : + IrBindableSymbol, IrPublicSymbolBase(descriptor, sig) { + + init { + assert(isOriginalDescriptor(descriptor)) { + "Substituted descriptor $descriptor for ${descriptor.original}" + } + assert(sig.isPublic) + } + + private fun isOriginalDescriptor(descriptor: DeclarationDescriptor): Boolean = + descriptor is WrappedDeclarationDescriptor<*> || + // TODO fix declaring/referencing value parameters: compute proper original descriptor + descriptor is ValueParameterDescriptor && isOriginalDescriptor(descriptor.containingDeclaration) || + descriptor == descriptor.original + + private var _owner: B? = null + override val owner: B + get() = _owner ?: throw IllegalStateException("Symbol for $signature is unbound") + + override fun bind(owner: B) { + if (_owner == null) { + _owner = owner + } else { + throw IllegalStateException("${javaClass.simpleName} for $signature is already bound") + } + } + + override val isPublicApi: Boolean = true + + override val isBound: Boolean + get() = _owner != null +} + +class IrClassPublicSymbolImpl(descriptor: ClassDescriptor, sig: IdSignature) : + IrBindablePublicSymbolBase(descriptor, sig), + IrClassSymbol { +} + +class IrEnumEntryPublicSymbolImpl(descriptor: ClassDescriptor, sig: IdSignature) : + IrBindablePublicSymbolBase(descriptor, sig), + IrEnumEntrySymbol { +} + +class IrSimpleFunctionPublicSymbolImpl(descriptor: FunctionDescriptor, sig: IdSignature) : + IrBindablePublicSymbolBase(descriptor, sig), + IrSimpleFunctionSymbol { +} + +class IrConstructorPublicSymbolImpl(descriptor: ClassConstructorDescriptor, sig: IdSignature) : + IrBindablePublicSymbolBase(descriptor, sig), + IrConstructorSymbol { +} + +class IrPropertyPublicSymbolImpl(descriptor: PropertyDescriptor, sig: IdSignature) : + IrBindablePublicSymbolBase(descriptor, sig), + IrPropertySymbol { +} + +class IrTypeAliasPublicSymbolImpl(descriptor: TypeAliasDescriptor, sig: IdSignature) : + IrBindablePublicSymbolBase(descriptor, sig), + IrTypeAliasSymbol { +} diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrScriptSymbolImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrScriptSymbolImpl.kt deleted file mode 100644 index 131eaabf425..00000000000 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrScriptSymbolImpl.kt +++ /dev/null @@ -1,13 +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.ir.symbols.impl - -import org.jetbrains.kotlin.descriptors.ScriptDescriptor -import org.jetbrains.kotlin.ir.declarations.IrScript -import org.jetbrains.kotlin.ir.symbols.IrScriptSymbol - -class IrScriptSymbolImpl(descriptor: ScriptDescriptor) : - IrScriptSymbol, IrBindableSymbolBase(descriptor)