Cleanup ConstraintStorage.buildResultingSubstitutor
This commit is contained in:
+1
-1
@@ -116,7 +116,7 @@ class CoroutineInferenceSession(
|
|||||||
*
|
*
|
||||||
* while substitutor from parameter map non-fixed types to the original type variable
|
* while substitutor from parameter map non-fixed types to the original type variable
|
||||||
* */
|
* */
|
||||||
val callSubstitutor = storage.buildResultingSubstitutor(commonSystem) as NewTypeSubstitutor // substitutor only for fixed variables
|
val callSubstitutor = storage.buildResultingSubstitutor(commonSystem) // substitutor only for fixed variables
|
||||||
|
|
||||||
for (initialConstraint in storage.initialConstraints) {
|
for (initialConstraint in storage.initialConstraints) {
|
||||||
val lower = nonFixedToVariablesSubstitutor.safeSubstitute(callSubstitutor.safeSubstitute(initialConstraint.a as UnwrappedType)) // TODO: SUB
|
val lower = nonFixedToVariablesSubstitutor.safeSubstitute(callSubstitutor.safeSubstitute(initialConstraint.a as UnwrappedType)) // TODO: SUB
|
||||||
|
|||||||
+4
-2
@@ -49,6 +49,7 @@ import org.jetbrains.kotlin.types.expressions.DataFlowAnalyzer
|
|||||||
import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver
|
import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver
|
||||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
|
||||||
|
import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContextDelegate
|
||||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
@@ -66,7 +67,8 @@ class KotlinToResolvedCallTransformer(
|
|||||||
private val additionalDiagnosticReporter: AdditionalDiagnosticReporter,
|
private val additionalDiagnosticReporter: AdditionalDiagnosticReporter,
|
||||||
private val moduleDescriptor: ModuleDescriptor,
|
private val moduleDescriptor: ModuleDescriptor,
|
||||||
private val dataFlowValueFactory: DataFlowValueFactory,
|
private val dataFlowValueFactory: DataFlowValueFactory,
|
||||||
private val builtIns: KotlinBuiltIns
|
private val builtIns: KotlinBuiltIns,
|
||||||
|
private val typeSystemContext: TypeSystemInferenceExtensionContextDelegate
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
private val REPORT_MISSING_NEW_INFERENCE_DIAGNOSTIC
|
private val REPORT_MISSING_NEW_INFERENCE_DIAGNOSTIC
|
||||||
@@ -106,7 +108,7 @@ class KotlinToResolvedCallTransformer(
|
|||||||
is CompletedCallResolutionResult, is ErrorCallResolutionResult -> {
|
is CompletedCallResolutionResult, is ErrorCallResolutionResult -> {
|
||||||
val candidate = (baseResolvedCall as SingleCallResolutionResult).resultCallAtom
|
val candidate = (baseResolvedCall as SingleCallResolutionResult).resultCallAtom
|
||||||
|
|
||||||
val resultSubstitutor = baseResolvedCall.constraintSystem.buildResultingSubstitutor()
|
val resultSubstitutor = baseResolvedCall.constraintSystem.buildResultingSubstitutor(typeSystemContext)
|
||||||
if (context.inferenceSession.writeOnlyStubs()) {
|
if (context.inferenceSession.writeOnlyStubs()) {
|
||||||
val stub = createStubResolvedCallAndWriteItToTrace<CallableDescriptor>(
|
val stub = createStubResolvedCallAndWriteItToTrace<CallableDescriptor>(
|
||||||
candidate,
|
candidate,
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.resolve.scopes.*
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.*
|
import org.jetbrains.kotlin.resolve.scopes.receivers.*
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.expressions.*
|
import org.jetbrains.kotlin.types.expressions.*
|
||||||
|
import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContext
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -190,7 +191,9 @@ class PSICallResolver(
|
|||||||
): OverloadResolutionResults<D> {
|
): OverloadResolutionResults<D> {
|
||||||
if (result is AllCandidatesResolutionResult) {
|
if (result is AllCandidatesResolutionResult) {
|
||||||
val resolvedCalls = result.allCandidates.map { (candidate, diagnostics) ->
|
val resolvedCalls = result.allCandidates.map { (candidate, diagnostics) ->
|
||||||
val resultingSubstitutor = candidate.getSystem().asReadOnlyStorage().buildResultingSubstitutor()
|
val system = candidate.getSystem()
|
||||||
|
val resultingSubstitutor =
|
||||||
|
system.asReadOnlyStorage().buildResultingSubstitutor(system as TypeSystemInferenceExtensionContext)
|
||||||
|
|
||||||
kotlinToResolvedCallTransformer.transformToResolvedCall<D>(
|
kotlinToResolvedCallTransformer.transformToResolvedCall<D>(
|
||||||
candidate.resolvedCall, null, resultingSubstitutor, diagnostics
|
candidate.resolvedCall, null, resultingSubstitutor, diagnostics
|
||||||
|
|||||||
+18
-15
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstituto
|
|||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
|
import org.jetbrains.kotlin.types.checker.ClassicTypeSystemContext
|
||||||
import org.jetbrains.kotlin.types.model.StubTypeMarker
|
import org.jetbrains.kotlin.types.model.StubTypeMarker
|
||||||
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
||||||
import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker
|
import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker
|
||||||
@@ -29,25 +30,27 @@ import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContext
|
|||||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||||
|
|
||||||
fun ConstraintStorage.buildCurrentSubstitutor(additionalBindings: Map<TypeConstructorMarker, StubTypeMarker>): NewTypeSubstitutorByConstructorMap =
|
fun ConstraintStorage.buildCurrentSubstitutor(additionalBindings: Map<TypeConstructorMarker, StubTypeMarker>): NewTypeSubstitutorByConstructorMap =
|
||||||
NewTypeSubstitutorByConstructorMap( (fixedTypeVariables.entries.associate { it.key to it.value } + additionalBindings).cast() ) // TODO: SUB
|
NewTypeSubstitutorByConstructorMap((fixedTypeVariables.entries.associate { it.key to it.value } + additionalBindings).cast()) // TODO: SUB
|
||||||
|
|
||||||
fun ConstraintStorage.buildResultingSubstitutor(context: TypeSystemInferenceExtensionContext): TypeSubstitutorMarker = with(context) {
|
fun ConstraintStorage.buildAbstractResultingSubstitutor(context: TypeSystemInferenceExtensionContext): TypeSubstitutorMarker =
|
||||||
val currentSubstitutorMap = fixedTypeVariables.entries.associate {
|
with(context) {
|
||||||
it.key to it.value
|
val currentSubstitutorMap = fixedTypeVariables.entries.associate {
|
||||||
}
|
it.key to it.value
|
||||||
val uninferredSubstitutorMap = notFixedTypeVariables.entries.associate { (freshTypeConstructor, typeVariable) ->
|
}
|
||||||
freshTypeConstructor to context.createErrorTypeWithCustomConstructor(
|
val uninferredSubstitutorMap = notFixedTypeVariables.entries.associate { (freshTypeConstructor, typeVariable) ->
|
||||||
"Uninferred type",
|
freshTypeConstructor to context.createErrorTypeWithCustomConstructor(
|
||||||
(typeVariable.typeVariable).freshTypeConstructor()
|
"Uninferred type",
|
||||||
)
|
(typeVariable.typeVariable).freshTypeConstructor()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return context.typeSubstitutorByTypeConstructor(currentSubstitutorMap + uninferredSubstitutorMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.typeSubstitutorByTypeConstructor(currentSubstitutorMap + uninferredSubstitutorMap)
|
fun ConstraintStorage.buildResultingSubstitutor(context: TypeSystemInferenceExtensionContext): NewTypeSubstitutor {
|
||||||
|
return buildAbstractResultingSubstitutor(context) as NewTypeSubstitutor
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ConstraintStorage.buildResultingSubstitutor(): NewTypeSubstitutor =
|
|
||||||
buildResultingSubstitutor(this as TypeSystemInferenceExtensionContext) as NewTypeSubstitutor
|
|
||||||
|
|
||||||
val CallableDescriptor.returnTypeOrNothing: UnwrappedType
|
val CallableDescriptor.returnTypeOrNothing: UnwrappedType
|
||||||
get() {
|
get() {
|
||||||
returnType?.let { return it.unwrap() }
|
returnType?.let { return it.unwrap() }
|
||||||
@@ -72,7 +75,7 @@ fun CallableDescriptor.substituteAndApproximateCapturedTypes(substitutor: NewTyp
|
|||||||
override fun prepareTopLevelType(topLevelType: KotlinType, position: Variance) =
|
override fun prepareTopLevelType(topLevelType: KotlinType, position: Variance) =
|
||||||
substitutor.safeSubstitute(topLevelType.unwrap()).let { substitutedType ->
|
substitutor.safeSubstitute(topLevelType.unwrap()).let { substitutedType ->
|
||||||
TypeApproximator(builtIns).approximateToSuperType(substitutedType, TypeApproximatorConfiguration.CapturedAndIntegerLiteralsTypesApproximation)
|
TypeApproximator(builtIns).approximateToSuperType(substitutedType, TypeApproximatorConfiguration.CapturedAndIntegerLiteralsTypesApproximation)
|
||||||
?: substitutedType
|
?: substitutedType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user