[KLIB] Use IrMessageLogger in klib linker to report errors
This commit is contained in:
+1
-3
@@ -5,8 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.serialization
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.LoggingContext
|
||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||
import org.jetbrains.kotlin.backend.common.lower.InnerClassesSupport
|
||||
import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideBuilder
|
||||
import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideClassFilter
|
||||
@@ -111,7 +109,7 @@ import org.jetbrains.kotlin.backend.common.serialization.proto.MemberAccessCommo
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.PublicIdSignature as ProtoPublicIdSignature
|
||||
|
||||
abstract class IrFileDeserializer(
|
||||
val logger: LoggingContext,
|
||||
val messageLogger: IrMessageLogger,
|
||||
val builtIns: IrBuiltIns,
|
||||
val symbolTable: SymbolTable,
|
||||
protected var deserializeBodies: Boolean,
|
||||
|
||||
+1
-2
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.serialization
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.LoggingContext
|
||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||
import org.jetbrains.kotlin.backend.common.serialization.encodings.*
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
@@ -104,7 +103,7 @@ import org.jetbrains.kotlin.backend.common.serialization.proto.NullableIrExpress
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.PublicIdSignature as ProtoPublicIdSignature
|
||||
|
||||
open class IrFileSerializer(
|
||||
val logger: LoggingContext,
|
||||
val messageLogger: IrMessageLogger,
|
||||
private val declarationTable: DeclarationTable,
|
||||
private val expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>,
|
||||
private val bodiesOnlyForInlines: Boolean = false,
|
||||
|
||||
+2
-2
@@ -5,14 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.serialization
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.LoggingContext
|
||||
import org.jetbrains.kotlin.builtins.FunctionInterfacePackageFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.util.IrMessageLogger
|
||||
import org.jetbrains.kotlin.library.SerializedIrFile
|
||||
import org.jetbrains.kotlin.library.SerializedIrModule
|
||||
|
||||
abstract class IrModuleSerializer<F : IrFileSerializer>(protected val logger: LoggingContext) {
|
||||
abstract class IrModuleSerializer<F : IrFileSerializer>(protected val messageLogger: IrMessageLogger) {
|
||||
abstract fun createSerializerForFile(file: IrFile): F
|
||||
|
||||
/**
|
||||
|
||||
+45
-17
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.serialization
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.LoggingContext
|
||||
import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideBuilder
|
||||
import org.jetbrains.kotlin.backend.common.overrides.FileLocalAwareLinker
|
||||
import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData
|
||||
@@ -20,11 +19,13 @@ import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl
|
||||
import org.jetbrains.kotlin.ir.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrAbstractFunctionFactory
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrLoop
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
|
||||
import org.jetbrains.kotlin.ir.linkage.IrDeserializer
|
||||
import org.jetbrains.kotlin.ir.linkage.KotlinIrLinkerInternalException
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
@@ -49,7 +50,7 @@ import org.jetbrains.kotlin.backend.common.serialization.proto.IrType as ProtoTy
|
||||
|
||||
abstract class KotlinIrLinker(
|
||||
private val currentModule: ModuleDescriptor?,
|
||||
val logger: LoggingContext,
|
||||
val messageLogger: IrMessageLogger,
|
||||
val builtIns: IrBuiltIns,
|
||||
val symbolTable: SymbolTable,
|
||||
private val exportedDependencies: List<ModuleDescriptor>
|
||||
@@ -110,7 +111,7 @@ abstract class KotlinIrLinker(
|
||||
private val moduleDeserializationState = ModuleDeserializationState()
|
||||
private val moduleReversedFileIndex = mutableMapOf<IdSignature, IrDeserializerForFile>()
|
||||
override val moduleDependencies by lazy {
|
||||
moduleDescriptor.allDependencyModules.filter { it != moduleDescriptor }.map { resolveModuleDeserializer(it) }
|
||||
moduleDescriptor.allDependencyModules.filter { it != moduleDescriptor }.map { resolveModuleDeserializer(it, null) }
|
||||
}
|
||||
|
||||
override fun init(delegate: IrModuleDeserializer) {
|
||||
@@ -128,7 +129,7 @@ abstract class KotlinIrLinker(
|
||||
fileToDeserializerMap.values.forEach { it.deserializeExpectActualMapping() }
|
||||
}
|
||||
|
||||
override fun referenceSimpleFunctionByLocalSignature(file: IrFile, idSignature: IdSignature) : IrSimpleFunctionSymbol =
|
||||
override fun referenceSimpleFunctionByLocalSignature(file: IrFile, idSignature: IdSignature): IrSimpleFunctionSymbol =
|
||||
fileToDeserializerMap[file]?.referenceSimpleFunctionByLocalSignature(idSignature)
|
||||
?: error("No deserializer for file $file in module ${moduleDescriptor.name}")
|
||||
|
||||
@@ -240,7 +241,7 @@ abstract class KotlinIrLinker(
|
||||
allowErrorNodes: Boolean
|
||||
) :
|
||||
IrFileDeserializer(
|
||||
logger,
|
||||
messageLogger,
|
||||
builtIns,
|
||||
symbolTable,
|
||||
!onlyHeaders,
|
||||
@@ -358,7 +359,11 @@ abstract class KotlinIrLinker(
|
||||
|
||||
val topLevelSig = idSig.topLevelSignature()
|
||||
if (topLevelSig in moduleDeserializer) return moduleDeserializer
|
||||
return moduleDeserializer.moduleDependencies.firstOrNull { topLevelSig in it } ?: handleNoModuleDeserializerFound(idSig)
|
||||
return moduleDeserializer.moduleDependencies.firstOrNull { topLevelSig in it } ?: handleNoModuleDeserializerFound(
|
||||
idSig,
|
||||
moduleDeserializer.moduleDescriptor,
|
||||
moduleDeserializer.moduleDependencies
|
||||
)
|
||||
}
|
||||
|
||||
private fun referenceIrSymbolData(symbol: IrSymbol, signature: IdSignature) {
|
||||
@@ -469,12 +474,33 @@ abstract class KotlinIrLinker(
|
||||
return codedInputStream
|
||||
}
|
||||
|
||||
protected open fun handleNoModuleDeserializerFound(idSignature: IdSignature): IrModuleDeserializer {
|
||||
error("Deserializer for declaration $idSignature is not found")
|
||||
protected open fun handleNoModuleDeserializerFound(idSignature: IdSignature, currentModule: ModuleDescriptor, dependencies: Collection<IrModuleDeserializer>): IrModuleDeserializer {
|
||||
val message = buildString {
|
||||
append("Module $currentModule has reference $idSignature, unfortunately neither itself nor its dependencies ")
|
||||
dependencies.joinTo(this, "\n\t", "[\n\t", "\n]")
|
||||
append(" contain this declaration")
|
||||
append("\n")
|
||||
append("Please check that project configuration is correct and has required dependencies.")
|
||||
}
|
||||
messageLogger.report(IrMessageLogger.Severity.ERROR, message, null)
|
||||
|
||||
throw KotlinIrLinkerInternalException
|
||||
}
|
||||
|
||||
protected open fun resolveModuleDeserializer(moduleDescriptor: ModuleDescriptor): IrModuleDeserializer {
|
||||
return deserializersForModules[moduleDescriptor] ?: error("No module deserializer found for $moduleDescriptor")
|
||||
protected open fun resolveModuleDeserializer(module: ModuleDescriptor, signature: IdSignature?): IrModuleDeserializer {
|
||||
return deserializersForModules[module] ?: run {
|
||||
val message = buildString {
|
||||
append("Could not load module ")
|
||||
append(module)
|
||||
signature?.let {
|
||||
append("; It was an attempt to find deserializer for ")
|
||||
append(it)
|
||||
}
|
||||
}
|
||||
messageLogger.report(IrMessageLogger.Severity.ERROR, message, null)
|
||||
|
||||
throw KotlinIrLinkerInternalException
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract fun createModuleDeserializer(
|
||||
@@ -542,7 +568,7 @@ abstract class KotlinIrLinker(
|
||||
|
||||
val descriptor = symbol.descriptor
|
||||
|
||||
val moduleDeserializer = resolveModuleDeserializer(descriptor.module)
|
||||
val moduleDeserializer = resolveModuleDeserializer(descriptor.module, symbol.signature)
|
||||
|
||||
// moduleDeserializer.deserializeIrSymbol(signature, symbol.kind())
|
||||
moduleDeserializer.declareIrSymbol(symbol)
|
||||
@@ -602,14 +628,16 @@ abstract class KotlinIrLinker(
|
||||
|
||||
override fun tryReferencingSimpleFunctionByLocalSignature(parent: IrDeclaration, idSignature: IdSignature): IrSimpleFunctionSymbol? {
|
||||
if (idSignature.isPublic) return null
|
||||
return deserializersForModules[parent.file.packageFragmentDescriptor.containingDeclaration]?.referenceSimpleFunctionByLocalSignature(parent.file, idSignature)
|
||||
?: error("No module deserializer for ${parent.render()}")
|
||||
val file = parent.file
|
||||
val moduleDescriptor = file.packageFragmentDescriptor.containingDeclaration
|
||||
return resolveModuleDeserializer(moduleDescriptor, null).referenceSimpleFunctionByLocalSignature(file, idSignature)
|
||||
}
|
||||
|
||||
override fun tryReferencingPropertyByLocalSignature(parent: IrDeclaration, idSignature: IdSignature): IrPropertySymbol? {
|
||||
if (idSignature.isPublic) return null
|
||||
return deserializersForModules[parent.file.packageFragmentDescriptor.containingDeclaration]?.referencePropertyByLocalSignature(parent.file, idSignature)
|
||||
?: error("No module deserializer for ${parent.render()}")
|
||||
val file = parent.file
|
||||
val moduleDescriptor = file.packageFragmentDescriptor.containingDeclaration
|
||||
return resolveModuleDeserializer(moduleDescriptor, null).referencePropertyByLocalSignature(file, idSignature)
|
||||
}
|
||||
|
||||
protected open fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>): IrModuleDeserializer =
|
||||
@@ -619,7 +647,7 @@ abstract class KotlinIrLinker(
|
||||
linkerExtensions = extensions
|
||||
if (moduleFragment != null) {
|
||||
val currentModuleDependencies = moduleFragment.descriptor.allDependencyModules.map {
|
||||
deserializersForModules[it] ?: error("No deserializer found for $it")
|
||||
resolveModuleDeserializer(it, null)
|
||||
}
|
||||
val currentModuleDeserializer = createCurrentModuleDeserializer(moduleFragment, currentModuleDependencies)
|
||||
deserializersForModules[moduleFragment.descriptor] =
|
||||
|
||||
Reference in New Issue
Block a user