Introduce basic suspend conversion in FE
#KT-15917 In Progress
This commit is contained in:
+4
-4
@@ -483,10 +483,10 @@ private fun KotlinResolutionCandidate.prepareExpectedType(
|
||||
argument: KotlinCallArgument,
|
||||
candidateParameter: ParameterDescriptor
|
||||
): UnwrappedType {
|
||||
val argumentType = getExpectedTypeWithSAMConversion(argument, candidateParameter) ?: argument.getExpectedType(
|
||||
candidateParameter,
|
||||
callComponents.languageVersionSettings
|
||||
)
|
||||
val argumentType =
|
||||
getExpectedTypeWithSAMConversion(argument, candidateParameter)
|
||||
?: getExpectedTypeWithSuspendConversion(argument, candidateParameter)
|
||||
?: argument.getExpectedType(candidateParameter, callComponents.languageVersionSettings)
|
||||
val resultType = knownTypeParametersResultingSubstitutor?.substitute(argumentType) ?: argumentType
|
||||
return resolvedCall.freshVariablesSubstitutor.safeSubstitute(resultType)
|
||||
}
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.resolve.calls.components
|
||||
|
||||
import org.jetbrains.kotlin.builtins.*
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
|
||||
fun KotlinResolutionCandidate.getExpectedTypeWithSuspendConversion(
|
||||
argument: KotlinCallArgument,
|
||||
candidateParameter: ParameterDescriptor
|
||||
): UnwrappedType? {
|
||||
if (!callComponents.languageVersionSettings.supportsFeature(LanguageFeature.SuspendConversion)) return null
|
||||
|
||||
if (argument !is SimpleKotlinCallArgument) return null
|
||||
|
||||
val argumentType = argument.receiver.stableType
|
||||
if (!argumentType.isFunctionType) return null
|
||||
if (argumentType.isSuspendFunctionType) return null
|
||||
|
||||
val parameterType = candidateParameter.type
|
||||
if (!parameterType.isSuspendFunctionType) return null
|
||||
|
||||
val nonSuspendParameterType = createFunctionType(
|
||||
callComponents.builtIns,
|
||||
parameterType.annotations,
|
||||
parameterType.getReceiverTypeFromFunctionType(),
|
||||
parameterType.getValueParameterTypesFromFunctionType().map { it.type },
|
||||
parameterNames = null,
|
||||
parameterType.getReturnTypeFromFunctionType(),
|
||||
suspendFunction = false
|
||||
)
|
||||
|
||||
resolvedCall.registerArgumentWithSuspendConversion(argument, nonSuspendParameterType)
|
||||
|
||||
return nonSuspendParameterType
|
||||
}
|
||||
@@ -71,6 +71,7 @@ abstract class ResolvedCallAtom : ResolvedAtom() {
|
||||
abstract val freshVariablesSubstitutor: FreshVariableNewTypeSubstitutor
|
||||
abstract val knownParametersSubstitutor: TypeSubstitutor
|
||||
abstract val argumentsWithConversion: Map<KotlinCallArgument, SamConversionDescription>
|
||||
abstract val argumentsWithSuspendConversion: Map<KotlinCallArgument, UnwrappedType>
|
||||
abstract val argumentsWithConstantConversion: Map<KotlinCallArgument, IntegerValueTypeConstant>
|
||||
}
|
||||
|
||||
|
||||
+15
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.*
|
||||
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstant
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
|
||||
|
||||
abstract class ResolutionPart {
|
||||
@@ -185,14 +186,21 @@ class MutableResolvedCallAtom(
|
||||
override lateinit var knownParametersSubstitutor: TypeSubstitutor
|
||||
lateinit var argumentToCandidateParameter: Map<KotlinCallArgument, ValueParameterDescriptor>
|
||||
private var samAdapterMap: HashMap<KotlinCallArgument, SamConversionDescription>? = null
|
||||
private var suspendAdapterMap: HashMap<KotlinCallArgument, UnwrappedType>? = null
|
||||
private var signedUnsignedConstantConversions: HashMap<KotlinCallArgument, IntegerValueTypeConstant>? = null
|
||||
|
||||
val hasSamConversion: Boolean
|
||||
get() = samAdapterMap != null
|
||||
|
||||
val hasSuspendConversion: Boolean
|
||||
get() = suspendAdapterMap != null
|
||||
|
||||
override val argumentsWithConversion: Map<KotlinCallArgument, SamConversionDescription>
|
||||
get() = samAdapterMap ?: emptyMap()
|
||||
|
||||
override val argumentsWithSuspendConversion: Map<KotlinCallArgument, UnwrappedType>
|
||||
get() = suspendAdapterMap ?: emptyMap()
|
||||
|
||||
override val argumentsWithConstantConversion: Map<KotlinCallArgument, IntegerValueTypeConstant>
|
||||
get() = signedUnsignedConstantConversions ?: emptyMap()
|
||||
|
||||
@@ -203,6 +211,13 @@ class MutableResolvedCallAtom(
|
||||
samAdapterMap!![argument] = samConversionDescription
|
||||
}
|
||||
|
||||
fun registerArgumentWithSuspendConversion(argument: KotlinCallArgument, convertedType: UnwrappedType) {
|
||||
if (suspendAdapterMap == null)
|
||||
suspendAdapterMap = hashMapOf()
|
||||
|
||||
suspendAdapterMap!![argument] = convertedType
|
||||
}
|
||||
|
||||
fun registerArgumentWithConstantConversion(argument: KotlinCallArgument, convertedConstant: IntegerValueTypeConstant) {
|
||||
if (signedUnsignedConstantConversions == null)
|
||||
signedUnsignedConstantConversions = hashMapOf()
|
||||
|
||||
Reference in New Issue
Block a user