Add support for new backend diagnostic to test infrastructure
This commit is contained in:
+13
@@ -5,14 +5,17 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.test.backend.handlers
|
package org.jetbrains.kotlin.test.backend.handlers
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.diagnostics.impl.BaseDiagnosticReporter
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.test.frontend.classic.handlers.ClassicDiagnosticReporter
|
import org.jetbrains.kotlin.test.frontend.classic.handlers.ClassicDiagnosticReporter
|
||||||
import org.jetbrains.kotlin.test.frontend.classic.handlers.withNewInferenceModeEnabled
|
import org.jetbrains.kotlin.test.frontend.classic.handlers.withNewInferenceModeEnabled
|
||||||
|
import org.jetbrains.kotlin.test.frontend.fir.handlers.toMetaInfos
|
||||||
import org.jetbrains.kotlin.test.model.BinaryArtifacts
|
import org.jetbrains.kotlin.test.model.BinaryArtifacts
|
||||||
import org.jetbrains.kotlin.test.model.FrontendKinds
|
import org.jetbrains.kotlin.test.model.FrontendKinds
|
||||||
import org.jetbrains.kotlin.test.model.TestModule
|
import org.jetbrains.kotlin.test.model.TestModule
|
||||||
import org.jetbrains.kotlin.test.services.TestServices
|
import org.jetbrains.kotlin.test.services.TestServices
|
||||||
import org.jetbrains.kotlin.test.services.dependencyProvider
|
import org.jetbrains.kotlin.test.services.dependencyProvider
|
||||||
|
import org.jetbrains.kotlin.test.services.globalMetadataInfoHandler
|
||||||
|
|
||||||
class JvmBackendDiagnosticsHandler(testServices: TestServices) : JvmBinaryArtifactHandler(testServices) {
|
class JvmBackendDiagnosticsHandler(testServices: TestServices) : JvmBinaryArtifactHandler(testServices) {
|
||||||
private val reporter = ClassicDiagnosticReporter(testServices)
|
private val reporter = ClassicDiagnosticReporter(testServices)
|
||||||
@@ -29,6 +32,16 @@ class JvmBackendDiagnosticsHandler(testServices: TestServices) : JvmBinaryArtifa
|
|||||||
val testFile = ktFileToTestFileMap[ktFile] ?: continue
|
val testFile = ktFileToTestFileMap[ktFile] ?: continue
|
||||||
reporter.reportDiagnostic(diagnostic, module, testFile, configuration, withNewInferenceModeEnabled)
|
reporter.reportDiagnostic(diagnostic, module, testFile, configuration, withNewInferenceModeEnabled)
|
||||||
}
|
}
|
||||||
|
val ktDiagnosticReporter = generationState.diagnosticReporter as BaseDiagnosticReporter
|
||||||
|
val globalMetadataInfoHandler = testServices.globalMetadataInfoHandler
|
||||||
|
for ((testFile, ktFile) in testFileToKtFileMap.entries) {
|
||||||
|
val ktDiagnostics = ktDiagnosticReporter.diagnosticsByFilePath[ktFile.virtualFilePath] ?: continue
|
||||||
|
ktDiagnostics.forEach {
|
||||||
|
val metaInfos =
|
||||||
|
it.toMetaInfos(testFile, globalMetadataInfoHandler, false, false)
|
||||||
|
globalMetadataInfoHandler.addMetadataInfosForFile(testFile, metaInfos)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {}
|
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {}
|
||||||
|
|||||||
+3
-1
@@ -9,7 +9,9 @@ import org.jetbrains.kotlin.backend.common.BackendException
|
|||||||
import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory
|
import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory
|
||||||
import org.jetbrains.kotlin.test.backend.classic.JavaCompilerFacade
|
import org.jetbrains.kotlin.test.backend.classic.JavaCompilerFacade
|
||||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives
|
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives
|
||||||
import org.jetbrains.kotlin.test.model.*
|
import org.jetbrains.kotlin.test.model.ArtifactKinds
|
||||||
|
import org.jetbrains.kotlin.test.model.BinaryArtifacts
|
||||||
|
import org.jetbrains.kotlin.test.model.TestModule
|
||||||
import org.jetbrains.kotlin.test.services.TestServices
|
import org.jetbrains.kotlin.test.services.TestServices
|
||||||
import org.jetbrains.kotlin.test.services.compilerConfigurationProvider
|
import org.jetbrains.kotlin.test.services.compilerConfigurationProvider
|
||||||
|
|
||||||
|
|||||||
+2
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
|||||||
import org.jetbrains.kotlin.codegen.ClassBuilderFactories
|
import org.jetbrains.kotlin.codegen.ClassBuilderFactories
|
||||||
import org.jetbrains.kotlin.codegen.CodegenFactory
|
import org.jetbrains.kotlin.codegen.CodegenFactory
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||||
|
import org.jetbrains.kotlin.diagnostics.DiagnosticReporterFactory
|
||||||
import org.jetbrains.kotlin.test.backend.ir.IrBackendInput
|
import org.jetbrains.kotlin.test.backend.ir.IrBackendInput
|
||||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives
|
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives
|
||||||
import org.jetbrains.kotlin.test.model.BackendKinds
|
import org.jetbrains.kotlin.test.model.BackendKinds
|
||||||
@@ -43,6 +44,7 @@ class ClassicFrontend2IrConverter(
|
|||||||
).codegenFactory(codegenFactory)
|
).codegenFactory(codegenFactory)
|
||||||
.isIrBackend(true)
|
.isIrBackend(true)
|
||||||
.ignoreErrors(CodegenTestDirectives.IGNORE_ERRORS in module.directives)
|
.ignoreErrors(CodegenTestDirectives.IGNORE_ERRORS in module.directives)
|
||||||
|
.diagnosticReporter(DiagnosticReporterFactory.createReporter())
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
return IrBackendInput(state, codegenFactory.convertToIr(CodegenFactory.IrConversionInput.fromGenerationState(state)))
|
return IrBackendInput(state, codegenFactory.convertToIr(CodegenFactory.IrConversionInput.fromGenerationState(state)))
|
||||||
|
|||||||
+44
-25
@@ -95,7 +95,12 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes
|
|||||||
// SYNTAX errors will be reported later
|
// SYNTAX errors will be reported later
|
||||||
if (diagnostic.factory == FirErrors.SYNTAX) return@flatMap emptyList()
|
if (diagnostic.factory == FirErrors.SYNTAX) return@flatMap emptyList()
|
||||||
if (!diagnostic.isValid) return@flatMap emptyList()
|
if (!diagnostic.isValid) return@flatMap emptyList()
|
||||||
diagnostic.toMetaInfos(file, lightTreeEnabled, lightTreeComparingModeEnabled)
|
diagnostic.toMetaInfos(
|
||||||
|
file,
|
||||||
|
globalMetadataInfoHandler,
|
||||||
|
lightTreeEnabled,
|
||||||
|
lightTreeComparingModeEnabled
|
||||||
|
)
|
||||||
}
|
}
|
||||||
globalMetadataInfoHandler.addMetadataInfosForFile(file, diagnosticsMetadataInfos)
|
globalMetadataInfoHandler.addMetadataInfosForFile(file, diagnosticsMetadataInfos)
|
||||||
collectSyntaxDiagnostics(file, firFile, lightTreeEnabled, lightTreeComparingModeEnabled)
|
collectSyntaxDiagnostics(file, firFile, lightTreeEnabled, lightTreeComparingModeEnabled)
|
||||||
@@ -103,27 +108,6 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtDiagnostic.toMetaInfos(
|
|
||||||
file: TestFile,
|
|
||||||
lightTreeEnabled: Boolean,
|
|
||||||
lightTreeComparingModeEnabled: Boolean,
|
|
||||||
forceRenderArguments: Boolean = false
|
|
||||||
): List<FirDiagnosticCodeMetaInfo> {
|
|
||||||
val ranges = factory.defaultPositioningStrategy.markDiagnostic(this)
|
|
||||||
return ranges.map { range ->
|
|
||||||
val metaInfo = FirDiagnosticCodeMetaInfo(this, FirMetaInfoUtils.renderDiagnosticNoArgs, range)
|
|
||||||
val shouldRenderArguments = forceRenderArguments || globalMetadataInfoHandler.getExistingMetaInfosForActualMetadata(file, metaInfo)
|
|
||||||
.any { it.description != null }
|
|
||||||
if (shouldRenderArguments) {
|
|
||||||
metaInfo.replaceRenderConfiguration(FirMetaInfoUtils.renderDiagnosticWithArgs)
|
|
||||||
}
|
|
||||||
if (lightTreeComparingModeEnabled) {
|
|
||||||
metaInfo.attributes += if (lightTreeEnabled) PsiLightTreeMetaInfoProcessor.LT else PsiLightTreeMetaInfoProcessor.PSI
|
|
||||||
}
|
|
||||||
metaInfo
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(InternalDiagnosticFactoryMethod::class)
|
@OptIn(InternalDiagnosticFactoryMethod::class)
|
||||||
private fun collectSyntaxDiagnostics(
|
private fun collectSyntaxDiagnostics(
|
||||||
testFile: TestFile,
|
testFile: TestFile,
|
||||||
@@ -134,12 +118,22 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes
|
|||||||
val metaInfos = if (firFile.psi != null) {
|
val metaInfos = if (firFile.psi != null) {
|
||||||
AnalyzingUtils.getSyntaxErrorRanges(firFile.psi!!).flatMap {
|
AnalyzingUtils.getSyntaxErrorRanges(firFile.psi!!).flatMap {
|
||||||
FirErrors.SYNTAX.on(KtRealPsiSourceElement(it), positioningStrategy = null)
|
FirErrors.SYNTAX.on(KtRealPsiSourceElement(it), positioningStrategy = null)
|
||||||
.toMetaInfos(testFile, lightTreeEnabled, lightTreeComparingModeEnabled)
|
.toMetaInfos(
|
||||||
|
testFile,
|
||||||
|
globalMetadataInfoHandler1 = globalMetadataInfoHandler,
|
||||||
|
lightTreeEnabled,
|
||||||
|
lightTreeComparingModeEnabled
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
collectLightTreeSyntaxErrors(firFile).flatMap { sourceElement ->
|
collectLightTreeSyntaxErrors(firFile).flatMap { sourceElement ->
|
||||||
FirErrors.SYNTAX.on(sourceElement, positioningStrategy = null)
|
FirErrors.SYNTAX.on(sourceElement, positioningStrategy = null)
|
||||||
.toMetaInfos(testFile, lightTreeEnabled, lightTreeComparingModeEnabled)
|
.toMetaInfos(
|
||||||
|
testFile,
|
||||||
|
globalMetadataInfoHandler1 = globalMetadataInfoHandler,
|
||||||
|
lightTreeEnabled,
|
||||||
|
lightTreeComparingModeEnabled
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +189,13 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes
|
|||||||
}.let(firFile::accept)
|
}.let(firFile::accept)
|
||||||
globalMetadataInfoHandler.addMetadataInfosForFile(
|
globalMetadataInfoHandler.addMetadataInfosForFile(
|
||||||
testFile,
|
testFile,
|
||||||
result.flatMap { it.toMetaInfos(testFile, lightTreeEnabled, lightTreeComparingModeEnabled, forceRenderArguments = true) }
|
result.flatMap { it.toMetaInfos(
|
||||||
|
testFile,
|
||||||
|
globalMetadataInfoHandler,
|
||||||
|
lightTreeEnabled,
|
||||||
|
lightTreeComparingModeEnabled,
|
||||||
|
forceRenderArguments = true
|
||||||
|
) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,3 +344,22 @@ class PsiLightTreeMetaInfoProcessor(testServices: TestServices) : AbstractTwoAtt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun KtDiagnostic.toMetaInfos(
|
||||||
|
file: TestFile,
|
||||||
|
globalMetadataInfoHandler1: GlobalMetadataInfoHandler,
|
||||||
|
lightTreeEnabled: Boolean,
|
||||||
|
lightTreeComparingModeEnabled: Boolean,
|
||||||
|
forceRenderArguments: Boolean = false
|
||||||
|
): List<FirDiagnosticCodeMetaInfo> = textRanges.map { range ->
|
||||||
|
val metaInfo = FirDiagnosticCodeMetaInfo(this, FirMetaInfoUtils.renderDiagnosticNoArgs, range)
|
||||||
|
val shouldRenderArguments = forceRenderArguments || globalMetadataInfoHandler1.getExistingMetaInfosForActualMetadata(file, metaInfo)
|
||||||
|
.any { it.description != null }
|
||||||
|
if (shouldRenderArguments) {
|
||||||
|
metaInfo.replaceRenderConfiguration(FirMetaInfoUtils.renderDiagnosticWithArgs)
|
||||||
|
}
|
||||||
|
if (lightTreeComparingModeEnabled) {
|
||||||
|
metaInfo.attributes += if (lightTreeEnabled) PsiLightTreeMetaInfoProcessor.LT else PsiLightTreeMetaInfoProcessor.PSI
|
||||||
|
}
|
||||||
|
metaInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user