Move SuspendFunction{N} interfaces to kotlin.coroutines package
#KT-25824: Fixed
This commit is contained in:
@@ -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;
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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<out T : BaseExpressionCodegen>(
|
||||
|
||||
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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
+6
-2
@@ -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)
|
||||
}
|
||||
|
||||
+1
@@ -7,6 +7,7 @@
|
||||
|
||||
// FILE: test.kt
|
||||
import kotlin.reflect.KSuspendFunction0
|
||||
import kotlin.coroutines.SuspendFunction0
|
||||
|
||||
class Test {
|
||||
suspend fun o() = "O"
|
||||
|
||||
-19
@@ -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"
|
||||
}
|
||||
+6
@@ -21,6 +21,10 @@ class A {
|
||||
suspend fun suspendFoo() {}
|
||||
}
|
||||
|
||||
inline fun <reified T : suspend () -> 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<suspend () -> Unit> {}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// !LANGUAGE: +Coroutines
|
||||
// !DIAGNOSTICS: -USELESS_IS_CHECK
|
||||
// SKIP_TXT
|
||||
|
||||
fun test() {
|
||||
suspend {} is <!UNRESOLVED_REFERENCE!>SuspendFunction0<!><*>
|
||||
suspend {} is kotlin.coroutines.SuspendFunction0<*>
|
||||
}
|
||||
+1
-1
@@ -11,7 +11,7 @@ typealias Test4 = <!WRONG_MODIFIER_TARGET!>suspend<!> Action
|
||||
typealias Test5 = List<suspend () -> Unit>
|
||||
typealias Test6 = <!WRONG_MODIFIER_TARGET!>suspend<!> List<() -> Unit>
|
||||
typealias Test7 = <!WRONG_MODIFIER_TARGET!>suspend<!> SAM
|
||||
typealias Test8 = <!WRONG_MODIFIER_TARGET!>suspend<!> SuspendFunction0<Unit>
|
||||
typealias Test8 = <!WRONG_MODIFIER_TARGET!>suspend<!> kotlin.coroutines.SuspendFunction0<Unit>
|
||||
typealias Test9 = suspend (() -> Unit) -> Unit
|
||||
typealias Test10 = suspend (suspend () -> Unit) -> Unit
|
||||
typealias Test11 = suspend () -> (suspend () -> Unit)
|
||||
|
||||
Vendored
+3
-3
@@ -1,4 +1,4 @@
|
||||
// JAVAC_SKIP
|
||||
typealias Test1 = SuspendFunction0<Unit>
|
||||
typealias Test2 = kotlin.SuspendFunction0<Unit>
|
||||
typealias Test3 = kotlin.coroutines.<!UNRESOLVED_REFERENCE!>SuspendFunction0<!><Unit>
|
||||
typealias Test1 = <!UNRESOLVED_REFERENCE!>SuspendFunction0<!><Unit>
|
||||
typealias Test2 = kotlin.<!UNRESOLVED_REFERENCE!>SuspendFunction0<!><Unit>
|
||||
typealias Test3 = kotlin.coroutines.SuspendFunction0<Unit>
|
||||
Vendored
+3
-3
@@ -1,5 +1,5 @@
|
||||
package
|
||||
|
||||
public typealias Test1 = suspend () -> kotlin.Unit
|
||||
public typealias Test2 = suspend () -> kotlin.Unit
|
||||
public typealias Test3 = [ERROR : kotlin.coroutines.SuspendFunction0<Unit>]<kotlin.Unit>
|
||||
public typealias Test1 = [ERROR : SuspendFunction0<Unit>]<kotlin.Unit>
|
||||
public typealias Test2 = [ERROR : kotlin.SuspendFunction0<Unit>]<kotlin.Unit>
|
||||
public typealias Test3 = suspend () -> kotlin.Unit
|
||||
|
||||
+5
@@ -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");
|
||||
|
||||
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java
Generated
+5
@@ -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");
|
||||
|
||||
-5
@@ -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");
|
||||
|
||||
-5
@@ -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");
|
||||
|
||||
-5
@@ -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");
|
||||
|
||||
@@ -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() {}
|
||||
@@ -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("<built-ins module>");
|
||||
|
||||
protected KotlinBuiltIns(@NotNull StorageManager storageManager) {
|
||||
protected KotlinBuiltIns(@NotNull final StorageManager storageManager) {
|
||||
this.storageManager = storageManager;
|
||||
|
||||
this.packageFragments = storageManager.createLazyValue(new Function0<PackageFragments>() {
|
||||
@@ -95,12 +85,13 @@ public abstract class KotlinBuiltIns {
|
||||
|
||||
Map<FqName, PackageFragmentDescriptor> nameToFragment = new LinkedHashMap<FqName, PackageFragmentDescriptor>();
|
||||
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<PackageFragmentDescriptor> allImportedByDefault = new LinkedHashSet<PackageFragmentDescriptor>(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<PackageFragmentDescriptor> allImportedByDefaultBuiltInsPackageFragments;
|
||||
|
||||
private PackageFragments(
|
||||
@NotNull PackageFragmentDescriptor builtInsPackageFragment,
|
||||
@NotNull PackageFragmentDescriptor coroutinesPackageFragment,
|
||||
@NotNull PackageFragmentDescriptor collectionsPackageFragment,
|
||||
@NotNull PackageFragmentDescriptor annotationPackageFragment,
|
||||
@NotNull Set<PackageFragmentDescriptor> allImportedByDefaultBuiltInsPackageFragments
|
||||
) {
|
||||
this.builtInsPackageFragment = builtInsPackageFragment;
|
||||
this.coroutinesPackageFragment = coroutinesPackageFragment;
|
||||
this.collectionsPackageFragment = collectionsPackageFragment;
|
||||
this.annotationPackageFragment = annotationPackageFragment;
|
||||
this.allImportedByDefaultBuiltInsPackageFragments = allImportedByDefaultBuiltInsPackageFragments;
|
||||
|
||||
+17
-14
@@ -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<BuiltInsPackageFragment>().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<BuiltInsPackageFragment>().first()
|
||||
}
|
||||
|
||||
override fun getParameters() = this@FunctionClassDescriptor.parameters
|
||||
|
||||
override fun getDeclarationDescriptor() = this@FunctionClassDescriptor
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
-5
@@ -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");
|
||||
|
||||
-5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user