diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestConfiguration.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestConfiguration.kt index 3c0b5c35fd6..39c7578e2ad 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestConfiguration.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestConfiguration.kt @@ -6,11 +6,14 @@ package org.jetbrains.kotlin.test import com.intellij.openapi.Disposable +import org.jetbrains.kotlin.test.directives.ConfigurationDirectives +import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives import org.jetbrains.kotlin.test.directives.model.DirectivesContainer import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives import org.jetbrains.kotlin.test.model.* import org.jetbrains.kotlin.test.services.MetaTestConfigurator import org.jetbrains.kotlin.test.services.ModuleStructureExtractor +import org.jetbrains.kotlin.test.services.SourceFilePreprocessor import org.jetbrains.kotlin.test.services.TestServices typealias Constructor = (TestServices) -> T diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestRunner.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestRunner.kt index bfd22272781..fe9b7ccb97f 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestRunner.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestRunner.kt @@ -49,7 +49,7 @@ class TestRunner(private val testConfiguration: TestConfiguration) { var failedException: Throwable? = null try { for (module in modules) { - processModule(services, module, dependencyProvider, moduleStructure) + processModule(module, dependencyProvider, moduleStructure) } } catch (e: Throwable) { failedException = e @@ -81,7 +81,6 @@ class TestRunner(private val testConfiguration: TestConfiguration) { } private fun processModule( - services: TestServices, module: TestModule, dependencyProvider: DependencyProviderImpl, moduleStructure: TestModuleStructure @@ -100,7 +99,7 @@ class TestRunner(private val testConfiguration: TestConfiguration) { } } - val backendKind = services.backendKindExtractor.backendKind(module.targetBackend) + val backendKind = module.backendKind if (!backendKind.shouldRunAnalysis) return val backendInputInfo = testConfiguration.getFacade(frontendKind, backendKind) diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/directives/ModuleStructureDirectives.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/directives/ModuleStructureDirectives.kt index de9b0d1e39c..db1c132c7dd 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/directives/ModuleStructureDirectives.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/directives/ModuleStructureDirectives.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.test.directives -import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.directives.model.SimpleDirectivesContainer object ModuleStructureDirectives : SimpleDirectivesContainer() { @@ -46,7 +45,7 @@ object ModuleStructureDirectives : SimpleDirectivesContainer() { """.trimIndent() ) - val TARGET_BACKEND_KIND by enumDirective( + val TARGET_BACKEND_KIND by stringDirective( """ Usage: // TARGET_BACKEND: {Backend} Declares backend for analyzing current module diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/model/Modules.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/model/Modules.kt index 2d751ec9ea2..e645417efda 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/model/Modules.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/model/Modules.kt @@ -7,15 +7,14 @@ package org.jetbrains.kotlin.test.model import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.platform.TargetPlatform -import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives import java.io.File data class TestModule( val name: String, val targetPlatform: TargetPlatform, - val targetBackend: TargetBackend?, val frontendKind: FrontendKind<*>, + val backendKind: BackendKind<*>, val files: List, val dependencies: List, val directives: RegisteredDirectives, diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/BackendKindExtractor.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/BackendKindExtractor.kt deleted file mode 100644 index 95b947e8c5e..00000000000 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/BackendKindExtractor.kt +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright 2010-2020 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.services - -import org.jetbrains.kotlin.test.TargetBackend -import org.jetbrains.kotlin.test.model.BackendKind - -abstract class BackendKindExtractor(protected val testServices: TestServices) : TestService { - abstract fun backendKind(targetBackend: TargetBackend?): BackendKind<*> -} - -val TestServices.backendKindExtractor: BackendKindExtractor by TestServices.testServiceAccessor() diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/DefaultsProvider.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/DefaultsProvider.kt index 54310fdb033..78c23446c93 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/DefaultsProvider.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/DefaultsProvider.kt @@ -7,8 +7,8 @@ package org.jetbrains.kotlin.test.services import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.platform.TargetPlatform -import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.builders.LanguageVersionSettingsBuilder +import org.jetbrains.kotlin.test.model.BackendKind import org.jetbrains.kotlin.test.model.DependencyKind import org.jetbrains.kotlin.test.model.FrontendKind @@ -18,11 +18,11 @@ import org.jetbrains.kotlin.test.model.FrontendKind * - default libraries */ class DefaultsProvider( + val defaultBackend: BackendKind<*>, val defaultFrontend: FrontendKind<*>, val defaultLanguageSettings: LanguageVersionSettings, private val defaultLanguageSettingsBuilder: LanguageVersionSettingsBuilder, val defaultPlatform: TargetPlatform, - val defaultTargetBackend: TargetBackend?, val defaultDependencyKind: DependencyKind ) : TestService { fun newLanguageSettingsBuilder(): LanguageVersionSettingsBuilder { diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/BlackBoxCodegenSuppressor.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/BlackBoxCodegenSuppressor.kt index 3af0577e4d0..47f9befff9a 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/BlackBoxCodegenSuppressor.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/BlackBoxCodegenSuppressor.kt @@ -25,7 +25,7 @@ class BlackBoxCodegenSuppressor(testServices: TestServices) : AfterAnalysisCheck val moduleStructure = testServices.moduleStructure val ignoredBackends = moduleStructure.modules.flatMap { it.directives[CodegenTestDirectives.IGNORE_BACKEND] } if (ignoredBackends.isEmpty()) return failedAssertions - val targetBackends = moduleStructure.modules.map { it.targetBackend } + val targetBackends = moduleStructure.modules.flatMap { it.targetBackends } val matchedBackend = ignoredBackends.intersect(targetBackends) if (ignoredBackends.contains(TargetBackend.ANY)) { return processAssertions(failedAssertions) @@ -50,4 +50,19 @@ class BlackBoxCodegenSuppressor(testServices: TestServices) : AfterAnalysisCheck listOf(AssertionError(message)) } } + + private val TestModule.targetBackends: List + get() = when (backendKind) { + BackendKinds.ClassicBackend -> when { + targetPlatform.isJvm() -> listOf(TargetBackend.JVM, TargetBackend.JVM_OLD) + targetPlatform.isJs() -> listOf(TargetBackend.JS) + else -> emptyList() + } + BackendKinds.IrBackend -> when { + targetPlatform.isJvm() -> listOf(TargetBackend.JVM_IR) + targetPlatform.isJs() -> listOf(TargetBackend.JS_IR) + else -> emptyList() + } + else -> emptyList() + } } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/DefaultsProviderBuilder.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/DefaultsProviderBuilder.kt index 5a99cc25118..e46324d3713 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/DefaultsProviderBuilder.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/DefaultsProviderBuilder.kt @@ -11,16 +11,16 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl import org.jetbrains.kotlin.fir.PrivateForInline import org.jetbrains.kotlin.platform.TargetPlatform -import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.services.DefaultsDsl import org.jetbrains.kotlin.test.services.DefaultsProvider +import org.jetbrains.kotlin.test.model.BackendKind import org.jetbrains.kotlin.test.model.DependencyKind import org.jetbrains.kotlin.test.model.FrontendKind @DefaultsDsl class DefaultsProviderBuilder { + lateinit var backend: BackendKind<*> lateinit var frontend: FrontendKind<*> - var targetBackend: TargetBackend? = null lateinit var targetPlatform: TargetPlatform lateinit var dependencyKind: DependencyKind @@ -40,11 +40,11 @@ class DefaultsProviderBuilder { @OptIn(PrivateForInline::class) fun build(): DefaultsProvider { return DefaultsProvider( + backend, frontend, languageVersionSettings ?: LanguageVersionSettingsImpl(LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE), languageVersionSettingsBuilder ?: LanguageVersionSettingsBuilder(), targetPlatform, - targetBackend, dependencyKind ) } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/TestConfigurationBuilder.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/TestConfigurationBuilder.kt index 49a1486f04f..fac2eca53fd 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/TestConfigurationBuilder.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/builders/TestConfigurationBuilder.kt @@ -37,15 +37,6 @@ class TestConfigurationBuilder { val defaultRegisteredDirectivesBuilder: RegisteredDirectivesBuilder = RegisteredDirectivesBuilder() private val configurationsByTestDataCondition: MutableList Unit>> = mutableListOf() - private val additionalServices: MutableList = mutableListOf() - - inline fun useAdditionalService(noinline serviceConstructor: (TestServices) -> T) { - useAdditionalService(service(serviceConstructor)) - } - - fun useAdditionalService(serviceRegistrationData: ServiceRegistrationData) { - additionalServices += serviceRegistrationData - } fun forTestsMatching(pattern: String, configuration: TestConfigurationBuilder.() -> Unit) { val regex = pattern.toMatchingRegexString().toRegex() @@ -149,8 +140,7 @@ class TestConfigurationBuilder { afterAnalysisCheckers, metaInfoHandlerEnabled, directives, - defaultRegisteredDirectivesBuilder.build(), - additionalServices + defaultRegisteredDirectivesBuilder.build() ) } } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/impl/TestConfigurationImpl.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/impl/TestConfigurationImpl.kt index ceb321cb223..e82d9f6534e 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/impl/TestConfigurationImpl.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/impl/TestConfigurationImpl.kt @@ -35,16 +35,11 @@ class TestConfigurationImpl( override val metaInfoHandlerEnabled: Boolean, directives: List, - override val defaultRegisteredDirectives: RegisteredDirectives, - additionalServices: List + override val defaultRegisteredDirectives: RegisteredDirectives ) : TestConfiguration() { override val rootDisposable: Disposable = TestDisposable() override val testServices: TestServices = TestServices() - init { - additionalServices.forEach { testServices.register(it) } - } - private val allDirectives = directives.toMutableSet() override val directives: DirectivesContainer by lazy { when (allDirectives.size) { diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractKotlinCompilerTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractKotlinCompilerTest.kt index e9b40727887..89db141e50f 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractKotlinCompilerTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractKotlinCompilerTest.kt @@ -12,10 +12,8 @@ import org.jetbrains.kotlin.test.builders.testRunner import org.jetbrains.kotlin.test.directives.ConfigurationDirectives import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives import org.jetbrains.kotlin.test.preprocessors.MetaInfosCleanupPreprocessor -import org.jetbrains.kotlin.test.services.BackendKindExtractor import org.jetbrains.kotlin.test.services.JUnit5Assertions import org.jetbrains.kotlin.test.services.SourceFilePreprocessor -import org.jetbrains.kotlin.test.services.impl.BackendKindExtractorImpl import org.jetbrains.kotlin.types.AbstractTypeChecker import org.jetbrains.kotlin.types.FlexibleTypeImpl @@ -33,7 +31,6 @@ abstract class AbstractKotlinCompilerTest { private val configuration: TestConfigurationBuilder.() -> Unit = { assertions = JUnit5Assertions - useAdditionalService(::BackendKindExtractorImpl) useSourcePreprocessor(*defaultPreprocessors.toTypedArray()) useDirectives(*defaultDirectiveContainers.toTypedArray()) configureDebugFlags() diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/BackendKindExtractorImpl.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/BackendKindExtractorImpl.kt deleted file mode 100644 index 8ddb190714d..00000000000 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/BackendKindExtractorImpl.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2010-2020 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.services.impl - -import org.jetbrains.kotlin.test.TargetBackend -import org.jetbrains.kotlin.test.model.BackendKind -import org.jetbrains.kotlin.test.model.BackendKinds -import org.jetbrains.kotlin.test.services.BackendKindExtractor -import org.jetbrains.kotlin.test.services.TestServices - -class BackendKindExtractorImpl(testServices: TestServices) : BackendKindExtractor(testServices) { - override fun backendKind(targetBackend: TargetBackend?): BackendKind<*> { - return when (targetBackend) { - TargetBackend.ANY, - TargetBackend.JVM, - TargetBackend.JVM_OLD, - TargetBackend.ANDROID, - TargetBackend.JVM_MULTI_MODULE_OLD_AGAINST_IR -> BackendKinds.ClassicBackend - - TargetBackend.JVM_IR, - TargetBackend.JVM_MULTI_MODULE_IR_AGAINST_OLD, - TargetBackend.JS, - TargetBackend.JS_IR, - TargetBackend.JS_IR_ES6, - TargetBackend.WASM -> BackendKinds.IrBackend - - null -> BackendKind.NoBackend - } - } -} diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/ModuleStructureExtractorImpl.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/ModuleStructureExtractorImpl.kt index 759e606dd84..e2724ea52a7 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/ModuleStructureExtractorImpl.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/ModuleStructureExtractorImpl.kt @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.platform.js.JsPlatforms import org.jetbrains.kotlin.platform.jvm.JvmPlatforms import org.jetbrains.kotlin.platform.konan.NativePlatforms import org.jetbrains.kotlin.test.Assertions -import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.builders.LanguageVersionSettingsBuilder import org.jetbrains.kotlin.test.directives.ModuleStructureDirectives import org.jetbrains.kotlin.test.directives.model.ComposedRegisteredDirectives @@ -62,7 +61,7 @@ class ModuleStructureExtractorImpl( private var currentModuleName: String? = null private var currentModuleTargetPlatform: TargetPlatform? = null private var currentModuleFrontendKind: FrontendKind<*>? = null - private var currentModuleTargetBackend: TargetBackend? = null + private var currentModuleBackendKind: BackendKind<*>? = null private var currentModuleLanguageVersionSettingsBuilder: LanguageVersionSettingsBuilder = initLanguageSettingsBuilder() private var dependenciesOfCurrentModule = mutableListOf() private var filesOfCurrentModule = mutableListOf() @@ -172,7 +171,12 @@ class ModuleStructureExtractorImpl( } } ModuleStructureDirectives.TARGET_BACKEND_KIND -> { - currentModuleTargetBackend = values.single() as TargetBackend + val name = values.singleOrNull() as? String ?: assertions.fail { + "Target backend specified incorrectly\nUsage: ${directive.description}" + } + currentModuleBackendKind = BackendKinds.fromString(name) ?: assertions.fail { + "Unknown backend: $name" + } } ModuleStructureDirectives.FILE -> { if (currentFileName != null) { @@ -211,8 +215,8 @@ class ModuleStructureExtractorImpl( val testModule = TestModule( name = moduleName, targetPlatform = currentModuleTargetPlatform ?: parseModulePlatformByName(moduleName) ?: defaultsProvider.defaultPlatform, - targetBackend = currentModuleTargetBackend ?: defaultsProvider.defaultTargetBackend, frontendKind = currentModuleFrontendKind ?: defaultsProvider.defaultFrontend, + backendKind = currentModuleBackendKind ?: defaultsProvider.defaultBackend, files = filesOfCurrentModule, dependencies = dependenciesOfCurrentModule, directives = moduleDirectives, @@ -267,8 +271,8 @@ class ModuleStructureExtractorImpl( firstFileInModule = true currentModuleName = null currentModuleTargetPlatform = null - currentModuleTargetBackend = null currentModuleFrontendKind = null + currentModuleBackendKind = null currentModuleLanguageVersionSettingsBuilder = initLanguageSettingsBuilder() filesOfCurrentModule = mutableListOf() dependenciesOfCurrentModule = mutableListOf()