Move reporting of interpreter's backend errors tests to fir module

This commit is contained in:
Ivan Kylchik
2021-12-14 23:31:46 +03:00
parent 44cf64a00c
commit 0f0b48f87b
8 changed files with 101 additions and 20 deletions
@@ -0,0 +1,32 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.test.runners;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/testData/diagnostics/firTestWithJvmBackend")
@TestDataPath("$PROJECT_ROOT")
public class FirDiagnosticsTestWithJvmIrBackendGenerated extends AbstractFirDiagnosticsTestWithJvmIrBackend {
@Test
public void testAllFilesPresentInFirTestWithJvmBackend() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/firTestWithJvmBackend"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("exceptionFromInterpreter_ir.kt")
public void testExceptionFromInterpreter_ir() throws Exception {
runTest("compiler/testData/diagnostics/firTestWithJvmBackend/exceptionFromInterpreter_ir.kt");
}
}
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl
import org.jetbrains.kotlin.ir.interpreter.IrInterpreter
import org.jetbrains.kotlin.ir.interpreter.isPrimitiveArray
@@ -29,7 +30,11 @@ class IrConstTransformer(
private fun IrExpression.reportIfError(original: IrExpression): IrExpression {
if (this is IrErrorExpression) {
onError(original, this)
return original
return when (mode) {
// need to pass any const value to be able to get some bytecode and then report error
EvaluationMode.ONLY_INTRINSIC_CONST -> IrConstImpl.int(startOffset, endOffset, type, 0)
else -> original
}
}
return this
}
@@ -6,6 +6,7 @@
const val divideByZero = <!EXCEPTION_IN_CONST_VAL_INITIALIZER!>1 / 0<!>
const val trimMarginException = "123".<!EXCEPTION_IN_CONST_VAL_INITIALIZER!>trimMargin(" ")<!>
//annotation class A(<!EXCEPTION_IN_CONST_VAL_INITIALIZER!>val i: Int<!>, val b: Int)
//@A(1 / 0, 2)
//fun foo() {}
annotation class A(val i: Int, val b: Int)
@A(<!EXCEPTION_IN_CONST_VAL_INITIALIZER!>1 / 0<!>, 2)
fun foo() {}
@@ -25,12 +25,6 @@ public class DiagnosticsTestWithJvmIrBackendGenerated extends AbstractDiagnostic
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithJvmBackend"), Pattern.compile("^(.+)\\.kts?$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("exceptionFromInterpreter_ir.kt")
public void testExceptionFromInterpreter_ir() throws Exception {
runTest("compiler/testData/diagnostics/testsWithJvmBackend/exceptionFromInterpreter_ir.kt");
}
@Test
@TestMetadata("indirectInlineCycle_ir.kt")
public void testIndirectInlineCycle_ir() throws Exception {
@@ -6,14 +6,17 @@
package org.jetbrains.kotlin.test.backend.handlers
import org.jetbrains.kotlin.diagnostics.impl.BaseDiagnosticsCollector
import org.jetbrains.kotlin.fir.psi
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.test.frontend.classic.handlers.ClassicDiagnosticReporter
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.FrontendKinds
import org.jetbrains.kotlin.test.model.TestFile
import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.services.TestServices
import org.jetbrains.kotlin.test.services.assertions
import org.jetbrains.kotlin.test.services.dependencyProvider
import org.jetbrains.kotlin.test.services.globalMetadataInfoHandler
@@ -21,8 +24,8 @@ class JvmBackendDiagnosticsHandler(testServices: TestServices) : JvmBinaryArtifa
private val reporter = ClassicDiagnosticReporter(testServices)
override fun processModule(module: TestModule, info: BinaryArtifacts.Jvm) {
val testFileToKtFileMap = testServices.dependencyProvider.getArtifact(module, FrontendKinds.ClassicFrontend).ktFiles
val ktFileToTestFileMap = testFileToKtFileMap.entries.map { it.value to it.key }.toMap()
val testFileToKtFileMap = getKtFiles(module)
val ktFileToTestFileMap = testFileToKtFileMap.entries.associate { it.value to it.key }
val generationState = info.classFileFactory.generationState
val diagnostics = generationState.collectedExtraJvmDiagnostics.all()
val configuration = reporter.createConfiguration(module)
@@ -44,5 +47,14 @@ class JvmBackendDiagnosticsHandler(testServices: TestServices) : JvmBinaryArtifa
}
}
private fun getKtFiles(module: TestModule): Map<TestFile, KtFile> {
return when (module.frontendKind) {
FrontendKinds.ClassicFrontend -> testServices.dependencyProvider.getArtifact(module, FrontendKinds.ClassicFrontend).ktFiles
FrontendKinds.FIR -> testServices.dependencyProvider.getArtifact(module, FrontendKinds.FIR).firFiles.entries
.associate { it.key to (it.value.psi as KtFile) }
else -> testServices.assertions.fail { "Unknown frontend kind ${module.frontendKind}" }
}
}
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {}
}
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.test.backend.ir.IrBackendInput
import org.jetbrains.kotlin.test.backend.ir.JvmIrBackendFacade
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
import org.jetbrains.kotlin.test.builders.classicFrontendHandlersStep
import org.jetbrains.kotlin.test.builders.classicFrontendStep
import org.jetbrains.kotlin.test.builders.jvmArtifactsHandlersStep
import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives
import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontend2ClassicBackendConverter
@@ -25,21 +24,26 @@ import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact
import org.jetbrains.kotlin.test.frontend.classic.handlers.ClassicDiagnosticsHandler
import org.jetbrains.kotlin.test.frontend.classic.handlers.DeclarationsDumpHandler
import org.jetbrains.kotlin.test.frontend.classic.handlers.OldNewInferenceMetaInfoProcessor
import org.jetbrains.kotlin.test.frontend.fir.Fir2IrResultsConverter
import org.jetbrains.kotlin.test.frontend.fir.FirFrontendFacade
import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact
import org.jetbrains.kotlin.test.model.*
import org.jetbrains.kotlin.test.services.configuration.CommonEnvironmentConfigurator
import org.jetbrains.kotlin.test.services.configuration.JvmEnvironmentConfigurator
import org.jetbrains.kotlin.test.services.sourceProviders.AdditionalDiagnosticsSourceFilesProvider
import org.jetbrains.kotlin.test.services.sourceProviders.CoroutineHelpersSourceFilesProvider
import org.jetbrains.kotlin.test.services.configuration.JvmEnvironmentConfigurator
import org.jetbrains.kotlin.test.services.configuration.ScriptingEnvironmentConfigurator
abstract class AbstractDiagnosticsTestWithJvmBackend<I : ResultingArtifact.BackendInput<I>> : AbstractKotlinCompilerTest() {
abstract class AbstractDiagnosticsTestWithJvmBackend<R : ResultingArtifact.FrontendOutput<R>, I : ResultingArtifact.BackendInput<I>> : AbstractKotlinCompilerTest() {
abstract val targetFrontend: FrontendKind<R>
abstract val targetBackend: TargetBackend
abstract val converter: Constructor<Frontend2BackendConverter<ClassicFrontendOutputArtifact, I>>
abstract val frontend: Constructor<FrontendFacade<R>>
abstract val converter: Constructor<Frontend2BackendConverter<R, I>>
abstract val backendFacade: Constructor<BackendFacade<I, BinaryArtifacts.Jvm>>
override fun TestConfigurationBuilder.configuration() {
globalDefaults {
frontend = FrontendKinds.ClassicFrontend
frontend = targetFrontend
targetBackend = this@AbstractDiagnosticsTestWithJvmBackend.targetBackend
targetPlatform = JvmPlatforms.defaultJvmPlatform
dependencyKind = DependencyKind.Binary
@@ -63,7 +67,7 @@ abstract class AbstractDiagnosticsTestWithJvmBackend<I : ResultingArtifact.Backe
::CoroutineHelpersSourceFilesProvider,
)
classicFrontendStep()
facadeStep(frontend)
classicFrontendHandlersStep {
useHandlers(
::DeclarationsDumpHandler,
@@ -82,10 +86,16 @@ abstract class AbstractDiagnosticsTestWithJvmBackend<I : ResultingArtifact.Backe
}
}
abstract class AbstractDiagnosticsTestWithOldJvmBackend : AbstractDiagnosticsTestWithJvmBackend<ClassicBackendInput>() {
abstract class AbstractDiagnosticsTestWithOldJvmBackend : AbstractDiagnosticsTestWithJvmBackend<ClassicFrontendOutputArtifact, ClassicBackendInput>() {
override val targetFrontend: FrontendKind<ClassicFrontendOutputArtifact>
get() = FrontendKinds.ClassicFrontend
override val targetBackend: TargetBackend
get() = TargetBackend.JVM_OLD
override val frontend: Constructor<FrontendFacade<ClassicFrontendOutputArtifact>>
get() = ::ClassicFrontendFacade
override val converter: Constructor<Frontend2BackendConverter<ClassicFrontendOutputArtifact, ClassicBackendInput>>
get() = ::ClassicFrontend2ClassicBackendConverter
@@ -93,13 +103,36 @@ abstract class AbstractDiagnosticsTestWithOldJvmBackend : AbstractDiagnosticsTes
get() = ::ClassicJvmBackendFacade
}
abstract class AbstractDiagnosticsTestWithJvmIrBackend : AbstractDiagnosticsTestWithJvmBackend<IrBackendInput>() {
abstract class AbstractDiagnosticsTestWithJvmIrBackend : AbstractDiagnosticsTestWithJvmBackend<ClassicFrontendOutputArtifact, IrBackendInput>() {
override val targetFrontend: FrontendKind<ClassicFrontendOutputArtifact>
get() = FrontendKinds.ClassicFrontend
override val targetBackend: TargetBackend
get() = TargetBackend.JVM_IR
override val frontend: Constructor<FrontendFacade<ClassicFrontendOutputArtifact>>
get() = ::ClassicFrontendFacade
override val converter: Constructor<Frontend2BackendConverter<ClassicFrontendOutputArtifact, IrBackendInput>>
get() = ::ClassicFrontend2IrConverter
override val backendFacade: Constructor<BackendFacade<IrBackendInput, BinaryArtifacts.Jvm>>
get() = ::JvmIrBackendFacade
}
abstract class AbstractFirDiagnosticsTestWithJvmIrBackend : AbstractDiagnosticsTestWithJvmBackend<FirOutputArtifact, IrBackendInput>() {
override val targetFrontend: FrontendKind<FirOutputArtifact>
get() = FrontendKinds.FIR
override val targetBackend: TargetBackend
get() = TargetBackend.JVM_IR
override val frontend: Constructor<FrontendFacade<FirOutputArtifact>>
get() = ::FirFrontendFacade
override val converter: Constructor<Frontend2BackendConverter<FirOutputArtifact, IrBackendInput>>
get() = ::Fir2IrResultsConverter
override val backendFacade: Constructor<BackendFacade<IrBackendInput, BinaryArtifacts.Jvm>>
get() = ::JvmIrBackendFacade
}
@@ -247,6 +247,10 @@ fun generateJUnit5CompilerTests(args: Array<String>) {
testClass<AbstractLoweredIrInterpreterTest> {
model("ir/loweredIr")
}
testClass<AbstractFirDiagnosticsTestWithJvmIrBackend> {
model("diagnostics/firTestWithJvmBackend")
}
}
testGroup(testsRoot = "compiler/fir/fir2ir/tests-gen", testDataRoot = "compiler/fir/fir2ir/testData") {