[FIR] Introduce ConeFunctionalTypeKind as a replacement of FunctionClassKind
This is needed to provide an ability to extend different kinds of functional types Also, cleanup and rename utilities related to functional types to avoid possible confusions
This commit is contained in:
committed by
Space Team
parent
c98c8d3682
commit
c86495dcae
+2
-2
@@ -233,8 +233,8 @@ class FirJvmSerializerExtension(
|
||||
private fun FirFunction.needsInlineParameterNullCheckRequirement(): Boolean =
|
||||
this is FirSimpleFunction && isInline && !isSuspend && !isParamAssertionsDisabled &&
|
||||
!Visibilities.isPrivate(visibility) &&
|
||||
(valueParameters.any { it.returnTypeRef.coneType.isBuiltinFunctionalType(session) } ||
|
||||
receiverParameter?.typeRef?.coneType?.isBuiltinFunctionalType(session) == true)
|
||||
(valueParameters.any { it.returnTypeRef.coneType.isSomeFunctionalType(session) } ||
|
||||
receiverParameter?.typeRef?.coneType?.isSomeFunctionalType(session) == true)
|
||||
|
||||
override fun serializeProperty(
|
||||
property: FirProperty,
|
||||
|
||||
+3
-3
@@ -172,8 +172,8 @@ class FirJvmTypeMapper(val session: FirSession) : FirSessionComponent {
|
||||
val parameters = classifier?.typeParameters.orEmpty().map { it.symbol }
|
||||
val arguments = type.arguments
|
||||
|
||||
if ((defaultType.isFunctionalType(session) && arguments.size > BuiltInFunctionArity.BIG_ARITY)
|
||||
|| defaultType.isKFunctionType(session)
|
||||
if ((defaultType.isSimpleFunctionType(session) && arguments.size > BuiltInFunctionArity.BIG_ARITY)
|
||||
|| defaultType.isReflectFunctionalType(session)
|
||||
) {
|
||||
writeGenericArguments(sw, listOf(arguments.last()), listOf(parameters.last()), mode)
|
||||
return
|
||||
@@ -264,7 +264,7 @@ class ConeTypeSystemCommonBackendContextForTypeMapping(
|
||||
|
||||
override fun SimpleTypeMarker.isSuspendFunction(): Boolean {
|
||||
require(this is ConeSimpleKotlinType)
|
||||
return isSuspendOrKSuspendFunctionType(session)
|
||||
return isSuspendFunctionType(session)
|
||||
}
|
||||
|
||||
override fun SimpleTypeMarker.isKClass(): Boolean {
|
||||
|
||||
+1
-1
@@ -538,7 +538,7 @@ class Fir2IrDeclarationStorage(
|
||||
?: if (isLambda) SpecialNames.ANONYMOUS else Name.special("<no name provided>")
|
||||
val visibility = simpleFunction?.visibility ?: Visibilities.Local
|
||||
val isSuspend =
|
||||
if (isLambda) ((function as FirAnonymousFunction).typeRef as? FirResolvedTypeRef)?.type?.isSuspendOrKSuspendFunctionType(session) == true
|
||||
if (isLambda) ((function as FirAnonymousFunction).typeRef as? FirResolvedTypeRef)?.type?.isSuspendFunctionType(session) == true
|
||||
else simpleFunction?.isSuspend == true
|
||||
val created = function.convertWithOffsets { startOffset, endOffset ->
|
||||
val result = declareIrSimpleFunction(signature, simpleFunction?.containerSource) { symbol ->
|
||||
|
||||
+6
-6
@@ -134,7 +134,7 @@ internal class AdapterGenerator(
|
||||
}
|
||||
|
||||
internal fun ConeKotlinType.kFunctionTypeToFunctionType(): IrSimpleType =
|
||||
kFunctionTypeToFunctionType(session).toIrType() as IrSimpleType
|
||||
reflectFunctionalTypeToNonReflectFunctionalType(session).toIrType() as IrSimpleType
|
||||
|
||||
internal fun generateAdaptedCallableReference(
|
||||
callableReferenceAccess: FirCallableReferenceAccess,
|
||||
@@ -479,7 +479,7 @@ internal class AdapterGenerator(
|
||||
}
|
||||
// If the expected type is a built-in functional type, we don't need SAM conversion.
|
||||
val expectedType = argument.getExpectedType(parameter)
|
||||
if (expectedType is ConeTypeParameterType || expectedType.isBuiltinFunctionalType(session)) {
|
||||
if (expectedType is ConeTypeParameterType || expectedType.isSomeFunctionalType(session)) {
|
||||
return false
|
||||
}
|
||||
// On the other hand, the actual type should be either a functional type or a subtype of a class that has a contributed `invoke`.
|
||||
@@ -514,10 +514,10 @@ internal class AdapterGenerator(
|
||||
return this
|
||||
}
|
||||
// Expect the expected type to be a suspend functional type.
|
||||
if (!parameterType.isSuspendOrKSuspendFunctionType(session)) {
|
||||
if (!parameterType.isSuspendFunctionType(session)) {
|
||||
return this
|
||||
}
|
||||
val expectedFunctionalType = parameterType.suspendFunctionTypeToFunctionType(session)
|
||||
val expectedFunctionalType = parameterType.customFunctionalTypeToSimpleFunctionalType(session)
|
||||
if (this is IrVararg) {
|
||||
// element-wise conversion if and only if we can build 1-to-1 mapping for elements.
|
||||
return applyConversionOnVararg(argument) { firVarargArgument ->
|
||||
@@ -546,9 +546,9 @@ internal class AdapterGenerator(
|
||||
argument: FirExpression
|
||||
): IrSimpleFunctionSymbol? {
|
||||
val argumentType = argument.typeRef.coneType
|
||||
val argumentTypeWithInvoke = argumentType.findSubtypeOfNonSuspendFunctionalType(session, expectedFunctionalType) ?: return null
|
||||
val argumentTypeWithInvoke = argumentType.findSubtypeOfSimpleFunctionalType(session, expectedFunctionalType) ?: return null
|
||||
|
||||
return if (argumentTypeWithInvoke.isBuiltinFunctionalType(session)) {
|
||||
return if (argumentTypeWithInvoke.isSomeFunctionalType(session)) {
|
||||
(argumentTypeWithInvoke as? ConeClassLikeType)?.findBaseInvokeSymbol(session, scopeSession)
|
||||
} else {
|
||||
argumentTypeWithInvoke.findContributedInvokeSymbol(
|
||||
|
||||
+1
-1
@@ -188,7 +188,7 @@ class CallAndReferenceGenerator(
|
||||
// This would cause ClassCastException in case of usual type approximation,
|
||||
// because '{ X1 & ... & Xm }' would be approximated to 'Nothing'.
|
||||
// JVM_OLD just relies on type mapping for generic argument types in such case.
|
||||
if (!kotlinType.isKFunctionType(session))
|
||||
if (!kotlinType.isReflectFunctionalType(session))
|
||||
return kotlinType
|
||||
if (kotlinType !is ConeSimpleKotlinType)
|
||||
return kotlinType
|
||||
|
||||
Reference in New Issue
Block a user