JvmDefault: remove -Xjvm-default modes "enable" and "compatibility"

#KT-54746
This commit is contained in:
Alexander Udalov
2023-04-22 00:28:51 +02:00
committed by Space Team
parent e0b5ae7781
commit a0790047f7
4 changed files with 16 additions and 23 deletions
@@ -466,7 +466,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
@Argument(
value = "-Xjvm-default",
valueDescription = "{all|all-compatibility|disable|enable|compatibility}",
valueDescription = "{all|all-compatibility|disable}",
description = """Emit JVM default methods for interface declarations with bodies. Default is 'disable'.
-Xjvm-default=all Generate JVM default methods for all interface declarations with bodies in the module.
Do not generate DefaultImpls stubs for interface declarations with bodies, which are generated by default
@@ -474,7 +474,6 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
mode and doesn't override it, then a DefaultImpls stub will be generated for it.
BREAKS BINARY COMPATIBILITY if some client code relies on the presence of DefaultImpls classes.
Note that if interface delegation is used, all interface methods are delegated.
The only exception are methods annotated with the deprecated @JvmDefault annotation.
-Xjvm-default=all-compatibility In addition to the 'all' mode, generate compatibility stubs in the DefaultImpls classes.
Compatibility stubs could be useful for library and runtime authors to keep backward binary compatibility
for existing clients compiled against previous library versions.
@@ -487,11 +486,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
additional implicit method with specialized signatures was generated in the 'disable' mode:
unlike in the 'disable' mode, the compiler will report an error if such method is not overridden explicitly
and the class is not annotated with @JvmDefaultWithoutCompatibility (see KT-39603 for more details).
-Xjvm-default=disable Default behavior. Do not generate JVM default methods and prohibit @JvmDefault annotation usage.
-Xjvm-default=enable Deprecated. Allow usages of @JvmDefault; only generate the default method for annotated method
in the interface (annotating an existing method can break binary compatibility).
-Xjvm-default=compatibility Deprecated. Allow usages of @JvmDefault; generate a compatibility accessor
in the DefaultImpls class in addition to the default interface method."""
-Xjvm-default=disable Default behavior. Do not generate JVM default methods."""
)
var jvmDefault: String = JvmDefaultMode.DEFAULT.description
set(value) {
@@ -871,8 +866,7 @@ Also sets `-jvm-target` value equal to the selected JDK version"""
result[JvmAnalysisFlags.jvmDefaultMode] = it
} ?: collector.report(
CompilerMessageSeverity.ERROR,
"Unknown @JvmDefault mode: $jvmDefault, " +
"supported modes: ${JvmDefaultMode.values().map { it.description }}"
"Unknown -Xjvm-default mode: $jvmDefault, supported modes: ${JvmDefaultMode.values().map { it.description }}"
)
result[JvmAnalysisFlags.inheritMultifileParts] = inheritMultifileParts
result[JvmAnalysisFlags.sanitizeParentheses] = sanitizeParentheses
@@ -78,10 +78,9 @@ internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTran
* create a bridge from DefaultImpls of derived to DefaultImpls of base, unless
* - the implementation is private, or belongs to java.lang.Object,
* or is a stub for function with default parameters ($default)
* - we're in -Xjvm-default=compatibility|all-compatibility mode, in which case we go via
* - we're in -Xjvm-default=all-compatibility mode, in which case we go via
* accessors on the parent class rather than the DefaultImpls if inherited method is compiled to JVM default
* - we're in -Xjvm-default=enable|all mode, and we have that default implementation,
* in which case we simply leave it.
* - we're in -Xjvm-default=all mode, and we have that default implementation, in which case we simply leave it.
*
* ```
* interface A { fun foo() = 0 }
+2 -7
View File
@@ -56,7 +56,7 @@ where advanced options include:
* ignore
* strict (experimental; treat as other supported nullability annotations)
* warn (report a warning)
-Xjvm-default={all|all-compatibility|disable|enable|compatibility}
-Xjvm-default={all|all-compatibility|disable}
Emit JVM default methods for interface declarations with bodies. Default is 'disable'.
-Xjvm-default=all Generate JVM default methods for all interface declarations with bodies in the module.
Do not generate DefaultImpls stubs for interface declarations with bodies, which are generated by default
@@ -64,7 +64,6 @@ where advanced options include:
mode and doesn't override it, then a DefaultImpls stub will be generated for it.
BREAKS BINARY COMPATIBILITY if some client code relies on the presence of DefaultImpls classes.
Note that if interface delegation is used, all interface methods are delegated.
The only exception are methods annotated with the deprecated @JvmDefault annotation.
-Xjvm-default=all-compatibility In addition to the 'all' mode, generate compatibility stubs in the DefaultImpls classes.
Compatibility stubs could be useful for library and runtime authors to keep backward binary compatibility
for existing clients compiled against previous library versions.
@@ -77,11 +76,7 @@ where advanced options include:
additional implicit method with specialized signatures was generated in the 'disable' mode:
unlike in the 'disable' mode, the compiler will report an error if such method is not overridden explicitly
and the class is not annotated with @JvmDefaultWithoutCompatibility (see KT-39603 for more details).
-Xjvm-default=disable Default behavior. Do not generate JVM default methods and prohibit @JvmDefault annotation usage.
-Xjvm-default=enable Deprecated. Allow usages of @JvmDefault; only generate the default method for annotated method
in the interface (annotating an existing method can break binary compatibility).
-Xjvm-default=compatibility Deprecated. Allow usages of @JvmDefault; generate a compatibility accessor
in the DefaultImpls class in addition to the default interface method.
-Xjvm-default=disable Default behavior. Do not generate JVM default methods.
-Xklib=<path> Paths to cross-platform libraries in .klib format
-Xlambdas={class|indy} Select code generation scheme for lambdas.
-Xlambdas=indy Generate lambdas using `invokedynamic` with `LambdaMetafactory.metafactory`. Requires `-jvm-target 1.8` or greater.
@@ -12,13 +12,13 @@ enum class JvmDefaultMode(val description: String) {
ALL_COMPATIBILITY("all-compatibility"),
ALL_INCOMPATIBLE("all");
val isEnabled
val isEnabled: Boolean
get() = this != DISABLE
val isCompatibility
val isCompatibility: Boolean
get() = this == ENABLE_WITH_DEFAULT_IMPLS || this == ALL_COMPATIBILITY
val forAllMethodsWithBody
val forAllMethodsWithBody: Boolean
get() = this == ALL_COMPATIBILITY || this == ALL_INCOMPATIBLE
companion object {
@@ -26,6 +26,11 @@ enum class JvmDefaultMode(val description: String) {
val DEFAULT = DISABLE
@JvmStatic
fun fromStringOrNull(string: String?) = values().find { it.description == string }
fun fromStringOrNull(string: String?): JvmDefaultMode? = when (string) {
DISABLE.description -> DISABLE
ALL_COMPATIBILITY.description -> ALL_COMPATIBILITY
ALL_INCOMPATIBLE.description -> ALL_INCOMPATIBLE
else -> null
}
}
}