[FE] Move substitutor related methods to TypeSystemContext
Also use TypeSystemContext instead of TypeSystemInferenceExtensionContext in AbstractExpectActualCompatibilityChecker This is needed to have an ability to implement ExpectActualMatchingContext for IR backend. IrTypeSystemContext may operate with type substitutors, but there is no sense to implement all methods from TypeSystemInferenceExtensionContext in it
This commit is contained in:
committed by
Space Team
parent
26d7494789
commit
623019cff1
+2
-5
@@ -25,10 +25,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.calls.mpp.ExpectActualMatchingContext
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContext
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.UnsafeCastFunction
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.castAll
|
||||
@@ -36,7 +33,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.castAll
|
||||
class FirExpectActualMatchingContext(
|
||||
private val actualSession: FirSession,
|
||||
private val scopeSession: ScopeSession
|
||||
) : ExpectActualMatchingContext<FirBasedSymbol<*>>, TypeSystemInferenceExtensionContext by actualSession.typeContext {
|
||||
) : ExpectActualMatchingContext<FirBasedSymbol<*>>, TypeSystemContext by actualSession.typeContext {
|
||||
override val shouldCheckReturnTypesOfCallables: Boolean
|
||||
get() = false
|
||||
|
||||
|
||||
@@ -28,14 +28,14 @@ import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.types.TypeSystemCommonBackendContext
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.ir.types.makeNotNull as irMakeNotNull
|
||||
import org.jetbrains.kotlin.ir.types.makeNullable as irMakeNullable
|
||||
import org.jetbrains.kotlin.ir.types.isMarkedNullable as irIsMarkedNullable
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
import org.jetbrains.kotlin.utils.compactIfPossible
|
||||
import org.jetbrains.kotlin.utils.memoryOptimizedFilterIsInstance
|
||||
import org.jetbrains.kotlin.utils.memoryOptimizedMap
|
||||
import org.jetbrains.kotlin.utils.compactIfPossible
|
||||
import org.jetbrains.kotlin.ir.types.isMarkedNullable as irIsMarkedNullable
|
||||
import org.jetbrains.kotlin.ir.types.isPrimitiveType as irTypePredicates_isPrimitiveType
|
||||
import org.jetbrains.kotlin.ir.types.makeNotNull as irMakeNotNull
|
||||
import org.jetbrains.kotlin.ir.types.makeNullable as irMakeNullable
|
||||
|
||||
interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesContext, TypeSystemCommonBackendContext {
|
||||
|
||||
@@ -589,6 +589,26 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
||||
override fun KotlinTypeMarker.isTypeVariableType(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun typeSubstitutorByTypeConstructor(map: Map<TypeConstructorMarker, KotlinTypeMarker>): TypeSubstitutorMarker {
|
||||
val typeParameters = mutableListOf<IrTypeParameterSymbol>()
|
||||
val typeArguments = mutableListOf<IrTypeArgument>()
|
||||
for ((key, value) in map) {
|
||||
typeParameters += key as IrTypeParameterSymbol
|
||||
typeArguments += value as IrTypeArgument
|
||||
}
|
||||
return IrTypeSubstitutor(typeParameters, typeArguments, irBuiltIns)
|
||||
}
|
||||
|
||||
override fun createEmptySubstitutor(): TypeSubstitutorMarker {
|
||||
return IrTypeSubstitutor(emptyList(), emptyList(), irBuiltIns)
|
||||
}
|
||||
|
||||
override fun TypeSubstitutorMarker.safeSubstitute(type: KotlinTypeMarker): KotlinTypeMarker {
|
||||
require(this is AbstractIrTypeSubstitutor)
|
||||
require(type is IrType)
|
||||
return substitute(type)
|
||||
}
|
||||
}
|
||||
|
||||
fun extractTypeParameters(parent: IrDeclarationParent): List<IrTypeParameter> {
|
||||
|
||||
+2
-2
@@ -15,9 +15,9 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContext
|
||||
import org.jetbrains.kotlin.types.model.TypeSystemContext
|
||||
|
||||
interface ExpectActualMatchingContext<T : DeclarationSymbolMarker> : TypeSystemInferenceExtensionContext {
|
||||
interface ExpectActualMatchingContext<T : DeclarationSymbolMarker> : TypeSystemContext {
|
||||
val shouldCheckReturnTypesOfCallables: Boolean
|
||||
|
||||
val RegularClassSymbolMarker.classId: ClassId
|
||||
|
||||
+2
-5
@@ -22,17 +22,14 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.*
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContext
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.UnsafeCastFunction
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.castAll
|
||||
import org.jetbrains.kotlin.utils.keysToMap
|
||||
|
||||
class ClassicExpectActualMatchingContext(val platformModule: ModuleDescriptor) : ExpectActualMatchingContext<MemberDescriptor>,
|
||||
TypeSystemInferenceExtensionContext by ClassicTypeSystemContextForCS(platformModule.builtIns, KotlinTypeRefiner.Default)
|
||||
TypeSystemContext by ClassicTypeSystemContextForCS(platformModule.builtIns, KotlinTypeRefiner.Default)
|
||||
{
|
||||
override val shouldCheckReturnTypesOfCallables: Boolean
|
||||
get() = true
|
||||
|
||||
@@ -227,12 +227,6 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
|
||||
fun CapturedTypeMarker.typeParameter(): TypeParameterMarker?
|
||||
fun CapturedTypeMarker.withNotNullProjection(): KotlinTypeMarker
|
||||
|
||||
fun typeSubstitutorByTypeConstructor(map: Map<TypeConstructorMarker, KotlinTypeMarker>): TypeSubstitutorMarker
|
||||
fun createEmptySubstitutor(): TypeSubstitutorMarker
|
||||
|
||||
fun TypeSubstitutorMarker.safeSubstitute(type: KotlinTypeMarker): KotlinTypeMarker
|
||||
|
||||
|
||||
fun TypeVariableMarker.defaultType(): SimpleTypeMarker
|
||||
|
||||
fun createTypeWithAlternativeForIntersectionResult(
|
||||
@@ -552,6 +546,14 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
|
||||
fun substitutionSupertypePolicy(type: SimpleTypeMarker): TypeCheckerState.SupertypesPolicy
|
||||
|
||||
fun KotlinTypeMarker.isTypeVariableType(): Boolean
|
||||
|
||||
fun typeSubstitutorByTypeConstructor(map: Map<TypeConstructorMarker, KotlinTypeMarker>): TypeSubstitutorMarker
|
||||
fun createEmptySubstitutor(): TypeSubstitutorMarker
|
||||
|
||||
/**
|
||||
* @returns substituted type or [type] if there were no substitution
|
||||
*/
|
||||
fun TypeSubstitutorMarker.safeSubstitute(type: KotlinTypeMarker): KotlinTypeMarker
|
||||
}
|
||||
|
||||
enum class CaptureStatus {
|
||||
|
||||
Reference in New Issue
Block a user