[NI] Refactoring: rename NonFixedType -> StubType

This commit is contained in:
Mikhail Zarechenskiy
2018-05-04 17:03:08 +03:00
parent 5187f6b060
commit 64b10d827d
8 changed files with 16 additions and 18 deletions
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.resolve.calls.model.KotlinCallComponents
import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate
import org.jetbrains.kotlin.resolve.calls.model.ResolvedLambdaAtom import org.jetbrains.kotlin.resolve.calls.model.ResolvedLambdaAtom
import org.jetbrains.kotlin.resolve.calls.tower.* import org.jetbrains.kotlin.resolve.calls.tower.*
import org.jetbrains.kotlin.types.NonFixedType import org.jetbrains.kotlin.types.StubType
import org.jetbrains.kotlin.types.TypeConstructor import org.jetbrains.kotlin.types.TypeConstructor
import org.jetbrains.kotlin.types.UnwrappedType import org.jetbrains.kotlin.types.UnwrappedType
import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver
@@ -38,7 +38,7 @@ class CoroutineInferenceSession(
callComponents: KotlinCallComponents, callComponents: KotlinCallComponents,
builtIns: KotlinBuiltIns, builtIns: KotlinBuiltIns,
private val topLevelCallContext: BasicCallResolutionContext, private val topLevelCallContext: BasicCallResolutionContext,
private val stubsForPostponedVariables: Map<NewTypeVariable, NonFixedType>, private val stubsForPostponedVariables: Map<NewTypeVariable, StubType>,
private val trace: BindingTrace, private val trace: BindingTrace,
private val kotlinToResolvedCallTransformer: KotlinToResolvedCallTransformer, private val kotlinToResolvedCallTransformer: KotlinToResolvedCallTransformer,
private val expressionTypingServices: ExpressionTypingServices, private val expressionTypingServices: ExpressionTypingServices,
@@ -86,7 +86,7 @@ class KotlinResolutionCallbacksImpl(
receiverType: UnwrappedType?, receiverType: UnwrappedType?,
parameters: List<UnwrappedType>, parameters: List<UnwrappedType>,
expectedReturnType: UnwrappedType?, expectedReturnType: UnwrappedType?,
stubsForPostponedVariables: Map<NewTypeVariable, NonFixedType> stubsForPostponedVariables: Map<NewTypeVariable, StubType>
): Pair<List<KotlinCallArgument>, InferenceSession?> { ): Pair<List<KotlinCallArgument>, InferenceSession?> {
val psiCallArgument = lambdaArgument.psiCallArgument as PSIFunctionKotlinCallArgument val psiCallArgument = lambdaArgument.psiCallArgument as PSIFunctionKotlinCallArgument
val outerCallContext = psiCallArgument.outerCallContext val outerCallContext = psiCallArgument.outerCallContext
@@ -12,8 +12,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.NewTypeVariable
import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.StubType
import org.jetbrains.kotlin.types.NonFixedType
import org.jetbrains.kotlin.types.UnwrappedType import org.jetbrains.kotlin.types.UnwrappedType
// stateless component // stateless component
@@ -37,7 +36,7 @@ interface KotlinResolutionCallbacks {
receiverType: UnwrappedType?, receiverType: UnwrappedType?,
parameters: List<UnwrappedType>, parameters: List<UnwrappedType>,
expectedReturnType: UnwrappedType?, // null means, that return type is not proper i.e. it depends on some type variables expectedReturnType: UnwrappedType?, // null means, that return type is not proper i.e. it depends on some type variables
stubsForPostponedVariables: Map<NewTypeVariable, NonFixedType> stubsForPostponedVariables: Map<NewTypeVariable, StubType>
): Pair<List<KotlinCallArgument>, InferenceSession?> ): Pair<List<KotlinCallArgument>, InferenceSession?>
fun bindStubResolvedCallForCandidate(candidate: ResolvedCallAtom) fun bindStubResolvedCallForCandidate(candidate: ResolvedCallAtom)
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.addSubsystemFromArgument
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.model.* import org.jetbrains.kotlin.resolve.calls.inference.model.*
import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.types.NonFixedType import org.jetbrains.kotlin.types.StubType
import org.jetbrains.kotlin.types.TypeConstructor import org.jetbrains.kotlin.types.TypeConstructor
import org.jetbrains.kotlin.types.UnwrappedType import org.jetbrains.kotlin.types.UnwrappedType
import org.jetbrains.kotlin.types.typeUtil.builtIns import org.jetbrains.kotlin.types.typeUtil.builtIns
@@ -19,8 +19,8 @@ class PostponedArgumentsAnalyzer(
private val callableReferenceResolver: CallableReferenceResolver private val callableReferenceResolver: CallableReferenceResolver
) { ) {
interface Context { interface Context {
fun buildCurrentSubstitutor(additionalBindings: Map<TypeConstructor, NonFixedType>): NewTypeSubstitutor fun buildCurrentSubstitutor(additionalBindings: Map<TypeConstructor, StubType>): NewTypeSubstitutor
fun bindingStubsForPostponedVariables(): Map<NewTypeVariable, NonFixedType> fun bindingStubsForPostponedVariables(): Map<NewTypeVariable, StubType>
// type can be proper if it not contains not fixed type variables // type can be proper if it not contains not fixed type variables
fun canBeProper(type: UnwrappedType): Boolean fun canBeProper(type: UnwrappedType): Boolean
@@ -20,11 +20,10 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutorByConstructorMap import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutorByConstructorMap
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
import org.jetbrains.kotlin.resolve.calls.inference.model.NewTypeVariable
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.*
fun ConstraintStorage.buildCurrentSubstitutor(additionalBindings: Map<TypeConstructor, NonFixedType>): NewTypeSubstitutorByConstructorMap = fun ConstraintStorage.buildCurrentSubstitutor(additionalBindings: Map<TypeConstructor, StubType>): NewTypeSubstitutorByConstructorMap =
NewTypeSubstitutorByConstructorMap(fixedTypeVariables.entries.associate { it.key to it.value } + additionalBindings) NewTypeSubstitutorByConstructorMap(fixedTypeVariables.entries.associate { it.key to it.value } + additionalBindings)
fun ConstraintStorage.buildResultingSubstitutor(): NewTypeSubstitutor { fun ConstraintStorage.buildResultingSubstitutor(): NewTypeSubstitutor {
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintS
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.components.ResultTypeResolver import org.jetbrains.kotlin.resolve.calls.inference.components.ResultTypeResolver
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
import org.jetbrains.kotlin.types.NonFixedType import org.jetbrains.kotlin.types.StubType
import org.jetbrains.kotlin.types.TypeConstructor import org.jetbrains.kotlin.types.TypeConstructor
import org.jetbrains.kotlin.types.UnwrappedType import org.jetbrains.kotlin.types.UnwrappedType
import org.jetbrains.kotlin.types.typeUtil.contains import org.jetbrains.kotlin.types.typeUtil.contains
@@ -273,14 +273,14 @@ class NewConstraintSystemImpl(
return buildCurrentSubstitutor(emptyMap()) return buildCurrentSubstitutor(emptyMap())
} }
override fun buildCurrentSubstitutor(additionalBindings: Map<TypeConstructor, NonFixedType>): NewTypeSubstitutor { override fun buildCurrentSubstitutor(additionalBindings: Map<TypeConstructor, StubType>): NewTypeSubstitutor {
checkState(State.BUILDING, State.COMPLETION) checkState(State.BUILDING, State.COMPLETION)
return storage.buildCurrentSubstitutor(additionalBindings) return storage.buildCurrentSubstitutor(additionalBindings)
} }
override fun bindingStubsForPostponedVariables(): Map<NewTypeVariable, NonFixedType> { override fun bindingStubsForPostponedVariables(): Map<NewTypeVariable, StubType> {
checkState(State.BUILDING, State.COMPLETION) checkState(State.BUILDING, State.COMPLETION)
return storage.postponedTypeVariables.associate { it to NonFixedType(it.freshTypeConstructor, it.defaultType.isMarkedNullable) } return storage.postponedTypeVariables.associate { it to StubType(it.freshTypeConstructor, it.defaultType.isMarkedNullable) }
} }
override fun currentStorage(): ConstraintStorage { override fun currentStorage(): ConstraintStorage {
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.resolve.scopes.MemberScope
// This type is used as a stub for postponed type variables, which are important for coroutine inference // This type is used as a stub for postponed type variables, which are important for coroutine inference
class NonFixedType( class StubType(
private val originalTypeVariable: TypeConstructor, private val originalTypeVariable: TypeConstructor,
override val isMarkedNullable: Boolean, override val isMarkedNullable: Boolean,
override val constructor: TypeConstructor = override val constructor: TypeConstructor =
@@ -32,7 +32,7 @@ class NonFixedType(
return if (newNullability == isMarkedNullable) return if (newNullability == isMarkedNullable)
this this
else else
NonFixedType(originalTypeVariable, newNullability, constructor, memberScope) StubType(originalTypeVariable, newNullability, constructor, memberScope)
} }
override fun toString(): String { override fun toString(): String {
@@ -186,7 +186,7 @@ object NewKotlinTypeChecker : KotlinTypeChecker {
return StrictEqualityTypeChecker.strictEqualTypes(subType.makeNullableAsSpecified(false), superType.makeNullableAsSpecified(false)) return StrictEqualityTypeChecker.strictEqualTypes(subType.makeNullableAsSpecified(false), superType.makeNullableAsSpecified(false))
} }
if (subType is NonFixedType || superType is NonFixedType) return true if (subType is StubType || superType is StubType) return true
if (superType is NewCapturedType && superType.lowerType != null) { if (superType is NewCapturedType && superType.lowerType != null) {
when (getLowerCapturedTypePolicy(subType, superType)) { when (getLowerCapturedTypePolicy(subType, superType)) {