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