K2: Implement partially constrained lambda analysis (PCLA)

It's expected to partially mimic the behavior of what
previously was called builder inference, but with more clear contracts
(documentation is in progress, though)

See a lot of fixed issues in the later commits with test data,
especially [red-to-green]

^KT-59791 In Progress
This commit is contained in:
Denis.Zharkov
2023-08-21 17:51:54 +02:00
committed by Space Team
parent 9ae5287df8
commit 276f5b26d8
44 changed files with 1356 additions and 1086 deletions
@@ -8,7 +8,9 @@ package org.jetbrains.kotlin.types.model
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
import org.jetbrains.kotlin.resolve.checkers.EmptyIntersectionTypeChecker
import org.jetbrains.kotlin.resolve.checkers.EmptyIntersectionTypeInfo
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.AbstractTypeChecker
import org.jetbrains.kotlin.types.TypeCheckerState
import org.jetbrains.kotlin.types.Variance
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
@@ -310,6 +312,9 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
*/
fun KotlinTypeMarker.convertToNonRaw(): KotlinTypeMarker
@K2Only
fun createSubstitutionFromSubtypingStubTypesToTypeVariables(): TypeSubstitutorMarker
fun createCapturedStarProjectionForSelfType(
typeVariable: TypeVariableTypeConstructorMarker,
typesForRecursiveTypeParameters: List<KotlinTypeMarker>,
@@ -588,3 +593,6 @@ fun requireOrDescribe(condition: Boolean, value: Any?) {
@RequiresOptIn("This kinds of type is obsolete and should not be used until you really need it")
annotation class ObsoleteTypeKind
@RequiresOptIn
annotation class K2Only
@@ -622,6 +622,11 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
errorSupportedOnlyInTypeInference()
}
@K2Only
override fun createSubstitutionFromSubtypingStubTypesToTypeVariables(): TypeSubstitutorMarker {
error("Only for K2")
}
override fun TypeSubstitutorMarker.safeSubstitute(type: KotlinTypeMarker): KotlinTypeMarker {
require(type is UnwrappedType, type::errorMessage)
require(this is TypeSubstitutor, this::errorMessage)