[FIR] Improved lambda completion: initial implementation

Repeat the logic of KotlinConstraintSystemCompleter in ConstraintSystemCompleter.
Implement additional context operations required for updated lambda completion algorithm.
This commit is contained in:
Pavel Kirpichenkov
2020-09-30 16:07:03 +03:00
parent 5eae6f2f4e
commit 712a2ce1ab
35 changed files with 614 additions and 368 deletions
@@ -208,14 +208,20 @@ object StandardNames {
return "Function$parameterCount"
}
@JvmStatic
fun getFunctionClassId(parameterCount: Int): ClassId {
return ClassId(BUILT_INS_PACKAGE_FQ_NAME, Name.identifier(getFunctionName(parameterCount)))
}
@JvmStatic
fun getKFunctionFqName(parameterCount: Int): FqNameUnsafe {
return reflect(FunctionClassKind.KFunction.classNamePrefix + parameterCount)
}
@JvmStatic
fun getFunctionClassId(parameterCount: Int): ClassId {
return ClassId(BUILT_INS_PACKAGE_FQ_NAME, Name.identifier(getFunctionName(parameterCount)))
fun getKFunctionClassId(parameterCount: Int): ClassId {
val fqName = getKFunctionFqName(parameterCount)
return ClassId(fqName.parent().toSafe(), fqName.shortName())
}
@JvmStatic
@@ -228,6 +234,17 @@ object StandardNames {
return ClassId(COROUTINES_PACKAGE_FQ_NAME_RELEASE, Name.identifier(getSuspendFunctionName(parameterCount)))
}
@JvmStatic
fun getKSuspendFunctionName(parameterCount: Int): FqNameUnsafe {
return reflect(FunctionClassKind.KSuspendFunction.classNamePrefix + parameterCount)
}
@JvmStatic
fun getKSuspendFunctionClassId(parameterCount: Int): ClassId {
val fqName = getKSuspendFunctionName(parameterCount)
return ClassId(fqName.parent().toSafe(), fqName.shortName())
}
@JvmStatic
fun isPrimitiveArray(arrayFqName: FqNameUnsafe): Boolean {
return FqNames.arrayClassFqNameToPrimitiveType.get(arrayFqName) != null
@@ -193,6 +193,20 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
fun TypeVariableTypeConstructorMarker.isContainedInInvariantOrContravariantPositions(): Boolean
fun KotlinTypeMarker.isSignedOrUnsignedNumberType(): Boolean
fun KotlinTypeMarker.isFunctionOrKFunctionWithAnySuspendability(): Boolean
fun KotlinTypeMarker.isSuspendFunctionTypeOrSubtype(): Boolean
fun KotlinTypeMarker.isExtensionFunctionType(): Boolean
fun KotlinTypeMarker.extractArgumentsForFunctionalTypeOrSubtype(): List<KotlinTypeMarker>
fun KotlinTypeMarker.getFunctionalTypeFromSupertypes(): KotlinTypeMarker
fun getFunctionTypeConstructor(parametersNumber: Int, isSuspend: Boolean): TypeConstructorMarker
fun getKFunctionTypeConstructor(parametersNumber: Int, isSuspend: Boolean): TypeConstructorMarker
}
@@ -5,10 +5,8 @@
package org.jetbrains.kotlin.types.checker
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.PrimitiveType
import org.jetbrains.kotlin.builtins.*
import org.jetbrains.kotlin.builtins.StandardNames.FqNames
import org.jetbrains.kotlin.builtins.isBuiltinFunctionalTypeOrSubtype
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
@@ -674,6 +672,39 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
} ?: error("Expected intersection type, found $firstCandidate")
}
override fun KotlinTypeMarker.isFunctionOrKFunctionWithAnySuspendability(): Boolean {
require(this is KotlinType, this::errorMessage)
return this.isFunctionOrKFunctionTypeWithAnySuspendability
}
override fun KotlinTypeMarker.isSuspendFunctionTypeOrSubtype(): Boolean {
require(this is KotlinType, this::errorMessage)
return this.isSuspendFunctionTypeOrSubtype
}
override fun KotlinTypeMarker.isExtensionFunctionType(): Boolean {
require(this is KotlinType, this::errorMessage)
return this.isExtensionFunctionType
}
override fun KotlinTypeMarker.extractArgumentsForFunctionalTypeOrSubtype(): List<KotlinTypeMarker> {
require(this is KotlinType, this::errorMessage)
return this.getPureArgumentsForFunctionalTypeOrSubtype()
}
override fun KotlinTypeMarker.getFunctionalTypeFromSupertypes(): KotlinTypeMarker {
require(this is KotlinType)
return this.extractFunctionalTypeFromSupertypes()
}
override fun getFunctionTypeConstructor(parametersNumber: Int, isSuspend: Boolean): TypeConstructorMarker {
return getFunctionDescriptor(builtIns, parametersNumber, isSuspend).typeConstructor
}
override fun getKFunctionTypeConstructor(parametersNumber: Int, isSuspend: Boolean): TypeConstructorMarker {
return getKFunctionDescriptor(builtIns, parametersNumber, isSuspend).typeConstructor
}
}
fun TypeVariance.convertVariance(): Variance {