diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/WrappedDescriptors.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/WrappedDescriptors.kt index 22713d1772a..eaa0d8c1175 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/WrappedDescriptors.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/descriptors/WrappedDescriptors.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.impl.ReceiverParameterDescriptorImpl import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.descriptors.IrBasedDeclarationDescriptor import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.types.classifierOrFail import org.jetbrains.kotlin.ir.types.toKotlinType @@ -31,9 +32,12 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.storage.LockBasedStorageManager import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.types.* +import java.lang.UnsupportedOperationException -abstract class WrappedDeclarationDescriptor(annotations: Annotations) : DeclarationDescriptor { +abstract class WrappedDeclarationDescriptor(annotations: Annotations) : + DeclarationDescriptor, IrBasedDeclarationDescriptor { + private val annotations_ = annotations override val annotations: Annotations @@ -112,9 +116,8 @@ abstract class WrappedCallableDescriptor( ) : CallableDescriptor, WrappedDeclarationDescriptor(annotations) { override fun getOriginal() = this - override fun substitute(substitutor: TypeSubstitutor): CallableDescriptor { - TODO("not implemented") - } + override fun substitute(substitutor: TypeSubstitutor): CallableDescriptor = + throw UnsupportedOperationException("Wrapped descriptors SHOULD NOT be substituted") override fun getOverriddenDescriptors(): Collection { TODO("not implemented") @@ -190,9 +193,8 @@ open class WrappedValueParameterDescriptor( override fun getOriginal() = this - override fun substitute(substitutor: TypeSubstitutor): ValueParameterDescriptor { - TODO("") - } + override fun substitute(substitutor: TypeSubstitutor): ValueParameterDescriptor = + throw UnsupportedOperationException("Wrapped descriptors SHOULD NOT be substituted") override fun getReturnType(): KotlinType? = owner.type.toKotlinType() @@ -583,9 +585,8 @@ open class WrappedClassDescriptor( override fun isExpect() = false - override fun substitute(substitutor: TypeSubstitutor): ClassifierDescriptorWithTypeParameters { - TODO("not implemented") - } + override fun substitute(substitutor: TypeSubstitutor): ClassifierDescriptorWithTypeParameters = + throw UnsupportedOperationException("Wrapped descriptors SHOULD NOT be substituted") override fun isActual() = false @@ -696,9 +697,8 @@ open class WrappedEnumEntryDescriptor( override fun isExpect() = false - override fun substitute(substitutor: TypeSubstitutor): ClassifierDescriptorWithTypeParameters { - TODO("not implemented") - } + override fun substitute(substitutor: TypeSubstitutor): ClassifierDescriptorWithTypeParameters = + throw UnsupportedOperationException("Wrapped descriptors SHOULD NOT be substituted") override fun isActual() = false @@ -783,9 +783,8 @@ open class WrappedPropertyDescriptor( override fun isExpect() = false - override fun substitute(substitutor: TypeSubstitutor): PropertyDescriptor { - TODO("not implemented") - } + override fun substitute(substitutor: TypeSubstitutor): PropertyDescriptor = + throw UnsupportedOperationException("Wrapped descriptors SHOULD NOT be substituted") override fun isActual() = false @@ -888,9 +887,8 @@ open class WrappedFieldDescriptor( override fun isExpect() = false - override fun substitute(substitutor: TypeSubstitutor): PropertyDescriptor { - TODO("not implemented") - } + override fun substitute(substitutor: TypeSubstitutor): PropertyDescriptor = + throw UnsupportedOperationException("Wrapped descriptors SHOULD NOT be substituted") override fun isActual() = false diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDeclarationDescriptor.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDeclarationDescriptor.kt new file mode 100644 index 00000000000..6a2188943cf --- /dev/null +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDeclarationDescriptor.kt @@ -0,0 +1,10 @@ +/* + * Copyright 2010-2019 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.ir.descriptors + +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor + +interface IrBasedDeclarationDescriptor : DeclarationDescriptor \ No newline at end of file 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/IrSymbolBase.kt index b916c767883..190e16be566 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/IrSymbolBase.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.ir.symbols.impl import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.descriptors.IrBasedDeclarationDescriptor import org.jetbrains.kotlin.ir.expressions.IrReturnableBlock import org.jetbrains.kotlin.ir.symbols.* @@ -25,27 +26,28 @@ abstract class IrSymbolBase(override val descript abstract class IrBindableSymbolBase(descriptor: D) : IrBindableSymbol, IrSymbolBase(descriptor) { + init { -// assert(isOriginalDescriptor(descriptor)) { -// "Substituted descriptor $descriptor for ${descriptor.original}" -// } + assert(isOriginalDescriptor(descriptor)) { + "Substituted descriptor $descriptor for ${descriptor.original}" + } } private fun isOriginalDescriptor(descriptor: DeclarationDescriptor): Boolean = - if (descriptor is ValueParameterDescriptor) - isOriginalDescriptor(descriptor.containingDeclaration) - else - descriptor == descriptor.original + descriptor is IrBasedDeclarationDescriptor || + descriptor is ValueParameterDescriptor && isOriginalDescriptor(descriptor.containingDeclaration) || + descriptor == descriptor.original private var _owner: B? = null override val owner: B get() = _owner ?: throw IllegalStateException("Symbol for $descriptor is unbound") override fun bind(owner: B) { - if (_owner == null) + if (_owner == null) { _owner = owner - else + } else { throw IllegalStateException("${javaClass.simpleName} for $descriptor is already bound") + } } override val isBound: Boolean diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt index 5384a37e6b5..8eb483df15a 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt @@ -17,20 +17,15 @@ package org.jetbrains.kotlin.ir.util import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.* import org.jetbrains.kotlin.ir.declarations.lazy.IrLazySymbolTable -import org.jetbrains.kotlin.ir.expressions.IrCall import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrExpressionBody import org.jetbrains.kotlin.ir.symbols.* import org.jetbrains.kotlin.ir.symbols.impl.* import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType -import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid -import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid -import org.jetbrains.kotlin.ir.visitors.acceptVoid interface IrDeserializer { fun findDeserializedDeclaration(symbol: IrSymbol): IrDeclaration? @@ -78,10 +73,15 @@ open class SymbolTable : ReferenceSymbolTable { abstract fun set(d: D, s: S) inline fun declare(d: D, createSymbol: () -> S, createOwner: (S) -> B): B { - val existing = get(d) + @Suppress("UNCHECKED_CAST") + val d0 = d.original as D + assert(d0 === d) { + "Non-original descriptor in declaration: $d\n\tExpected: $d0" + } + val existing = get(d0) val symbol = if (existing == null) { val new = createSymbol() - set(d, new) + set(d0, new) new } else { unboundSymbols.remove(existing) @@ -91,13 +91,18 @@ open class SymbolTable : ReferenceSymbolTable { } inline fun referenced(d: D, orElse: () -> S): S { - val s = get(d) + @Suppress("UNCHECKED_CAST") + val d0 = d.original as D + assert(d0 === d) { + "Non-original descriptor in declaration: $d\n\tExpected: $d0" + } + val s = get(d0) if (s == null) { val new = orElse() assert(unboundSymbols.add(new)) { "Symbol for ${new.descriptor} was already referenced" } - set(d, new) + set(d0, new) return new } return s @@ -113,13 +118,6 @@ open class SymbolTable : ReferenceSymbolTable { override fun set(d: D, s: S) { descriptorToSymbol[d] = s } - - fun copyTo(other: FlatSymbolTable) { - for ((d, s) in descriptorToSymbol) { - other.descriptorToSymbol[d] = s - } - other.unboundSymbols.addAll(unboundSymbols) - } } private class ScopedSymbolTable> diff --git a/compiler/testData/codegen/box/builtinStubMethods/extendJavaCollections/abstractMap.kt b/compiler/testData/codegen/box/builtinStubMethods/extendJavaCollections/abstractMap.kt index ed727468178..c8bb76a50ba 100644 --- a/compiler/testData/codegen/box/builtinStubMethods/extendJavaCollections/abstractMap.kt +++ b/compiler/testData/codegen/box/builtinStubMethods/extendJavaCollections/abstractMap.kt @@ -1,5 +1,4 @@ // TARGET_BACKEND: JVM -// IGNORE_BACKEND: JVM_IR import java.util.AbstractMap import java.util.Collections diff --git a/compiler/testData/codegen/box/builtinStubMethods/extendJavaCollections/hashMap.kt b/compiler/testData/codegen/box/builtinStubMethods/extendJavaCollections/hashMap.kt index 455c00e03fe..280ed1e4a8c 100644 --- a/compiler/testData/codegen/box/builtinStubMethods/extendJavaCollections/hashMap.kt +++ b/compiler/testData/codegen/box/builtinStubMethods/extendJavaCollections/hashMap.kt @@ -1,6 +1,5 @@ // KJS_WITH_FULL_RUNTIME // IGNORE_BACKEND: NATIVE -// IGNORE_BACKEND: JVM_IR class A : HashMap() fun box(): String { diff --git a/compiler/testData/codegen/box/casts/mutableCollections/asWithMutable.kt b/compiler/testData/codegen/box/casts/mutableCollections/asWithMutable.kt index 19f332acc1c..ba84efefebb 100644 --- a/compiler/testData/codegen/box/casts/mutableCollections/asWithMutable.kt +++ b/compiler/testData/codegen/box/casts/mutableCollections/asWithMutable.kt @@ -1,5 +1,4 @@ // KJS_WITH_FULL_RUNTIME -// IGNORE_BACKEND: JVM_IR // WITH_RUNTIME class Itr : Iterator by ArrayList().iterator() diff --git a/compiler/testData/codegen/box/casts/mutableCollections/isWithMutable.kt b/compiler/testData/codegen/box/casts/mutableCollections/isWithMutable.kt index f5695af1698..f3f382bde0c 100644 --- a/compiler/testData/codegen/box/casts/mutableCollections/isWithMutable.kt +++ b/compiler/testData/codegen/box/casts/mutableCollections/isWithMutable.kt @@ -1,5 +1,4 @@ // KJS_WITH_FULL_RUNTIME -// IGNORE_BACKEND: JVM_IR // WITH_RUNTIME class Itr : Iterator by ArrayList().iterator() diff --git a/compiler/testData/codegen/box/delegatedProperty/propertyMetadataShouldBeCached.kt b/compiler/testData/codegen/box/delegatedProperty/propertyMetadataShouldBeCached.kt index 2aa87b44c25..0a74c9f497b 100644 --- a/compiler/testData/codegen/box/delegatedProperty/propertyMetadataShouldBeCached.kt +++ b/compiler/testData/codegen/box/delegatedProperty/propertyMetadataShouldBeCached.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // TARGET_BACKEND: JVM import java.util.IdentityHashMap diff --git a/compiler/testData/codegen/box/jdk/iteratingOverHashMap.kt b/compiler/testData/codegen/box/jdk/iteratingOverHashMap.kt index e1b5ec7f4d1..bdbdbfbf127 100644 --- a/compiler/testData/codegen/box/jdk/iteratingOverHashMap.kt +++ b/compiler/testData/codegen/box/jdk/iteratingOverHashMap.kt @@ -1,5 +1,4 @@ // KJS_WITH_FULL_RUNTIME -// IGNORE_BACKEND: JVM_IR fun box() : String { if (!testIteratingOverMap1()) return "fail 1" diff --git a/compiler/testData/codegen/box/specialBuiltins/entrySetSOE.kt b/compiler/testData/codegen/box/specialBuiltins/entrySetSOE.kt index 6adf01e21b1..e29d879353b 100644 --- a/compiler/testData/codegen/box/specialBuiltins/entrySetSOE.kt +++ b/compiler/testData/codegen/box/specialBuiltins/entrySetSOE.kt @@ -1,5 +1,4 @@ // KJS_WITH_FULL_RUNTIME -// IGNORE_BACKEND: JVM_IR // IGNORE_BACKEND: NATIVE open class Map1 : HashMap() diff --git a/compiler/testData/codegen/box/super/superConstructor/kt17464_linkedMapOf.kt b/compiler/testData/codegen/box/super/superConstructor/kt17464_linkedMapOf.kt index 02a8575981d..b4d06baa10b 100644 --- a/compiler/testData/codegen/box/super/superConstructor/kt17464_linkedMapOf.kt +++ b/compiler/testData/codegen/box/super/superConstructor/kt17464_linkedMapOf.kt @@ -1,5 +1,4 @@ // KJS_WITH_FULL_RUNTIME -// IGNORE_BACKEND: JVM_IR // WITH_RUNTIME // FULL_JDK diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/descriptors/JavaPropertyDescriptor.java b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/descriptors/JavaPropertyDescriptor.java index ca1fda2e972..fef7e46b4ef 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/descriptors/JavaPropertyDescriptor.java +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/descriptors/JavaPropertyDescriptor.java @@ -102,6 +102,7 @@ public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements Ja @NotNull KotlinType enhancedReturnType, @Nullable Pair, ?> additionalUserData ) { + PropertyDescriptor enhancedOriginal = getOriginal() == this ? null : getOriginal(); JavaPropertyDescriptor enhanced = new JavaPropertyDescriptor( getContainingDeclaration(), getAnnotations(), @@ -110,7 +111,7 @@ public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements Ja isVar(), getName(), getSource(), - getOriginal() == this ? null : getOriginal(), + enhancedOriginal, getKind(), isStaticFinal, additionalUserData); @@ -120,7 +121,9 @@ public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements Ja if (getter != null) { newGetter = new PropertyGetterDescriptorImpl( enhanced, getter.getAnnotations(), getter.getModality(), getter.getVisibility(), - getter.isDefault(), getter.isExternal(), getter.isInline(), getKind(), getter, getter.getSource() + getter.isDefault(), getter.isExternal(), getter.isInline(), getKind(), + enhancedOriginal == null ? null : enhancedOriginal.getGetter(), + getter.getSource() ); newGetter.setInitialSignatureDescriptor(getter.getInitialSignatureDescriptor()); newGetter.initialize(enhancedReturnType); @@ -131,7 +134,9 @@ public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements Ja if (setter != null) { newSetter = new PropertySetterDescriptorImpl( enhanced, setter.getAnnotations(), setter.getModality(), setter.getVisibility(), - setter.isDefault(), setter.isExternal(), setter.isInline(), getKind(), setter, setter.getSource() + setter.isDefault(), setter.isExternal(), setter.isInline(), getKind(), + enhancedOriginal == null ? null : enhancedOriginal.getSetter(), + setter.getSource() ); newSetter.setInitialSignatureDescriptor(newSetter.getInitialSignatureDescriptor()); newSetter.initialize(setter.getValueParameters().get(0)); diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java index aba8b5d969b..0a3154a4f70 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java @@ -334,6 +334,16 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp public PropertyDescriptor build() { return doSubstitute(this); } + + PropertyGetterDescriptor getOriginalGetter() { + if (original == null) return null; + return original.getGetter(); + } + + PropertySetterDescriptor getOriginalSetter() { + if (original == null) return null; + return original.getSetter(); + } } @NotNull @@ -389,7 +399,8 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp PropertyGetterDescriptorImpl newGetter = getter == null ? null : new PropertyGetterDescriptorImpl( substitutedDescriptor, getter.getAnnotations(), copyConfiguration.modality, normalizeVisibility(getter.getVisibility(), copyConfiguration.kind), - getter.isDefault(), getter.isExternal(), getter.isInline(), copyConfiguration.kind, copyConfiguration.original == null ? null : copyConfiguration.original.getGetter(), + getter.isDefault(), getter.isExternal(), getter.isInline(), copyConfiguration.kind, + copyConfiguration.getOriginalGetter(), SourceElement.NO_SOURCE ); if (newGetter != null) { @@ -399,7 +410,8 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp } PropertySetterDescriptorImpl newSetter = setter == null ? null : new PropertySetterDescriptorImpl( substitutedDescriptor, setter.getAnnotations(), copyConfiguration.modality, normalizeVisibility(setter.getVisibility(), copyConfiguration.kind), - setter.isDefault(), setter.isExternal(), setter.isInline(), copyConfiguration.kind, copyConfiguration.original == null ? null : copyConfiguration.original.getSetter(), + setter.isDefault(), setter.isExternal(), setter.isInline(), copyConfiguration.kind, + copyConfiguration.getOriginalSetter(), SourceElement.NO_SOURCE ); if (newSetter != null) {