diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt index b7c2ae9731e..734c72e2ef2 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt @@ -489,6 +489,7 @@ default: `indy-with-constants` for JVM target 9 or greater, `inline` otherwise"" result[JvmAnalysisFlags.enableJvmPreview] = enableJvmPreview result[AnalysisFlags.allowUnstableDependencies] = allowUnstableDependencies || useFir result[JvmAnalysisFlags.disableUltraLightClasses] = disableUltraLightClasses + result[JvmAnalysisFlags.useIR] = useIR return result } diff --git a/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmAnalysisFlags.kt b/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmAnalysisFlags.kt index dd97e61cb3e..c984dde8662 100644 --- a/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmAnalysisFlags.kt +++ b/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmAnalysisFlags.kt @@ -33,6 +33,9 @@ object JvmAnalysisFlags { @JvmStatic val enableJvmPreview by AnalysisFlag.Delegates.Boolean + @JvmStatic + val useIR by AnalysisFlag.Delegates.Boolean + private object Delegates { object JavaTypeEnhancementStateWarnByDefault { operator fun provideDelegate(instance: Any?, property: KProperty<*>): AnalysisFlag.Delegate = diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index f3c6f2932ea..c84ae801dba 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -10078,28 +10078,6 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/functionLiterals/return/unresolvedReferenceInReturnBlock.kt"); } } - - @Nested - @TestMetadata("compiler/testData/diagnostics/tests/functionLiterals/suspend") - @TestDataPath("$PROJECT_ROOT") - public class Suspend { - @Test - public void testAllFilesPresentInSuspend() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/functionLiterals/suspend"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); - } - - @Test - @TestMetadata("disabled.kt") - public void testDisabled() throws Exception { - runTest("compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.kt"); - } - - @Test - @TestMetadata("enabled.kt") - public void testEnabled() throws Exception { - runTest("compiler/testData/diagnostics/tests/functionLiterals/suspend/enabled.kt"); - } - } } @Nested diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/SuspendInFunInterfaceChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/SuspendInFunInterfaceChecker.kt new file mode 100644 index 00000000000..be24d8a3b96 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/SuspendInFunInterfaceChecker.kt @@ -0,0 +1,40 @@ +/* + * 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. + */ + +package org.jetbrains.kotlin.resolve.jvm.checkers + +import org.jetbrains.kotlin.config.JvmAnalysisFlags +import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.psi.KtClass +import org.jetbrains.kotlin.psi.KtDeclaration +import org.jetbrains.kotlin.psi.KtNamedFunction +import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker +import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext +import org.jetbrains.kotlin.resolve.sam.getSingleAbstractMethodOrNull +import org.jetbrains.kotlin.resolve.source.getPsi + +class SuspendInFunInterfaceChecker : DeclarationChecker { + override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) { + if (declaration !is KtClass) return + if (descriptor !is ClassDescriptor || !descriptor.isFun) return + + val funKeyword = declaration.getFunKeyword() ?: return + + val abstractMember = getSingleAbstractMethodOrNull(descriptor) ?: return + if (!abstractMember.isSuspend) return + + if (context.languageVersionSettings.supportsFeature(LanguageFeature.SuspendFunctionsInFunInterfaces) && + context.languageVersionSettings.getFlag(JvmAnalysisFlags.useIR) + ) return + + val ktFunction = abstractMember.source.getPsi() as? KtNamedFunction + val reportOn = ktFunction?.modifierList?.getModifier(KtTokens.SUSPEND_KEYWORD) ?: funKeyword + context.trace.report(Errors.FUN_INTERFACE_WITH_SUSPEND_FUNCTION.on(reportOn)) + } +} \ No newline at end of file diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt index f95625be0c8..b91ab50f6a4 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt @@ -36,6 +36,7 @@ object JvmPlatformConfigurator : PlatformConfiguratorBase( JvmInlineApplicabilityChecker(), StrictfpApplicabilityChecker(), JvmAnnotationsTargetNonExistentAccessorChecker(), + SuspendInFunInterfaceChecker(), BadInheritedJavaSignaturesChecker, JvmMultifileClassStateChecker, SynchronizedOnInlineMethodChecker, diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/FunInterfaceDeclarationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/FunInterfaceDeclarationChecker.kt index 09f5494a82a..de57932e910 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/FunInterfaceDeclarationChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/FunInterfaceDeclarationChecker.kt @@ -61,15 +61,6 @@ class FunInterfaceDeclarationChecker : DeclarationChecker { ) { val ktFunction = abstractMember.source.getPsi() as? KtNamedFunction - if (abstractMember.isSuspend && - !(context.languageVersionSettings.supportsFeature(LanguageFeature.SuspendFunctionsInFunInterfaces) && - context.languageVersionSettings.supportsFeature(LanguageFeature.JvmIrEnabledByDefault)) - ) { - val reportOn = ktFunction?.modifierList?.getModifier(KtTokens.SUSPEND_KEYWORD) ?: funInterfaceKeyword - context.trace.report(Errors.FUN_INTERFACE_WITH_SUSPEND_FUNCTION.on(reportOn)) - return - } - if (abstractMember.typeParameters.isNotEmpty()) { val reportOn = ktFunction?.typeParameterList ?: ktFunction?.funKeyword ?: funInterfaceKeyword context.trace.report(Errors.FUN_INTERFACE_ABSTRACT_METHOD_WITH_TYPE_PARAMETERS.on(reportOn)) diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/builders/LanguageVersionSettingsBuilder.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/builders/LanguageVersionSettingsBuilder.kt index 17c2da42026..5a5a82f40e1 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/builders/LanguageVersionSettingsBuilder.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/builders/LanguageVersionSettingsBuilder.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.test.builders import org.jetbrains.kotlin.config.* +import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives import org.jetbrains.kotlin.test.directives.model.singleOrZeroValue @@ -49,7 +50,11 @@ class LanguageVersionSettingsBuilder { analysisFlags[flag] = value } - fun configureUsingDirectives(directives: RegisteredDirectives, environmentConfigurators: List) { + fun configureUsingDirectives( + directives: RegisteredDirectives, + environmentConfigurators: List, + targetBackend: TargetBackend? + ) { val apiVersion = directives.singleOrZeroValue(LanguageSettingsDirectives.API_VERSION) if (apiVersion != null) { this.apiVersion = apiVersion @@ -69,6 +74,7 @@ class LanguageVersionSettingsBuilder { analysisFlag(JvmAnalysisFlags.inheritMultifileParts, trueOrNull(LanguageSettingsDirectives.INHERIT_MULTIFILE_PARTS in directives)), analysisFlag(JvmAnalysisFlags.sanitizeParentheses, trueOrNull(LanguageSettingsDirectives.SANITIZE_PARENTHESES in directives)), analysisFlag(JvmAnalysisFlags.enableJvmPreview, trueOrNull(LanguageSettingsDirectives.ENABLE_JVM_PREVIEW in directives)), + analysisFlag(JvmAnalysisFlags.useIR, targetBackend == TargetBackend.JVM_IR || targetBackend == null), analysisFlag(AnalysisFlags.explicitApiVersion, trueOrNull(apiVersion != null)), ) diff --git a/compiler/testData/cli/jvm/suspendInFunInterfaceIrDisabled.args b/compiler/testData/cli/jvm/suspendInFunInterfaceIrDisabled.args new file mode 100644 index 00000000000..c3e4e704343 --- /dev/null +++ b/compiler/testData/cli/jvm/suspendInFunInterfaceIrDisabled.args @@ -0,0 +1,4 @@ +$TESTDATA_DIR$/suspendInFunInterfaceIrDisabled.kt +-d +$TEMP_DIR$ +-Xuse-old-backend diff --git a/compiler/testData/cli/jvm/suspendInFunInterfaceIrDisabled.kt b/compiler/testData/cli/jvm/suspendInFunInterfaceIrDisabled.kt new file mode 100644 index 00000000000..dc7eb99909e --- /dev/null +++ b/compiler/testData/cli/jvm/suspendInFunInterfaceIrDisabled.kt @@ -0,0 +1,3 @@ +fun interface FIC { + suspend fun foo() +} diff --git a/compiler/testData/cli/jvm/suspendInFunInterfaceIrDisabled.out b/compiler/testData/cli/jvm/suspendInFunInterfaceIrDisabled.out new file mode 100644 index 00000000000..55a958d858a --- /dev/null +++ b/compiler/testData/cli/jvm/suspendInFunInterfaceIrDisabled.out @@ -0,0 +1,4 @@ +compiler/testData/cli/jvm/suspendInFunInterfaceIrDisabled.kt:2:5: error: 'suspend' modifier is not allowed on a single abstract member + suspend fun foo() + ^ +COMPILATION_ERROR diff --git a/compiler/testData/cli/jvm/suspendInFunInterfaceIrEnabled.args b/compiler/testData/cli/jvm/suspendInFunInterfaceIrEnabled.args new file mode 100644 index 00000000000..72b35ae22ea --- /dev/null +++ b/compiler/testData/cli/jvm/suspendInFunInterfaceIrEnabled.args @@ -0,0 +1,4 @@ +$TESTDATA_DIR$/suspendInFunInterfaceIrEnabled.kt +-d +$TEMP_DIR$ +-Xuse-ir diff --git a/compiler/testData/cli/jvm/suspendInFunInterfaceIrEnabled.kt b/compiler/testData/cli/jvm/suspendInFunInterfaceIrEnabled.kt new file mode 100644 index 00000000000..dc7eb99909e --- /dev/null +++ b/compiler/testData/cli/jvm/suspendInFunInterfaceIrEnabled.kt @@ -0,0 +1,3 @@ +fun interface FIC { + suspend fun foo() +} diff --git a/compiler/testData/cli/jvm/suspendInFunInterfaceIrEnabled.out b/compiler/testData/cli/jvm/suspendInFunInterfaceIrEnabled.out new file mode 100644 index 00000000000..d86bac9de59 --- /dev/null +++ b/compiler/testData/cli/jvm/suspendInFunInterfaceIrEnabled.out @@ -0,0 +1 @@ +OK diff --git a/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.fir.kt deleted file mode 100644 index bed693bc60e..00000000000 --- a/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.fir.kt +++ /dev/null @@ -1,5 +0,0 @@ -// LANGUAGE: -SuspendFunctionsInFunInterfaces, +JvmIrEnabledByDefault - -fun interface I { - suspend fun foo() -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.kt b/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.kt deleted file mode 100644 index 13dbacc491d..00000000000 --- a/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.kt +++ /dev/null @@ -1,5 +0,0 @@ -// LANGUAGE: -SuspendFunctionsInFunInterfaces, +JvmIrEnabledByDefault - -fun interface I { - suspend fun foo() -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.txt b/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.txt deleted file mode 100644 index a191729edc7..00000000000 --- a/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.txt +++ /dev/null @@ -1,8 +0,0 @@ -package - -public fun interface I { - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public abstract suspend fun foo(): kotlin.Unit - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/suspend/enabled.kt b/compiler/testData/diagnostics/tests/functionLiterals/suspend/enabled.kt deleted file mode 100644 index 04b3a511767..00000000000 --- a/compiler/testData/diagnostics/tests/functionLiterals/suspend/enabled.kt +++ /dev/null @@ -1,6 +0,0 @@ -// FIR_IDENTICAL -// LANGUAGE: +SuspendFunctionsInFunInterfaces, +JvmIrEnabledByDefault - -fun interface I { - suspend fun foo() -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/suspend/enabled.txt b/compiler/testData/diagnostics/tests/functionLiterals/suspend/enabled.txt deleted file mode 100644 index a191729edc7..00000000000 --- a/compiler/testData/diagnostics/tests/functionLiterals/suspend/enabled.txt +++ /dev/null @@ -1,8 +0,0 @@ -package - -public fun interface I { - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public abstract suspend fun foo(): kotlin.Unit - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 2d95ffeb026..c6fa5fbffdc 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -10084,28 +10084,6 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/functionLiterals/return/unresolvedReferenceInReturnBlock.kt"); } } - - @Nested - @TestMetadata("compiler/testData/diagnostics/tests/functionLiterals/suspend") - @TestDataPath("$PROJECT_ROOT") - public class Suspend { - @Test - public void testAllFilesPresentInSuspend() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/functionLiterals/suspend"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); - } - - @Test - @TestMetadata("disabled.kt") - public void testDisabled() throws Exception { - runTest("compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.kt"); - } - - @Test - @TestMetadata("enabled.kt") - public void testEnabled() throws Exception { - runTest("compiler/testData/diagnostics/tests/functionLiterals/suspend/enabled.kt"); - } - } } @Nested diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/configuration/JvmEnvironmentConfigurator.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/configuration/JvmEnvironmentConfigurator.kt index 97defd76641..5de55528894 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/configuration/JvmEnvironmentConfigurator.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/configuration/JvmEnvironmentConfigurator.kt @@ -11,10 +11,7 @@ import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots import org.jetbrains.kotlin.cli.jvm.config.jvmClasspathRoots import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime -import org.jetbrains.kotlin.config.CompilerConfiguration -import org.jetbrains.kotlin.config.CompilerConfigurationKey -import org.jetbrains.kotlin.config.JVMConfigurationKeys -import org.jetbrains.kotlin.config.JvmTarget +import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.platform.jvm.JvmPlatforms import org.jetbrains.kotlin.test.ConfigurationKind import org.jetbrains.kotlin.test.TestJdkKind diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/ModuleStructureExtractorImpl.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/ModuleStructureExtractorImpl.kt index ca947221ebc..5b008c05a2c 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/ModuleStructureExtractorImpl.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/impl/ModuleStructureExtractorImpl.kt @@ -284,13 +284,14 @@ class ModuleStructureExtractorImpl( val moduleDirectives = moduleDirectivesBuilder.build() + testServices.defaultDirectives + globalDirectives moduleDirectives.forEach { it.checkDirectiveApplicability(contextIsGlobal = isImplicitModule, contextIsModule = true) } - currentModuleLanguageVersionSettingsBuilder.configureUsingDirectives(moduleDirectives, environmentConfigurators) + val targetBackend = currentModuleTargetBackend ?: defaultsProvider.defaultTargetBackend + currentModuleLanguageVersionSettingsBuilder.configureUsingDirectives(moduleDirectives, environmentConfigurators, targetBackend) val moduleName = currentModuleName ?: defaultModuleName val targetPlatform = currentModuleTargetPlatform ?: parseModulePlatformByName(moduleName) ?: defaultsProvider.defaultPlatform val testModule = TestModule( name = moduleName, targetPlatform = targetPlatform, - targetBackend = currentModuleTargetBackend ?: defaultsProvider.defaultTargetBackend, + targetBackend = targetBackend, frontendKind = currentModuleFrontendKind ?: defaultsProvider.defaultFrontend, binaryKind = defaultsProvider.defaultArtifactKind ?: targetPlatform.toArtifactKind(), files = filesOfCurrentModule, diff --git a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java index e434fa6c490..e2d1db5c45c 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -766,6 +766,16 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/suppressAllWarningsJvm.args"); } + @TestMetadata("suspendInFunInterfaceIrDisabled.args") + public void testSuspendInFunInterfaceIrDisabled() throws Exception { + runTest("compiler/testData/cli/jvm/suspendInFunInterfaceIrDisabled.args"); + } + + @TestMetadata("suspendInFunInterfaceIrEnabled.args") + public void testSuspendInFunInterfaceIrEnabled() throws Exception { + runTest("compiler/testData/cli/jvm/suspendInFunInterfaceIrEnabled.args"); + } + @TestMetadata("suspensionPointInMonitor.args") public void testSuspensionPointInMonitor() throws Exception { runTest("compiler/testData/cli/jvm/suspensionPointInMonitor.args");