From e7ef453d226236eb01c1dfdd649d9691bffab004 Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Thu, 14 Nov 2019 23:00:59 +0300 Subject: [PATCH] Got rid of klib file registry --- .../serialization/LegacyDescriptorUtils.kt | 6 +- .../metadata/DeserializedSourceFile.kt | 22 ++++++++ .../metadata/KlibMetadataFileRegistry.kt | 55 ------------------- .../metadata/KlibMetadataPackageFragment.kt | 15 ----- 4 files changed, 27 insertions(+), 71 deletions(-) create mode 100644 compiler/util-klib-metadata/src/org/jetbrains/kotlin/library/metadata/DeserializedSourceFile.kt delete mode 100644 compiler/util-klib-metadata/src/org/jetbrains/kotlin/library/metadata/KlibMetadataFileRegistry.kt diff --git a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/LegacyDescriptorUtils.kt b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/LegacyDescriptorUtils.kt index b85a15ba16d..d61eaa7d0d8 100644 --- a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/LegacyDescriptorUtils.kt +++ b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/LegacyDescriptorUtils.kt @@ -7,11 +7,14 @@ package org.jetbrains.kotlin.backend.common.serialization import org.jetbrains.kotlin.backend.common.descriptors.propertyIfAccessor import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.konan.kotlinLibrary +import org.jetbrains.kotlin.library.metadata.DeserializedSourceFile import org.jetbrains.kotlin.library.metadata.KlibMetadataDeserializedPackageFragment import org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.OverridingUtil import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker +import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor @@ -52,7 +55,8 @@ val ModuleDescriptor.isForwardDeclarationModule get() = private fun sourceByIndex(descriptor: CallableMemberDescriptor, index: Int): SourceFile { val fragment = descriptor.findPackage() as KlibMetadataDeserializedPackageFragment - return fragment.fileRegistry.sourceFile(index) + val fileName = fragment.proto.strings.stringList[index] + return DeserializedSourceFile(fileName, index, descriptor.module.kotlinLibrary) } fun CallableMemberDescriptor.findSourceFile(): SourceFile { diff --git a/compiler/util-klib-metadata/src/org/jetbrains/kotlin/library/metadata/DeserializedSourceFile.kt b/compiler/util-klib-metadata/src/org/jetbrains/kotlin/library/metadata/DeserializedSourceFile.kt new file mode 100644 index 00000000000..f5efea4f49a --- /dev/null +++ b/compiler/util-klib-metadata/src/org/jetbrains/kotlin/library/metadata/DeserializedSourceFile.kt @@ -0,0 +1,22 @@ +/* + * 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.library.metadata + +import org.jetbrains.kotlin.descriptors.SourceFile +import org.jetbrains.kotlin.library.KotlinLibrary + +class DeserializedSourceFile( + val name_: String, val index: Int, val library: KotlinLibrary +) : SourceFile { + override fun getName(): String? = name_ + + override fun equals(other: Any?): Boolean { + return other is DeserializedSourceFile && library == other.library && index == other.index + } + + override fun hashCode(): Int { + return library.hashCode() xor index + } +} \ No newline at end of file diff --git a/compiler/util-klib-metadata/src/org/jetbrains/kotlin/library/metadata/KlibMetadataFileRegistry.kt b/compiler/util-klib-metadata/src/org/jetbrains/kotlin/library/metadata/KlibMetadataFileRegistry.kt deleted file mode 100644 index 737da7039dd..00000000000 --- a/compiler/util-klib-metadata/src/org/jetbrains/kotlin/library/metadata/KlibMetadataFileRegistry.kt +++ /dev/null @@ -1,55 +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.library.metadata - -import org.jetbrains.kotlin.descriptors.SourceFile -import org.jetbrains.kotlin.library.KotlinLibrary - -class KlibMetadataFileRegistry { - private val sourceToIndex = mutableMapOf() - private val indexToSource = mutableMapOf() - - fun assign(file: SourceFile): Int { - return sourceToIndex.getOrPut(file) { - sourceToIndex.size - } - } - - fun provide(fileName: String, index: Int, library: KotlinLibrary) { - assert(indexToSource[index] == null) - indexToSource[index] = - DeserializedSourceFile(fileName, index, library) - } - - fun sourceFile(index: Int): SourceFile = - indexToSource[index] ?: throw Error("Unknown file for $index") - - fun filesAndClear() = - sourceToIndex.keys.sortedBy { - sourceToIndex[it] - }.also{ - clear() - } - - - fun clear() { - sourceToIndex.clear() - indexToSource.clear() - } -} - -class DeserializedSourceFile( - val name_: String, val index: Int, val library: KotlinLibrary -) : SourceFile { - override fun getName(): String? = name_ - - override fun equals(other: Any?): Boolean { - return other is DeserializedSourceFile && library == other.library && index == other.index - } - - override fun hashCode(): Int { - return library.hashCode() xor index - } -} \ No newline at end of file diff --git a/compiler/util-klib-metadata/src/org/jetbrains/kotlin/library/metadata/KlibMetadataPackageFragment.kt b/compiler/util-klib-metadata/src/org/jetbrains/kotlin/library/metadata/KlibMetadataPackageFragment.kt index 377e3528de3..9074683dea2 100644 --- a/compiler/util-klib-metadata/src/org/jetbrains/kotlin/library/metadata/KlibMetadataPackageFragment.kt +++ b/compiler/util-klib-metadata/src/org/jetbrains/kotlin/library/metadata/KlibMetadataPackageFragment.kt @@ -19,16 +19,6 @@ import org.jetbrains.kotlin.serialization.deserialization.getClassId import org.jetbrains.kotlin.serialization.deserialization.getName import org.jetbrains.kotlin.storage.StorageManager -private val KotlinLibrary.fileSources: KlibMetadataFileRegistry get() { - val result = KlibMetadataFileRegistry() - val proto = parseModuleHeader(moduleHeaderData) - proto.fileList.forEachIndexed { index, it -> - result.provide(it.name, index, this) - } - return result -} - - class KlibMetadataDeserializedPackageFragment( fqName: FqName, private val library: KotlinLibrary, @@ -44,11 +34,6 @@ class KlibMetadataDeserializedPackageFragment( (packageAccessHandler ?: SimplePackageAccessHandler).loadPackageFragment(library, fqName.asString(), partName) } - val fileRegistry: KlibMetadataFileRegistry by lazy { - library.fileSources - } - - override val proto: ProtoBuf.PackageFragment get() { packageAccessHandler?.markNeededForLink(library, fqName.asString())