From e6297f92fafa2eb3608be4ac3513a92b644d6075 Mon Sep 17 00:00:00 2001 From: Alexander Shabalin Date: Wed, 15 Mar 2023 08:22:37 +0000 Subject: [PATCH] [K/N] Issue deprecation warning when using legacy MM Merge-request: KT-MR-9091 Merged-by: Alexander Shabalin --- .../jetbrains/kotlin/backend/konan/KonanConfig.kt | 13 ++++++++----- .../kotlin/konan/blackboxtest/CompilerOutputTest.kt | 9 +++++++-- .../NativeTestGroupingMessageCollector.kt | 7 ++++++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt index e9d1741d8c6..ebb6ee3ee76 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt @@ -82,22 +82,25 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration val memoryModel: MemoryModel by lazy { when (configuration.get(BinaryOptions.memoryModel)) { - MemoryModel.STRICT -> MemoryModel.STRICT + MemoryModel.STRICT -> { + configuration.report(CompilerMessageSeverity.STRONG_WARNING, "Legacy MM is deprecated and will be removed in version 1.9.20") + MemoryModel.STRICT + } MemoryModel.RELAXED -> { configuration.report(CompilerMessageSeverity.ERROR, - "Relaxed MM is deprecated and isn't expected to work right way with current Kotlin version. Using legacy MM.") + "Relaxed MM is deprecated and isn't expected to work right way with current Kotlin version.") MemoryModel.STRICT } MemoryModel.EXPERIMENTAL -> { if (!target.supportsThreads()) { configuration.report(CompilerMessageSeverity.STRONG_WARNING, - "New MM requires threads, which are not supported on target ${target.name}. Using legacy MM.") + "New MM requires threads, which are not supported on a deprecated target ${target.name}. Using deprecated legacy MM.") MemoryModel.STRICT } else { MemoryModel.EXPERIMENTAL } } - null -> defaultMemoryModel + null -> defaultMemoryModel // If target does not support threads, it's deprecated, no need to spam with our own deprecation message. }.also { if (it == MemoryModel.EXPERIMENTAL && destroyRuntimeMode == DestroyRuntimeMode.LEGACY) { configuration.report(CompilerMessageSeverity.ERROR, @@ -544,4 +547,4 @@ private fun String.isRelease(): Boolean { ?: throw IllegalStateException("Cannot parse Kotlin/Native version: $this") return metaString.isEmpty() && build.isEmpty() -} \ No newline at end of file +} diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/CompilerOutputTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/CompilerOutputTest.kt index 07b12bf59d0..ec7d6d95e72 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/CompilerOutputTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/CompilerOutputTest.kt @@ -14,6 +14,7 @@ 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 @@ -88,10 +89,14 @@ class CompilerOutputTest : AbstractNativeSimpleTest() { } private fun normalizeOutput(output: String, exitCode: ExitCode): String { - return AbstractCliTest.getNormalizedCompilerOutput( + var normalizedOutput = AbstractCliTest.getNormalizedCompilerOutput( output, exitCode, "compiler/testData/compileKotlinAgainstCustomBinaries/" ) + if (testRunSettings.get() != MemoryModel.EXPERIMENTAL) { + normalizedOutput = normalizedOutput.replace("warning: legacy MM is deprecated and will be removed in version 1.9.20\n", "") + } + return normalizedOutput } -} \ No newline at end of file +} diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/NativeTestGroupingMessageCollector.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/NativeTestGroupingMessageCollector.kt index 67174248ddd..ad3415d66e3 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/NativeTestGroupingMessageCollector.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/NativeTestGroupingMessageCollector.kt @@ -72,7 +72,8 @@ internal class NativeTestGroupingMessageCollector( || isUnsafeCompilerArgumentsWarning(message) || isLibraryIncludedMoreThanOnceWarning(message) || isK2Experimental(message) - || isPartialLinkageWarning(message) -> { + || isPartialLinkageWarning(message) + || isLegacyMMWarning(message) -> { // These warnings are known and should not be reported as errors. severity } @@ -117,6 +118,9 @@ 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) + override fun hasErrors() = hasWarningsWithRaisedSeverity || super.hasErrors() companion object { @@ -125,6 +129,7 @@ internal class NativeTestGroupingMessageCollector( 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 val PARTIAL_LINKAGE_WARNING_REGEX = Regex(".+ uses unlinked symbols(:.*)?") + private const val LEGACY_MM_WARNING_PREFIX = "Legacy MM is deprecated and will be removed" private fun parseLanguageFeatureArg(arg: String): String? = substringAfter(arg, "-XXLanguage:-") ?: substringAfter(arg, "-XXLanguage:+")