diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 04442ce6343..8c7364a96c9 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -4605,7 +4605,8 @@ The "returned" value of try expression with no finally is either the last expres return Unit.INSTANCE; } - CodegenUtilKt.generateAsCast(v, rightKotlinType, boxedRightType, safeAs); + CodegenUtilKt.generateAsCast(v, rightKotlinType, boxedRightType, safeAs, + state.getLanguageVersionSettings().supportsFeature(LanguageFeature.ReleaseCoroutines)); return Unit.INSTANCE; }); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index 338ea3fa8c7..97e7ae1fa0b 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.codegen.state.GenerationState; import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper; import org.jetbrains.kotlin.config.JvmDefaultMode; import org.jetbrains.kotlin.config.JvmTarget; +import org.jetbrains.kotlin.config.LanguageFeature; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.annotations.Annotated; import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor; @@ -431,7 +432,8 @@ public class FunctionCodegen { } if (!functionDescriptor.isExternal()) { - generateMethodBody(mv, functionDescriptor, methodContext, jvmSignature, strategy, memberCodegen, state.getJvmDefaultMode()); + generateMethodBody(mv, functionDescriptor, methodContext, jvmSignature, strategy, memberCodegen, state.getJvmDefaultMode(), + state.getLanguageVersionSettings().supportsFeature(LanguageFeature.ReleaseCoroutines)); } else if (staticInCompanionObject) { // native @JvmStatic foo() in companion object should delegate to the static native function moved to the outer class @@ -614,7 +616,8 @@ public class FunctionCodegen { @NotNull JvmMethodSignature signature, @NotNull FunctionGenerationStrategy strategy, @NotNull MemberCodegen parentCodegen, - @NotNull JvmDefaultMode jvmDefaultMode + @NotNull JvmDefaultMode jvmDefaultMode, + boolean isReleaseCoroutines ) { mv.visitCode(); @@ -624,7 +627,8 @@ public class FunctionCodegen { KotlinTypeMapper typeMapper = parentCodegen.typeMapper; if (BuiltinSpecialBridgesUtil.shouldHaveTypeSafeBarrier(functionDescriptor, typeMapper::mapAsmMethod)) { generateTypeCheckBarrierIfNeeded( - new InstructionAdapter(mv), functionDescriptor, signature.getReturnType(), null, typeMapper); + new InstructionAdapter(mv), functionDescriptor, signature.getReturnType(), null, typeMapper, + isReleaseCoroutines); } Label methodEnd; @@ -1447,7 +1451,8 @@ public class FunctionCodegen { MemberCodegen.markLineNumberForDescriptor(owner.getThisDescriptor(), iv); if (delegateTo.getArgumentTypes().length > 0 && isSpecialBridge) { - generateTypeCheckBarrierIfNeeded(iv, descriptor, bridge.getReturnType(), delegateTo.getArgumentTypes(), typeMapper); + generateTypeCheckBarrierIfNeeded(iv, descriptor, bridge.getReturnType(), delegateTo.getArgumentTypes(), typeMapper, + state.getLanguageVersionSettings().supportsFeature(LanguageFeature.ReleaseCoroutines)); } iv.load(0, OBJECT_TYPE); @@ -1492,7 +1497,8 @@ public class FunctionCodegen { @NotNull FunctionDescriptor descriptor, @NotNull Type returnType, @Nullable Type[] delegateParameterTypes, - @NotNull KotlinTypeMapper typeMapper + @NotNull KotlinTypeMapper typeMapper, + boolean isReleaseCoroutines ) { BuiltinMethodsWithSpecialGenericSignature.TypeSafeBarrierDescription typeSafeBarrierDescription = BuiltinMethodsWithSpecialGenericSignature.getDefaultValueForOverriddenBuiltinFunction(descriptor); @@ -1526,7 +1532,7 @@ public class FunctionCodegen { } else { targetBoxedType = boxType(delegateParameterTypes[i]); } - CodegenUtilKt.generateIsCheck(iv, kotlinType, targetBoxedType); + CodegenUtilKt.generateIsCheck(iv, kotlinType, targetBoxedType, isReleaseCoroutines); iv.ifeq(defaultBranch); } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt index c91c7caddd7..caae7885cfe 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt @@ -59,12 +59,11 @@ import java.io.PrintWriter import java.io.StringWriter import java.util.* -@JvmOverloads fun generateIsCheck( v: InstructionAdapter, kotlinType: KotlinType, asmType: Type, - isReleaseCoroutines: Boolean = false + isReleaseCoroutines: Boolean ) { if (TypeUtils.isNullableType(kotlinType)) { val nope = Label() @@ -90,13 +89,12 @@ fun generateIsCheck( } } -@JvmOverloads fun generateAsCast( v: InstructionAdapter, kotlinType: KotlinType, asmType: Type, isSafe: Boolean, - isReleaseCoroutines: Boolean = false + isReleaseCoroutines: Boolean ) { if (!isSafe) { if (!TypeUtils.isNullableType(kotlinType)) { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt index 7c46a9e00b4..7f3b53d5cb4 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.codegen.intrinsics.bytecode import org.jetbrains.kotlin.codegen.intrinsics.classId import org.jetbrains.kotlin.codegen.state.GenerationState import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper +import org.jetbrains.kotlin.config.isReleaseCoroutines import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.isInlineOnly import org.jetbrains.kotlin.name.Name @@ -74,7 +75,7 @@ abstract class InlineCodegen( private val initialFrameSize = codegen.frameMap.currentSize - private val reifiedTypeInliner = ReifiedTypeInliner(typeParameterMappings) + private val reifiedTypeInliner = ReifiedTypeInliner(typeParameterMappings, state.languageVersionSettings.isReleaseCoroutines()) protected val functionDescriptor: FunctionDescriptor = if (InlineUtil.isArrayConstructorWithLambda(function)) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ReifiedTypeInliner.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ReifiedTypeInliner.kt index a6a63c4c80f..0228822eaad 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ReifiedTypeInliner.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ReifiedTypeInliner.kt @@ -57,7 +57,7 @@ class ReificationArgument( } } -class ReifiedTypeInliner(private val parametersMapping: TypeParameterMappings?) { +class ReifiedTypeInliner(private val parametersMapping: TypeParameterMappings?, private val isReleaseCoroutines: Boolean) { enum class OperationKind { NEW_ARRAY, AS, SAFE_AS, IS, JAVA_CLASS, ENUM_REIFIED; @@ -168,7 +168,7 @@ class ReifiedTypeInliner(private val parametersMapping: TypeParameterMappings?) if (stubCheckcast !is TypeInsnNode) return false val newMethodNode = MethodNode(API) - generateAsCast(InstructionAdapter(newMethodNode), kotlinType, asmType, safe) + generateAsCast(InstructionAdapter(newMethodNode), kotlinType, asmType, safe, isReleaseCoroutines) instructions.insert(insn, newMethodNode.instructions) instructions.remove(stubCheckcast) @@ -188,7 +188,7 @@ class ReifiedTypeInliner(private val parametersMapping: TypeParameterMappings?) if (stubInstanceOf !is TypeInsnNode) return false val newMethodNode = MethodNode(API) - generateIsCheck(InstructionAdapter(newMethodNode), kotlinType, asmType) + generateIsCheck(InstructionAdapter(newMethodNode), kotlinType, asmType, isReleaseCoroutines) instructions.insert(insn, newMethodNode.instructions) instructions.remove(stubInstanceOf) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SourceCompilerForInline.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SourceCompilerForInline.kt index 1acf6d9616c..8f9c06fbd78 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SourceCompilerForInline.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SourceCompilerForInline.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.backend.common.CodegenUtil import org.jetbrains.kotlin.codegen.* import org.jetbrains.kotlin.codegen.context.* import org.jetbrains.kotlin.codegen.state.GenerationState +import org.jetbrains.kotlin.config.isReleaseCoroutines import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.incremental.KotlinLookupLocation import org.jetbrains.kotlin.incremental.components.LookupLocation @@ -188,7 +189,10 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid else -> FunctionGenerationStrategy.FunctionDefault(state, expression as KtDeclarationWithBody) } - FunctionCodegen.generateMethodBody(adapter, descriptor, context, jvmMethodSignature, strategy, parentCodegen, state.jvmDefaultMode) + FunctionCodegen.generateMethodBody( + adapter, descriptor, context, jvmMethodSignature, strategy, parentCodegen, state.jvmDefaultMode, + state.languageVersionSettings.isReleaseCoroutines() + ) if (isLambda) { codegen.propagateChildReifiedTypeParametersUsages(parentCodegen.reifiedTypeParametersUsages) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/TypeIntrinsics.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/TypeIntrinsics.kt index 305eed42e60..c303344efac 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/TypeIntrinsics.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/TypeIntrinsics.kt @@ -164,8 +164,7 @@ object TypeIntrinsics { } private val KOTLIN_FUNCTION_INTERFACE_REGEX = Regex("^kotlin\\.Function([0-9]+)$") - // TODO: move to correct package - private val KOTLIN_SUSPEND_FUNCTION_INTERFACE_REGEX = Regex("^kotlin\\.SuspendFunction([0-9]+)$") + private val KOTLIN_SUSPEND_FUNCTION_INTERFACE_REGEX = Regex("^kotlin\\.coroutines\\.SuspendFunction([0-9]+)$") /** * @return function type arity (non-negative), or -1 if the given type is not a function type @@ -179,7 +178,7 @@ object TypeIntrinsics { } /** - * @return function type arity (non-negative, counting continuation), or -1 if the given type is not a function type + * @return function type arity (non-negative, not counting continuation), or -1 if the given type is not a function type */ private fun getSuspendFunctionTypeArity(kotlinType: KotlinType): Int = getFunctionTypeArityByRegex(kotlinType, KOTLIN_SUSPEND_FUNCTION_INTERFACE_REGEX) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index b5732810055..e6bc2ffd4b8 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.codegen.pseudoInsns.fakeAlwaysFalseIfeq import org.jetbrains.kotlin.codegen.pseudoInsns.fixStackAndJump import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter import org.jetbrains.kotlin.codegen.state.GenerationState +import org.jetbrains.kotlin.config.isReleaseCoroutines import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl @@ -650,14 +651,17 @@ class ExpressionCodegen( StackValue.putUnitInstance(mv) } val boxedType = boxType(asmType) - generateAsCast(mv, expression.typeOperand.toKotlinType(), boxedType, expression.operator == IrTypeOperator.SAFE_CAST) + generateAsCast( + mv, expression.typeOperand.toKotlinType(), boxedType, expression.operator == IrTypeOperator.SAFE_CAST, + state.languageVersionSettings.isReleaseCoroutines() + ) return onStack(boxedType) } IrTypeOperator.INSTANCEOF, IrTypeOperator.NOT_INSTANCEOF -> { gen(expression.argument, OBJECT_TYPE, data) val type = boxType(asmType) - generateIsCheck(mv, expression.typeOperand.toKotlinType(), type) + generateIsCheck(mv, expression.typeOperand.toKotlinType(), type, state.languageVersionSettings.isReleaseCoroutines()) if (IrTypeOperator.NOT_INSTANCEOF == expression.operator) { StackValue.not(StackValue.onStack(Type.BOOLEAN_TYPE)).put(Type.BOOLEAN_TYPE, mv) } diff --git a/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/fromJava.kt b/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/fromJava.kt index 899de8bc52a..f12f40b336c 100644 --- a/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/fromJava.kt +++ b/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/fromJava.kt @@ -7,6 +7,7 @@ // FILE: test.kt import kotlin.reflect.KSuspendFunction0 +import kotlin.coroutines.SuspendFunction0 class Test { suspend fun o() = "O" diff --git a/compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunction12.kt b/compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunction12.kt deleted file mode 100644 index 917ecf9b4f0..00000000000 --- a/compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunction12.kt +++ /dev/null @@ -1,19 +0,0 @@ -// IGNORE_BACKEND: JS_IR, JS -// IGNORE_BACKEND: JVM_IR -// WITH_RUNTIME -// WITH_COROUTINES -// LANGUAGE_VERSION: 1.2 - -import helpers.* -import kotlin.coroutines.* - -val lambda1 = { x: Any -> } as (Any) -> Unit -val suspendLambda0: suspend () -> Unit = {} - -fun box(): String { - assert(lambda1 is SuspendFunction0<*>) { "Failed: lambda1 !is SuspendFunction0<*>" } - assert(suspendLambda0 is Function1<*, *>) { "Failed: suspendLambda0 is Function1<*, *>" } - assert(suspendLambda0 is SuspendFunction0<*>) { "Failed: suspendLambda0 is SuspendFunction0<*>" } - - return "OK" -} \ No newline at end of file diff --git a/compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt b/compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt index 2e43794aa9c..3196f991ba6 100644 --- a/compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt +++ b/compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt @@ -21,6 +21,10 @@ class A { suspend fun suspendFoo() {} } +inline fun Unit> checkReified(noinline x: (Any?) -> Unit) { + if(x is T) throw IllegalStateException("x is T") +} + fun box(): String { val f1 = ::fn1 as Any val sf0 = ::suspendFn0 as Any @@ -57,5 +61,7 @@ fun box(): String { assert(safoo is Function2<*, *, *>) { "safoo is Function2<*, *, *>" } assert(safoo is SuspendFunction1<*, *>) { "asfoo is SuspendFunction1<*, *>" } + checkReified Unit> {} + return "OK" } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionN.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionN.kt new file mode 100644 index 00000000000..95709df9529 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionN.kt @@ -0,0 +1,8 @@ +// !LANGUAGE: +Coroutines +// !DIAGNOSTICS: -USELESS_IS_CHECK +// SKIP_TXT + +fun test() { + suspend {} is SuspendFunction0<*> + suspend {} is kotlin.coroutines.SuspendFunction0<*> +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/modifierApplicability.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/modifierApplicability.kt index 0b7ac11bfc1..29ca315a5f2 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/modifierApplicability.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/modifierApplicability.kt @@ -11,7 +11,7 @@ typealias Test4 = suspend Action typealias Test5 = List Unit> typealias Test6 = suspend List<() -> Unit> typealias Test7 = suspend SAM -typealias Test8 = suspend SuspendFunction0 +typealias Test8 = suspend kotlin.coroutines.SuspendFunction0 typealias Test9 = suspend (() -> Unit) -> Unit typealias Test10 = suspend (suspend () -> Unit) -> Unit typealias Test11 = suspend () -> (suspend () -> Unit) diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/suspendFunctionN.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/suspendFunctionN.kt index a9904c79178..0ca30dc5602 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/suspendFunctionN.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/suspendFunctionN.kt @@ -1,4 +1,4 @@ // JAVAC_SKIP -typealias Test1 = SuspendFunction0 -typealias Test2 = kotlin.SuspendFunction0 -typealias Test3 = kotlin.coroutines.SuspendFunction0 \ No newline at end of file +typealias Test1 = SuspendFunction0 +typealias Test2 = kotlin.SuspendFunction0 +typealias Test3 = kotlin.coroutines.SuspendFunction0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/suspendFunctionN.txt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/suspendFunctionN.txt index 75632423c62..db83bfa873b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/suspendFunctionN.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/suspendFunctionN.txt @@ -1,5 +1,5 @@ package -public typealias Test1 = suspend () -> kotlin.Unit -public typealias Test2 = suspend () -> kotlin.Unit -public typealias Test3 = [ERROR : kotlin.coroutines.SuspendFunction0] +public typealias Test1 = [ERROR : SuspendFunction0] +public typealias Test2 = [ERROR : kotlin.SuspendFunction0] +public typealias Test3 = suspend () -> kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index de9e713fa3b..7645adebff0 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -1553,6 +1553,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendExternalFunctions.kt"); } + @TestMetadata("suspendFunctionN.kt") + public void testSuspendFunctionN() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionN.kt"); + } + @TestMetadata("suspendFunctions.kt") public void testSuspendFunctions_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctions.kt", "kotlin.coroutines.experimental"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index 5b81c1323f8..7caefffaa29 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -1553,6 +1553,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendExternalFunctions.kt"); } + @TestMetadata("suspendFunctionN.kt") + public void testSuspendFunctionN() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionN.kt"); + } + @TestMetadata("suspendFunctions.kt") public void testSuspendFunctions_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctions.kt", "kotlin.coroutines.experimental"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 9241ed1dfcd..559e9f39ac1 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -6505,11 +6505,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/suspendDestructuringInLambdas.kt", "kotlin.coroutines"); } - @TestMetadata("suspendFunction12.kt") - public void testSuspendFunction12() throws Exception { - runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunction12.kt"); - } - @TestMetadata("suspendFunctionIsAs.kt") public void testSuspendFunctionIsAs() throws Exception { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 8bdd22788f4..1da9477fb38 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -6505,11 +6505,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/suspendDestructuringInLambdas.kt", "kotlin.coroutines"); } - @TestMetadata("suspendFunction12.kt") - public void testSuspendFunction12() throws Exception { - runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunction12.kt"); - } - @TestMetadata("suspendFunctionIsAs.kt") public void testSuspendFunctionIsAs() throws Exception { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 443cf6d09d3..c2b9dc1b2f4 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -6505,11 +6505,6 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/suspendDestructuringInLambdas.kt", "kotlin.coroutines"); } - @TestMetadata("suspendFunction12.kt") - public void testSuspendFunction12() throws Exception { - runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunction12.kt"); - } - @TestMetadata("suspendFunctionIsAs.kt") public void testSuspendFunctionIsAs() throws Exception { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt"); diff --git a/core/builtins/native/kotlin/Coroutines.kt b/core/builtins/native/kotlin/Coroutines.kt new file mode 100644 index 00000000000..9d78a4d85ba --- /dev/null +++ b/core/builtins/native/kotlin/Coroutines.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package kotlin.coroutines + +/** + * This is neccesary to force generation of coroutines.kotlin_builtins file, thus providing builtin package fragment for kotlin.coroutines + * package. This way we can use kotlin.coroutines.SuspendFunction{N} interfaces in code. + */ +private fun hackToForceKotlinBuiltinsForKotlinCoroutinesPackage() {} diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java index be6af6fa056..355f10e3b84 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2018 JetBrains s.r.o. 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.builtins; @@ -50,6 +39,7 @@ import java.util.*; import static kotlin.collections.SetsKt.setOf; import static org.jetbrains.kotlin.builtins.PrimitiveType.*; +import static org.jetbrains.kotlin.resolve.DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_RELEASE; import static org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName; import static org.jetbrains.kotlin.utils.CollectionsKt.newHashMapWithExpectedSize; import static org.jetbrains.kotlin.utils.CollectionsKt.newHashSetWithExpectedSize; @@ -85,7 +75,7 @@ public abstract class KotlinBuiltIns { public static final FqNames FQ_NAMES = new FqNames(); public static final Name BUILTINS_MODULE_NAME = Name.special(""); - protected KotlinBuiltIns(@NotNull StorageManager storageManager) { + protected KotlinBuiltIns(@NotNull final StorageManager storageManager) { this.storageManager = storageManager; this.packageFragments = storageManager.createLazyValue(new Function0() { @@ -95,12 +85,13 @@ public abstract class KotlinBuiltIns { Map nameToFragment = new LinkedHashMap(); PackageFragmentDescriptor kotlin = createPackage(provider, nameToFragment, BUILT_INS_PACKAGE_FQ_NAME); + PackageFragmentDescriptor kotlinCoroutines = createPackage(provider, null, COROUTINES_PACKAGE_FQ_NAME_RELEASE); PackageFragmentDescriptor kotlinCollections = createPackage(provider, nameToFragment, COLLECTIONS_PACKAGE_FQ_NAME); createPackage(provider, nameToFragment, RANGES_PACKAGE_FQ_NAME); PackageFragmentDescriptor kotlinAnnotation = createPackage(provider, nameToFragment, ANNOTATION_PACKAGE_FQ_NAME); Set allImportedByDefault = new LinkedHashSet(nameToFragment.values()); - return new PackageFragments(kotlin, kotlinCollections, kotlinAnnotation, allImportedByDefault); + return new PackageFragments(kotlin, kotlinCoroutines, kotlinCollections, kotlinAnnotation, allImportedByDefault); } }); @@ -152,7 +143,7 @@ public abstract class KotlinBuiltIns { public ClassDescriptor invoke(Integer arity) { return new FunctionClassDescriptor( getStorageManager(), - packageFragments.invoke().builtInsPackageFragment, + packageFragments.invoke().coroutinesPackageFragment, FunctionClassDescriptor.Kind.SuspendFunction, arity ); @@ -278,17 +269,20 @@ public abstract class KotlinBuiltIns { private static class PackageFragments { public final PackageFragmentDescriptor builtInsPackageFragment; + public final PackageFragmentDescriptor coroutinesPackageFragment; public final PackageFragmentDescriptor collectionsPackageFragment; public final PackageFragmentDescriptor annotationPackageFragment; public final Set allImportedByDefaultBuiltInsPackageFragments; private PackageFragments( @NotNull PackageFragmentDescriptor builtInsPackageFragment, + @NotNull PackageFragmentDescriptor coroutinesPackageFragment, @NotNull PackageFragmentDescriptor collectionsPackageFragment, @NotNull PackageFragmentDescriptor annotationPackageFragment, @NotNull Set allImportedByDefaultBuiltInsPackageFragments ) { this.builtInsPackageFragment = builtInsPackageFragment; + this.coroutinesPackageFragment = coroutinesPackageFragment; this.collectionsPackageFragment = collectionsPackageFragment; this.annotationPackageFragment = annotationPackageFragment; this.allImportedByDefaultBuiltInsPackageFragments = allImportedByDefaultBuiltInsPackageFragments; diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/FunctionClassDescriptor.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/FunctionClassDescriptor.kt index 09c8d7fdc35..590d345fb32 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/FunctionClassDescriptor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/functions/FunctionClassDescriptor.kt @@ -15,7 +15,7 @@ import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns +import org.jetbrains.kotlin.resolve.DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_RELEASE import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.types.* @@ -38,7 +38,7 @@ class FunctionClassDescriptor( enum class Kind(val packageFqName: FqName, val classNamePrefix: String) { Function(BUILT_INS_PACKAGE_FQ_NAME, "Function"), - SuspendFunction(BUILT_INS_PACKAGE_FQ_NAME, "SuspendFunction"), + SuspendFunction(COROUTINES_PACKAGE_FQ_NAME_RELEASE, "SuspendFunction"), KFunction(KOTLIN_REFLECT_FQ_NAME, "KFunction"), KSuspendFunction(KOTLIN_REFLECT_FQ_NAME, "KSuspendFunction"); @@ -110,7 +110,7 @@ class FunctionClassDescriptor( fun add(packageFragment: PackageFragmentDescriptor, name: Name) { val descriptor = packageFragment.getMemberScope().getContributedClassifier(name, NoLookupLocation.FROM_BUILTINS) as? ClassDescriptor - ?: error("Class $name not found in $packageFragment") + ?: error("Class $name not found in $packageFragment") val typeConstructor = descriptor.typeConstructor @@ -124,7 +124,7 @@ class FunctionClassDescriptor( when (functionKind) { Kind.SuspendFunction -> // SuspendFunction$N<...> <: Function - add(containingDeclaration, Name.identifier("Function")) + add(getBuiltInPackage(BUILT_INS_PACKAGE_FQ_NAME), Name.identifier("Function")) Kind.KSuspendFunction -> // KSuspendFunction$N<...> <: KFunction add(containingDeclaration, Name.identifier("KFunction")) else -> // Add unnumbered base class, e.g. Function for Function{n}, KFunction for KFunction{n} @@ -132,21 +132,24 @@ class FunctionClassDescriptor( } // For K{Suspend}Function{n}, add corresponding numbered {Suspend}Function{n} class, e.g. {Suspend}Function2 for K{Suspend}Function2 - val numberedSupertypeKind = when (functionKind) { - Kind.KFunction -> Kind.Function - Kind.KSuspendFunction -> Kind.SuspendFunction - else -> null - } - if (numberedSupertypeKind != null) { - val packageView = containingDeclaration.containingDeclaration.getPackage(BUILT_INS_PACKAGE_FQ_NAME) - val kotlinPackageFragment = packageView.fragments.filterIsInstance().first() - - add(kotlinPackageFragment, numberedSupertypeKind.numberedClassName(arity)) + when (functionKind) { + Kind.KFunction -> add(getBuiltInPackage(BUILT_INS_PACKAGE_FQ_NAME), Kind.Function.numberedClassName(arity)) + Kind.KSuspendFunction -> add( + getBuiltInPackage(COROUTINES_PACKAGE_FQ_NAME_RELEASE), + Kind.SuspendFunction.numberedClassName(arity) + ) + else -> { + } } return result.toList() } + private fun getBuiltInPackage(fqName: FqName): BuiltInsPackageFragment { + val packageView = containingDeclaration.containingDeclaration.getPackage(fqName) + return packageView.fragments.filterIsInstance().first() + } + override fun getParameters() = this@FunctionClassDescriptor.parameters override fun getDeclarationDescriptor() = this@FunctionClassDescriptor diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/naming/encodeSignature.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/naming/encodeSignature.kt index a1fd6f49752..e9722c7c413 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/naming/encodeSignature.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/naming/encodeSignature.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.js.naming import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.builtins.isSuspendFunctionType import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.types.KotlinType @@ -80,7 +81,11 @@ private fun StringBuilder.encodeForSignature( return append(typeParameterNamer(declaration)) } - append(DescriptorUtils.getFqName(declaration).asString()) + if (type.isSuspendFunctionType) { + append(DescriptorUtils.getFqName(declaration).asString().replace("kotlin.coroutines.SuspendFunction", "kotlin.SuspendFunction")) + } else { + append(DescriptorUtils.getFqName(declaration).asString()) + } val parameters = declaration.typeConstructor.parameters if (type.arguments.isNotEmpty() && parameters.isNotEmpty()) { diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java index 8aa376f5423..05ae17c4d8d 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java @@ -5665,11 +5665,6 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/suspendDestructuringInLambdas.kt", "kotlin.coroutines.experimental"); } - @TestMetadata("suspendFunction12.kt") - public void testSuspendFunction12() throws Exception { - runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunction12.kt"); - } - @TestMetadata("suspendFunctionIsAs.kt") public void testSuspendFunctionIsAs() throws Exception { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 939316f4e32..1307580fb34 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -6220,11 +6220,6 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/suspendDestructuringInLambdas.kt", "kotlin.coroutines"); } - @TestMetadata("suspendFunction12.kt") - public void testSuspendFunction12() throws Exception { - runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunction12.kt"); - } - @TestMetadata("suspendFunctionIsAs.kt") public void testSuspendFunctionIsAs() throws Exception { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt");