diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt index 97a7aee5242..60267840fd7 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt @@ -165,7 +165,12 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr put(JVMConfigurationKeys.PARAMETERS_METADATA, arguments.javaParameters) - val useIR = (arguments.useIR && !arguments.useOldBackend) || arguments.useFir + val useIR = arguments.useFir || + if (languageVersionSettings.supportsFeature(LanguageFeature.JvmIrEnabledByDefault)) { + !arguments.useOldBackend + } else { + arguments.useIR && !arguments.useOldBackend + } put(JVMConfigurationKeys.IR, useIR) val abiStability = JvmAbiStability.fromStringOrNull(arguments.abiStability) diff --git a/compiler/testData/cli/jvm/jvmIrByDefault.kt b/compiler/testData/cli/jvm/jvmIrByDefault.kt new file mode 100644 index 00000000000..16576cea591 --- /dev/null +++ b/compiler/testData/cli/jvm/jvmIrByDefault.kt @@ -0,0 +1,13 @@ +// This test checks that with -language-version 1.4 we're using the old JVM backend, +// and with -language-version 1.5 -- the new JVM IR backend. +// JVM IR doesn't produce classes for local functions, so the test checks which backend +// is used by asserting that the file for the anonymous class does or doesn't exist. + +// Feel free to remove both _1_4 and _1_5 tests as soon as either the old JVM backend +// or LV 1.4 is removed, whichever happens earlier. + +class C { + fun test() { + fun local() {} + } +} diff --git a/compiler/testData/cli/jvm/jvmIrByDefault1_4.args b/compiler/testData/cli/jvm/jvmIrByDefault1_4.args new file mode 100644 index 00000000000..e82803d8640 --- /dev/null +++ b/compiler/testData/cli/jvm/jvmIrByDefault1_4.args @@ -0,0 +1,5 @@ +$TESTDATA_DIR$/jvmIrByDefault.kt +-d +$TEMP_DIR$ +-language-version +1.4 diff --git a/compiler/testData/cli/jvm/jvmIrByDefault1_4.out b/compiler/testData/cli/jvm/jvmIrByDefault1_4.out new file mode 100644 index 00000000000..d86bac9de59 --- /dev/null +++ b/compiler/testData/cli/jvm/jvmIrByDefault1_4.out @@ -0,0 +1 @@ +OK diff --git a/compiler/testData/cli/jvm/jvmIrByDefault1_4.test b/compiler/testData/cli/jvm/jvmIrByDefault1_4.test new file mode 100644 index 00000000000..6992627b278 --- /dev/null +++ b/compiler/testData/cli/jvm/jvmIrByDefault1_4.test @@ -0,0 +1 @@ +// EXISTS: C$test$1.class diff --git a/compiler/testData/cli/jvm/jvmIrByDefault1_5.args b/compiler/testData/cli/jvm/jvmIrByDefault1_5.args new file mode 100644 index 00000000000..21fdb80fe66 --- /dev/null +++ b/compiler/testData/cli/jvm/jvmIrByDefault1_5.args @@ -0,0 +1,5 @@ +$TESTDATA_DIR$/jvmIrByDefault.kt +-d +$TEMP_DIR$ +-language-version +1.5 diff --git a/compiler/testData/cli/jvm/jvmIrByDefault1_5.out b/compiler/testData/cli/jvm/jvmIrByDefault1_5.out new file mode 100644 index 00000000000..5be61f3d3c9 --- /dev/null +++ b/compiler/testData/cli/jvm/jvmIrByDefault1_5.out @@ -0,0 +1,2 @@ +warning: language version 1.5 is experimental, there are no backwards compatibility guarantees for new language and library features +OK diff --git a/compiler/testData/cli/jvm/jvmIrByDefault1_5.test b/compiler/testData/cli/jvm/jvmIrByDefault1_5.test new file mode 100644 index 00000000000..c7ca4da7275 --- /dev/null +++ b/compiler/testData/cli/jvm/jvmIrByDefault1_5.test @@ -0,0 +1 @@ +// ABSENT: C$test$1.class diff --git a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java index 7ae942f9f08..4966fb383e0 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -541,6 +541,16 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/jvmDefaultAll.args"); } + @TestMetadata("jvmIrByDefault1_4.args") + public void testJvmIrByDefault1_4() throws Exception { + runTest("compiler/testData/cli/jvm/jvmIrByDefault1_4.args"); + } + + @TestMetadata("jvmIrByDefault1_5.args") + public void testJvmIrByDefault1_5() throws Exception { + runTest("compiler/testData/cli/jvm/jvmIrByDefault1_5.args"); + } + @TestMetadata("jvmRecordOk.args") public void testJvmRecordOk() throws Exception { runTest("compiler/testData/cli/jvm/jvmRecordOk.args"); diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index f18abdfe537..0a6ec5932cc 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -144,6 +144,7 @@ enum class LanguageFeature( AllowSealedInheritorsInDifferentFilesOfSamePackage(KOTLIN_1_5), SealedInterfaces(KOTLIN_1_5), + JvmIrEnabledByDefault(KOTLIN_1_5), /* * Improvements include the following: