[K/N] KFC-446: K2 platform: Native alpha

Merge-request: KT-MR-7905
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
This commit is contained in:
Vladimir Sukharev
2023-01-04 16:10:40 +00:00
committed by Space Team
parent 97be632c9a
commit 924898afb7
134 changed files with 46701 additions and 100 deletions
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.generators.model.annotation
import org.jetbrains.kotlin.konan.blackboxtest.*
import org.jetbrains.kotlin.konan.blackboxtest.support.ClassLevelProperty
import org.jetbrains.kotlin.konan.blackboxtest.support.EnforcedProperty
import org.jetbrains.kotlin.konan.blackboxtest.support.group.K2Pipeline
import org.jetbrains.kotlin.konan.blackboxtest.support.group.UseExtTestCaseGroupProvider
import org.jetbrains.kotlin.konan.blackboxtest.support.group.UseStandardTestCaseGroupProvider
import org.jetbrains.kotlin.test.TargetBackend
@@ -30,6 +31,16 @@ fun main() {
}
}
testGroup("native/native.tests/tests-gen", "compiler/testData") {
testClass<AbstractNativeCodegenBoxTest>(
suiteTestClassName = "K2NativeCodegenBoxTestGenerated",
annotations = listOf(codegen(), provider<UseExtTestCaseGroupProvider>(), provider<K2Pipeline>())
) {
model("codegen/box", targetBackend = TargetBackend.NATIVE)
model("codegen/boxInline", targetBackend = TargetBackend.NATIVE)
}
}
// Samples (how to utilize the abilities of new test infrastructure).
testGroup("native/native.tests/tests-gen", "native/native.tests/testData") {
testClass<AbstractNativeBlackBoxTest>(
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.NativeTestSupport.getOrCr
import org.jetbrains.kotlin.konan.blackboxtest.support.NativeTestSupport.getOrCreateTestRunProvider
import org.jetbrains.kotlin.konan.blackboxtest.support.group.DisabledTests
import org.jetbrains.kotlin.konan.blackboxtest.support.group.DisabledTestsIfProperty
import org.jetbrains.kotlin.konan.blackboxtest.support.group.K2Pipeline
import org.jetbrains.kotlin.konan.blackboxtest.support.group.TestCaseGroupProvider
import org.jetbrains.kotlin.konan.blackboxtest.support.runner.SimpleTestRunProvider
import org.jetbrains.kotlin.konan.blackboxtest.support.runner.TestRunProvider
@@ -196,6 +197,8 @@ private object NativeTestSupport {
output += computeForcedStandaloneTestKind(enforcedProperties)
output += computeForcedNoopTestRunner(enforcedProperties)
output += computeTimeouts(enforcedProperties)
// Parse annotations of current class, since there's no way to put annotations to upper-level enclosing class
output += computePipelineType(testClass.get())
return nativeTargets
}
@@ -428,6 +431,12 @@ private object NativeTestSupport {
return Binaries(testBinariesDir, sharedBinariesDir, givenBinariesDir)
}
private fun computePipelineType(testClass: Class<*>): PipelineType {
return if (testClass.annotations.any { it is K2Pipeline })
PipelineType.K2
else PipelineType.K1
}
/*************** Test class settings (simplified) ***************/
private fun ExtensionContext.getOrCreateSimpleTestClassSettings(): SimpleTestClassSettings =
@@ -71,6 +71,7 @@ internal class NativeTestGroupingMessageCollector(
isPreReleaseBinariesWarning(message)
|| isUnsafeCompilerArgumentsWarning(message)
|| isLibraryIncludedMoreThanOnceWarning(message)
|| isK2Experimental(message)
|| isPartialLinkageWarning(message) -> {
// These warnings are known and should not be reported as errors.
severity
@@ -113,12 +114,16 @@ internal class NativeTestGroupingMessageCollector(
private fun isPartialLinkageWarning(message: String): Boolean =
partialLinkageEnabled && message.matches(PARTIAL_LINKAGE_WARNING_REGEX)
private fun isK2Experimental(message: String): Boolean = message.startsWith(K2_NATIVE_EXPERIMENTAL_WARNING_PREFIX)
override fun hasErrors() = hasWarningsWithRaisedSeverity || super.hasErrors()
companion object {
private const val PRE_RELEASE_WARNING_PREFIX = "Following manually enabled features will force generation of pre-release binaries: "
private const val UNSAFE_COMPILER_ARGS_WARNING_PREFIX = "ATTENTION!\nThis build uses unsafe internal compiler arguments:\n\n"
private const val LIBRARY_INCLUDED_MORE_THAN_ONCE_WARNING_PREFIX = "library included more than once: "
private const val K2_NATIVE_EXPERIMENTAL_WARNING_PREFIX = "New compiler pipeline K2 is experimental in Kotlin/Native."
private val PARTIAL_LINKAGE_WARNING_REGEX = Regex(".+ uses unlinked symbols(:.*)?")
private fun parseLanguageFeatureArg(arg: String): String? =
@@ -122,6 +122,7 @@ internal abstract class SourceBasedCompilation<A : TestCompilationArtifact>(
private val sanitizer: Sanitizer,
private val gcType: GCType,
private val gcScheduler: GCScheduler,
private val pipelineType: PipelineType,
freeCompilerArgs: TestCompilerArgs,
override val sourceModules: Collection<TestModule>,
dependencies: CategorizedDependencies,
@@ -142,6 +143,7 @@ internal abstract class SourceBasedCompilation<A : TestCompilationArtifact>(
sanitizer.compilerFlag?.let { compilerFlag -> add(compilerFlag) }
gcType.compilerFlag?.let { compilerFlag -> add(compilerFlag) }
gcScheduler.compilerFlag?.let { compilerFlag -> add(compilerFlag) }
pipelineType.compilerFlag?.let { compilerFlag -> add(compilerFlag) }
}
override fun applyDependencies(argsBuilder: ArgsBuilder): Unit = with(argsBuilder) {
@@ -169,6 +171,7 @@ internal class LibraryCompilation(
sanitizer = settings.get(),
gcType = settings.get(),
gcScheduler = settings.get(),
pipelineType = settings.get(),
freeCompilerArgs = freeCompilerArgs,
sourceModules = sourceModules,
dependencies = CategorizedDependencies(dependencies),
@@ -252,6 +255,7 @@ internal class ExecutableCompilation(
sanitizer = settings.get(),
gcType = settings.get(),
gcScheduler = settings.get(),
pipelineType = settings.get(),
freeCompilerArgs = freeCompilerArgs,
sourceModules = sourceModules,
dependencies = CategorizedDependencies(dependencies),
@@ -31,8 +31,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType
import org.jetbrains.kotlin.resolve.ImportPath
import org.jetbrains.kotlin.resolve.checkers.OptInNames
import org.jetbrains.kotlin.test.*
import org.jetbrains.kotlin.test.InTextDirectivesUtils.isCompatibleTarget
import org.jetbrains.kotlin.test.InTextDirectivesUtils.isIgnoredTarget
import org.jetbrains.kotlin.test.InTextDirectivesUtils.*
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
import org.jetbrains.kotlin.utils.addIfNotNull
@@ -73,6 +72,7 @@ internal class ExtTestCaseGroupProvider : TestCaseGroupProvider, TestDisposable(
testRoots = settings.get(),
generatedSources = settings.get(),
customKlibs = settings.get(),
pipelineType = settings.get(),
timeouts = settings.get()
)
@@ -97,6 +97,7 @@ private class ExtTestDataFile(
testRoots: TestRoots,
private val generatedSources: GeneratedSources,
private val customKlibs: CustomKlibs,
private val pipelineType: PipelineType,
private val timeouts: Timeouts
) {
private val structure by lazy {
@@ -136,12 +137,21 @@ private class ExtTestDataFile(
val isRelevant: Boolean =
isCompatibleTarget(TargetBackend.NATIVE, testDataFile) // Checks TARGET_BACKEND/DONT_TARGET_EXACT_BACKEND directives.
&& !isIgnoredTarget(TargetBackend.NATIVE, testDataFile) // Checks IGNORE_BACKEND directive.
&& !isIgnoredNativeTarget(pipelineType, testDataFile) // Checks IGNORE_BACKEND directives.
&& testDataFileSettings.languageSettings.none { it in INCOMPATIBLE_LANGUAGE_SETTINGS }
&& INCOMPATIBLE_DIRECTIVES.none { it in structure.directives }
&& structure.directives[API_VERSION_DIRECTIVE] !in INCOMPATIBLE_API_VERSIONS
&& structure.directives[LANGUAGE_VERSION_DIRECTIVE] !in INCOMPATIBLE_LANGUAGE_VERSIONS
private fun isIgnoredNativeTarget(pipelineType: PipelineType, testDataFile: File): Boolean {
return when (pipelineType) {
PipelineType.K1 ->
isIgnoredTarget(TargetBackend.NATIVE, testDataFile, IGNORE_BACKEND_DIRECTIVE_PREFIX, IGNORE_BACKEND_K1_DIRECTIVE_PREFIX)
PipelineType.K2 ->
isIgnoredTarget(TargetBackend.NATIVE, testDataFile, IGNORE_BACKEND_DIRECTIVE_PREFIX, IGNORE_BACKEND_K2_DIRECTIVE_PREFIX)
}
}
private fun assembleFreeCompilerArgs(): TestCompilerArgs {
val args = mutableListOf<String>()
testDataFileSettings.languageSettings.sorted().mapTo(args) { "-XXLanguage:$it" }
@@ -0,0 +1,8 @@
/*
* Copyright 2010-2022 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.konan.blackboxtest.support.group
@Target(AnnotationTarget.CLASS)
internal annotation class K2Pipeline
@@ -238,3 +238,10 @@ internal sealed interface CacheMode {
"$testTarget${if (debuggable) "-g" else ""}$cacheKind"
}
}
internal enum class PipelineType(val compilerFlag: String?) {
K1(null),
K2("-Xuse-k2");
override fun toString() = compilerFlag?.let { "($it)" }.orEmpty()
}