[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
@@ -51,26 +51,6 @@ class ClassicConstraintSystemUtilContext(
return kotlinTypeRefiner.refineType(this)
}
override fun extractFunctionalTypeFromSupertypes(type: KotlinTypeMarker): KotlinTypeMarker {
require(type is KotlinType)
return type.extractFunctionalTypeFromSupertypes()
}
override fun KotlinTypeMarker.extractArgumentsForFunctionalTypeOrSubtype(): List<KotlinTypeMarker> {
require(this is KotlinType)
return this.getPureArgumentsForFunctionalTypeOrSubtype()
}
override fun KotlinTypeMarker.isFunctionOrKFunctionTypeWithAnySuspendability(): Boolean {
require(this is KotlinType)
return this.isFunctionOrKFunctionTypeWithAnySuspendability
}
override fun KotlinTypeMarker.isSuspendFunctionTypeOrSubtype(): Boolean {
require(this is KotlinType)
return this.isSuspendFunctionTypeOrSubtype
}
override fun <T> createArgumentConstraintPosition(argument: T): ArgumentConstraintPosition<T> {
require(argument is ResolvedAtom)
@Suppress("UNCHECKED_CAST")
@@ -95,22 +75,9 @@ class ClassicConstraintSystemUtilContext(
}
}
override fun KotlinTypeMarker.isExtensionFunctionType(): Boolean {
require(this is KotlinType)
return this.isExtensionFunctionType
}
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
}
override fun isAnonymousFunction(argument: PostponedAtomWithRevisableExpectedType): Boolean {
require(argument is ResolvedAtom)
return argument.atom is FunctionExpression
override fun PostponedAtomWithRevisableExpectedType.isAnonymousFunction(): Boolean {
require(this is ResolvedAtom)
return this.atom is FunctionExpression
}
override fun PostponedAtomWithRevisableExpectedType.isFunctionExpressionWithReceiver(): Boolean {
@@ -150,9 +150,9 @@ class KotlinConstraintSystemCompleter(
c: ConstraintSystemCompletionContext,
argument: PostponedAtomWithRevisableExpectedType,
diagnosticsHolder: KotlinDiagnosticsHolder
): Boolean = with(ctx) {
): Boolean = with(c) {
val revisedExpectedType: UnwrappedType =
argument.revisedExpectedType?.takeIf { it.isFunctionOrKFunctionTypeWithAnySuspendability() }?.cast() ?: return false
argument.revisedExpectedType?.takeIf { it.isFunctionOrKFunctionWithAnySuspendability() }?.cast() ?: return false
when (argument) {
is PostponedCallableReferenceAtom ->
@@ -212,8 +212,7 @@ class CallableReferenceWithRevisedExpectedTypeAtom(
class PostponedCallableReferenceAtom(
eagerCallableReferenceAtom: EagerCallableReferenceAtom
) : AbstractPostponedCallableReferenceAtom(eagerCallableReferenceAtom.atom, eagerCallableReferenceAtom.expectedType),
PostponedCallableReferenceMarker,
PostponedAtomWithRevisableExpectedType
PostponedCallableReferenceMarker
{
override var revisedExpectedType: UnwrappedType? = null
private set