[PL] Halt compilation when there are linkage issues logged with the ERROR severity
^KT-61097
This commit is contained in:
committed by
Space Team
parent
288163437d
commit
8be98da1d3
+1
-1
@@ -135,7 +135,7 @@ object PartialLinkageUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A workaround for KT-58837 until KT-58904 is fixed. TODO: Merge with IrMessageLogger.
|
// A workaround for KT-58837 until KT-58904 is fixed. TODO: Merge with IrMessageLogger.
|
||||||
class PartialLinkageLogger(private val irLogger: IrMessageLogger, logLevel: PartialLinkageLogLevel) {
|
class PartialLinkageLogger(val irLogger: IrMessageLogger, val logLevel: PartialLinkageLogLevel) {
|
||||||
class Location(val moduleName: String, val filePath: String, val lineNumber: Int, val columnNumber: Int) {
|
class Location(val moduleName: String, val filePath: String, val lineNumber: Int, val columnNumber: Int) {
|
||||||
fun render(): StringBuilder = StringBuilder().apply {
|
fun render(): StringBuilder = StringBuilder().apply {
|
||||||
append(moduleName)
|
append(moduleName)
|
||||||
|
|||||||
+4
@@ -29,6 +29,10 @@ abstract class KotlinIrLinkerIssue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object PartialLinkageErrorsLogged : KotlinIrLinkerIssue() {
|
||||||
|
override val errorMessage = "There are linkage errors reported by the partial linkage engine"
|
||||||
|
}
|
||||||
|
|
||||||
class UnexpectedUnboundIrSymbols(unboundSymbols: Set<IrSymbol>, whenDetected: String) : KotlinIrLinkerIssue() {
|
class UnexpectedUnboundIrSymbols(unboundSymbols: Set<IrSymbol>, whenDetected: String) : KotlinIrLinkerIssue() {
|
||||||
override val errorMessage = buildString {
|
override val errorMessage = buildString {
|
||||||
// cause:
|
// cause:
|
||||||
|
|||||||
+8
-1
@@ -5,12 +5,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.common.linkage.partial
|
package org.jetbrains.kotlin.backend.common.linkage.partial
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.common.linkage.issues.PartialLinkageErrorsLogged
|
||||||
import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideBuilder
|
import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideBuilder
|
||||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||||
import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageConfig
|
import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageConfig
|
||||||
|
import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageLogLevel
|
||||||
import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageLogger
|
import org.jetbrains.kotlin.ir.linkage.partial.PartialLinkageLogger
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||||
import org.jetbrains.kotlin.ir.util.IrMessageLogger
|
import org.jetbrains.kotlin.ir.util.IrMessageLogger
|
||||||
@@ -29,7 +31,7 @@ else
|
|||||||
internal class PartialLinkageSupportForLinkerImpl(
|
internal class PartialLinkageSupportForLinkerImpl(
|
||||||
builtIns: IrBuiltIns,
|
builtIns: IrBuiltIns,
|
||||||
allowErrorTypes: Boolean,
|
allowErrorTypes: Boolean,
|
||||||
logger: PartialLinkageLogger
|
private val logger: PartialLinkageLogger
|
||||||
) : PartialLinkageSupportForLinker {
|
) : PartialLinkageSupportForLinker {
|
||||||
private val stubGenerator = MissingDeclarationStubGenerator(builtIns)
|
private val stubGenerator = MissingDeclarationStubGenerator(builtIns)
|
||||||
private val classifierExplorer = ClassifierExplorer(builtIns, stubGenerator, allowErrorTypes)
|
private val classifierExplorer = ClassifierExplorer(builtIns, stubGenerator, allowErrorTypes)
|
||||||
@@ -81,5 +83,10 @@ internal class PartialLinkageSupportForLinkerImpl(
|
|||||||
|
|
||||||
// Patch the stubs which were not patched yet.
|
// Patch the stubs which were not patched yet.
|
||||||
patcher.patchDeclarations(stubGenerator.grabDeclarationsToPatch())
|
patcher.patchDeclarations(stubGenerator.grabDeclarationsToPatch())
|
||||||
|
|
||||||
|
// Make sure that there are no linkage issues that have been reported with the 'error' severity.
|
||||||
|
// If there are, abort the current compilation.
|
||||||
|
if (logger.logLevel == PartialLinkageLogLevel.ERROR && patcher.linkageIssuesLogged > 0)
|
||||||
|
PartialLinkageErrorsLogged.raiseIssue(logger.irLogger)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-5
@@ -33,11 +33,22 @@ internal class PartialLinkageSupportForLoweringsImpl(
|
|||||||
) : PartialLinkageSupportForLowerings {
|
) : PartialLinkageSupportForLowerings {
|
||||||
override val isEnabled get() = true
|
override val isEnabled get() = true
|
||||||
|
|
||||||
// N.B. errorMessagesRendered is always >= than throwExpressionsGenerated.
|
/** To track the amount of rendered linkage issues. */
|
||||||
var throwExpressionsGenerated = 0 // Track each generate `throw` expression.
|
var linkageIssuesRendered = 0
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var errorMessagesRendered = 0 // Track each rendered error message.
|
/**
|
||||||
|
* To track the amount of logged linkage issues.
|
||||||
|
* Note that the following condition is always true: [linkageIssuesLogged] <= [linkageIssuesRendered].
|
||||||
|
*/
|
||||||
|
var linkageIssuesLogged = 0
|
||||||
|
private set
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To track the amount of generated `throw` expressions.
|
||||||
|
* Note that the following condition is always true: [throwExpressionsGenerated] <= [linkageIssuesRendered].
|
||||||
|
*/
|
||||||
|
var throwExpressionsGenerated = 0
|
||||||
private set
|
private set
|
||||||
|
|
||||||
override fun throwLinkageError(
|
override fun throwLinkageError(
|
||||||
@@ -51,7 +62,7 @@ internal class PartialLinkageSupportForLoweringsImpl(
|
|||||||
else
|
else
|
||||||
renderAndLogLinkageError(partialLinkageCase, element, file) // Render + log with the appropriate severity.
|
renderAndLogLinkageError(partialLinkageCase, element, file) // Render + log with the appropriate severity.
|
||||||
|
|
||||||
throwExpressionsGenerated++ // Track each generate `throw` expression.
|
throwExpressionsGenerated++ // Track each generated `throw` expression.
|
||||||
|
|
||||||
return IrCallImpl(
|
return IrCallImpl(
|
||||||
startOffset = element.startOffset,
|
startOffset = element.startOffset,
|
||||||
@@ -70,13 +81,14 @@ internal class PartialLinkageSupportForLoweringsImpl(
|
|||||||
val errorMessage = renderLinkageError(partialLinkageCase)
|
val errorMessage = renderLinkageError(partialLinkageCase)
|
||||||
val locationInSourceCode = file.computeLocationForOffset(element.startOffsetOfFirstDenotableIrElement())
|
val locationInSourceCode = file.computeLocationForOffset(element.startOffsetOfFirstDenotableIrElement())
|
||||||
|
|
||||||
|
linkageIssuesLogged++ // Track each logged linkage issue.
|
||||||
logger.log(errorMessage, locationInSourceCode)
|
logger.log(errorMessage, locationInSourceCode)
|
||||||
|
|
||||||
return errorMessage
|
return errorMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderLinkageError(partialLinkageCase: PartialLinkageCase): String {
|
private fun renderLinkageError(partialLinkageCase: PartialLinkageCase): String {
|
||||||
errorMessagesRendered++ // Track each rendered error message.
|
linkageIssuesRendered++ // Track each rendered linkage issue.
|
||||||
return partialLinkageCase.renderLinkageError()
|
return partialLinkageCase.renderLinkageError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -58,6 +58,8 @@ internal class PartiallyLinkedIrTreePatcher(
|
|||||||
// Used only to generate IR expressions that throw linkage errors.
|
// Used only to generate IR expressions that throw linkage errors.
|
||||||
private val supportForLowerings by lazy { PartialLinkageSupportForLoweringsImpl(builtIns, logger) }
|
private val supportForLowerings by lazy { PartialLinkageSupportForLoweringsImpl(builtIns, logger) }
|
||||||
|
|
||||||
|
val linkageIssuesLogged get() = supportForLowerings.linkageIssuesLogged
|
||||||
|
|
||||||
fun shouldBeSkipped(declaration: IrDeclaration): Boolean = PLModule.determineModuleFor(declaration).shouldBeSkipped
|
fun shouldBeSkipped(declaration: IrDeclaration): Boolean = PLModule.determineModuleFor(declaration).shouldBeSkipped
|
||||||
|
|
||||||
fun patchModuleFragments(roots: Sequence<IrModuleFragment>) {
|
fun patchModuleFragments(roots: Sequence<IrModuleFragment>) {
|
||||||
@@ -887,7 +889,7 @@ internal class PartiallyLinkedIrTreePatcher(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private inner class AnnotationChecker(currentFile: PLFile) : ExpressionTransformer(currentFile) {
|
private inner class AnnotationChecker(currentFile: PLFile) : ExpressionTransformer(currentFile) {
|
||||||
private val currentErrorMessagesCount get() = supportForLowerings.errorMessagesRendered
|
private val currentErrorMessagesCount get() = supportForLowerings.linkageIssuesRendered
|
||||||
private val initialErrorMessagesCount = currentErrorMessagesCount // Memoize the number of PL errors generated to this moment.
|
private val initialErrorMessagesCount = currentErrorMessagesCount // Memoize the number of PL errors generated to this moment.
|
||||||
|
|
||||||
var isUsableAnnotation = true
|
var isUsableAnnotation = true
|
||||||
|
|||||||
Reference in New Issue
Block a user