Minor, reformat and slightly refactor JvmRuntimeTypes.kt
This commit is contained in:
@@ -30,34 +30,24 @@ class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSetti
|
|||||||
private val kotlinCoroutinesJvmInternalPackage =
|
private val kotlinCoroutinesJvmInternalPackage =
|
||||||
MutablePackageFragmentDescriptor(module, languageVersionSettings.coroutinesJvmInternalPackageFqName())
|
MutablePackageFragmentDescriptor(module, languageVersionSettings.coroutinesJvmInternalPackageFqName())
|
||||||
|
|
||||||
private fun klass(name: String) = lazy { createClass(kotlinJvmInternalPackage, name) }
|
private fun internal(className: String, packageFragment: PackageFragmentDescriptor = kotlinJvmInternalPackage): Lazy<ClassDescriptor> =
|
||||||
|
lazy { createClass(packageFragment, className) }
|
||||||
|
|
||||||
private val lambda: ClassDescriptor by klass("Lambda")
|
private fun coroutinesInternal(name: String): Lazy<ClassDescriptor> =
|
||||||
val functionReference: ClassDescriptor by klass("FunctionReference")
|
lazy { createCoroutineSuperClass(name) }
|
||||||
private val localVariableReference: ClassDescriptor by klass("LocalVariableReference")
|
|
||||||
private val mutableLocalVariableReference: ClassDescriptor by klass("MutableLocalVariableReference")
|
|
||||||
|
|
||||||
private val coroutineImpl: ClassDescriptor by lazy {
|
private val lambda: ClassDescriptor by internal("Lambda")
|
||||||
createClass(kotlinCoroutinesJvmInternalPackage, "CoroutineImpl")
|
private val functionReference: ClassDescriptor by internal("FunctionReference")
|
||||||
}
|
private val localVariableReference: ClassDescriptor by internal("LocalVariableReference")
|
||||||
|
private val mutableLocalVariableReference: ClassDescriptor by internal("MutableLocalVariableReference")
|
||||||
|
|
||||||
private val continuationImpl by lazy {
|
private val coroutineImpl: ClassDescriptor by internal("CoroutineImpl", kotlinCoroutinesJvmInternalPackage)
|
||||||
createCoroutineSuperClass("ContinuationImpl")
|
private val continuationImpl: ClassDescriptor by coroutinesInternal("ContinuationImpl")
|
||||||
}
|
private val restrictedContinuationImpl: ClassDescriptor by coroutinesInternal("RestrictedContinuationImpl")
|
||||||
|
private val suspendLambda: ClassDescriptor by coroutinesInternal("SuspendLambda")
|
||||||
|
private val restrictedSuspendLambda: ClassDescriptor by coroutinesInternal("RestrictedSuspendLambda")
|
||||||
|
|
||||||
private val restrictedContinuationImpl by lazy {
|
private val suspendFunctionInterface: ClassDescriptor? by lazy {
|
||||||
createCoroutineSuperClass("RestrictedContinuationImpl")
|
|
||||||
}
|
|
||||||
|
|
||||||
private val suspendLambda by lazy {
|
|
||||||
createCoroutineSuperClass("SuspendLambda")
|
|
||||||
}
|
|
||||||
|
|
||||||
private val restrictedSuspendLambda by lazy {
|
|
||||||
createCoroutineSuperClass("RestrictedSuspendLambda")
|
|
||||||
}
|
|
||||||
|
|
||||||
private val suspendFunctionInterface by lazy {
|
|
||||||
if (languageVersionSettings.isReleaseCoroutines())
|
if (languageVersionSettings.isReleaseCoroutines())
|
||||||
createClass(kotlinCoroutinesJvmInternalPackage, "SuspendFunction", ClassKind.INTERFACE)
|
createClass(kotlinCoroutinesJvmInternalPackage, "SuspendFunction", ClassKind.INTERFACE)
|
||||||
else null
|
else null
|
||||||
@@ -79,20 +69,20 @@ class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSetti
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createClass(
|
private fun createClass(
|
||||||
packageFragment: PackageFragmentDescriptor,
|
packageFragment: PackageFragmentDescriptor,
|
||||||
name: String,
|
name: String,
|
||||||
classKind: ClassKind = ClassKind.CLASS
|
classKind: ClassKind = ClassKind.CLASS
|
||||||
): ClassDescriptor =
|
): ClassDescriptor =
|
||||||
MutableClassDescriptor(packageFragment, classKind, /* isInner = */ false, /* isExternal = */ false,
|
MutableClassDescriptor(
|
||||||
Name.identifier(name), SourceElement.NO_SOURCE, LockBasedStorageManager.NO_LOCKS).apply {
|
packageFragment, classKind, false, false, Name.identifier(name), SourceElement.NO_SOURCE, LockBasedStorageManager.NO_LOCKS
|
||||||
modality = Modality.FINAL
|
).apply {
|
||||||
visibility = Visibilities.PUBLIC
|
modality = Modality.FINAL
|
||||||
setTypeParameterDescriptors(emptyList())
|
visibility = Visibilities.PUBLIC
|
||||||
createTypeConstructor()
|
setTypeParameterDescriptors(emptyList())
|
||||||
}
|
createTypeConstructor()
|
||||||
|
}
|
||||||
|
|
||||||
fun getSupertypesForClosure(descriptor: FunctionDescriptor): Collection<KotlinType> {
|
fun getSupertypesForClosure(descriptor: FunctionDescriptor): Collection<KotlinType> {
|
||||||
|
|
||||||
val actualFunctionDescriptor =
|
val actualFunctionDescriptor =
|
||||||
if (descriptor.isSuspend)
|
if (descriptor.isSuspend)
|
||||||
getOrCreateJvmSuspendFunctionView(descriptor, languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines))
|
getOrCreateJvmSuspendFunctionView(descriptor, languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines))
|
||||||
@@ -100,17 +90,19 @@ class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSetti
|
|||||||
descriptor
|
descriptor
|
||||||
|
|
||||||
val functionType = createFunctionType(
|
val functionType = createFunctionType(
|
||||||
descriptor.builtIns,
|
descriptor.builtIns,
|
||||||
Annotations.EMPTY,
|
Annotations.EMPTY,
|
||||||
actualFunctionDescriptor.extensionReceiverParameter?.type,
|
actualFunctionDescriptor.extensionReceiverParameter?.type,
|
||||||
actualFunctionDescriptor.valueParameters.map { it.type },
|
actualFunctionDescriptor.valueParameters.map { it.type },
|
||||||
null,
|
null,
|
||||||
actualFunctionDescriptor.returnType!!
|
actualFunctionDescriptor.returnType!!
|
||||||
)
|
)
|
||||||
|
|
||||||
if (descriptor.isSuspend) {
|
if (descriptor.isSuspend) {
|
||||||
return mutableListOf<KotlinType>().apply {
|
return mutableListOf<KotlinType>().apply {
|
||||||
if (actualFunctionDescriptor.extensionReceiverParameter?.type?.isRestrictsSuspensionReceiver(languageVersionSettings) == true) {
|
if (actualFunctionDescriptor.extensionReceiverParameter?.type
|
||||||
|
?.isRestrictsSuspensionReceiver(languageVersionSettings) == true
|
||||||
|
) {
|
||||||
if (descriptor.isSuspendLambdaOrLocalFunction()) {
|
if (descriptor.isSuspendLambdaOrLocalFunction()) {
|
||||||
add(restrictedSuspendLambda.defaultType)
|
add(restrictedSuspendLambda.defaultType)
|
||||||
} else {
|
} else {
|
||||||
@@ -134,9 +126,9 @@ class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSetti
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getSupertypesForFunctionReference(
|
fun getSupertypesForFunctionReference(
|
||||||
referencedFunction: FunctionDescriptor,
|
referencedFunction: FunctionDescriptor,
|
||||||
anonymousFunctionDescriptor: AnonymousFunctionDescriptor,
|
anonymousFunctionDescriptor: AnonymousFunctionDescriptor,
|
||||||
isBound: Boolean
|
isBound: Boolean
|
||||||
): Collection<KotlinType> {
|
): Collection<KotlinType> {
|
||||||
val receivers = computeExpectedNumberOfReceivers(referencedFunction, isBound)
|
val receivers = computeExpectedNumberOfReceivers(referencedFunction, isBound)
|
||||||
|
|
||||||
@@ -144,7 +136,7 @@ class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSetti
|
|||||||
referencedFunction.builtIns,
|
referencedFunction.builtIns,
|
||||||
Annotations.EMPTY,
|
Annotations.EMPTY,
|
||||||
if (isBound) null else referencedFunction.extensionReceiverParameter?.type
|
if (isBound) null else referencedFunction.extensionReceiverParameter?.type
|
||||||
?: referencedFunction.dispatchReceiverParameter?.type,
|
?: referencedFunction.dispatchReceiverParameter?.type,
|
||||||
anonymousFunctionDescriptor.valueParameters.drop(receivers).map { it.type },
|
anonymousFunctionDescriptor.valueParameters.drop(receivers).map { it.type },
|
||||||
null,
|
null,
|
||||||
referencedFunction.returnType!!,
|
referencedFunction.returnType!!,
|
||||||
@@ -161,9 +153,9 @@ class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSetti
|
|||||||
}
|
}
|
||||||
|
|
||||||
val arity =
|
val arity =
|
||||||
(if (descriptor.extensionReceiverParameter != null) 1 else 0) +
|
(if (descriptor.extensionReceiverParameter != null) 1 else 0) +
|
||||||
(if (descriptor.dispatchReceiverParameter != null) 1 else 0) -
|
(if (descriptor.dispatchReceiverParameter != null) 1 else 0) -
|
||||||
if (isBound) 1 else 0
|
if (isBound) 1 else 0
|
||||||
|
|
||||||
return (if (isMutable) mutablePropertyReferences else propertyReferences)[arity].defaultType
|
return (if (isMutable) mutablePropertyReferences else propertyReferences)[arity].defaultType
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user