[K/N] Do not compile for deprecated targets and legacy MM

^KT-56533
^KT-58853
This commit is contained in:
Alexander Shabalin
2023-05-12 16:02:48 +02:00
committed by Space Team
parent d1ce55cbd2
commit aea8bac7d2
54 changed files with 128 additions and 2191 deletions
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.LibraryCompil
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationArtifact
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationResult
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationResult.Companion.assertSuccess
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.MemoryModel
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.junit.jupiter.api.Test
import java.io.File
@@ -89,14 +88,10 @@ class CompilerOutputTest : AbstractNativeSimpleTest() {
}
private fun normalizeOutput(output: String, exitCode: ExitCode): String {
var normalizedOutput = AbstractCliTest.getNormalizedCompilerOutput(
return AbstractCliTest.getNormalizedCompilerOutput(
output,
exitCode,
"compiler/testData/compileKotlinAgainstCustomBinaries/"
)
if (testRunSettings.get<MemoryModel>() != MemoryModel.EXPERIMENTAL) {
normalizedOutput = normalizedOutput.replace("warning: legacy MM is deprecated and will be removed in version 1.9.20\n", "")
}
return normalizedOutput
}
}
@@ -60,7 +60,6 @@ internal enum class ClassLevelProperty(shortName: String) {
FORCE_STANDALONE("forceStandalone"),
COMPILE_ONLY("compileOnly"),
OPTIMIZATION_MODE("optimizationMode"),
MEMORY_MODEL("memoryModel"),
USE_THREAD_STATE_CHECKER("useThreadStateChecker"),
GC_TYPE("gcType"),
GC_SCHEDULER("gcScheduler"),
@@ -150,13 +150,9 @@ private object NativeTestSupport {
val enforcedProperties = EnforcedProperties(enclosingTestClass)
val optimizationMode = computeOptimizationMode(enforcedProperties)
val memoryModel = computeMemoryModel(enforcedProperties)
val threadStateChecker = computeThreadStateChecker(enforcedProperties)
if (threadStateChecker == ThreadStateChecker.ENABLED) {
assertEquals(MemoryModel.EXPERIMENTAL, memoryModel) {
"Thread state checker can be enabled only with experimental memory model"
}
assertEquals(OptimizationMode.DEBUG, optimizationMode) {
"Thread state checker can be enabled only with debug optimization mode"
}
@@ -164,18 +160,8 @@ private object NativeTestSupport {
val sanitizer = computeSanitizer(enforcedProperties)
val gcType = computeGCType(enforcedProperties)
if (gcType != GCType.UNSPECIFIED) {
assertEquals(MemoryModel.EXPERIMENTAL, memoryModel) {
"GC type can be specified only with experimental memory model"
}
}
val gcScheduler = computeGCScheduler(enforcedProperties)
if (gcScheduler != GCScheduler.UNSPECIFIED) {
assertEquals(MemoryModel.EXPERIMENTAL, memoryModel) {
"GC scheduler can be specified only with experimental memory model"
}
}
val nativeHome = getOrCreateTestProcessSettings().get<KotlinNativeHome>()
@@ -194,7 +180,6 @@ private object NativeTestSupport {
}
output += optimizationMode
output += memoryModel
output += threadStateChecker
output += gcType
output += gcScheduler
@@ -221,9 +206,6 @@ private object NativeTestSupport {
default = OptimizationMode.DEBUG
)
private fun computeMemoryModel(enforcedProperties: EnforcedProperties): MemoryModel =
ClassLevelProperty.MEMORY_MODEL.readValue(enforcedProperties, MemoryModel.values(), default = MemoryModel.EXPERIMENTAL)
private fun computeThreadStateChecker(enforcedProperties: EnforcedProperties): ThreadStateChecker {
val useThreadStateChecker =
ClassLevelProperty.USE_THREAD_STATE_CHECKER.readValue(enforcedProperties, String::toBooleanStrictOrNull, default = false)
@@ -68,7 +68,6 @@ internal class NativeTestGroupingMessageCollector(
|| isUnsafeCompilerArgumentsWarning(message)
|| isLibraryIncludedMoreThanOnceWarning(message)
|| isK2Experimental(message)
|| isLegacyMMWarning(message)
|| isPartialLinkageWarning(message) -> {
// These warnings are known and should not be reported as errors.
severity
@@ -110,9 +109,6 @@ internal class NativeTestGroupingMessageCollector(
private fun isK2Experimental(message: String): Boolean = message.startsWith(K2_NATIVE_EXPERIMENTAL_WARNING_PREFIX)
// Legacy MM is deprecated and will be removed in 1.9.20. Until that moment we still need to run tests with it.
private fun isLegacyMMWarning(message: String): Boolean = message.startsWith(LEGACY_MM_WARNING_PREFIX)
private fun isPartialLinkageWarning(message: String): Boolean = message.matches(PARTIAL_LINKAGE_WARNING_REGEX)
override fun hasErrors() = hasWarningsWithRaisedSeverity || super.hasErrors()
@@ -122,7 +118,6 @@ internal class NativeTestGroupingMessageCollector(
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 = "Language version 2.0 is experimental"
private const val LEGACY_MM_WARNING_PREFIX = "Legacy MM is deprecated and will be removed"
private val PARTIAL_LINKAGE_WARNING_REGEX = Regex("^<[^<>]+>( @ (?:(?!: ).)+)?: .*")
@@ -128,7 +128,6 @@ internal abstract class SourceBasedCompilation<A : TestCompilationArtifact>(
classLoader: KotlinNativeClassLoader,
optimizationMode: OptimizationMode,
compilerOutputInterceptor: CompilerOutputInterceptor,
private val memoryModel: MemoryModel,
private val threadStateChecker: ThreadStateChecker,
private val sanitizer: Sanitizer,
private val gcType: GCType,
@@ -150,7 +149,6 @@ internal abstract class SourceBasedCompilation<A : TestCompilationArtifact>(
) {
override fun applySpecificArgs(argsBuilder: ArgsBuilder): Unit = with(argsBuilder) {
add("-repo", home.librariesDir.path)
memoryModel.compilerFlags?.let { compilerFlags -> add(compilerFlags) }
threadStateChecker.compilerFlag?.let { compilerFlag -> add(compilerFlag) }
sanitizer.compilerFlag?.let { compilerFlag -> add(compilerFlag) }
gcType.compilerFlag?.let { compilerFlag -> add(compilerFlag) }
@@ -191,7 +189,6 @@ internal class LibraryCompilation(
classLoader = settings.get(),
optimizationMode = settings.get(),
compilerOutputInterceptor = settings.get(),
memoryModel = settings.get(),
threadStateChecker = settings.get(),
sanitizer = settings.get(),
gcType = settings.get(),
@@ -225,7 +222,6 @@ internal class ObjCFrameworkCompilation(
classLoader = settings.get(),
optimizationMode = settings.get(),
compilerOutputInterceptor = settings.get(),
memoryModel = settings.get(),
threadStateChecker = settings.get(),
sanitizer = settings.get(),
gcType = settings.get(),
@@ -310,7 +306,6 @@ internal class ExecutableCompilation(
classLoader = settings.get(),
optimizationMode = settings.get(),
compilerOutputInterceptor = settings.get(),
memoryModel = settings.get(),
threadStateChecker = settings.get(),
sanitizer = settings.get(),
gcType = settings.get(),
@@ -75,7 +75,6 @@ internal class ExtTestCaseGroupProvider : TestCaseGroupProvider, TestDisposable(
customKlibs = settings.get(),
pipelineType = settings.get(),
timeouts = settings.get(),
memoryModel = settings.get(),
)
if (extTestDataFile.isRelevant)
@@ -101,7 +100,6 @@ private class ExtTestDataFile(
private val customKlibs: CustomKlibs,
private val pipelineType: PipelineType,
private val timeouts: Timeouts,
private val memoryModel: MemoryModel
) {
private val structure by lazy {
val allSourceTransformers: ExternalSourceTransformers = if (customSourceTransformers.isNullOrEmpty())
@@ -141,7 +139,6 @@ private class ExtTestDataFile(
val isRelevant: Boolean =
isCompatibleTarget(TargetBackend.NATIVE, testDataFile) // Checks TARGET_BACKEND/DONT_TARGET_EXACT_BACKEND directives.
&& !isIgnoredTarget(pipelineType, testDataFile, TargetBackend.NATIVE) // Checks IGNORE_BACKEND directives.
&& (memoryModel != MemoryModel.LEGACY || !isIgnoredTarget(pipelineType, testDataFile, TargetBackend.NATIVE_WITH_LEGACY_MM)) // 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
@@ -180,10 +177,6 @@ private class ExtTestDataFile(
fun createTestCase(settings: Settings, sharedModules: ThreadSafeCache<String, TestModule.Shared?>): TestCase {
assertTrue(isRelevant)
if (settings.get<MemoryModel>() == MemoryModel.LEGACY) {
makeObjectsMutable()
}
val definitelyStandaloneTest = settings.get<ForcedStandaloneTestKind>().value
val isStandaloneTest = definitelyStandaloneTest || determineIfStandaloneTest()
patchPackageNames(isStandaloneTest)
@@ -221,25 +214,6 @@ private class ExtTestDataFile(
isStandaloneTest
}
/** Annotate all objects and companion objects with [THREAD_LOCAL_ANNOTATION] to make them mutable. */
private fun makeObjectsMutable() = with(structure) {
filesToTransform.forEach { handler ->
handler.accept(object : KtTreeVisitorVoid() {
override fun visitObjectDeclaration(objectDeclaration: KtObjectDeclaration) {
if (!objectDeclaration.isObjectLiteral()) {
// FIXME: find only those that have vars inside
addAnnotationEntry(
objectDeclaration,
handler.psiFactory.createAnnotationEntry(THREAD_LOCAL_ANNOTATION)
).ensureSurroundedByWhiteSpace()
}
super.visitObjectDeclaration(objectDeclaration)
}
})
}
}
/**
* For every Kotlin file (*.kt) stored in this text:
*
@@ -581,8 +555,6 @@ private class ExtTestDataFile(
private fun Directives.multiValues(key: String, predicate: (String) -> Boolean = { true }): Set<String> =
listValues(key)?.flatMap { it.split(' ') }?.filter(predicate)?.toSet().orEmpty()
private const val THREAD_LOCAL_ANNOTATION = "@kotlin.native.ThreadLocal"
private val BOX_FUNCTION_NAME = Name.identifier("box")
private val OPT_IN_ANNOTATION_NAME = Name.identifier("OptIn")
private val HELPERS_PACKAGE_NAME = Name.identifier("helpers")
@@ -117,20 +117,7 @@ internal enum class OptimizationMode(private val description: String, val compil
}
/**
* The Kotlin/Native memory model.
*/
internal enum class MemoryModel(val compilerFlags: List<String>?) {
/**
* but it should be done at some point.
*/
LEGACY(listOf("-memory-model", "strict")),
EXPERIMENTAL(listOf("-memory-model", "experimental"));
override fun toString() = compilerFlags?.joinToString(prefix = "(", separator = " ", postfix = ")").orEmpty()
}
/**
* Thread state checked. Can be applied only with [MemoryModel.EXPERIMENTAL], [OptimizationMode.DEBUG], [CacheMode.WithoutCache].
* Thread state checked. Can be applied only with [OptimizationMode.DEBUG], [CacheMode.WithoutCache].
*/
internal enum class ThreadStateChecker(val compilerFlag: String?) {
DISABLED(null),
@@ -150,7 +137,7 @@ internal enum class Sanitizer(val compilerFlag: String?) {
}
/**
* Garbage collector type. Can be applied only with [MemoryModel.EXPERIMENTAL].
* Garbage collector type.
*/
internal enum class GCType(val compilerFlag: String?) {
UNSPECIFIED(null),