From b158ece2329d95ca3b425ec063c12a9917c5e487 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 5 Sep 2022 13:45:56 +0200 Subject: [PATCH] Tweak module exclusion filter for -Xjvm-default=all - Remove obsolete exclusion of core & stdlib modules, since they are now compiled with JVM target 1.8, but leave `:core:descriptors` because of an issue in Proguard. - Remove binary-compatibility-validator and update test data instead. - Replace some "contains" checks with equality for clarity. - Remove modules from -Werror filter which no longer use the deprecated compatibility mode. --- .../kotlin/common-configuration.gradle.kts | 37 ++++++++----------- .../load/kotlin/FileBasedKotlinClass.java | 8 ---- .../src/test/kotlin/cases/default/default.txt | 5 +-- .../kotlin/cases/interfaces/interfaces.txt | 16 +------- 4 files changed, 19 insertions(+), 47 deletions(-) diff --git a/buildSrc/src/main/kotlin/common-configuration.gradle.kts b/buildSrc/src/main/kotlin/common-configuration.gradle.kts index 65ddb774e7c..ed74b6b084b 100644 --- a/buildSrc/src/main/kotlin/common-configuration.gradle.kts +++ b/buildSrc/src/main/kotlin/common-configuration.gradle.kts @@ -158,10 +158,6 @@ fun Project.configureKotlinCompilationOptions() { // TODO: fix remaining warnings and remove this property. val tasksWithWarnings = listOf( ":kotlin-gradle-plugin:compileCommonKotlin", - // Temporarily disable -Werror for the following modules because of deprecation warning for `-Xjvm-default=compatibility`. - // These modules should be removed after they are migrated to `-Xjvm-default=all/all-compatibility`. - ":compiler:frontend:compileKotlin", - ":kotlin-scripting-intellij:compileKotlin", ) val projectsWithEnabledContextReceivers: List by rootProject.extra @@ -190,23 +186,7 @@ fun Project.configureKotlinCompilationOptions() { if (project.path in projectsWithEnabledContextReceivers) { freeCompilerArgs += "-Xcontext-receivers" } - - //TODO: migrate modules to defaults - //TODO: different gradle versions bundle different Kotlin compilers, not all of them support defaults - if (!project.path.contains("-gradle") && - !project.path.contains("kotlin-project-model") && - !project.path.contains(":binary-compatibility-validator") && - !project.path.contains("runtime") && - //TODO: tune performance in tree and tree.impl modules - !project.path.contains(":compiler:ir.tree") && - //HACK: filter modules with JVM target 1.6 - //TODO: remove after removing 1.6 target - !project.path.startsWith(":core") && - !project.path.startsWith(":kotlin-stdlib") && - !project.path.startsWith(":kotlinx-metadata") && - !project.path.startsWith(":kotlin-scripting") && - !project.path.startsWith(":compiler:tests-common-jvm6") - ) { + if (!skipJvmDefaultAllForModule(project.path)) { freeCompilerArgs += "-Xjvm-default=all" } } @@ -268,3 +248,18 @@ fun Project.configureTests() { apply(from = "$rootDir/gradle/testRetry.gradle.kts") } } + +// TODO: migrate remaining modules to the new JVM default scheme. +fun skipJvmDefaultAllForModule(path: String): Boolean = +// Gradle plugin modules are disabled because different Gradle versions bundle different Kotlin compilers, + // and not all of them support the new JVM default scheme. + "-gradle" in path || "-runtime" in path || path == ":kotlin-project-model" || + // Visitor/transformer interfaces in ir.tree are very sensitive to the way interface methods are implemented. + // Enabling default method generation results in a performance loss of several % on full pipeline test on Kotlin. + // TODO: investigate the performance difference and enable new mode for ir.tree. + path == ":compiler:ir.tree" || + // Workaround a Proguard issue: + // java.lang.IllegalAccessError: tried to access method kotlin.reflect.jvm.internal.impl.types.checker.ClassicTypeSystemContext$substitutionSupertypePolicy$2.( + // Lkotlin/reflect/jvm/internal/impl/types/checker/ClassicTypeSystemContext;Lkotlin/reflect/jvm/internal/impl/types/TypeSubstitutor; + // )V from class kotlin.reflect.jvm.internal.impl.resolve.OverridingUtilTypeSystemContext + path == ":core:descriptors" diff --git a/compiler/frontend.common.jvm/src/org/jetbrains/kotlin/load/kotlin/FileBasedKotlinClass.java b/compiler/frontend.common.jvm/src/org/jetbrains/kotlin/load/kotlin/FileBasedKotlinClass.java index b6fdb45d03f..5d223877927 100644 --- a/compiler/frontend.common.jvm/src/org/jetbrains/kotlin/load/kotlin/FileBasedKotlinClass.java +++ b/compiler/frontend.common.jvm/src/org/jetbrains/kotlin/load/kotlin/FileBasedKotlinClass.java @@ -11,7 +11,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap; import org.jetbrains.kotlin.descriptors.SourceElement; -import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass; import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader; import org.jetbrains.kotlin.load.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor; import org.jetbrains.kotlin.name.ClassId; @@ -355,11 +354,4 @@ public abstract class FileBasedKotlinClass implements KotlinJvmBinaryClass { @Override public abstract String toString(); - - // Declared explicitly to workaround KT-18489 - @Nullable - @Override - public String getContainingLibrary() { - return KotlinJvmBinaryClass.DefaultImpls.getContainingLibrary(this); - } } diff --git a/libraries/tools/binary-compatibility-validator/src/test/kotlin/cases/default/default.txt b/libraries/tools/binary-compatibility-validator/src/test/kotlin/cases/default/default.txt index ae2b40a241c..017a954fb9e 100644 --- a/libraries/tools/binary-compatibility-validator/src/test/kotlin/cases/default/default.txt +++ b/libraries/tools/binary-compatibility-validator/src/test/kotlin/cases/default/default.txt @@ -7,11 +7,8 @@ public class cases/default/ClassFunctions { public abstract interface class cases/default/InterfaceFunctions { public abstract fun withAllDefaults (ILjava/lang/String;)V - public abstract fun withSomeDefaults (ILjava/lang/String;)V -} - -public final class cases/default/InterfaceFunctions$DefaultImpls { public static synthetic fun withAllDefaults$default (Lcases/default/InterfaceFunctions;ILjava/lang/String;ILjava/lang/Object;)V + public abstract fun withSomeDefaults (ILjava/lang/String;)V public static synthetic fun withSomeDefaults$default (Lcases/default/InterfaceFunctions;ILjava/lang/String;ILjava/lang/Object;)V } diff --git a/libraries/tools/binary-compatibility-validator/src/test/kotlin/cases/interfaces/interfaces.txt b/libraries/tools/binary-compatibility-validator/src/test/kotlin/cases/interfaces/interfaces.txt index 4f37b42f3af..5f2f266a887 100644 --- a/libraries/tools/binary-compatibility-validator/src/test/kotlin/cases/interfaces/interfaces.txt +++ b/libraries/tools/binary-compatibility-validator/src/test/kotlin/cases/interfaces/interfaces.txt @@ -1,26 +1,14 @@ public abstract interface class cases/interfaces/BaseWithImpl { - public abstract fun foo ()I -} - -public final class cases/interfaces/BaseWithImpl$DefaultImpls { - public static fun foo (Lcases/interfaces/BaseWithImpl;)I + public fun foo ()I } public abstract interface class cases/interfaces/DerivedWithImpl : cases/interfaces/BaseWithImpl { - public abstract fun foo ()I -} - -public final class cases/interfaces/DerivedWithImpl$DefaultImpls { - public static fun foo (Lcases/interfaces/DerivedWithImpl;)I + public fun foo ()I } public abstract interface class cases/interfaces/DerivedWithoutImpl : cases/interfaces/BaseWithImpl { } -public final class cases/interfaces/DerivedWithoutImpl$DefaultImpls { - public static fun foo (Lcases/interfaces/DerivedWithoutImpl;)I -} - public abstract interface class cases/interfaces/EmptyImpls { public abstract fun getProperty ()Ljava/lang/String; }