[Plugin API] Add API to load top level declaration by its signature
- request from JP Compose, #KT-44100
This commit is contained in:
+19
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.library.IrLibrary
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.protobuf.CodedInputStream
|
||||
import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite.newInstance
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
@@ -64,6 +65,7 @@ abstract class KotlinIrLinker(
|
||||
|
||||
private val modulesWithReachableTopLevels = mutableSetOf<IrModuleDeserializer>()
|
||||
|
||||
// TODO: replace with Map<Name, IrModuleDeserializer>
|
||||
protected val deserializersForModules = mutableMapOf<ModuleDescriptor, IrModuleDeserializer>()
|
||||
|
||||
abstract val fakeOverrideBuilder: FakeOverrideBuilder
|
||||
@@ -665,6 +667,23 @@ abstract class KotlinIrLinker(
|
||||
// symbolTable.noUnboundLeft("unbound after fake overrides:")
|
||||
}
|
||||
|
||||
private fun topLevelKindToSymbolKind(kind: IrDeserializer.TopLevelSymbolKind): BinarySymbolData.SymbolKind {
|
||||
return when (kind) {
|
||||
IrDeserializer.TopLevelSymbolKind.CLASS_SYMBOL -> BinarySymbolData.SymbolKind.CLASS_SYMBOL
|
||||
IrDeserializer.TopLevelSymbolKind.PROPERTY_SYMBOL -> BinarySymbolData.SymbolKind.PROPERTY_SYMBOL
|
||||
IrDeserializer.TopLevelSymbolKind.FUNCTION_SYMBOL -> BinarySymbolData.SymbolKind.FUNCTION_SYMBOL
|
||||
IrDeserializer.TopLevelSymbolKind.TYPEALIAS_SYMBOL -> BinarySymbolData.SymbolKind.TYPEALIAS_SYMBOL
|
||||
}
|
||||
}
|
||||
|
||||
override fun resolveBySignatureInModule(signature: IdSignature, kind: IrDeserializer.TopLevelSymbolKind, moduleName: Name): IrSymbol {
|
||||
val moduleDeserializer =
|
||||
deserializersForModules.entries.find { it.key.name == moduleName }?.value ?: error("No module for name '$moduleName' found")
|
||||
assert(signature == signature.topLevelSignature()) { "Signature '$signature' has to be top level" }
|
||||
if (signature !in moduleDeserializer) error("No signature $signature in module $moduleName")
|
||||
return moduleDeserializer.deserializeIrSymbol(signature, topLevelKindToSymbolKind(kind))
|
||||
}
|
||||
|
||||
// The issue here is that an expect can not trigger its actual deserialization by reachability
|
||||
// because the expect can not see the actual higher in the module dependency dag.
|
||||
// So we force deserialization of actuals for all deserialized expect symbols here.
|
||||
|
||||
Reference in New Issue
Block a user