Split language and api version lifetimes, restore apiVersion 1.3 support

KT-49007
This commit is contained in:
Ilya Gorbunov
2021-09-17 21:01:35 +03:00
committed by TeamCityServer
parent 47adc4fdaa
commit ec5c06238d
6 changed files with 82 additions and 78 deletions
@@ -1,17 +1,6 @@
/* /*
* Copyright 2010-2017 JetBrains s.r.o. * Copyright 2010-2021 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.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.jetbrains.kotlin.cli.common.arguments package org.jetbrains.kotlin.cli.common.arguments
@@ -50,7 +39,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
@get:Transient @get:Transient
var autoAdvanceApiVersion: Boolean by FreezableVar(true) var autoAdvanceApiVersion: Boolean by FreezableVar(true)
@GradleOption(DefaultValues.LanguageVersions::class) @GradleOption(DefaultValues.ApiVersions::class)
@Argument( @Argument(
value = "-api-version", value = "-api-version",
valueDescription = "<version>", valueDescription = "<version>",
@@ -548,13 +537,13 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
// If only "-language-version" is specified, API version is assumed to be equal to the language version // If only "-language-version" is specified, API version is assumed to be equal to the language version
// (API version cannot be greater than the language version) // (API version cannot be greater than the language version)
val apiVersion = parseVersion(collector, apiVersion, "API") ?: languageVersion val apiVersion = ApiVersion.createByLanguageVersion(parseVersion(collector, apiVersion, "API") ?: languageVersion)
checkApiVersionIsNotGreaterThenLanguageVersion(languageVersion, apiVersion, collector) checkApiVersionIsNotGreaterThenLanguageVersion(languageVersion, apiVersion, collector)
val languageVersionSettings = LanguageVersionSettingsImpl( val languageVersionSettings = LanguageVersionSettingsImpl(
languageVersion, languageVersion,
ApiVersion.createByLanguageVersion(apiVersion), apiVersion,
configureAnalysisFlags(collector, languageVersion), configureAnalysisFlags(collector, languageVersion),
configureLanguageFeatures(collector) configureLanguageFeatures(collector)
) )
@@ -570,10 +559,10 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
private fun checkApiVersionIsNotGreaterThenLanguageVersion( private fun checkApiVersionIsNotGreaterThenLanguageVersion(
languageVersion: LanguageVersion, languageVersion: LanguageVersion,
apiVersion: LanguageVersion, apiVersion: ApiVersion,
collector: MessageCollector collector: MessageCollector
) { ) {
if (apiVersion > languageVersion) { if (apiVersion > ApiVersion.createByLanguageVersion(languageVersion)) {
collector.report( collector.report(
CompilerMessageSeverity.ERROR, CompilerMessageSeverity.ERROR,
"-api-version (${apiVersion.versionString}) cannot be greater than -language-version (${languageVersion.versionString})" "-api-version (${apiVersion.versionString}) cannot be greater than -language-version (${languageVersion.versionString})"
@@ -591,14 +580,14 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
} }
} }
private fun checkOutdatedVersions(language: LanguageVersion, api: LanguageVersion, collector: MessageCollector) { private fun checkOutdatedVersions(language: LanguageVersion, api: ApiVersion, collector: MessageCollector) {
val (version, versionKind) = findOutdatedVersion(language, api) ?: return val (version, supportedVersion, versionKind) = findOutdatedVersion(language, api) ?: return
when { when {
version.isUnsupported -> { version.isUnsupported -> {
collector.report( collector.report(
CompilerMessageSeverity.ERROR, CompilerMessageSeverity.ERROR,
"${versionKind.text} version ${version.versionString} is no longer supported; " + "${versionKind.text} version ${version.versionString} is no longer supported; " +
"please, use version ${LanguageVersion.OLDEST_DEPRECATED.versionString} or greater." "please, use version ${supportedVersion!!.versionString} or greater."
) )
} }
version.isDeprecated -> { version.isDeprecated -> {
@@ -611,12 +600,12 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
} }
} }
private fun findOutdatedVersion(language: LanguageVersion, api: LanguageVersion): Pair<LanguageVersion, VersionKind>? { private fun findOutdatedVersion(language: LanguageVersion, api: ApiVersion): Triple<LanguageOrApiVersion, LanguageOrApiVersion?, VersionKind>? {
return when { return when {
language.isUnsupported -> language to VersionKind.LANGUAGE language.isUnsupported -> Triple(language, LanguageVersion.FIRST_SUPPORTED, VersionKind.LANGUAGE)
api.isUnsupported -> api to VersionKind.API api.isUnsupported -> Triple(api, ApiVersion.FIRST_SUPPORTED, VersionKind.API)
language.isDeprecated -> language to VersionKind.LANGUAGE language.isDeprecated -> Triple(language, null, VersionKind.LANGUAGE)
api.isDeprecated -> api to VersionKind.API api.isDeprecated -> Triple(api, null, VersionKind.API)
else -> null else -> null
} }
} }
@@ -1,23 +1,13 @@
/* /*
* Copyright 2010-2017 JetBrains s.r.o. * Copyright 2010-2021 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.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.jetbrains.kotlin.cli.common.arguments package org.jetbrains.kotlin.cli.common.arguments
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.CALL import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.CALL
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.NO_CALL import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.NO_CALL
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.config.JvmTarget import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.LanguageVersion import org.jetbrains.kotlin.config.LanguageVersion
@@ -37,6 +27,14 @@ open class DefaultValues(val defaultValue: String, val possibleValues: List<Stri
.map { "\"${it.description}\"" } .map { "\"${it.description}\"" }
) )
object ApiVersions : DefaultValues(
"null",
LanguageVersion.values()
.map(ApiVersion.Companion::createByLanguageVersion)
.filterNot { it.isUnsupported }
.map { "\"${it.description}\"" }
)
object JvmTargetVersions : DefaultValues( object JvmTargetVersions : DefaultValues(
"\"" + JvmTarget.DEFAULT.description + "\"", "\"" + JvmTarget.DEFAULT.description + "\"",
JvmTarget.values().map { "\"${it.description}\"" } JvmTarget.values().map { "\"${it.description}\"" }
+1 -1
View File
@@ -1,2 +1,2 @@
error: API version 1.1 is no longer supported; please, use version 1.4 or greater. error: API version 1.1 is no longer supported; please, use version 1.3 or greater.
COMPILATION_ERROR COMPILATION_ERROR
@@ -1,17 +1,6 @@
/* /*
* Copyright 2010-2017 JetBrains s.r.o. * Copyright 2010-2021 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.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.jetbrains.kotlin.config package org.jetbrains.kotlin.config
@@ -20,13 +9,17 @@ import org.jetbrains.kotlin.utils.DescriptionAware
class ApiVersion private constructor( class ApiVersion private constructor(
val version: MavenComparableVersion, val version: MavenComparableVersion,
val versionString: String override val versionString: String
) : Comparable<ApiVersion>, DescriptionAware { ) : Comparable<ApiVersion>, DescriptionAware, LanguageOrApiVersion {
val isStable: Boolean
get() = this <= ApiVersion.LATEST_STABLE
override val description: String override val isStable: Boolean
get() = if (isStable) versionString else "$versionString (EXPERIMENTAL)" get() = this <= LATEST_STABLE
override val isDeprecated: Boolean
get() = FIRST_SUPPORTED <= this && this < FIRST_NON_DEPRECATED
override val isUnsupported: Boolean
get() = this < FIRST_SUPPORTED
override fun compareTo(other: ApiVersion): Int = override fun compareTo(other: ApiVersion): Int =
version.compareTo(other.version) version.compareTo(other.version)
@@ -70,6 +63,12 @@ class ApiVersion private constructor(
@JvmField @JvmField
val LATEST_STABLE: ApiVersion = createByLanguageVersion(LanguageVersion.LATEST_STABLE) val LATEST_STABLE: ApiVersion = createByLanguageVersion(LanguageVersion.LATEST_STABLE)
@JvmField
val FIRST_SUPPORTED: ApiVersion = createByLanguageVersion(LanguageVersion.FIRST_API_SUPPORTED)
@JvmField
val FIRST_NON_DEPRECATED: ApiVersion = createByLanguageVersion(LanguageVersion.FIRST_NON_DEPRECATED)
@JvmStatic @JvmStatic
fun createByLanguageVersion(version: LanguageVersion): ApiVersion = parse(version.versionString)!! fun createByLanguageVersion(version: LanguageVersion): ApiVersion = parse(version.versionString)!!
@@ -326,7 +326,7 @@ enum class LanguageFeature(
} }
} }
enum class LanguageVersion(val major: Int, val minor: Int) : DescriptionAware { enum class LanguageVersion(val major: Int, val minor: Int) : DescriptionAware, LanguageOrApiVersion {
KOTLIN_1_0(1, 0), KOTLIN_1_0(1, 0),
KOTLIN_1_1(1, 1), KOTLIN_1_1(1, 1),
KOTLIN_1_2(1, 2), KOTLIN_1_2(1, 2),
@@ -337,26 +337,18 @@ enum class LanguageVersion(val major: Int, val minor: Int) : DescriptionAware {
KOTLIN_1_7(1, 7), KOTLIN_1_7(1, 7),
; ;
val isStable: Boolean override val isStable: Boolean
get() = this <= LATEST_STABLE get() = this <= LATEST_STABLE
val isDeprecated: Boolean override val isDeprecated: Boolean
get() = OLDEST_DEPRECATED <= this && this < FIRST_SUPPORTED get() = FIRST_SUPPORTED <= this && this < FIRST_NON_DEPRECATED
val isUnsupported: Boolean override val isUnsupported: Boolean
get() = this < OLDEST_DEPRECATED get() = this < FIRST_SUPPORTED
val versionString: String override val versionString: String
get() = "$major.$minor" get() = "$major.$minor"
override val description: String
get() = when {
!isStable -> "$versionString (EXPERIMENTAL)"
isDeprecated -> "$versionString (DEPRECATED)"
isUnsupported -> "$versionString (UNSUPPORTED)"
else -> versionString
}
override fun toString() = versionString override fun toString() = versionString
companion object { companion object {
@@ -367,17 +359,43 @@ enum class LanguageVersion(val major: Int, val minor: Int) : DescriptionAware {
fun fromFullVersionString(str: String) = fun fromFullVersionString(str: String) =
str.split(".", "-").let { if (it.size >= 2) fromVersionString("${it[0]}.${it[1]}") else null } str.split(".", "-").let { if (it.size >= 2) fromVersionString("${it[0]}.${it[1]}") else null }
@JvmField // Version status
val OLDEST_DEPRECATED = KOTLIN_1_4 // 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7
// Language: UNSUPPORTED -------> DEPRECATED -> STABLE ---> EXPERIMENTAL
// API: UNSUPPORTED --> DEPRECATED ------> STABLE ---> EXPERIMENTAL
@JvmField @JvmField
val FIRST_SUPPORTED = KOTLIN_1_5 val FIRST_API_SUPPORTED = KOTLIN_1_3
@JvmField
val FIRST_SUPPORTED = KOTLIN_1_4
@JvmField
val FIRST_NON_DEPRECATED = KOTLIN_1_5
@JvmField @JvmField
val LATEST_STABLE = KOTLIN_1_6 val LATEST_STABLE = KOTLIN_1_6
} }
} }
interface LanguageOrApiVersion : DescriptionAware {
val versionString: String
val isStable: Boolean
val isDeprecated: Boolean
val isUnsupported: Boolean
override val description: String
get() = when {
!isStable -> "$versionString (EXPERIMENTAL)"
isDeprecated -> "$versionString (DEPRECATED)"
isUnsupported -> "$versionString (UNSUPPORTED)"
else -> versionString
}
}
fun LanguageVersion.isStableOrReadyForPreview(): Boolean = fun LanguageVersion.isStableOrReadyForPreview(): Boolean =
isStable isStable
@@ -7,7 +7,7 @@ interface KotlinCommonOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonToo
/** /**
* Allow using declarations only from the specified version of bundled libraries * Allow using declarations only from the specified version of bundled libraries
* Possible values: "1.4 (DEPRECATED)", "1.5", "1.6", "1.7 (EXPERIMENTAL)" * Possible values: "1.3 (DEPRECATED)", "1.4 (DEPRECATED)", "1.5", "1.6", "1.7 (EXPERIMENTAL)"
* Default value: null * Default value: null
*/ */
var apiVersion: kotlin.String? var apiVersion: kotlin.String?