Got rid of klib file registry
This commit is contained in:
committed by
alexander-gorshenev
parent
f49bc0e96d
commit
e7ef453d22
+5
-1
@@ -7,11 +7,14 @@ package org.jetbrains.kotlin.backend.common.serialization
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.descriptors.propertyIfAccessor
|
import org.jetbrains.kotlin.backend.common.descriptors.propertyIfAccessor
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
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.KlibMetadataDeserializedPackageFragment
|
||||||
import org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf
|
import org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||||
import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker
|
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.DeserializedPropertyDescriptor
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor
|
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor
|
||||||
|
|
||||||
@@ -52,7 +55,8 @@ val ModuleDescriptor.isForwardDeclarationModule get() =
|
|||||||
|
|
||||||
private fun sourceByIndex(descriptor: CallableMemberDescriptor, index: Int): SourceFile {
|
private fun sourceByIndex(descriptor: CallableMemberDescriptor, index: Int): SourceFile {
|
||||||
val fragment = descriptor.findPackage() as KlibMetadataDeserializedPackageFragment
|
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 {
|
fun CallableMemberDescriptor.findSourceFile(): SourceFile {
|
||||||
|
|||||||
+22
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
-55
@@ -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<SourceFile, Int>()
|
|
||||||
private val indexToSource = mutableMapOf<Int, SourceFile>()
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-15
@@ -19,16 +19,6 @@ import org.jetbrains.kotlin.serialization.deserialization.getClassId
|
|||||||
import org.jetbrains.kotlin.serialization.deserialization.getName
|
import org.jetbrains.kotlin.serialization.deserialization.getName
|
||||||
import org.jetbrains.kotlin.storage.StorageManager
|
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(
|
class KlibMetadataDeserializedPackageFragment(
|
||||||
fqName: FqName,
|
fqName: FqName,
|
||||||
private val library: KotlinLibrary,
|
private val library: KotlinLibrary,
|
||||||
@@ -44,11 +34,6 @@ class KlibMetadataDeserializedPackageFragment(
|
|||||||
(packageAccessHandler ?: SimplePackageAccessHandler).loadPackageFragment(library, fqName.asString(), partName)
|
(packageAccessHandler ?: SimplePackageAccessHandler).loadPackageFragment(library, fqName.asString(), partName)
|
||||||
}
|
}
|
||||||
|
|
||||||
val fileRegistry: KlibMetadataFileRegistry by lazy {
|
|
||||||
library.fileSources
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
override val proto: ProtoBuf.PackageFragment
|
override val proto: ProtoBuf.PackageFragment
|
||||||
get() {
|
get() {
|
||||||
packageAccessHandler?.markNeededForLink(library, fqName.asString())
|
packageAccessHandler?.markNeededForLink(library, fqName.asString())
|
||||||
|
|||||||
Reference in New Issue
Block a user