[PL] Log partial linkage messages at different severity
As specified in -Xpartial-linkage-loglevel CLI argument.
This commit is contained in:
committed by
Space Team
parent
d738646a61
commit
1fef48bb60
+16
-4
@@ -10,17 +10,29 @@ import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageConfig
|
||||
import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageLogLevel
|
||||
import org.jetbrains.kotlin.ir.util.IrMessageLogger
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.allUnbound
|
||||
|
||||
fun createPartialLinkageSupportForLinker(isEnabled: Boolean, builtIns: IrBuiltIns, messageLogger: IrMessageLogger) =
|
||||
if (isEnabled) PartialLinkageSupportForLinkerImpl(builtIns, messageLogger) else PartialLinkageSupportForLinker.DISABLED
|
||||
fun createPartialLinkageSupportForLinker(
|
||||
partialLinkageConfig: PartialLinkageConfig,
|
||||
builtIns: IrBuiltIns,
|
||||
messageLogger: IrMessageLogger
|
||||
): PartialLinkageSupportForLinker = if (partialLinkageConfig.isEnabled)
|
||||
PartialLinkageSupportForLinkerImpl(builtIns, partialLinkageConfig.logLevel, messageLogger)
|
||||
else
|
||||
PartialLinkageSupportForLinker.DISABLED
|
||||
|
||||
internal class PartialLinkageSupportForLinkerImpl(builtIns: IrBuiltIns, messageLogger: IrMessageLogger) : PartialLinkageSupportForLinker {
|
||||
internal class PartialLinkageSupportForLinkerImpl(
|
||||
builtIns: IrBuiltIns,
|
||||
logLevel: PartialLinkageLogLevel,
|
||||
messageLogger: IrMessageLogger
|
||||
) : PartialLinkageSupportForLinker {
|
||||
private val stubGenerator = MissingDeclarationStubGenerator(builtIns)
|
||||
private val classifierExplorer = ClassifierExplorer(builtIns, stubGenerator)
|
||||
private val patcher = PartiallyLinkedIrTreePatcher(builtIns, classifierExplorer, stubGenerator, messageLogger)
|
||||
private val patcher = PartiallyLinkedIrTreePatcher(builtIns, classifierExplorer, stubGenerator, logLevel, messageLogger)
|
||||
|
||||
override val isEnabled get() = true
|
||||
|
||||
|
||||
+21
-10
@@ -14,31 +14,42 @@ import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
||||
import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageCase
|
||||
import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageSupportForLowerings
|
||||
import org.jetbrains.kotlin.ir.linkage.partial.PartiallyLinkedDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.linkage.partial.*
|
||||
import org.jetbrains.kotlin.ir.util.IrMessageLogger
|
||||
import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageUtils.File as PLFile
|
||||
|
||||
fun createPartialLinkageSupportForLowerings(isEnabled: Boolean, builtIns: IrBuiltIns, messageLogger: IrMessageLogger) =
|
||||
if (isEnabled) PartialLinkageSupportForLoweringsImpl(builtIns, messageLogger) else PartialLinkageSupportForLowerings.DISABLED
|
||||
fun createPartialLinkageSupportForLowerings(
|
||||
partialLinkageConfig: PartialLinkageConfig,
|
||||
builtIns: IrBuiltIns,
|
||||
messageLogger: IrMessageLogger
|
||||
): PartialLinkageSupportForLowerings = if (partialLinkageConfig.isEnabled)
|
||||
PartialLinkageSupportForLoweringsImpl(builtIns, partialLinkageConfig.logLevel, messageLogger)
|
||||
else
|
||||
PartialLinkageSupportForLowerings.DISABLED
|
||||
|
||||
internal class PartialLinkageSupportForLoweringsImpl(
|
||||
private val builtIns: IrBuiltIns,
|
||||
logLevel: PartialLinkageLogLevel,
|
||||
private val messageLogger: IrMessageLogger
|
||||
) : PartialLinkageSupportForLowerings {
|
||||
override val isEnabled get() = true
|
||||
|
||||
private val irLoggerSeverity = when (logLevel) {
|
||||
PartialLinkageLogLevel.INFO -> IrMessageLogger.Severity.INFO
|
||||
PartialLinkageLogLevel.WARNING -> IrMessageLogger.Severity.WARNING
|
||||
PartialLinkageLogLevel.ERROR -> IrMessageLogger.Severity.ERROR
|
||||
}
|
||||
|
||||
override fun throwLinkageError(
|
||||
partialLinkageCase: PartialLinkageCase,
|
||||
element: IrElement,
|
||||
file: PLFile,
|
||||
suppressWarningInCompilerOutput: Boolean
|
||||
doNotLog: Boolean
|
||||
): IrCall {
|
||||
val errorMessage = if (suppressWarningInCompilerOutput)
|
||||
partialLinkageCase.renderLinkageError()
|
||||
val errorMessage = if (doNotLog)
|
||||
partialLinkageCase.renderLinkageError() // Just render a message.
|
||||
else
|
||||
renderAndLogLinkageError(partialLinkageCase, element, file)
|
||||
renderAndLogLinkageError(partialLinkageCase, element, file) // Render + log with the appropriate severity.
|
||||
|
||||
return IrCallImpl(
|
||||
startOffset = element.startOffset,
|
||||
@@ -57,7 +68,7 @@ internal class PartialLinkageSupportForLoweringsImpl(
|
||||
val errorMessage = partialLinkageCase.renderLinkageError()
|
||||
val locationInSourceCode = file.computeLocationForOffset(element.startOffsetOfFirstDenotableIrElement())
|
||||
|
||||
messageLogger.report(IrMessageLogger.Severity.WARNING, errorMessage, locationInSourceCode) // It's OK. We log it as a warning.
|
||||
messageLogger.report(irLoggerSeverity, errorMessage, locationInSourceCode) // It's OK. We log it as a warning.
|
||||
|
||||
return errorMessage
|
||||
}
|
||||
|
||||
+9
-15
@@ -19,11 +19,8 @@ import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyDeclarationBase
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin.PARTIAL_LINKAGE_RUNTIME_ERROR
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCompositeImpl
|
||||
import org.jetbrains.kotlin.ir.linkage.partial.ExploredClassifier
|
||||
import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageCase
|
||||
import org.jetbrains.kotlin.ir.linkage.partial.*
|
||||
import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageCase.*
|
||||
import org.jetbrains.kotlin.ir.linkage.partial.PartiallyLinkedDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.linkage.partial.isPartialLinkageRuntimeError
|
||||
import org.jetbrains.kotlin.ir.overrides.isEffectivelyPrivate
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrAnonymousInitializerSymbolImpl
|
||||
@@ -46,6 +43,7 @@ internal class PartiallyLinkedIrTreePatcher(
|
||||
private val builtIns: IrBuiltIns,
|
||||
private val classifierExplorer: ClassifierExplorer,
|
||||
private val stubGenerator: MissingDeclarationStubGenerator,
|
||||
logLevel: PartialLinkageLogLevel,
|
||||
private val messageLogger: IrMessageLogger
|
||||
) {
|
||||
// Avoid revisiting roots that already have been visited.
|
||||
@@ -58,7 +56,7 @@ internal class PartiallyLinkedIrTreePatcher(
|
||||
private val IrModuleFragment.shouldBeSkipped: Boolean get() = files.isEmpty() || name.asString() == stdlibModule.name
|
||||
|
||||
// Used only to generate IR expressions that throw linkage errors.
|
||||
private val supportForLowerings by lazy { PartialLinkageSupportForLoweringsImpl(builtIns, messageLogger) }
|
||||
private val supportForLowerings by lazy { PartialLinkageSupportForLoweringsImpl(builtIns, logLevel, messageLogger) }
|
||||
|
||||
fun patchModuleFragments(roots: Sequence<IrModuleFragment>) {
|
||||
roots.forEach { root ->
|
||||
@@ -183,10 +181,7 @@ internal class PartiallyLinkedIrTreePatcher(
|
||||
anonInitializer.body.statements.clear()
|
||||
|
||||
// Generate IR call that throws linkage error. Report compiler warning.
|
||||
anonInitializer.body.statements += partialLinkageCase.throwLinkageError(
|
||||
anonInitializer,
|
||||
suppressWarningInCompilerOutput = false
|
||||
)
|
||||
anonInitializer.body.statements += partialLinkageCase.throwLinkageError(anonInitializer)
|
||||
|
||||
// Finish processing of the current class.
|
||||
declaration.typeParameters.forEach { tp ->
|
||||
@@ -251,7 +246,7 @@ internal class PartiallyLinkedIrTreePatcher(
|
||||
// Note: Don't log errors for members of unlinked class.
|
||||
// - All such members are unusable anyway since their dispatch receiver (class) is unusable.
|
||||
// - Also, this reduces the number of compiler error messages and makes the compiler output less polluted.
|
||||
suppressWarningInCompilerOutput = declaration.isDirectMemberOf(unusableClassifierInSignature)
|
||||
doNotLog = declaration.isDirectMemberOf(unusableClassifierInSignature)
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -286,7 +281,7 @@ internal class PartiallyLinkedIrTreePatcher(
|
||||
// Note: Don't log errors for members of unlinked class.
|
||||
// - All such members are unusable anyway since their dispatch receiver (class) is unusable.
|
||||
// - Also, this reduces the number of compiler error messages and makes the compiler output less polluted.
|
||||
suppressWarningInCompilerOutput = declaration.isDirectMemberOf(unusableClassifierInSignature)
|
||||
doNotLog = declaration.isDirectMemberOf(unusableClassifierInSignature)
|
||||
)
|
||||
|
||||
// Don't remove inline functions, this may harm linkage in K/N backend with enabled static caches.
|
||||
@@ -442,8 +437,8 @@ internal class PartiallyLinkedIrTreePatcher(
|
||||
}
|
||||
}
|
||||
|
||||
private fun PartialLinkageCase.throwLinkageError(declaration: IrDeclaration, suppressWarningInCompilerOutput: Boolean): IrCall =
|
||||
supportForLowerings.throwLinkageError(this, declaration, currentFile, suppressWarningInCompilerOutput)
|
||||
private fun PartialLinkageCase.throwLinkageError(declaration: IrDeclaration, doNotLog: Boolean = false): IrCall =
|
||||
supportForLowerings.throwLinkageError(this, declaration, currentFile, doNotLog)
|
||||
}
|
||||
|
||||
private inner class ExpressionTransformer(startingFile: PLFile?) : FileAwareIrElementTransformerVoid(startingFile) {
|
||||
@@ -981,8 +976,7 @@ internal class PartiallyLinkedIrTreePatcher(
|
||||
val linkageError = supportForLowerings.throwLinkageError(
|
||||
partialLinkageCase,
|
||||
element = this,
|
||||
transformer.currentFile,
|
||||
suppressWarningInCompilerOutput = false
|
||||
transformer.currentFile
|
||||
)
|
||||
|
||||
return if (directChildren.statements.isNotEmpty())
|
||||
|
||||
+1
-4
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.backend.common.serialization
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.linkage.issues.*
|
||||
import org.jetbrains.kotlin.backend.common.linkage.partial.PartialLinkageSupportForLinker
|
||||
import org.jetbrains.kotlin.backend.common.linkage.partial.createPartialLinkageSupportForLinker
|
||||
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
|
||||
@@ -31,7 +30,6 @@ abstract class KotlinIrLinker(
|
||||
val builtIns: IrBuiltIns,
|
||||
val symbolTable: SymbolTable,
|
||||
private val exportedDependencies: List<ModuleDescriptor>,
|
||||
partialLinkageEnabled: Boolean,
|
||||
val symbolProcessor: IrSymbolDeserializer.(IrSymbol, IdSignature) -> IrSymbol = { s, _ -> s },
|
||||
) : IrDeserializer, FileLocalAwareLinker {
|
||||
|
||||
@@ -53,8 +51,7 @@ abstract class KotlinIrLinker(
|
||||
|
||||
private lateinit var linkerExtensions: Collection<IrDeserializer.IrLinkerExtension>
|
||||
|
||||
val partialLinkageSupport: PartialLinkageSupportForLinker =
|
||||
createPartialLinkageSupportForLinker(partialLinkageEnabled, builtIns, messageLogger)
|
||||
open val partialLinkageSupport: PartialLinkageSupportForLinker get() = PartialLinkageSupportForLinker.DISABLED
|
||||
|
||||
protected open val userVisibleIrModulesSupport: UserVisibleIrModulesSupport get() = UserVisibleIrModulesSupport.DEFAULT
|
||||
|
||||
|
||||
Reference in New Issue
Block a user