Remove obsolete experimental coroutines support
in compiler.
This commit is contained in:
@@ -22,15 +22,13 @@ object StandardNames {
|
||||
|
||||
@JvmField val CHAR_CODE = Name.identifier("code")
|
||||
|
||||
@JvmField val COROUTINES_PACKAGE_FQ_NAME_RELEASE = FqName("kotlin.coroutines")
|
||||
@JvmField val COROUTINES_PACKAGE_FQ_NAME = FqName("kotlin.coroutines")
|
||||
|
||||
@JvmField val COROUTINES_PACKAGE_FQ_NAME_EXPERIMENTAL = COROUTINES_PACKAGE_FQ_NAME_RELEASE.child(Name.identifier("experimental"))
|
||||
@JvmField val COROUTINES_JVM_INTERNAL_PACKAGE_FQ_NAME = FqName("kotlin.coroutines.jvm.internal")
|
||||
|
||||
@JvmField val COROUTINES_INTRINSICS_PACKAGE_FQ_NAME_EXPERIMENTAL = COROUTINES_PACKAGE_FQ_NAME_EXPERIMENTAL.child(Name.identifier("intrinsics"))
|
||||
@JvmField val COROUTINES_INTRINSICS_PACKAGE_FQ_NAME = FqName("kotlin.coroutines.intrinsics")
|
||||
|
||||
@JvmField val CONTINUATION_INTERFACE_FQ_NAME_EXPERIMENTAL = COROUTINES_PACKAGE_FQ_NAME_EXPERIMENTAL.child(Name.identifier("Continuation"))
|
||||
|
||||
@JvmField val CONTINUATION_INTERFACE_FQ_NAME_RELEASE = COROUTINES_PACKAGE_FQ_NAME_RELEASE.child(Name.identifier("Continuation"))
|
||||
@JvmField val CONTINUATION_INTERFACE_FQ_NAME = COROUTINES_PACKAGE_FQ_NAME.child(Name.identifier("Continuation"))
|
||||
|
||||
@JvmField val RESULT_FQ_NAME = FqName("kotlin.Result")
|
||||
|
||||
@@ -68,7 +66,7 @@ object StandardNames {
|
||||
ANNOTATION_PACKAGE_FQ_NAME,
|
||||
KOTLIN_REFLECT_FQ_NAME,
|
||||
BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier("internal")),
|
||||
COROUTINES_PACKAGE_FQ_NAME_RELEASE
|
||||
COROUTINES_PACKAGE_FQ_NAME
|
||||
)
|
||||
|
||||
object FqNames {
|
||||
@@ -237,7 +235,7 @@ object StandardNames {
|
||||
|
||||
@JvmStatic
|
||||
fun getSuspendFunctionClassId(parameterCount: Int): ClassId {
|
||||
return ClassId(COROUTINES_PACKAGE_FQ_NAME_RELEASE, Name.identifier(getSuspendFunctionName(parameterCount)))
|
||||
return ClassId(COROUTINES_PACKAGE_FQ_NAME, Name.identifier(getSuspendFunctionName(parameterCount)))
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ enum class FunctionClassKind(
|
||||
val isReflectType: Boolean
|
||||
) {
|
||||
Function(StandardNames.BUILT_INS_PACKAGE_FQ_NAME, "Function", isSuspendType = false, isReflectType = false),
|
||||
SuspendFunction(StandardNames.COROUTINES_PACKAGE_FQ_NAME_RELEASE, "SuspendFunction", isSuspendType = true, isReflectType = false),
|
||||
SuspendFunction(StandardNames.COROUTINES_PACKAGE_FQ_NAME, "SuspendFunction", isSuspendType = true, isReflectType = false),
|
||||
KFunction(StandardNames.KOTLIN_REFLECT_FQ_NAME, "KFunction", isSuspendType = false, isReflectType = true),
|
||||
KSuspendFunction(StandardNames.KOTLIN_REFLECT_FQ_NAME, "KSuspendFunction", isSuspendType = true, isReflectType = true);
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ object StandardClassIds {
|
||||
val constantAllowedTypes = primitiveTypes + unsignedTypes + String
|
||||
|
||||
val Continuation =
|
||||
ClassId(StandardNames.COROUTINES_PACKAGE_FQ_NAME_RELEASE, StandardNames.CONTINUATION_INTERFACE_FQ_NAME_RELEASE.shortName())
|
||||
ClassId(StandardNames.COROUTINES_PACKAGE_FQ_NAME, StandardNames.CONTINUATION_INTERFACE_FQ_NAME.shortName())
|
||||
|
||||
@Suppress("FunctionName")
|
||||
fun FunctionN(n: Int): ClassId {
|
||||
|
||||
+8
-6
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.load.java.lazy.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.isContinuation
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.CONTINUATION_INTERFACE_FQ_NAME
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl
|
||||
@@ -228,10 +228,8 @@ class LazyJavaClassMemberScope(
|
||||
|
||||
private fun SimpleFunctionDescriptor.createSuspendView(): SimpleFunctionDescriptor? {
|
||||
val continuationParameter = valueParameters.lastOrNull()?.takeIf {
|
||||
isContinuation(
|
||||
it.type.constructor.declarationDescriptor?.fqNameUnsafe?.takeIf(FqNameUnsafe::isSafe)?.toSafe(),
|
||||
c.components.settings.isReleaseCoroutines
|
||||
)
|
||||
it.type.constructor.declarationDescriptor?.fqNameUnsafe?.takeIf(FqNameUnsafe::isSafe)
|
||||
?.toSafe() == CONTINUATION_INTERFACE_FQ_NAME
|
||||
} ?: return null
|
||||
|
||||
val functionDescriptor = newCopyBuilder()
|
||||
@@ -699,7 +697,11 @@ class LazyJavaClassMemberScope(
|
||||
classDescriptor.declaredTypeParameters +
|
||||
constructor.typeParameters.map { p -> c.typeParameterResolver.resolveTypeParameter(p)!! }
|
||||
|
||||
constructorDescriptor.initialize(valueParameters.descriptors, constructor.visibility.toDescriptorVisibility(), constructorTypeParameters)
|
||||
constructorDescriptor.initialize(
|
||||
valueParameters.descriptors,
|
||||
constructor.visibility.toDescriptorVisibility(),
|
||||
constructorTypeParameters
|
||||
)
|
||||
constructorDescriptor.setHasStableParameterNames(false)
|
||||
constructorDescriptor.setHasSynthesizedParameterNames(valueParameters.hasSynthesizedNames)
|
||||
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ fun <T : Any> mapType(
|
||||
|
||||
if (kotlinType.isSuspendFunctionType) {
|
||||
return mapType(
|
||||
transformSuspendFunctionToRuntimeFunctionType(kotlinType, typeMappingConfiguration.releaseCoroutines()),
|
||||
transformSuspendFunctionToRuntimeFunctionType(kotlinType),
|
||||
factory, mode, typeMappingConfiguration, descriptorTypeWriter, writeGenericType
|
||||
)
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ public abstract class KotlinBuiltIns {
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getSuspendFunction(int parameterCount) {
|
||||
return getBuiltInClassByFqName(COROUTINES_PACKAGE_FQ_NAME_RELEASE.child(Name.identifier(getSuspendFunctionName(parameterCount))));
|
||||
return getBuiltInClassByFqName(COROUTINES_PACKAGE_FQ_NAME.child(Name.identifier(getSuspendFunctionName(parameterCount))));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -316,7 +316,7 @@ public abstract class KotlinBuiltIns {
|
||||
@NotNull
|
||||
public ClassDescriptor getKSuspendFunction(int parameterCount) {
|
||||
Name name = Name.identifier(FunctionClassKind.KSuspendFunction.getClassNamePrefix() + parameterCount);
|
||||
return getBuiltInClassByFqName(COROUTINES_PACKAGE_FQ_NAME_RELEASE.child(name));
|
||||
return getBuiltInClassByFqName(COROUTINES_PACKAGE_FQ_NAME.child(name));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
package org.jetbrains.kotlin.builtins
|
||||
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.BUILT_INS_PACKAGE_FQ_NAME
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.COROUTINES_PACKAGE_FQ_NAME_RELEASE
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.COROUTINES_PACKAGE_FQ_NAME
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.KOTLIN_REFLECT_FQ_NAME
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.K_FUNCTION_PREFIX
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.K_SUSPEND_FUNCTION_PREFIX
|
||||
@@ -204,7 +204,7 @@ class ReflectionTypes(module: ModuleDescriptor, private val notFoundClasses: Not
|
||||
|| shortName == "KCallable" || shortName == "KAnnotatedElement"
|
||||
|
||||
}
|
||||
if (packageName == BUILT_INS_PACKAGE_FQ_NAME || packageName == COROUTINES_PACKAGE_FQ_NAME_RELEASE) {
|
||||
if (packageName == BUILT_INS_PACKAGE_FQ_NAME || packageName == COROUTINES_PACKAGE_FQ_NAME) {
|
||||
return shortName.startsWith("Function") // FunctionN, Function
|
||||
|| shortName.startsWith("SuspendFunction")
|
||||
}
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@
|
||||
package org.jetbrains.kotlin.builtins.functions
|
||||
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.BUILT_INS_PACKAGE_FQ_NAME
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.COROUTINES_PACKAGE_FQ_NAME_RELEASE
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.COROUTINES_PACKAGE_FQ_NAME
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.KOTLIN_REFLECT_FQ_NAME
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
@@ -102,7 +102,7 @@ class FunctionClassDescriptor(
|
||||
FunctionClassKind.SuspendFunction -> // SuspendFunction$N<...> <: Function
|
||||
listOf(functionClassId)
|
||||
FunctionClassKind.KSuspendFunction -> // KSuspendFunction$N<...> <: KFunction
|
||||
listOf(kFunctionClassId, ClassId(COROUTINES_PACKAGE_FQ_NAME_RELEASE, FunctionClassKind.SuspendFunction.numberedClassName(arity)))
|
||||
listOf(kFunctionClassId, ClassId(COROUTINES_PACKAGE_FQ_NAME, FunctionClassKind.SuspendFunction.numberedClassName(arity)))
|
||||
}
|
||||
|
||||
val moduleDescriptor = containingDeclaration.containingDeclaration
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.builtins.functions
|
||||
|
||||
import org.jetbrains.kotlin.builtins.FunctionInterfacePackageFragment
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.BUILT_INS_PACKAGE_FQ_NAME
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.COROUTINES_PACKAGE_FQ_NAME_RELEASE
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.COROUTINES_PACKAGE_FQ_NAME
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.KOTLIN_REFLECT_FQ_NAME
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.deserialization.ClassDescriptorFactory
|
||||
@@ -79,7 +79,7 @@ fun functionInterfacePackageFragmentProvider(
|
||||
val fragments = listOf(
|
||||
KOTLIN_REFLECT_FQ_NAME,
|
||||
BUILT_INS_PACKAGE_FQ_NAME,
|
||||
COROUTINES_PACKAGE_FQ_NAME_RELEASE
|
||||
COROUTINES_PACKAGE_FQ_NAME
|
||||
).map { fqName ->
|
||||
FunctionInterfacePackageFragmentImpl(classFactory, module, fqName)
|
||||
}
|
||||
|
||||
@@ -5,10 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.builtins
|
||||
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.CONTINUATION_INTERFACE_FQ_NAME_EXPERIMENTAL
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.CONTINUATION_INTERFACE_FQ_NAME_RELEASE
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.COROUTINES_PACKAGE_FQ_NAME_EXPERIMENTAL
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.COROUTINES_PACKAGE_FQ_NAME_RELEASE
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.CONTINUATION_INTERFACE_FQ_NAME
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.COROUTINES_PACKAGE_FQ_NAME
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
@@ -17,18 +15,17 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.EmptyPackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.MutableClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
|
||||
private val FAKE_CONTINUATION_CLASS_DESCRIPTOR_EXPERIMENTAL =
|
||||
private val FAKE_CONTINUATION_CLASS_DESCRIPTOR =
|
||||
MutableClassDescriptor(
|
||||
EmptyPackageFragmentDescriptor(ErrorUtils.getErrorModule(), COROUTINES_PACKAGE_FQ_NAME_EXPERIMENTAL),
|
||||
EmptyPackageFragmentDescriptor(ErrorUtils.getErrorModule(), COROUTINES_PACKAGE_FQ_NAME),
|
||||
ClassKind.INTERFACE, /* isInner = */ false, /* isExternal = */ false,
|
||||
CONTINUATION_INTERFACE_FQ_NAME_EXPERIMENTAL.shortName(), SourceElement.NO_SOURCE, LockBasedStorageManager.NO_LOCKS
|
||||
CONTINUATION_INTERFACE_FQ_NAME.shortName(), SourceElement.NO_SOURCE, LockBasedStorageManager.NO_LOCKS
|
||||
).apply {
|
||||
modality = Modality.ABSTRACT
|
||||
visibility = DescriptorVisibilities.PUBLIC
|
||||
@@ -40,48 +37,26 @@ private val FAKE_CONTINUATION_CLASS_DESCRIPTOR_EXPERIMENTAL =
|
||||
createTypeConstructor()
|
||||
}
|
||||
|
||||
private val FAKE_CONTINUATION_CLASS_DESCRIPTOR_RELEASE =
|
||||
MutableClassDescriptor(
|
||||
EmptyPackageFragmentDescriptor(ErrorUtils.getErrorModule(), COROUTINES_PACKAGE_FQ_NAME_RELEASE),
|
||||
ClassKind.INTERFACE, /* isInner = */ false, /* isExternal = */ false,
|
||||
CONTINUATION_INTERFACE_FQ_NAME_RELEASE.shortName(), SourceElement.NO_SOURCE, LockBasedStorageManager.NO_LOCKS
|
||||
).apply {
|
||||
modality = Modality.ABSTRACT
|
||||
visibility = DescriptorVisibilities.PUBLIC
|
||||
setTypeParameterDescriptors(
|
||||
TypeParameterDescriptorImpl.createWithDefaultBound(
|
||||
this, Annotations.EMPTY, false, Variance.IN_VARIANCE, Name.identifier("T"), 0, LockBasedStorageManager.NO_LOCKS
|
||||
).let(::listOf)
|
||||
)
|
||||
createTypeConstructor()
|
||||
}
|
||||
|
||||
fun transformSuspendFunctionToRuntimeFunctionType(suspendFunType: KotlinType, isReleaseCoroutines: Boolean): SimpleType {
|
||||
fun transformSuspendFunctionToRuntimeFunctionType(suspendFunType: KotlinType): SimpleType {
|
||||
assert(suspendFunType.isSuspendFunctionType) {
|
||||
"This type should be suspend function type: $suspendFunType"
|
||||
}
|
||||
|
||||
return createFunctionType(
|
||||
suspendFunType.builtIns,
|
||||
suspendFunType.annotations,
|
||||
suspendFunType.getReceiverTypeFromFunctionType(),
|
||||
suspendFunType.getValueParameterTypesFromFunctionType().map(TypeProjection::getType) +
|
||||
KotlinTypeFactory.simpleType(
|
||||
suspendFunType.builtIns,
|
||||
suspendFunType.annotations,
|
||||
suspendFunType.getReceiverTypeFromFunctionType(),
|
||||
suspendFunType.getValueParameterTypesFromFunctionType().map(TypeProjection::getType) +
|
||||
KotlinTypeFactory.simpleType(
|
||||
Annotations.EMPTY,
|
||||
// Continuation interface is not a part of built-ins anymore, it has been moved to stdlib.
|
||||
// While it must be somewhere in the dependencies, but here we don't have a reference to the module,
|
||||
// and it's rather complicated to inject it by now, so we just use a fake class descriptor.
|
||||
if (isReleaseCoroutines) FAKE_CONTINUATION_CLASS_DESCRIPTOR_RELEASE.typeConstructor
|
||||
else FAKE_CONTINUATION_CLASS_DESCRIPTOR_EXPERIMENTAL.typeConstructor,
|
||||
FAKE_CONTINUATION_CLASS_DESCRIPTOR.typeConstructor,
|
||||
listOf(suspendFunType.getReturnTypeFromFunctionType().asTypeProjection()), nullable = false
|
||||
),
|
||||
// TODO: names
|
||||
null,
|
||||
suspendFunType.builtIns.nullableAnyType
|
||||
),
|
||||
// TODO: names
|
||||
null,
|
||||
suspendFunType.builtIns.nullableAnyType
|
||||
).makeNullableAsSpecified(suspendFunType.isMarkedNullable)
|
||||
}
|
||||
|
||||
fun isContinuation(name: FqName?, isReleaseCoroutines: Boolean): Boolean {
|
||||
return if (isReleaseCoroutines) name == CONTINUATION_INTERFACE_FQ_NAME_RELEASE
|
||||
else name == CONTINUATION_INTERFACE_FQ_NAME_EXPERIMENTAL
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.CONTINUATION_INTERFACE_FQ_NAME_EXPERIMENTAL
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.CONTINUATION_INTERFACE_FQ_NAME_RELEASE
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.CONTINUATION_INTERFACE_FQ_NAME
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -30,19 +29,15 @@ fun ModuleDescriptor.resolveClassByFqName(fqName: FqName, lookupLocation: Lookup
|
||||
?.getContributedClassifier(fqName.shortName(), lookupLocation) as? ClassDescriptor
|
||||
}
|
||||
|
||||
fun ModuleDescriptor.findContinuationClassDescriptorOrNull(lookupLocation: LookupLocation, releaseCoroutines: Boolean) =
|
||||
if (releaseCoroutines)
|
||||
resolveClassByFqName(CONTINUATION_INTERFACE_FQ_NAME_RELEASE, lookupLocation)
|
||||
else
|
||||
resolveClassByFqName(CONTINUATION_INTERFACE_FQ_NAME_EXPERIMENTAL, lookupLocation)
|
||||
fun ModuleDescriptor.findContinuationClassDescriptorOrNull(lookupLocation: LookupLocation): ClassDescriptor? =
|
||||
resolveClassByFqName(CONTINUATION_INTERFACE_FQ_NAME, lookupLocation)
|
||||
|
||||
fun ModuleDescriptor.findContinuationClassDescriptor(lookupLocation: LookupLocation, releaseCoroutines: Boolean) =
|
||||
findContinuationClassDescriptorOrNull(lookupLocation, releaseCoroutines).sure { "Continuation interface is not found" }
|
||||
fun ModuleDescriptor.findContinuationClassDescriptor(lookupLocation: LookupLocation) =
|
||||
findContinuationClassDescriptorOrNull(lookupLocation).sure { "Continuation interface is not found" }
|
||||
|
||||
fun ModuleDescriptor.getContinuationOfTypeOrAny(kotlinType: KotlinType, isReleaseCoroutines: Boolean) =
|
||||
fun ModuleDescriptor.getContinuationOfTypeOrAny(kotlinType: KotlinType) =
|
||||
module.findContinuationClassDescriptorOrNull(
|
||||
NoLookupLocation.FROM_DESERIALIZATION,
|
||||
isReleaseCoroutines
|
||||
NoLookupLocation.FROM_DESERIALIZATION
|
||||
)?.defaultType?.let {
|
||||
KotlinTypeFactory.simpleType(
|
||||
it,
|
||||
|
||||
-3
@@ -27,9 +27,6 @@ interface DeserializationConfiguration {
|
||||
val readDeserializedContracts: Boolean
|
||||
get() = false
|
||||
|
||||
val releaseCoroutines: Boolean
|
||||
get() = false
|
||||
|
||||
/**
|
||||
* We may want to preserve the order of the declarations the same as in the serialized object
|
||||
* (for example, to later create a decompiled code with the original order of declarations).
|
||||
|
||||
+13
-103
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.builtins.isSuspendFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.FieldDescriptorImpl
|
||||
@@ -16,13 +15,9 @@ import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.*
|
||||
import org.jetbrains.kotlin.protobuf.MessageLite
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.*
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberDescriptor.CoroutinesCompatibilityMode
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
|
||||
class MemberDeserializer(private val c: DeserializationContext) {
|
||||
private val annotationDeserializer = AnnotationDeserializer(c.components.moduleDescriptor, c.components.notFoundClasses)
|
||||
@@ -147,40 +142,21 @@ class MemberDeserializer(private val c: DeserializationContext) {
|
||||
property.initialize(
|
||||
getter, setter,
|
||||
FieldDescriptorImpl(getPropertyFieldAnnotations(proto, isDelegate = false), property),
|
||||
FieldDescriptorImpl(getPropertyFieldAnnotations(proto, isDelegate = true), property),
|
||||
property.checkExperimentalCoroutine(local.typeDeserializer)
|
||||
FieldDescriptorImpl(getPropertyFieldAnnotations(proto, isDelegate = true), property)
|
||||
)
|
||||
|
||||
return property
|
||||
}
|
||||
|
||||
private fun DeserializedMemberDescriptor.checkExperimentalCoroutine(
|
||||
typeDeserializer: TypeDeserializer
|
||||
): DeserializedMemberDescriptor.CoroutinesCompatibilityMode {
|
||||
if (!versionAndReleaseCoroutinesMismatch()) return CoroutinesCompatibilityMode.COMPATIBLE
|
||||
|
||||
forceUpperBoundsComputation(typeDeserializer)
|
||||
|
||||
return if (typeDeserializer.experimentalSuspendFunctionTypeEncountered)
|
||||
CoroutinesCompatibilityMode.INCOMPATIBLE
|
||||
else
|
||||
CoroutinesCompatibilityMode.COMPATIBLE
|
||||
}
|
||||
|
||||
private fun forceUpperBoundsComputation(typeDeserializer: TypeDeserializer) {
|
||||
typeDeserializer.ownTypeParameters.forEach { it.upperBounds }
|
||||
}
|
||||
|
||||
private fun DeserializedSimpleFunctionDescriptor.initializeWithCoroutinesExperimentalityStatus(
|
||||
extensionReceiverParameter: ReceiverParameterDescriptor?,
|
||||
dispatchReceiverParameter: ReceiverParameterDescriptor?,
|
||||
typeParameters: List<TypeParameterDescriptor>,
|
||||
unsubstitutedValueParameters: List<ValueParameterDescriptor>,
|
||||
unsubstitutedReturnType: KotlinType?,
|
||||
modality: Modality?,
|
||||
visibility: DescriptorVisibility,
|
||||
userDataMap: Map<out CallableDescriptor.UserDataKey<*>, *>,
|
||||
isSuspend: Boolean
|
||||
extensionReceiverParameter: ReceiverParameterDescriptor?,
|
||||
dispatchReceiverParameter: ReceiverParameterDescriptor?,
|
||||
typeParameters: List<TypeParameterDescriptor>,
|
||||
unsubstitutedValueParameters: List<ValueParameterDescriptor>,
|
||||
unsubstitutedReturnType: KotlinType?,
|
||||
modality: Modality?,
|
||||
visibility: DescriptorVisibility,
|
||||
userDataMap: Map<out CallableDescriptor.UserDataKey<*>, *>
|
||||
) {
|
||||
initialize(
|
||||
extensionReceiverParameter,
|
||||
@@ -190,63 +166,12 @@ class MemberDeserializer(private val c: DeserializationContext) {
|
||||
unsubstitutedReturnType,
|
||||
modality,
|
||||
visibility,
|
||||
userDataMap,
|
||||
computeExperimentalityModeForFunctions(
|
||||
extensionReceiverParameter,
|
||||
unsubstitutedValueParameters,
|
||||
typeParameters,
|
||||
unsubstitutedReturnType,
|
||||
isSuspend
|
||||
)
|
||||
userDataMap
|
||||
)
|
||||
}
|
||||
|
||||
private fun DeserializedCallableMemberDescriptor.computeExperimentalityModeForFunctions(
|
||||
extensionReceiverParameter: ReceiverParameterDescriptor?,
|
||||
parameters: Collection<ValueParameterDescriptor>,
|
||||
typeParameters: Collection<TypeParameterDescriptor>,
|
||||
returnType: KotlinType?,
|
||||
isSuspend: Boolean
|
||||
): DeserializedMemberDescriptor.CoroutinesCompatibilityMode {
|
||||
if (!versionAndReleaseCoroutinesMismatch()) return CoroutinesCompatibilityMode.COMPATIBLE
|
||||
if (fqNameOrNull() == KOTLIN_SUSPEND_BUILT_IN_FUNCTION_FQ_NAME) return CoroutinesCompatibilityMode.COMPATIBLE
|
||||
|
||||
val types = parameters.map { it.type } + listOfNotNull(extensionReceiverParameter?.type)
|
||||
|
||||
if (returnType?.containsSuspendFunctionType() == true) return CoroutinesCompatibilityMode.INCOMPATIBLE
|
||||
if (typeParameters.any { typeParameter -> typeParameter.upperBounds.any { it.containsSuspendFunctionType() } }) {
|
||||
return CoroutinesCompatibilityMode.INCOMPATIBLE
|
||||
}
|
||||
|
||||
val maxFromParameters = types.map { type ->
|
||||
when {
|
||||
type.isSuspendFunctionType && type.arguments.size <= 3 ->
|
||||
if (type.arguments.any { it.type.containsSuspendFunctionType() })
|
||||
CoroutinesCompatibilityMode.INCOMPATIBLE
|
||||
else
|
||||
CoroutinesCompatibilityMode.NEEDS_WRAPPER
|
||||
|
||||
type.containsSuspendFunctionType() -> CoroutinesCompatibilityMode.INCOMPATIBLE
|
||||
|
||||
else -> CoroutinesCompatibilityMode.COMPATIBLE
|
||||
}
|
||||
}.maxOrNull() ?: CoroutinesCompatibilityMode.COMPATIBLE
|
||||
|
||||
return maxOf(
|
||||
if (isSuspend)
|
||||
CoroutinesCompatibilityMode.NEEDS_WRAPPER
|
||||
else
|
||||
CoroutinesCompatibilityMode.COMPATIBLE,
|
||||
maxFromParameters
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
private fun KotlinType.containsSuspendFunctionType() = contains(UnwrappedType::isSuspendFunctionType)
|
||||
|
||||
|
||||
private fun DeserializedMemberDescriptor.versionAndReleaseCoroutinesMismatch(): Boolean =
|
||||
c.components.configuration.releaseCoroutines && versionRequirements.none {
|
||||
versionRequirements.none {
|
||||
it.version == VersionRequirement.Version(1, 3) && it.kind == ProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION
|
||||
}
|
||||
|
||||
@@ -285,8 +210,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
|
||||
local.typeDeserializer.type(proto.returnType(c.typeTable)),
|
||||
ProtoEnumFlags.modality(Flags.MODALITY.get(flags)),
|
||||
ProtoEnumFlags.descriptorVisibility(Flags.VISIBILITY.get(flags)),
|
||||
emptyMap<CallableDescriptor.UserDataKey<*>, Any?>(),
|
||||
Flags.IS_SUSPEND.get(flags)
|
||||
emptyMap<CallableDescriptor.UserDataKey<*>, Any?>()
|
||||
)
|
||||
function.isOperator = Flags.IS_OPERATOR.get(flags)
|
||||
function.isInfix = Flags.IS_INFIX.get(flags)
|
||||
@@ -321,8 +245,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
|
||||
typeAlias.initialize(
|
||||
local.typeDeserializer.ownTypeParameters,
|
||||
local.typeDeserializer.simpleType(proto.underlyingType(c.typeTable), expandTypeAliases = false),
|
||||
local.typeDeserializer.simpleType(proto.expandedType(c.typeTable), expandTypeAliases = false),
|
||||
typeAlias.checkExperimentalCoroutine(local.typeDeserializer)
|
||||
local.typeDeserializer.simpleType(proto.expandedType(c.typeTable), expandTypeAliases = false)
|
||||
)
|
||||
|
||||
return typeAlias
|
||||
@@ -349,19 +272,6 @@ class MemberDeserializer(private val c: DeserializationContext) {
|
||||
|
||||
descriptor.setHasStableParameterNames(!Flags.IS_CONSTRUCTOR_WITH_NON_STABLE_PARAMETER_NAMES.get(proto.flags))
|
||||
|
||||
val doesClassContainIncompatibility =
|
||||
(c.containingDeclaration as? DeserializedClassDescriptor)
|
||||
?.c?.typeDeserializer?.experimentalSuspendFunctionTypeEncountered == true
|
||||
&& descriptor.versionAndReleaseCoroutinesMismatch()
|
||||
|
||||
descriptor.coroutinesExperimentalCompatibilityMode =
|
||||
if (doesClassContainIncompatibility)
|
||||
CoroutinesCompatibilityMode.INCOMPATIBLE
|
||||
else descriptor.computeExperimentalityModeForFunctions(
|
||||
null, descriptor.valueParameters, descriptor.typeParameters,
|
||||
descriptor.returnType, isSuspend = false
|
||||
)
|
||||
|
||||
return descriptor
|
||||
}
|
||||
|
||||
|
||||
+3
-11
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.builtins.*
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.CONTINUATION_INTERFACE_FQ_NAME
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
@@ -25,8 +26,7 @@ class TypeDeserializer(
|
||||
private val parent: TypeDeserializer?,
|
||||
typeParameterProtos: List<ProtoBuf.TypeParameter>,
|
||||
private val debugName: String,
|
||||
private val containerPresentableName: String,
|
||||
var experimentalSuspendFunctionTypeEncountered: Boolean = false
|
||||
private val containerPresentableName: String
|
||||
) {
|
||||
private val classifierDescriptors: (Int) -> ClassifierDescriptor? =
|
||||
c.storageManager.createMemoizedFunctionWithNullableValues { fqNameIndex ->
|
||||
@@ -195,13 +195,9 @@ class TypeDeserializer(
|
||||
}
|
||||
|
||||
private fun transformRuntimeFunctionTypeToSuspendFunction(funType: KotlinType): SimpleType? {
|
||||
val isReleaseCoroutines = c.components.configuration.releaseCoroutines
|
||||
|
||||
val continuationArgumentType = funType.getValueParameterTypesFromFunctionType().lastOrNull()?.type ?: return null
|
||||
val continuationArgumentFqName = continuationArgumentType.constructor.declarationDescriptor?.fqNameSafe
|
||||
if (continuationArgumentType.arguments.size != 1 || !(isContinuation(continuationArgumentFqName, true) ||
|
||||
isContinuation(continuationArgumentFqName, false))
|
||||
) {
|
||||
if (continuationArgumentType.arguments.size != 1 || continuationArgumentFqName != CONTINUATION_INTERFACE_FQ_NAME) {
|
||||
return funType as SimpleType?
|
||||
}
|
||||
|
||||
@@ -212,10 +208,6 @@ class TypeDeserializer(
|
||||
return createSimpleSuspendFunctionType(funType, suspendReturnType)
|
||||
}
|
||||
|
||||
// Load experimental suspend function type as suspend function type
|
||||
experimentalSuspendFunctionTypeEncountered = experimentalSuspendFunctionTypeEncountered ||
|
||||
(isReleaseCoroutines && isContinuation(continuationArgumentFqName, !isReleaseCoroutines))
|
||||
|
||||
return createSimpleSuspendFunctionType(funType, suspendReturnType)
|
||||
}
|
||||
|
||||
|
||||
+2
-63
@@ -34,14 +34,6 @@ interface DeserializedMemberDescriptor : DeserializedDescriptor, MemberDescripto
|
||||
// Information about the origin of this callable's container (class or package part on JVM) or null if there's no such information.
|
||||
// TODO: merge with sourceElement of containingDeclaration
|
||||
override val containerSource: DeserializedContainerSource?
|
||||
|
||||
val coroutinesExperimentalCompatibilityMode: CoroutinesCompatibilityMode
|
||||
|
||||
enum class CoroutinesCompatibilityMode {
|
||||
COMPATIBLE,
|
||||
NEEDS_WRAPPER,
|
||||
INCOMPATIBLE
|
||||
}
|
||||
}
|
||||
|
||||
interface DeserializedCallableMemberDescriptor : DeserializedMemberDescriptor, CallableMemberDescriptor
|
||||
@@ -64,34 +56,6 @@ class DeserializedSimpleFunctionDescriptor(
|
||||
source ?: SourceElement.NO_SOURCE
|
||||
) {
|
||||
|
||||
override var coroutinesExperimentalCompatibilityMode = DeserializedMemberDescriptor.CoroutinesCompatibilityMode.COMPATIBLE
|
||||
private set
|
||||
|
||||
fun initialize(
|
||||
extensionReceiverParameter: ReceiverParameterDescriptor?,
|
||||
dispatchReceiverParameter: ReceiverParameterDescriptor?,
|
||||
typeParameters: List<TypeParameterDescriptor>,
|
||||
unsubstitutedValueParameters: List<ValueParameterDescriptor>,
|
||||
unsubstitutedReturnType: KotlinType?,
|
||||
modality: Modality?,
|
||||
visibility: DescriptorVisibility,
|
||||
userDataMap: Map<out CallableDescriptor.UserDataKey<*>, *>,
|
||||
isExperimentalCoroutineInReleaseEnvironment: DeserializedMemberDescriptor.CoroutinesCompatibilityMode
|
||||
): SimpleFunctionDescriptorImpl {
|
||||
return super.initialize(
|
||||
extensionReceiverParameter,
|
||||
dispatchReceiverParameter,
|
||||
typeParameters,
|
||||
unsubstitutedValueParameters,
|
||||
unsubstitutedReturnType,
|
||||
modality,
|
||||
visibility,
|
||||
userDataMap
|
||||
).also {
|
||||
this.coroutinesExperimentalCompatibilityMode = isExperimentalCoroutineInReleaseEnvironment
|
||||
}
|
||||
}
|
||||
|
||||
override fun createSubstitutedCopy(
|
||||
newOwner: DeclarationDescriptor,
|
||||
original: FunctionDescriptor?,
|
||||
@@ -105,7 +69,6 @@ class DeserializedSimpleFunctionDescriptor(
|
||||
proto, nameResolver, typeTable, versionRequirementTable, containerSource, source
|
||||
).also {
|
||||
it.setHasStableParameterNames(hasStableParameterNames())
|
||||
it.coroutinesExperimentalCompatibilityMode = coroutinesExperimentalCompatibilityMode
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,20 +96,6 @@ class DeserializedPropertyDescriptor(
|
||||
containingDeclaration, original, annotations, modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE,
|
||||
isLateInit, isConst, isExpect, false, isExternal, isDelegated
|
||||
) {
|
||||
override var coroutinesExperimentalCompatibilityMode = DeserializedMemberDescriptor.CoroutinesCompatibilityMode.COMPATIBLE
|
||||
private set
|
||||
|
||||
fun initialize(
|
||||
getter: PropertyGetterDescriptorImpl?,
|
||||
setter: PropertySetterDescriptor?,
|
||||
backingField: FieldDescriptor?,
|
||||
delegateField: FieldDescriptor?,
|
||||
isExperimentalCoroutineInReleaseEnvironment: DeserializedMemberDescriptor.CoroutinesCompatibilityMode
|
||||
) {
|
||||
super.initialize(getter, setter, backingField, delegateField)
|
||||
.also { this.coroutinesExperimentalCompatibilityMode = isExperimentalCoroutineInReleaseEnvironment }
|
||||
}
|
||||
|
||||
override fun createSubstitutedCopy(
|
||||
newOwner: DeclarationDescriptor,
|
||||
newModality: Modality,
|
||||
@@ -180,9 +129,6 @@ class DeserializedClassConstructorDescriptor(
|
||||
) : DeserializedCallableMemberDescriptor,
|
||||
ClassConstructorDescriptorImpl(containingDeclaration, original, annotations, isPrimary, kind, source ?: SourceElement.NO_SOURCE) {
|
||||
|
||||
override var coroutinesExperimentalCompatibilityMode = DeserializedMemberDescriptor.CoroutinesCompatibilityMode.COMPATIBLE
|
||||
internal set
|
||||
|
||||
override fun createSubstitutedCopy(
|
||||
newOwner: DeclarationDescriptor,
|
||||
original: FunctionDescriptor?,
|
||||
@@ -196,7 +142,6 @@ class DeserializedClassConstructorDescriptor(
|
||||
proto, nameResolver, typeTable, versionRequirementTable, containerSource, source
|
||||
).also {
|
||||
it.setHasStableParameterNames(hasStableParameterNames())
|
||||
it.coroutinesExperimentalCompatibilityMode = coroutinesExperimentalCompatibilityMode
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,14 +174,10 @@ class DeserializedTypeAliasDescriptor(
|
||||
private lateinit var typeConstructorParameters: List<TypeParameterDescriptor>
|
||||
private lateinit var defaultTypeImpl: SimpleType
|
||||
|
||||
override var coroutinesExperimentalCompatibilityMode = DeserializedMemberDescriptor.CoroutinesCompatibilityMode.COMPATIBLE
|
||||
private set
|
||||
|
||||
fun initialize(
|
||||
declaredTypeParameters: List<TypeParameterDescriptor>,
|
||||
underlyingType: SimpleType,
|
||||
expandedType: SimpleType,
|
||||
isExperimentalCoroutineInReleaseEnvironment: DeserializedMemberDescriptor.CoroutinesCompatibilityMode
|
||||
expandedType: SimpleType
|
||||
) {
|
||||
initialize(declaredTypeParameters)
|
||||
this.underlyingType = underlyingType
|
||||
@@ -244,7 +185,6 @@ class DeserializedTypeAliasDescriptor(
|
||||
typeConstructorParameters = computeConstructorTypeParameters()
|
||||
defaultTypeImpl = computeDefaultType()
|
||||
constructors = getTypeAliasConstructors()
|
||||
this.coroutinesExperimentalCompatibilityMode = isExperimentalCoroutineInReleaseEnvironment
|
||||
}
|
||||
|
||||
override val classDescriptor: ClassDescriptor?
|
||||
@@ -261,8 +201,7 @@ class DeserializedTypeAliasDescriptor(
|
||||
substituted.initialize(
|
||||
declaredTypeParameters,
|
||||
substitutor.safeSubstitute(underlyingType, Variance.INVARIANT).asSimpleType(),
|
||||
substitutor.safeSubstitute(expandedType, Variance.INVARIANT).asSimpleType(),
|
||||
coroutinesExperimentalCompatibilityMode
|
||||
substitutor.safeSubstitute(expandedType, Variance.INVARIANT).asSimpleType()
|
||||
)
|
||||
|
||||
return substituted
|
||||
|
||||
Reference in New Issue
Block a user