IR: compute file local signatures from descriptors
This commit is contained in:
committed by
TeamCityServer
parent
b6ddd758ec
commit
4d2bcf7e66
@@ -167,10 +167,19 @@ sealed class IdSignature {
|
||||
override fun hashCode(): Int = hashCode
|
||||
}
|
||||
|
||||
class FileSignature(val fileSymbol: IrFileSymbol) : IdSignature() {
|
||||
override fun equals(other: Any?): Boolean = other is FileSignature && fileSymbol == other.fileSymbol
|
||||
class FileSignature(
|
||||
private val id: Any,
|
||||
private val fqName: FqName,
|
||||
val fileName: String
|
||||
) : IdSignature() {
|
||||
|
||||
override fun hashCode(): Int = fileSymbol.owner.hashCode()
|
||||
constructor(fileSymbol: IrFileSymbol) : this(
|
||||
fileSymbol, fileSymbol.owner.fqName, fileSymbol.owner.fileEntry.name
|
||||
)
|
||||
|
||||
override fun equals(other: Any?): Boolean = other is FileSignature && id == other.id
|
||||
|
||||
override fun hashCode(): Int = id.hashCode()
|
||||
|
||||
override val isPubliclyVisible: Boolean
|
||||
get() = true
|
||||
@@ -186,10 +195,10 @@ sealed class IdSignature {
|
||||
error("Should not reach here ($this)")
|
||||
}
|
||||
|
||||
override fun packageFqName(): FqName = fileSymbol.owner.fqName
|
||||
override fun packageFqName(): FqName = fqName
|
||||
|
||||
override fun render(): String {
|
||||
return "File '${fileSymbol.owner.fileEntry.name}'"
|
||||
return "File '$fileName'"
|
||||
}
|
||||
|
||||
override val hasTopLevel: Boolean
|
||||
@@ -386,4 +395,6 @@ interface IdSignatureComposer {
|
||||
fun composeEnumEntrySignature(descriptor: ClassDescriptor): IdSignature?
|
||||
fun composeFieldSignature(descriptor: PropertyDescriptor): IdSignature?
|
||||
fun composeAnonInitSignature(descriptor: ClassDescriptor): IdSignature?
|
||||
|
||||
fun withFileSignature(fileSignature: IdSignature.FileSignature, body: () -> Unit)
|
||||
}
|
||||
|
||||
+4
-3
@@ -16,9 +16,10 @@ import org.jetbrains.kotlin.backend.common.serialization.proto.FileSignature as
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IdSignature as ProtoIdSignature
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.LocalSignature as ProtoLocalSignature
|
||||
|
||||
class IdSignatureDeserializer(private val libraryFile: IrLibraryFile, fileSymbol: IrFileSymbol?) {
|
||||
|
||||
private val fileSignature: FileSignature? = fileSymbol?.let { FileSignature(it) }
|
||||
class IdSignatureDeserializer(
|
||||
private val libraryFile: IrLibraryFile,
|
||||
private val fileSignature: FileSignature?
|
||||
) {
|
||||
|
||||
private fun loadSignatureProto(index: Int): ProtoIdSignature {
|
||||
return libraryFile.signature(index)
|
||||
|
||||
+2
-1
@@ -26,6 +26,7 @@ class IrSymbolDeserializer(
|
||||
val enqueueLocalTopLevelDeclaration: (IdSignature) -> Unit,
|
||||
val handleExpectActualMapping: (IdSignature, IrSymbol) -> IrSymbol,
|
||||
val symbolProcessor: IrSymbolDeserializer.(IrSymbol, IdSignature) -> IrSymbol = { s, _ -> s },
|
||||
private val fileSignature: IdSignature.FileSignature = IdSignature.FileSignature(fileSymbol),
|
||||
val deserializePublicSymbol: (IdSignature, BinarySymbolData.SymbolKind) -> IrSymbol
|
||||
) {
|
||||
|
||||
@@ -84,7 +85,7 @@ class IrSymbolDeserializer(
|
||||
}
|
||||
}
|
||||
|
||||
val signatureDeserializer = IdSignatureDeserializer(libraryFile, fileSymbol)
|
||||
val signatureDeserializer = IdSignatureDeserializer(libraryFile, fileSignature)
|
||||
|
||||
fun deserializeIdSignature(index: Int): IdSignature {
|
||||
return signatureDeserializer.deserializeIdSignature(index)
|
||||
|
||||
+6
-3
@@ -17,15 +17,14 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
|
||||
open class IdSignatureDescriptor(private val mangler: KotlinMangler.DescriptorMangler) : IdSignatureComposer {
|
||||
|
||||
protected open fun createSignatureBuilder(type: SpecialDeclarationType): DescriptorBasedSignatureBuilder = DescriptorBasedSignatureBuilder(mangler, type)
|
||||
protected open fun createSignatureBuilder(type: SpecialDeclarationType): DescriptorBasedSignatureBuilder = DescriptorBasedSignatureBuilder(type)
|
||||
|
||||
protected open inner class DescriptorBasedSignatureBuilder(private val mangler: KotlinMangler.DescriptorMangler, private val type: SpecialDeclarationType) :
|
||||
protected open inner class DescriptorBasedSignatureBuilder(private val type: SpecialDeclarationType) :
|
||||
IdSignatureBuilder<DeclarationDescriptor>(),
|
||||
DeclarationDescriptorVisitor<Unit, Nothing?> {
|
||||
|
||||
override fun accept(d: DeclarationDescriptor) {
|
||||
d.accept(this, null)
|
||||
assert(!isTopLevelPrivate) { "$d is Top level private" }
|
||||
}
|
||||
|
||||
private fun createContainer() {
|
||||
@@ -195,4 +194,8 @@ open class IdSignatureDescriptor(private val mangler: KotlinMangler.DescriptorMa
|
||||
createSignatureBuilder(SpecialDeclarationType.ANON_INIT).buildSignature(descriptor)
|
||||
else null
|
||||
}
|
||||
|
||||
override fun withFileSignature(fileSignature: IdSignature.FileSignature, body: () -> Unit) {
|
||||
body()
|
||||
}
|
||||
}
|
||||
+42
-5
@@ -9,25 +9,37 @@ import org.jetbrains.kotlin.backend.common.serialization.mangle.SpecialDeclarati
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.ir.util.KotlinMangler
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaForKotlinOverridePropertyDescriptor
|
||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageFragment
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.overriddenTreeAsSequence
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
|
||||
class JvmIdSignatureDescriptor(private val mangler: KotlinMangler.DescriptorMangler) : IdSignatureDescriptor(mangler) {
|
||||
class JvmIdSignatureDescriptor(mangler: KotlinMangler.DescriptorMangler) : IdSignatureDescriptor(mangler) {
|
||||
|
||||
private inner class JvmDescriptorBasedSignatureBuilder(type: SpecialDeclarationType) :
|
||||
DescriptorBasedSignatureBuilder(type) {
|
||||
|
||||
override val currentFileSignature: IdSignature.FileSignature?
|
||||
get() = externallyGivenFileSignature ?: storedFileSignature
|
||||
|
||||
private inner class JvmDescriptorBasedSignatureBuilder(mangler: KotlinMangler.DescriptorMangler, type: SpecialDeclarationType) :
|
||||
DescriptorBasedSignatureBuilder(mangler, type) {
|
||||
override fun platformSpecificFunction(descriptor: FunctionDescriptor) {
|
||||
keepTrackOfOverridesForPossiblyClashingFakeOverride(descriptor)
|
||||
computeStoredFileSignature(descriptor)
|
||||
}
|
||||
|
||||
override fun isKotlinPackage(descriptor: PackageFragmentDescriptor): Boolean {
|
||||
return descriptor !is LazyJavaPackageFragment
|
||||
return true
|
||||
// return descriptor !is LazyJavaPackageFragment
|
||||
}
|
||||
|
||||
override fun platformSpecificClass(descriptor: ClassDescriptor) {
|
||||
computeStoredFileSignature(descriptor)
|
||||
}
|
||||
|
||||
override fun platformSpecificProperty(descriptor: PropertyDescriptor) {
|
||||
@@ -35,14 +47,21 @@ class JvmIdSignatureDescriptor(private val mangler: KotlinMangler.DescriptorMang
|
||||
setSpecialJavaProperty(descriptor is JavaForKotlinOverridePropertyDescriptor)
|
||||
setSyntheticJavaProperty(descriptor is SyntheticJavaPropertyDescriptor)
|
||||
keepTrackOfOverridesForPossiblyClashingFakeOverride(descriptor)
|
||||
computeStoredFileSignature(descriptor)
|
||||
}
|
||||
|
||||
override fun platformSpecificGetter(descriptor: PropertyGetterDescriptor) {
|
||||
keepTrackOfOverridesForPossiblyClashingFakeOverride(descriptor)
|
||||
computeStoredFileSignature(descriptor)
|
||||
}
|
||||
|
||||
override fun platformSpecificSetter(descriptor: PropertySetterDescriptor) {
|
||||
keepTrackOfOverridesForPossiblyClashingFakeOverride(descriptor)
|
||||
computeStoredFileSignature(descriptor)
|
||||
}
|
||||
|
||||
override fun platformSpecificAlias(descriptor: TypeAliasDescriptor) {
|
||||
computeStoredFileSignature(descriptor)
|
||||
}
|
||||
|
||||
override fun platformSpecificModule(descriptor: ModuleDescriptor) {
|
||||
@@ -87,8 +106,26 @@ class JvmIdSignatureDescriptor(private val mangler: KotlinMangler.DescriptorMang
|
||||
val descriptor = it.constructor.declarationDescriptor
|
||||
descriptor is TypeParameterDescriptor && descriptor.containingDeclaration is ClassDescriptor
|
||||
}
|
||||
|
||||
private fun computeStoredFileSignature(descriptor: DeclarationDescriptorWithSource) {
|
||||
storedFileSignature = IdSignature.FileSignature(
|
||||
descriptor.source.containingFile,
|
||||
descriptor.containingPackage() ?: FqName.ROOT,
|
||||
descriptor.source.containingFile.name ?: "unknown"
|
||||
)
|
||||
}
|
||||
|
||||
var storedFileSignature: IdSignature.FileSignature? = null
|
||||
}
|
||||
|
||||
override fun createSignatureBuilder(type: SpecialDeclarationType): DescriptorBasedSignatureBuilder =
|
||||
JvmDescriptorBasedSignatureBuilder(mangler, type)
|
||||
JvmDescriptorBasedSignatureBuilder(type)
|
||||
|
||||
override fun withFileSignature(fileSignature: IdSignature.FileSignature, body: () -> Unit) {
|
||||
externallyGivenFileSignature = fileSignature
|
||||
body()
|
||||
externallyGivenFileSignature = null
|
||||
}
|
||||
|
||||
private var externallyGivenFileSignature: IdSignature.FileSignature? = null
|
||||
}
|
||||
|
||||
+5
-1
@@ -62,11 +62,13 @@ fun deserializeFromByteArray(
|
||||
|
||||
// Only needed for local signature computation.
|
||||
val dummyIrFile = IrFileImpl(NaiveSourceBasedFileEntryImpl("<unknown>"), IrFileSymbolImpl(), toplevelParent.packageFqName!!)
|
||||
val dummyFileSignature = IdSignature.FileSignature(Any(), toplevelParent.packageFqName!!, "<unknown>")
|
||||
|
||||
val symbolDeserializer = IrSymbolDeserializer(
|
||||
symbolTable,
|
||||
irLibraryFile,
|
||||
fileSymbol = dummyIrFile.symbol,
|
||||
fileSignature = dummyFileSignature,
|
||||
/* TODO */ actuals = emptyList(),
|
||||
enqueueLocalTopLevelDeclaration = {}, // just link to it in symbolTable
|
||||
handleExpectActualMapping = { _, symbol -> symbol } no expect declarations
|
||||
@@ -100,7 +102,9 @@ fun deserializeFromByteArray(
|
||||
}
|
||||
}
|
||||
|
||||
ExternalDependenciesGenerator(stubGenerator.symbolTable, listOf(stubGenerator)).generateUnboundSymbolsAsDependencies()
|
||||
stubGenerator.symbolTable.signaturer.withFileSignature(dummyFileSignature) {
|
||||
ExternalDependenciesGenerator(stubGenerator.symbolTable, listOf(stubGenerator)).generateUnboundSymbolsAsDependencies()
|
||||
}
|
||||
buildFakeOverridesForLocalClasses(stubGenerator.symbolTable, typeSystemContext, symbolDeserializer, toplevelParent)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ object JvmIrMangler : IrBasedKotlinManglerImpl() {
|
||||
|
||||
class JvmDescriptorMangler(private val mainDetector: MainFunctionDetector?) : DescriptorBasedKotlinManglerImpl() {
|
||||
private object ExportChecker : DescriptorExportCheckerVisitor() {
|
||||
override fun DeclarationDescriptor.isPlatformSpecificExported() = false
|
||||
override fun DeclarationDescriptor.isPlatformSpecificExported() = true
|
||||
}
|
||||
|
||||
private class JvmDescriptorManglerComputer(
|
||||
|
||||
@@ -296,6 +296,10 @@ private fun getIrBuiltIns(): IrBuiltIns {
|
||||
override fun composeAnonInitSignature(descriptor: ClassDescriptor): IdSignature? = null
|
||||
|
||||
override fun composeFieldSignature(descriptor: PropertyDescriptor): IdSignature? = null
|
||||
|
||||
override fun withFileSignature(fileSignature: IdSignature.FileSignature, body: () -> Unit) {
|
||||
body()
|
||||
}
|
||||
}
|
||||
val symbolTable = SymbolTable(signaturer, IrFactoryImpl)
|
||||
val typeTranslator = TypeTranslatorImpl(symbolTable, languageSettings, moduleDescriptor)
|
||||
|
||||
Reference in New Issue
Block a user