FIR: Fix synthetic type variables to independent stub types
This commit is contained in:
committed by
teamcity
parent
580410863f
commit
df9da371cb
@@ -322,7 +322,11 @@ fun ConeIntersectionType.mapTypes(func: (ConeKotlinType) -> ConeKotlinType): Con
|
|||||||
return ConeIntersectionType(intersectedTypes.map(func), alternativeType?.let(func))
|
return ConeIntersectionType(intersectedTypes.map(func), alternativeType?.let(func))
|
||||||
}
|
}
|
||||||
|
|
||||||
data class ConeStubTypeConstructor(val variable: ConeTypeVariable, val isTypeVariableInSubtyping: Boolean) : TypeConstructorMarker
|
data class ConeStubTypeConstructor(
|
||||||
|
val variable: ConeTypeVariable,
|
||||||
|
val isTypeVariableInSubtyping: Boolean,
|
||||||
|
val isForFixation: Boolean = false,
|
||||||
|
) : TypeConstructorMarker
|
||||||
|
|
||||||
sealed class ConeStubType(val constructor: ConeStubTypeConstructor, override val nullability: ConeNullability) : StubTypeMarker,
|
sealed class ConeStubType(val constructor: ConeStubTypeConstructor, override val nullability: ConeNullability) : StubTypeMarker,
|
||||||
ConeSimpleKotlinType() {
|
ConeSimpleKotlinType() {
|
||||||
@@ -363,6 +367,9 @@ open class ConeStubTypeForBuilderInference(constructor: ConeStubTypeConstructor,
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ConeStubTypeForFixation(constructor: ConeStubTypeConstructor, nullability: ConeNullability) :
|
||||||
|
ConeStubTypeForBuilderInference(constructor, nullability)
|
||||||
|
|
||||||
class ConeStubTypeForTypeVariableInSubtyping(constructor: ConeStubTypeConstructor, nullability: ConeNullability) :
|
class ConeStubTypeForTypeVariableInSubtyping(constructor: ConeStubTypeConstructor, nullability: ConeNullability) :
|
||||||
ConeStubType(constructor, nullability) {
|
ConeStubType(constructor, nullability) {
|
||||||
constructor(variable: ConeTypeVariable, nullability: ConeNullability) : this(
|
constructor(variable: ConeTypeVariable, nullability: ConeNullability) : this(
|
||||||
|
|||||||
@@ -435,6 +435,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
|
|||||||
override fun TypeConstructorMarker.unwrapStubTypeVariableConstructor(): TypeConstructorMarker {
|
override fun TypeConstructorMarker.unwrapStubTypeVariableConstructor(): TypeConstructorMarker {
|
||||||
if (this !is ConeStubTypeConstructor) return this
|
if (this !is ConeStubTypeConstructor) return this
|
||||||
if (this.isTypeVariableInSubtyping) return this
|
if (this.isTypeVariableInSubtyping) return this
|
||||||
|
if (this.isForFixation) return this
|
||||||
return this.variable.typeConstructor
|
return this.variable.typeConstructor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-9
@@ -226,15 +226,21 @@ class ConstraintSystemCompleter(private val components: BodyResolveComponents, p
|
|||||||
|
|
||||||
val variableWithConstraints = notFixedTypeVariables.getValue(variableForFixation.variable)
|
val variableWithConstraints = notFixedTypeVariables.getValue(variableForFixation.variable)
|
||||||
|
|
||||||
if (variableForFixation.hasProperConstraint) {
|
when {
|
||||||
fixVariable(asConstraintSystemCompletionContext(), topLevelType, variableWithConstraints, postponedArguments)
|
variableForFixation.hasProperConstraint -> {
|
||||||
return true
|
fixVariable(asConstraintSystemCompletionContext(), topLevelType, variableWithConstraints, postponedArguments)
|
||||||
} else if (context.inferenceSession.isSyntheticTypeVariable(variableWithConstraints.typeVariable)) {
|
return true
|
||||||
val variable = variableWithConstraints.typeVariable as ConeTypeVariable
|
}
|
||||||
context.inferenceSession.fixSyntheticTypeVariableWithNotEnoughInformation(variable, asConstraintSystemCompletionContext())
|
context.inferenceSession.isSyntheticTypeVariable(variableWithConstraints.typeVariable) -> {
|
||||||
return true
|
context.inferenceSession.fixSyntheticTypeVariableWithNotEnoughInformation(
|
||||||
} else {
|
variableWithConstraints.typeVariable as ConeTypeVariable,
|
||||||
processVariableWhenNotEnoughInformation(this, variableWithConstraints, topLevelAtoms)
|
asConstraintSystemCompletionContext()
|
||||||
|
)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
processVariableWhenNotEnoughInformation(this, variableWithConstraints, topLevelAtoms)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-5
@@ -112,15 +112,16 @@ class FirDelegatedPropertyInferenceSession(
|
|||||||
private fun createNonFixedTypeToVariableSubstitutor(): ConeSubstitutor {
|
private fun createNonFixedTypeToVariableSubstitutor(): ConeSubstitutor {
|
||||||
val typeContext = components.session.typeContext
|
val typeContext = components.session.typeContext
|
||||||
|
|
||||||
val bindings = mutableMapOf<TypeConstructorMarker, ConeKotlinType>()
|
val bindings = mutableMapOf<TypeVariableMarker, ConeKotlinType>()
|
||||||
for ((variable, stubType) in stubTypesByTypeVariable) {
|
for ((variable, synthetic) in syntheticTypeVariableByTypeVariable) {
|
||||||
bindings[stubType.constructor] = variable.defaultType(typeContext) as ConeKotlinType
|
bindings[synthetic] = variable.defaultType(typeContext) as ConeKotlinType
|
||||||
}
|
}
|
||||||
|
|
||||||
return object : AbstractConeSubstitutor(typeContext) {
|
return object : AbstractConeSubstitutor(typeContext) {
|
||||||
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
|
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
|
||||||
if (type !is ConeStubType) return null
|
if (type !is ConeStubType) return null
|
||||||
return bindings[type.constructor].updateNullabilityIfNeeded(type)
|
if (type.constructor.isTypeVariableInSubtyping) return null
|
||||||
|
return bindings[type.constructor.variable].updateNullabilityIfNeeded(type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -151,9 +152,13 @@ class FirDelegatedPropertyInferenceSession(
|
|||||||
typeVariable: TypeVariableMarker,
|
typeVariable: TypeVariableMarker,
|
||||||
completionContext: ConstraintSystemCompletionContext
|
completionContext: ConstraintSystemCompletionContext
|
||||||
) {
|
) {
|
||||||
|
typeVariable as ConeTypeVariable
|
||||||
completionContext.fixVariable(
|
completionContext.fixVariable(
|
||||||
typeVariable,
|
typeVariable,
|
||||||
stubTypeBySyntheticTypeVariable[typeVariable]!!,
|
ConeStubTypeForFixation(
|
||||||
|
ConeStubTypeConstructor(typeVariable, isTypeVariableInSubtyping = false, isForFixation = true),
|
||||||
|
ConeNullability.create(typeVariable.defaultType.isMarkedNullable)
|
||||||
|
),
|
||||||
ConeFixVariableConstraintPosition(typeVariable)
|
ConeFixVariableConstraintPosition(typeVariable)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user