Skip to content

Commit 3914037

Browse files
ddolovovSpace Team
authored andcommitted
[Wasm] Soften the stdlib/kotlin-test version checker
Allow the compiler to consume libraries of the same LV but potentially compiled by a newer (minor) version of the compiler. ^KT-82208 Fixed
1 parent a43f249 commit 3914037

File tree

4 files changed

+70
-37
lines changed

4 files changed

+70
-37
lines changed

compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/checkers/WasmLibrarySpecialCompatibilityChecker.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.backend.common.diagnostics.LibrarySpecialCompatibili
99
import org.jetbrains.kotlin.library.KotlinLibrary
1010
import org.jetbrains.kotlin.library.isWasmKotlinTest
1111
import org.jetbrains.kotlin.library.isWasmStdlib
12-
import org.jetbrains.kotlin.utils.addToStdlib.runUnless
1312

1413
object WasmLibrarySpecialCompatibilityChecker : LibrarySpecialCompatibilityChecker() {
1514
override fun shouldCheckLibrary(library: KotlinLibrary) = library.isWasmStdlib || library.isWasmKotlinTest
@@ -20,10 +19,19 @@ object WasmLibrarySpecialCompatibilityChecker : LibrarySpecialCompatibilityCheck
2019
library.isWasmKotlinTest -> "kotlin-test"
2120
else -> null
2221
}
23-
return runUnless(libraryVersion == compilerVersion) {
24-
"The version of the Kotlin/Wasm $libraryDisplayName library ($libraryVersion) differs from the version of the compiler ($compilerVersion).\n" +
25-
"Please, make sure that the $libraryDisplayName library has the same version as the compiler. " +
26-
"Adjust your project's settings if necessary."
22+
23+
val rootCause = when {
24+
libraryVersion < compilerVersion ->
25+
"The Kotlin/Wasm $libraryDisplayName library has an older version ($libraryVersion) than the compiler ($compilerVersion). Such a configuration is not supported."
26+
27+
!libraryVersion.hasSameLanguageVersion(compilerVersion) ->
28+
"The Kotlin/Wasm $libraryDisplayName library has a more recent version ($libraryVersion) than the compiler supports. The compiler version is $compilerVersion."
29+
30+
else -> return null
2731
}
32+
33+
return "$rootCause\nPlease, make sure that the $libraryDisplayName library has the version in the range " +
34+
"[${compilerVersion.toComparableVersionString()} .. ${compilerVersion.toLanguageVersionString()}.${KotlinVersion.MAX_COMPONENT_VALUE}]. " +
35+
"Adjust your project's settings if necessary."
2836
}
2937
}

js/js.tests/testFixtures/org/jetbrains/kotlin/js/testOld/klib/LibrarySpecialCompatibilityChecksTest.kt

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,18 @@ import org.jetbrains.kotlin.konan.file.File as KFile
2222

2323
abstract class LibrarySpecialCompatibilityChecksTest : TestCaseWithTmpdir() {
2424

25-
fun testJsSameBasicCompilerVersion() = testSameBasicCompilerVersion(isWasm = false)
26-
27-
fun testWasmSameBasicCompilerVersion() = testSameBasicCompilerVersion(isWasm = true)
28-
29-
private fun testSameBasicCompilerVersion(isWasm: Boolean) {
25+
fun testSameBasicCompilerVersion() {
3026
for (versionsWithSameBasicVersion in SORTED_TEST_VERSION_GROUPS) {
3127
for (libraryVersion in versionsWithSameBasicVersion) {
3228
for (compilerVersion in versionsWithSameBasicVersion) {
33-
compileDummyLibrary(
34-
libraryVersion = libraryVersion,
35-
compilerVersion = compilerVersion,
36-
isWasm = isWasm,
37-
expectedWarningStatus = WarningStatus.NO_WARNINGS
38-
)
29+
for (isWasm in listOf(false, true)) {
30+
compileDummyLibrary(
31+
libraryVersion = libraryVersion,
32+
compilerVersion = compilerVersion,
33+
isWasm = isWasm,
34+
expectedWarningStatus = WarningStatus.NO_WARNINGS
35+
)
36+
}
3937
}
4038
}
4139
}
@@ -64,16 +62,26 @@ abstract class LibrarySpecialCompatibilityChecksTest : TestCaseWithTmpdir() {
6462
}
6563
}
6664

67-
fun testWasmMismatchingVersions() {
65+
fun testWasmNewerCompilerVersion() {
6866
testCurrentAndNextBasicVersions { currentVersion, nextVersion ->
69-
for ((libraryVersion, compilerVersion) in listOf(currentVersion to nextVersion, nextVersion to currentVersion)) {
70-
compileDummyLibrary(
71-
libraryVersion = libraryVersion,
72-
compilerVersion = compilerVersion,
73-
isWasm = true,
74-
expectedWarningStatus = WarningStatus.WASM_WARNING
75-
)
76-
}
67+
compileDummyLibrary(
68+
libraryVersion = currentVersion,
69+
compilerVersion = nextVersion,
70+
isWasm = true,
71+
expectedWarningStatus = WarningStatus.WASM_OLD_LIBRARY_WARNING
72+
)
73+
}
74+
}
75+
76+
fun testWasmOlderCompilerVersion() {
77+
testCurrentAndNextBasicVersions { currentVersion, nextVersion ->
78+
val sameLanguageVersion = haveSameLanguageVersion(currentVersion, nextVersion)
79+
compileDummyLibrary(
80+
libraryVersion = nextVersion,
81+
compilerVersion = currentVersion,
82+
isWasm = true,
83+
expectedWarningStatus = if (sameLanguageVersion) WarningStatus.NO_WARNINGS else WarningStatus.WASM_TOO_NEW_LIBRARY_WARNING
84+
)
7785
}
7886
}
7987

@@ -130,18 +138,20 @@ abstract class LibrarySpecialCompatibilityChecksTest : TestCaseWithTmpdir() {
130138

131139
protected abstract fun MessageCollectorImpl.hasJsOldLibraryError(specificVersions: Pair<TestVersion, TestVersion>? = null): Boolean
132140
protected abstract fun MessageCollectorImpl.hasJsTooNewLibraryError(specificVersions: Pair<TestVersion, TestVersion>? = null): Boolean
133-
protected abstract fun MessageCollectorImpl.hasWasmError(specificVersions: Pair<TestVersion, TestVersion>? = null): Boolean
141+
protected abstract fun MessageCollectorImpl.hasWasmOldLibraryError(specificVersions: Pair<TestVersion, TestVersion>? = null): Boolean
142+
protected abstract fun MessageCollectorImpl.hasWasmTooNewLibraryError(specificVersions: Pair<TestVersion, TestVersion>? = null): Boolean
134143

135144
private fun MessageCollectorImpl.checkMessage(
136145
expectedWarningStatus: WarningStatus,
137146
libraryVersion: TestVersion?,
138147
compilerVersion: TestVersion?,
139148
) {
140149
val success = when (expectedWarningStatus) {
141-
WarningStatus.NO_WARNINGS -> !hasJsOldLibraryError() && !hasJsTooNewLibraryError() && !hasWasmError()
150+
WarningStatus.NO_WARNINGS -> !hasJsOldLibraryError() && !hasJsTooNewLibraryError() && !hasWasmOldLibraryError() && !hasWasmTooNewLibraryError()
142151
WarningStatus.JS_OLD_LIBRARY_WARNING -> hasJsOldLibraryError(libraryVersion!! to compilerVersion!!)
143152
WarningStatus.JS_TOO_NEW_LIBRARY_WARNING -> hasJsTooNewLibraryError(libraryVersion!! to compilerVersion!!)
144-
WarningStatus.WASM_WARNING -> hasWasmError(libraryVersion!! to compilerVersion!!)
153+
WarningStatus.WASM_OLD_LIBRARY_WARNING -> hasWasmOldLibraryError(libraryVersion!! to compilerVersion!!)
154+
WarningStatus.WASM_TOO_NEW_LIBRARY_WARNING -> hasWasmTooNewLibraryError(libraryVersion!! to compilerVersion!!)
145155
}
146156
if (!success) fail(
147157
buildString {
@@ -197,7 +207,7 @@ abstract class LibrarySpecialCompatibilityChecksTest : TestCaseWithTmpdir() {
197207
private fun createFakeUnzippedLibraryWithSpecificVersion(isWasm: Boolean, version: TestVersion?): File {
198208
val rawVersion = version?.toString()
199209

200-
val patchedLibraryDir = createDir("dependencies/fakeLib-${rawVersion ?: "unknown"}")
210+
val patchedLibraryDir = createDir("dependencies/fakeLib-${rawVersion ?: "unknown"}-${if (isWasm) "wasm" else "js"}")
201211
val manifestFile = patchedLibraryDir.resolve("default").resolve("manifest")
202212
if (manifestFile.exists()) return patchedLibraryDir
203213

@@ -229,7 +239,7 @@ abstract class LibrarySpecialCompatibilityChecksTest : TestCaseWithTmpdir() {
229239
private fun createFakeZippedLibraryWithSpecificVersion(isWasm: Boolean, version: TestVersion?): File {
230240
val rawVersion = version?.toString()
231241

232-
val patchedLibraryFile = createFile("dependencies/fakeLib-${rawVersion ?: "unknown"}.klib")
242+
val patchedLibraryFile = createFile("dependencies/fakeLib-${rawVersion ?: "unknown"}-${if (isWasm) "wasm" else "js"}.klib")
233243
if (patchedLibraryFile.exists()) return patchedLibraryFile
234244

235245
val unzippedLibraryDir = createFakeUnzippedLibraryWithSpecificVersion(isWasm, version)
@@ -251,7 +261,7 @@ abstract class LibrarySpecialCompatibilityChecksTest : TestCaseWithTmpdir() {
251261
protected fun createDir(name: String): File = tmpdir.resolve(name).apply { mkdirs() }
252262
protected fun createFile(name: String): File = tmpdir.resolve(name).apply { parentFile.mkdirs() }
253263

254-
protected enum class WarningStatus { NO_WARNINGS, JS_OLD_LIBRARY_WARNING, JS_TOO_NEW_LIBRARY_WARNING, WASM_WARNING }
264+
protected enum class WarningStatus { NO_WARNINGS, JS_OLD_LIBRARY_WARNING, JS_TOO_NEW_LIBRARY_WARNING, WASM_OLD_LIBRARY_WARNING, WASM_TOO_NEW_LIBRARY_WARNING }
255265

256266
protected class TestVersion(val basicVersion: KotlinVersion, val postfix: String) : Comparable<TestVersion> {
257267
constructor(major: Int, minor: Int, patch: Int, postfix: String = "") : this(KotlinVersion(major, minor, patch), postfix)

js/js.tests/tests/org/jetbrains/kotlin/js/testOld/klib/JsWasmStdlibSpecialCompatibilityChecksTest.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,17 @@ class JsWasmStdlibSpecialCompatibilityChecksTest : LibrarySpecialCompatibilityCh
2828
return messages.any { stdlibMessagePart in it.message && compilerMessagePart in it.message }
2929
}
3030

31-
override fun MessageCollectorImpl.hasWasmError(specificVersions: Pair<TestVersion, TestVersion>?): Boolean {
32-
val stdlibMessagePart = "The version of the Kotlin/Wasm standard library" + specificVersions?.first?.let { " ($it)" }.orEmpty()
33-
val compilerMessagePart = "differs from the version of the compiler" + specificVersions?.second?.let { " ($it)" }.orEmpty()
31+
override fun MessageCollectorImpl.hasWasmOldLibraryError(specificVersions: Pair<TestVersion, TestVersion>?): Boolean {
32+
val stdlibMessagePart = "Kotlin/Wasm standard library has an older version" + specificVersions?.first?.let { " ($it)" }.orEmpty()
33+
val compilerMessagePart = "than the compiler" + specificVersions?.second?.let { " ($it)" }.orEmpty()
34+
35+
return messages.any { stdlibMessagePart in it.message && compilerMessagePart in it.message }
36+
}
37+
38+
override fun MessageCollectorImpl.hasWasmTooNewLibraryError(specificVersions: Pair<TestVersion, TestVersion>?): Boolean {
39+
val stdlibMessagePart =
40+
"The Kotlin/Wasm standard library has a more recent version" + specificVersions?.first?.let { " ($it)" }.orEmpty()
41+
val compilerMessagePart = "The compiler version is " + specificVersions?.second?.toString().orEmpty()
3442

3543
return messages.any { stdlibMessagePart in it.message && compilerMessagePart in it.message }
3644
}

js/js.tests/tests/org/jetbrains/kotlin/js/testOld/klib/JsWasmTestLibSpecialCompatibilityChecksTest.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ class JsWasmTestLibSpecialCompatibilityChecksTest : LibrarySpecialCompatibilityC
3333
return messages.any { stdlibMessagePart in it.message && compilerMessagePart in it.message }
3434
}
3535

36-
override fun MessageCollectorImpl.hasWasmError(specificVersions: Pair<TestVersion, TestVersion>?): Boolean {
36+
override fun MessageCollectorImpl.hasWasmOldLibraryError(specificVersions: Pair<TestVersion, TestVersion>?): Boolean {
37+
val stdlibMessagePart = "Kotlin/Wasm kotlin-test library has an older version" + specificVersions?.first?.let { " ($it)" }.orEmpty()
38+
val compilerMessagePart = "than the compiler" + specificVersions?.second?.let { " ($it)" }.orEmpty()
39+
40+
return messages.any { stdlibMessagePart in it.message && compilerMessagePart in it.message }
41+
}
42+
43+
override fun MessageCollectorImpl.hasWasmTooNewLibraryError(specificVersions: Pair<TestVersion, TestVersion>?): Boolean {
3744
val stdlibMessagePart =
38-
"The version of the Kotlin/Wasm kotlin-test library" + specificVersions?.first?.let { " ($it)" }.orEmpty()
39-
val compilerMessagePart = "differs from the version of the compiler" + specificVersions?.second?.let { " ($it)" }.orEmpty()
45+
"The Kotlin/Wasm kotlin-test library has a more recent version" + specificVersions?.first?.let { " ($it)" }.orEmpty()
46+
val compilerMessagePart = "The compiler version is " + specificVersions?.second?.toString().orEmpty()
4047

4148
return messages.any { stdlibMessagePart in it.message && compilerMessagePart in it.message }
4249
}

0 commit comments

Comments
 (0)