diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt index 8141bb248a4..3ebb347efec 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt @@ -354,6 +354,14 @@ class Fir2IrClassifierStorage( if (firClass is FirAnonymousObject || firClass is FirRegularClass && firClass.visibility == Visibilities.LOCAL) { return createIrClass(firClass).symbol } + val signature = signatureComposer.composeSignature(firClass) + symbolTable.referenceClassIfAny(signature)?.let { irClassSymbol -> + val irClass = irClassSymbol.owner + classCache[firClass as FirRegularClass] = irClass + processClassHeader(firClass, irClass) + declarationStorage.preCacheBuiltinClassMembers(firClass, irClass) + return irClassSymbol + } // TODO: remove all this code and change to unbound symbol creation val classId = firClassSymbol.classId val parentId = classId.outerClassId diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrComponents.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrComponents.kt index 9738c33bdbe..fefd160edb9 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrComponents.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrComponents.kt @@ -18,4 +18,5 @@ interface Fir2IrComponents { val classifierStorage: Fir2IrClassifierStorage val declarationStorage: Fir2IrDeclarationStorage val typeConverter: Fir2IrTypeConverter + val signatureComposer: Fir2IrSignatureComposer } \ No newline at end of file diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrComponentsStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrComponentsStorage.kt index f0f83dc781b..f2335331422 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrComponentsStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrComponentsStorage.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.backend import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.resolve.ScopeSession +import org.jetbrains.kotlin.fir.signaturer.FirBasedSignatureComposer import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns import org.jetbrains.kotlin.ir.util.SymbolTable @@ -19,4 +20,6 @@ class Fir2IrComponentsStorage( override lateinit var classifierStorage: Fir2IrClassifierStorage override lateinit var declarationStorage: Fir2IrDeclarationStorage override lateinit var typeConverter: Fir2IrTypeConverter + + override val signatureComposer = FirBasedSignatureComposer() } \ No newline at end of file diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrSignatureComposer.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrSignatureComposer.kt new file mode 100644 index 00000000000..75e8b6c6bb6 --- /dev/null +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrSignatureComposer.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.backend + +import org.jetbrains.kotlin.fir.declarations.FirDeclaration +import org.jetbrains.kotlin.ir.util.IdSignature + +interface Fir2IrSignatureComposer { + fun composeSignature(declaration: FirDeclaration): IdSignature +} \ No newline at end of file diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/signaturer/FirBasedSignatureComposer.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/signaturer/FirBasedSignatureComposer.kt new file mode 100644 index 00000000000..20a737acefd --- /dev/null +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/signaturer/FirBasedSignatureComposer.kt @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.signaturer + +import org.jetbrains.kotlin.descriptors.Visibilities +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.backend.Fir2IrSignatureComposer +import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.render +import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid +import org.jetbrains.kotlin.ir.util.IdSignature + +class FirBasedSignatureComposer : Fir2IrSignatureComposer { + + class SignatureBuilder : FirVisitorVoid() { + var hashId: Long? = null + var mask = 0L + + private fun setExpected(f: Boolean) { + mask = mask or IdSignature.Flags.IS_EXPECT.encode(f) + } + + override fun visitElement(element: FirElement) { + TODO("Not yet implemented") + } + + override fun visitRegularClass(regularClass: FirRegularClass) { + setExpected(regularClass.isExpect) + //platformSpecificClass(descriptor) + } + } + + override fun composeSignature(declaration: FirDeclaration): IdSignature { + val builder = SignatureBuilder() + declaration.accept(builder) + if (declaration is FirRegularClass && declaration.visibility != Visibilities.LOCAL) { + val classId = declaration.classId + return IdSignature.PublicSignature(classId.packageFqName, classId.relativeClassName, builder.hashId, builder.mask) + } + throw AssertionError("Unsupported FIR declaration in signature composer: ${declaration.render()}") + } +} \ No newline at end of file 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 9dc7d3c34fd..58ad95760c0 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 @@ -421,6 +421,9 @@ open class SymbolTable( override fun referenceClass(descriptor: ClassDescriptor) = classSymbolTable.referenced(descriptor) { createClassSymbol(descriptor) } + fun referenceClassIfAny(sig: IdSignature): IrClassSymbol? = + classSymbolTable.get(sig) + override fun referenceClassFromLinker(descriptor: ClassDescriptor, sig: IdSignature): IrClassSymbol = classSymbolTable.run { if (sig.isPublic) referenced(sig) { IrClassPublicSymbolImpl(descriptor, sig) } diff --git a/compiler/testData/codegen/box/builtinStubMethods/Collection.kt b/compiler/testData/codegen/box/builtinStubMethods/Collection.kt index 49b27b4f46f..906d1129d26 100644 --- a/compiler/testData/codegen/box/builtinStubMethods/Collection.kt +++ b/compiler/testData/codegen/box/builtinStubMethods/Collection.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM class MyCollection: Collection { diff --git a/compiler/testData/codegen/box/builtinStubMethods/immutableRemove.kt b/compiler/testData/codegen/box/builtinStubMethods/immutableRemove.kt index 08a37031bb4..32aa73212f8 100644 --- a/compiler/testData/codegen/box/builtinStubMethods/immutableRemove.kt +++ b/compiler/testData/codegen/box/builtinStubMethods/immutableRemove.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // SKIP_JDK6 // TARGET_BACKEND: JVM // FULL_JDK diff --git a/compiler/testData/codegen/box/builtinStubMethods/nonTrivialSubstitution.kt b/compiler/testData/codegen/box/builtinStubMethods/nonTrivialSubstitution.kt index 9e25991a74c..cdc268b382c 100644 --- a/compiler/testData/codegen/box/builtinStubMethods/nonTrivialSubstitution.kt +++ b/compiler/testData/codegen/box/builtinStubMethods/nonTrivialSubstitution.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM class MyCollection : Collection>> { diff --git a/compiler/testData/codegen/box/collections/removeClash.kt b/compiler/testData/codegen/box/collections/removeClash.kt index dfe718ab809..da848e744c8 100644 --- a/compiler/testData/codegen/box/collections/removeClash.kt +++ b/compiler/testData/codegen/box/collections/removeClash.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class Queue(override val size: Int) : Collection { override fun contains(element: T): Boolean = TODO() diff --git a/compiler/testData/codegen/box/collections/toArrayInJavaClass.kt b/compiler/testData/codegen/box/collections/toArrayInJavaClass.kt index 2b308b34d2a..1f365e8065f 100644 --- a/compiler/testData/codegen/box/collections/toArrayInJavaClass.kt +++ b/compiler/testData/codegen/box/collections/toArrayInJavaClass.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/inlineClasses/callSpeciallyOverriddenPropertyOfInlineClass.kt b/compiler/testData/codegen/box/inlineClasses/callSpeciallyOverriddenPropertyOfInlineClass.kt index 9337ead1dc4..79c9e9218b0 100644 --- a/compiler/testData/codegen/box/inlineClasses/callSpeciallyOverriddenPropertyOfInlineClass.kt +++ b/compiler/testData/codegen/box/inlineClasses/callSpeciallyOverriddenPropertyOfInlineClass.kt @@ -1,5 +1,4 @@ // !LANGUAGE: +InlineClasses -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM inline class UInt(val x: Int) diff --git a/compiler/testData/codegen/box/specialBuiltins/redundantStubForSize.kt b/compiler/testData/codegen/box/specialBuiltins/redundantStubForSize.kt index 31fc74505f8..df0376cc9cb 100644 --- a/compiler/testData/codegen/box/specialBuiltins/redundantStubForSize.kt +++ b/compiler/testData/codegen/box/specialBuiltins/redundantStubForSize.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class A1 { open val size: Int = 56 } diff --git a/compiler/testData/codegen/box/toArray/incorrectToArrayDetection.kt b/compiler/testData/codegen/box/toArray/incorrectToArrayDetection.kt index ecb89ec3d3a..90bd84d0a2b 100644 --- a/compiler/testData/codegen/box/toArray/incorrectToArrayDetection.kt +++ b/compiler/testData/codegen/box/toArray/incorrectToArrayDetection.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // SKIP_JDK6 // TARGET_BACKEND: JVM // FULL_JDK diff --git a/compiler/testData/codegen/box/toArray/toArrayAlreadyPresent.kt b/compiler/testData/codegen/box/toArray/toArrayAlreadyPresent.kt index b690ff6eccc..3be85f8dad4 100644 --- a/compiler/testData/codegen/box/toArray/toArrayAlreadyPresent.kt +++ b/compiler/testData/codegen/box/toArray/toArrayAlreadyPresent.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME diff --git a/compiler/testData/ir/irText/classes/dataClassesGeneric.fir.txt b/compiler/testData/ir/irText/classes/dataClassesGeneric.fir.txt index 635912065f4..0b7a4cb4dc2 100644 --- a/compiler/testData/ir/irText/classes/dataClassesGeneric.fir.txt +++ b/compiler/testData/ir/irText/classes/dataClassesGeneric.fir.txt @@ -175,7 +175,7 @@ FILE fqName: fileName:/dataClassesGeneric.kt $this: VALUE_PARAMETER GENERATED_DATA_CLASS_MEMBER name: type:.Test2.Test2> BLOCK_BODY RETURN type=kotlin.Nothing from='public open fun hashCode (): kotlin.Int declared in .Test2' - CALL 'public open fun hashCode (): kotlin.Int declared in kotlin.Any' type=kotlin.Int origin=null + CALL 'public open fun hashCode (): kotlin.Int [fake_override] declared in kotlin.Number' type=kotlin.Int origin=null $this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:T of .Test2 visibility:private [final]' type=T of .Test2 origin=null receiver: GET_VAR ': .Test2.Test2> declared in .Test2.hashCode' type=.Test2.Test2> origin=null FUN GENERATED_DATA_CLASS_MEMBER name:toString visibility:public modality:OPEN <> ($this:.Test2.Test2>) returnType:kotlin.String