[Linker] Do not generate wrapped descriptor if descriptor is provided
Fixes metadata-based interop in Kotlin/Native.
This commit is contained in:
committed by
Sergey Bogolepov
parent
6eec8c28ad
commit
221d24c597
+62
-32
@@ -214,45 +214,75 @@ abstract class KotlinIrLinker(
|
||||
private fun loadStringProto(index: Int): String {
|
||||
return String(readString(moduleDescriptor, fileIndex, index))
|
||||
}
|
||||
|
||||
// TODO: this function allows passing descriptor for all kinds of symbols.
|
||||
// It is incorrect.
|
||||
private fun referenceDeserializedSymbol(
|
||||
symbolKind: BinarySymbolData.SymbolKind,
|
||||
idSig: IdSignature,
|
||||
idSignature: IdSignature,
|
||||
descriptor: DeclarationDescriptor?
|
||||
) =
|
||||
symbolTable.run {
|
||||
): IrSymbol {
|
||||
fun checkDescriptorIsNull(symbolKind: BinarySymbolData.SymbolKind) {
|
||||
assert(descriptor == null) { "Symbol with kind $symbolKind should not have non-wrapped descriptor" }
|
||||
}
|
||||
|
||||
return symbolTable.run {
|
||||
when (symbolKind) {
|
||||
BinarySymbolData.SymbolKind.ANONYMOUS_INIT_SYMBOL ->
|
||||
IrAnonymousInitializerSymbolImpl(WrappedClassDescriptor()).also { require(idSig.isLocal) }
|
||||
BinarySymbolData.SymbolKind.CLASS_SYMBOL -> // TODO: FunctionInterfaces
|
||||
referenceClassFromLinker(descriptor as ClassDescriptor? ?: WrappedClassDescriptor(), idSig)
|
||||
BinarySymbolData.SymbolKind.CONSTRUCTOR_SYMBOL ->
|
||||
referenceConstructorFromLinker(WrappedClassConstructorDescriptor(), idSig)
|
||||
BinarySymbolData.SymbolKind.TYPE_PARAMETER_SYMBOL ->
|
||||
referenceTypeParameterFromLinker(WrappedTypeParameterDescriptor(), idSig)
|
||||
BinarySymbolData
|
||||
.SymbolKind.ENUM_ENTRY_SYMBOL -> referenceEnumEntryFromLinker(WrappedEnumEntryDescriptor(), idSig)
|
||||
BinarySymbolData
|
||||
.SymbolKind.STANDALONE_FIELD_SYMBOL -> referenceFieldFromLinker(WrappedFieldDescriptor(), idSig)
|
||||
BinarySymbolData
|
||||
.SymbolKind.FIELD_SYMBOL -> referenceFieldFromLinker(WrappedPropertyDescriptor(), idSig)
|
||||
BinarySymbolData.SymbolKind.FUNCTION_SYMBOL -> //TODO: FunctionInterfaces
|
||||
referenceSimpleFunctionFromLinker(descriptor as FunctionDescriptor? ?: WrappedSimpleFunctionDescriptor(), idSig)
|
||||
BinarySymbolData
|
||||
.SymbolKind.TYPEALIAS_SYMBOL -> referenceTypeAliasFromLinker(WrappedTypeAliasDescriptor(), idSig)
|
||||
BinarySymbolData
|
||||
.SymbolKind.PROPERTY_SYMBOL -> referencePropertyFromLinker(WrappedPropertyDescriptor(), idSig)
|
||||
BinarySymbolData
|
||||
.SymbolKind.VARIABLE_SYMBOL -> IrVariableSymbolImpl(WrappedVariableDescriptor())
|
||||
BinarySymbolData
|
||||
.SymbolKind.VALUE_PARAMETER_SYMBOL -> IrValueParameterSymbolImpl(WrappedValueParameterDescriptor())
|
||||
BinarySymbolData.SymbolKind.RECEIVER_PARAMETER_SYMBOL ->
|
||||
IrValueParameterSymbolImpl(WrappedReceiverParameterDescriptor())
|
||||
BinarySymbolData.SymbolKind.LOCAL_DELEGATED_PROPERTY_SYMBOL ->
|
||||
BinarySymbolData.SymbolKind.ANONYMOUS_INIT_SYMBOL -> {
|
||||
checkDescriptorIsNull(symbolKind)
|
||||
IrAnonymousInitializerSymbolImpl(WrappedClassDescriptor())
|
||||
.also { require(idSignature.isLocal) }
|
||||
}
|
||||
// TODO: FunctionInterfaces
|
||||
BinarySymbolData.SymbolKind.CLASS_SYMBOL -> referenceClassFromLinker(
|
||||
descriptor as? ClassDescriptor ?: WrappedClassDescriptor(), idSignature
|
||||
)
|
||||
BinarySymbolData.SymbolKind.CONSTRUCTOR_SYMBOL -> referenceConstructorFromLinker(
|
||||
descriptor as? ClassConstructorDescriptor ?: WrappedClassConstructorDescriptor(), idSignature
|
||||
)
|
||||
BinarySymbolData.SymbolKind.TYPE_PARAMETER_SYMBOL -> {
|
||||
checkDescriptorIsNull(symbolKind)
|
||||
referenceTypeParameterFromLinker(WrappedTypeParameterDescriptor(), idSignature)
|
||||
}
|
||||
BinarySymbolData.SymbolKind.ENUM_ENTRY_SYMBOL -> referenceEnumEntryFromLinker(
|
||||
descriptor as? ClassDescriptor ?: WrappedEnumEntryDescriptor(), idSignature
|
||||
)
|
||||
BinarySymbolData.SymbolKind.STANDALONE_FIELD_SYMBOL -> {
|
||||
checkDescriptorIsNull(symbolKind)
|
||||
referenceFieldFromLinker(WrappedFieldDescriptor(), idSignature)
|
||||
}
|
||||
BinarySymbolData.SymbolKind.FIELD_SYMBOL -> {
|
||||
checkDescriptorIsNull(symbolKind)
|
||||
referenceFieldFromLinker(WrappedPropertyDescriptor(), idSignature)
|
||||
}
|
||||
//TODO: FunctionInterfaces
|
||||
BinarySymbolData.SymbolKind.FUNCTION_SYMBOL -> referenceSimpleFunctionFromLinker(
|
||||
descriptor as? FunctionDescriptor ?: WrappedSimpleFunctionDescriptor(), idSignature
|
||||
)
|
||||
BinarySymbolData.SymbolKind.TYPEALIAS_SYMBOL -> referenceTypeAliasFromLinker(
|
||||
descriptor as? TypeAliasDescriptor ?: WrappedTypeAliasDescriptor(), idSignature
|
||||
)
|
||||
BinarySymbolData.SymbolKind.PROPERTY_SYMBOL -> referencePropertyFromLinker(
|
||||
descriptor as? PropertyDescriptor ?: WrappedPropertyDescriptor(), idSignature
|
||||
)
|
||||
BinarySymbolData.SymbolKind.VARIABLE_SYMBOL -> {
|
||||
checkDescriptorIsNull(symbolKind)
|
||||
IrVariableSymbolImpl(WrappedVariableDescriptor())
|
||||
}
|
||||
BinarySymbolData.SymbolKind.VALUE_PARAMETER_SYMBOL -> {
|
||||
checkDescriptorIsNull(symbolKind)
|
||||
IrValueParameterSymbolImpl(WrappedValueParameterDescriptor())
|
||||
}
|
||||
BinarySymbolData.SymbolKind.RECEIVER_PARAMETER_SYMBOL -> IrValueParameterSymbolImpl(
|
||||
descriptor as? ReceiverParameterDescriptor ?: WrappedReceiverParameterDescriptor()
|
||||
)
|
||||
BinarySymbolData.SymbolKind.LOCAL_DELEGATED_PROPERTY_SYMBOL -> {
|
||||
checkDescriptorIsNull(symbolKind)
|
||||
IrLocalDelegatedPropertySymbolImpl(WrappedVariableDescriptorWithAccessor())
|
||||
else -> TODO("Unexpected classifier symbol kind: $symbolKind")
|
||||
}
|
||||
else -> error("Unexpected classifier symbol kind: $symbolKind")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun isGlobalIdSignature(isSignature: IdSignature): Boolean {
|
||||
return isSignature in globalDeserializationState || isSpecialSignature(isSignature)
|
||||
|
||||
Reference in New Issue
Block a user