From 86d8468b8bbdf7013602ae8b8847d11b4f58fd5b Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Mon, 6 Sep 2021 12:56:00 +0300 Subject: [PATCH] Introduce a compiler X-flag to use the builder inference by default for all calls ^KT-48622 Fixed --- .../cli/common/arguments/CommonCompilerArguments.kt | 11 +++++++++++ compiler/testData/cli/js/jsExtraHelp.out | 2 ++ .../testData/cli/jvm/builderInferenceByDefault.args | 4 ++++ .../testData/cli/jvm/builderInferenceByDefault.kt | 8 ++++++++ .../testData/cli/jvm/builderInferenceByDefault.out | 7 +++++++ compiler/testData/cli/jvm/extraHelp.out | 2 ++ .../org/jetbrains/kotlin/cli/CliTestGenerated.java | 5 +++++ 7 files changed, 39 insertions(+) create mode 100644 compiler/testData/cli/jvm/builderInferenceByDefault.args create mode 100644 compiler/testData/cli/jvm/builderInferenceByDefault.kt create mode 100644 compiler/testData/cli/jvm/builderInferenceByDefault.out diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index 3674d02f1f9..efe615b0b77 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -374,6 +374,13 @@ abstract class CommonCompilerArguments : CommonToolArguments() { ) var unrestrictedBuilderInference: Boolean by FreezableVar(false) + @Argument( + value = "-Xenable-builder-inference", + description = "Use the builder inference by default, for all calls with lambdas which can't be resolved without it.\n" + + "The corresponding calls' declarations may not be marked with @BuilderInference." + ) + var enableBuilderInference: Boolean by FreezableVar(false) + @Argument( value = "-Xself-upper-bound-inference", description = "Support inferring type arguments based on only self upper bounds of the corresponding type parameters" @@ -422,6 +429,10 @@ abstract class CommonCompilerArguments : CommonToolArguments() { put(LanguageFeature.UnrestrictedBuilderInference, LanguageFeature.State.ENABLED) } + if (enableBuilderInference) { + put(LanguageFeature.UseBuilderInferenceWithoutAnnotation, LanguageFeature.State.ENABLED) + } + if (selfUpperBoundInference) { put(LanguageFeature.TypeInferenceOnCallsWithSelfTypes, LanguageFeature.State.ENABLED) } diff --git a/compiler/testData/cli/js/jsExtraHelp.out b/compiler/testData/cli/js/jsExtraHelp.out index 41f4eda337b..33654c4829f 100644 --- a/compiler/testData/cli/js/jsExtraHelp.out +++ b/compiler/testData/cli/js/jsExtraHelp.out @@ -52,6 +52,8 @@ where advanced options include: -Xdump-fqname FqName of declaration that should be dumped -Xdump-perf= Dump detailed performance statistics to the specified file -Xeffect-system Enable experimental language feature: effect system + -Xenable-builder-inference Use the builder inference by default, for all calls with lambdas which can't be resolved without it. + The corresponding calls' declarations may not be marked with @BuilderInference. -Xexpect-actual-linker Enable experimental expect/actual linker -Xexplicit-api={strict|warning|disable} Force compiler to report errors on all public API declarations without explicit visibility or return type. diff --git a/compiler/testData/cli/jvm/builderInferenceByDefault.args b/compiler/testData/cli/jvm/builderInferenceByDefault.args new file mode 100644 index 00000000000..9283152015f --- /dev/null +++ b/compiler/testData/cli/jvm/builderInferenceByDefault.args @@ -0,0 +1,4 @@ +$TESTDATA_DIR$/builderInferenceByDefault.kt +-d +$TEMP_DIR$ +-Xenable-builder-inference diff --git a/compiler/testData/cli/jvm/builderInferenceByDefault.kt b/compiler/testData/cli/jvm/builderInferenceByDefault.kt new file mode 100644 index 00000000000..e1367f26c6f --- /dev/null +++ b/compiler/testData/cli/jvm/builderInferenceByDefault.kt @@ -0,0 +1,8 @@ +fun buildMap(builderAction: MutableMap.() -> Unit): Map = mapOf() + +fun box(): String { + val x = buildMap { + put("", "") + } + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/cli/jvm/builderInferenceByDefault.out b/compiler/testData/cli/jvm/builderInferenceByDefault.out new file mode 100644 index 00000000000..b70c533f321 --- /dev/null +++ b/compiler/testData/cli/jvm/builderInferenceByDefault.out @@ -0,0 +1,7 @@ +compiler/testData/cli/jvm/builderInferenceByDefault.kt:1:21: warning: parameter 'builderAction' is never used +fun buildMap(builderAction: MutableMap.() -> Unit): Map = mapOf() + ^ +compiler/testData/cli/jvm/builderInferenceByDefault.kt:4:9: warning: variable 'x' is never used + val x = buildMap { + ^ +OK diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 60f3de6a5b2..31b31eae8ef 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -154,6 +154,8 @@ where advanced options include: -Xdump-fqname FqName of declaration that should be dumped -Xdump-perf= Dump detailed performance statistics to the specified file -Xeffect-system Enable experimental language feature: effect system + -Xenable-builder-inference Use the builder inference by default, for all calls with lambdas which can't be resolved without it. + The corresponding calls' declarations may not be marked with @BuilderInference. -Xexpect-actual-linker Enable experimental expect/actual linker -Xexplicit-api={strict|warning|disable} Force compiler to report errors on all public API declarations without explicit visibility or return type. diff --git a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java index 5ac6aca9f72..29e2c05b699 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -106,6 +106,11 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/bothJvmIrAndOldBackend.args"); } + @TestMetadata("builderInferenceByDefault.args") + public void testBuilderInferenceByDefault() throws Exception { + runTest("compiler/testData/cli/jvm/builderInferenceByDefault.args"); + } + @TestMetadata("classAndFileClassClash.args") public void testClassAndFileClassClash() throws Exception { runTest("compiler/testData/cli/jvm/classAndFileClassClash.args");