[NI] Extract FE 1.0 specific part from NewCommonSuperTypeCalculator
This commit is contained in:
+2
-8
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
|||||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.*
|
import org.jetbrains.kotlin.fir.declarations.builder.*
|
||||||
import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic
|
|
||||||
import org.jetbrains.kotlin.fir.typeContext
|
import org.jetbrains.kotlin.fir.typeContext
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.withReplacedConeType
|
import org.jetbrains.kotlin.fir.scopes.impl.withReplacedConeType
|
||||||
import org.jetbrains.kotlin.fir.serialization.FirElementSerializer
|
import org.jetbrains.kotlin.fir.serialization.FirElementSerializer
|
||||||
@@ -39,7 +38,6 @@ import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
|||||||
import org.jetbrains.kotlin.metadata.jvm.serialization.JvmStringTable
|
import org.jetbrains.kotlin.metadata.jvm.serialization.JvmStringTable
|
||||||
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
||||||
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
||||||
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
|
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
import org.jetbrains.org.objectweb.asm.commons.Method
|
import org.jetbrains.org.objectweb.asm.commons.Method
|
||||||
|
|
||||||
@@ -60,11 +58,7 @@ class FirJvmClassCodegen(
|
|||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
private val approximator = object : AbstractTypeApproximator(session.typeContext) {
|
private val approximator = object : AbstractTypeApproximator(session.typeContext) {}
|
||||||
override fun createErrorType(message: String): SimpleTypeMarker {
|
|
||||||
return ConeKotlinErrorType(ConeIntermediateDiagnostic(message))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun FirTypeRef.approximated(
|
private fun FirTypeRef.approximated(
|
||||||
toSuper: Boolean,
|
toSuper: Boolean,
|
||||||
@@ -197,4 +191,4 @@ class FirJvmClassCodegen(
|
|||||||
state.globalSerializationBindings.put(FirJvmSerializerExtension.FIELD_FOR_PROPERTY, metadata.property, fieldType to fieldName)
|
state.globalSerializationBindings.put(FirJvmSerializerExtension.FIELD_FOR_PROPERTY, metadata.property, fieldType to fieldName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-8
@@ -7,10 +7,8 @@ package org.jetbrains.kotlin.fir.resolve.inference
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.PrivateForInline
|
import org.jetbrains.kotlin.fir.PrivateForInline
|
||||||
import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
|
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
|
||||||
import org.jetbrains.kotlin.fir.types.ConeClassErrorType
|
|
||||||
import org.jetbrains.kotlin.fir.types.ConeInferenceContext
|
import org.jetbrains.kotlin.fir.types.ConeInferenceContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintIncorporator
|
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintIncorporator
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector
|
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector
|
||||||
@@ -19,7 +17,6 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.TrivialConstraint
|
|||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl
|
import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl
|
||||||
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
||||||
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
|
|
||||||
|
|
||||||
class InferenceComponents(
|
class InferenceComponents(
|
||||||
val ctx: ConeInferenceContext,
|
val ctx: ConeInferenceContext,
|
||||||
@@ -27,11 +24,7 @@ class InferenceComponents(
|
|||||||
val returnTypeCalculator: ReturnTypeCalculator,
|
val returnTypeCalculator: ReturnTypeCalculator,
|
||||||
val scopeSession: ScopeSession
|
val scopeSession: ScopeSession
|
||||||
) {
|
) {
|
||||||
val approximator: AbstractTypeApproximator = object : AbstractTypeApproximator(ctx) {
|
val approximator: AbstractTypeApproximator = object : AbstractTypeApproximator(ctx) {}
|
||||||
override fun createErrorType(message: String): SimpleTypeMarker {
|
|
||||||
return ConeClassErrorType(ConeIntermediateDiagnostic(message))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle.create(ctx)
|
val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle.create(ctx)
|
||||||
private val incorporator = ConstraintIncorporator(approximator, trivialConstraintTypeInferenceOracle)
|
private val incorporator = ConstraintIncorporator(approximator, trivialConstraintTypeInferenceOracle)
|
||||||
private val injector = ConstraintInjector(incorporator, approximator, KotlinTypeRefiner.Default)
|
private val injector = ConstraintInjector(incorporator, approximator, KotlinTypeRefiner.Default)
|
||||||
|
|||||||
@@ -334,6 +334,10 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
|||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun createErrorType(debugName: String): ConeClassErrorType {
|
||||||
|
return ConeClassErrorType(ConeIntermediateDiagnostic(debugName))
|
||||||
|
}
|
||||||
|
|
||||||
override fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker {
|
override fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker {
|
||||||
return ConeKotlinErrorType(ConeIntermediateDiagnostic("$debugName c: $constructor"))
|
return ConeKotlinErrorType(ConeIntermediateDiagnostic("$debugName c: $constructor"))
|
||||||
}
|
}
|
||||||
@@ -358,8 +362,6 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
|||||||
return createErrorType("Unknown reason")
|
return createErrorType("Unknown reason")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createErrorType(reason: String) = ConeClassErrorType(ConeIntermediateDiagnostic(reason))
|
|
||||||
|
|
||||||
override fun findCommonIntegerLiteralTypesSuperType(explicitSupertypes: List<SimpleTypeMarker>): SimpleTypeMarker? {
|
override fun findCommonIntegerLiteralTypesSuperType(explicitSupertypes: List<SimpleTypeMarker>): SimpleTypeMarker? {
|
||||||
return ConeIntegerLiteralTypeImpl.findCommonSuperType(explicitSupertypes)
|
return ConeIntegerLiteralTypeImpl.findCommonSuperType(explicitSupertypes)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.resolve.TemporaryBindingTrace
|
|||||||
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver
|
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver
|
||||||
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator
|
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
|
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.commonSuperType
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceAdaptation
|
import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceAdaptation
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.SuspendConversionStrategy
|
import org.jetbrains.kotlin.resolve.calls.components.SuspendConversionStrategy
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.isVararg
|
import org.jetbrains.kotlin.resolve.calls.components.isVararg
|
||||||
|
|||||||
+1
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.psi2ir.findSingleFunction
|
|||||||
import org.jetbrains.kotlin.psi2ir.intermediate.safeCallOnDispatchReceiver
|
import org.jetbrains.kotlin.psi2ir.intermediate.safeCallOnDispatchReceiver
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator
|
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.commonSuperType
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.checkers.PrimitiveNumericComparisonInfo
|
import org.jetbrains.kotlin.resolve.checkers.PrimitiveNumericComparisonInfo
|
||||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
|
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
|
||||||
|
|||||||
@@ -282,6 +282,10 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
|||||||
override fun SimpleTypeMarker.isPrimitiveType(): Boolean =
|
override fun SimpleTypeMarker.isPrimitiveType(): Boolean =
|
||||||
this is IrSimpleType && irTypePredicates_isPrimitiveType()
|
this is IrSimpleType && irTypePredicates_isPrimitiveType()
|
||||||
|
|
||||||
|
override fun createErrorType(debugName: String): SimpleTypeMarker {
|
||||||
|
TODO("IrTypeSystemContext doesn't support constraint system resolution")
|
||||||
|
}
|
||||||
|
|
||||||
override fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker =
|
override fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker =
|
||||||
TODO("IrTypeSystemContext doesn't support constraint system resolution")
|
TODO("IrTypeSystemContext doesn't support constraint system resolution")
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.resolve.calls
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.types.UnwrappedType
|
||||||
|
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext
|
||||||
|
|
||||||
|
fun NewCommonSuperTypeCalculator.commonSuperType(types: List<UnwrappedType>): UnwrappedType {
|
||||||
|
return SimpleClassicTypeSystemContext.commonSuperType(types) as UnwrappedType
|
||||||
|
}
|
||||||
+5
-9
@@ -16,18 +16,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.calls
|
package org.jetbrains.kotlin.resolve.calls
|
||||||
|
|
||||||
import org.jetbrains.kotlin.types.*
|
|
||||||
import org.jetbrains.kotlin.types.AbstractFlexibilityChecker.hasDifferentFlexibilityAtDepth
|
import org.jetbrains.kotlin.types.AbstractFlexibilityChecker.hasDifferentFlexibilityAtDepth
|
||||||
|
import org.jetbrains.kotlin.types.AbstractNullabilityChecker
|
||||||
import org.jetbrains.kotlin.types.AbstractNullabilityChecker.hasPathByNotMarkedNullableNodes
|
import org.jetbrains.kotlin.types.AbstractNullabilityChecker.hasPathByNotMarkedNullableNodes
|
||||||
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext
|
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||||
|
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||||
import org.jetbrains.kotlin.types.model.*
|
import org.jetbrains.kotlin.types.model.*
|
||||||
|
|
||||||
object NewCommonSuperTypeCalculator {
|
object NewCommonSuperTypeCalculator {
|
||||||
// TODO: Bridge for old calls
|
|
||||||
fun commonSuperType(types: List<UnwrappedType>): UnwrappedType {
|
|
||||||
return SimpleClassicTypeSystemContext.commonSuperType(types) as UnwrappedType
|
|
||||||
}
|
|
||||||
|
|
||||||
fun TypeSystemCommonSuperTypesContext.commonSuperType(types: List<KotlinTypeMarker>): KotlinTypeMarker {
|
fun TypeSystemCommonSuperTypesContext.commonSuperType(types: List<KotlinTypeMarker>): KotlinTypeMarker {
|
||||||
val maxDepth = types.maxOfOrNull { it.typeDepth() } ?: 0
|
val maxDepth = types.maxOfOrNull { it.typeDepth() } ?: 0
|
||||||
return commonSuperType(types, -maxDepth, true)
|
return commonSuperType(types, -maxDepth, true)
|
||||||
@@ -96,8 +92,8 @@ object NewCommonSuperTypeCalculator {
|
|||||||
contextStubTypesEqualToAnything: AbstractTypeCheckerContext,
|
contextStubTypesEqualToAnything: AbstractTypeCheckerContext,
|
||||||
contextStubTypesNotEqual: AbstractTypeCheckerContext
|
contextStubTypesNotEqual: AbstractTypeCheckerContext
|
||||||
): SimpleTypeMarker {
|
): SimpleTypeMarker {
|
||||||
if (types.any { it is ErrorType }) {
|
if (types.any { it.isError() }) {
|
||||||
return ErrorUtils.createErrorType("CST(${types.joinToString()}")
|
return createErrorType("CST(${types.joinToString()}")
|
||||||
}
|
}
|
||||||
|
|
||||||
// i.e. result type also should be marked nullable
|
// i.e. result type also should be marked nullable
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ abstract class AbstractTypeApproximator(val ctx: TypeSystemInferenceExtensionCon
|
|||||||
const val CACHE_FOR_INCORPORATION_MAX_SIZE = 500
|
const val CACHE_FOR_INCORPORATION_MAX_SIZE = 500
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun createErrorType(message: String): SimpleTypeMarker
|
|
||||||
|
|
||||||
// null means that this input type is the result, i.e. input type not contains not-allowed kind of types
|
// null means that this input type is the result, i.e. input type not contains not-allowed kind of types
|
||||||
// type <: resultType
|
// type <: resultType
|
||||||
fun approximateToSuperType(type: KotlinTypeMarker, conf: TypeApproximatorConfiguration): KotlinTypeMarker? =
|
fun approximateToSuperType(type: KotlinTypeMarker, conf: TypeApproximatorConfiguration): KotlinTypeMarker? =
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.config.LanguageFeature
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.ClassicTypeSystemContextForCS
|
import org.jetbrains.kotlin.resolve.calls.components.ClassicTypeSystemContextForCS
|
||||||
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
|
|
||||||
|
|
||||||
class TypeApproximator(builtIns: KotlinBuiltIns) : AbstractTypeApproximator(ClassicTypeSystemContextForCS(builtIns)) {
|
class TypeApproximator(builtIns: KotlinBuiltIns) : AbstractTypeApproximator(ClassicTypeSystemContextForCS(builtIns)) {
|
||||||
fun approximateDeclarationType(baseType: KotlinType, local: Boolean, languageVersionSettings: LanguageVersionSettings): UnwrappedType {
|
fun approximateDeclarationType(baseType: KotlinType, local: Boolean, languageVersionSettings: LanguageVersionSettings): UnwrappedType {
|
||||||
@@ -39,9 +38,5 @@ class TypeApproximator(builtIns: KotlinBuiltIns) : AbstractTypeApproximator(Clas
|
|||||||
// resultType <: type
|
// resultType <: type
|
||||||
fun approximateToSubType(type: UnwrappedType, conf: TypeApproximatorConfiguration): UnwrappedType? =
|
fun approximateToSubType(type: UnwrappedType, conf: TypeApproximatorConfiguration): UnwrappedType? =
|
||||||
super.approximateToSubType(type, conf) as UnwrappedType?
|
super.approximateToSubType(type, conf) as UnwrappedType?
|
||||||
|
|
||||||
override fun createErrorType(message: String): SimpleTypeMarker {
|
|
||||||
return ErrorUtils.createErrorType(message)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ interface TypeSystemTypeFactoryContext {
|
|||||||
fun createTypeArgument(type: KotlinTypeMarker, variance: TypeVariance): TypeArgumentMarker
|
fun createTypeArgument(type: KotlinTypeMarker, variance: TypeVariance): TypeArgumentMarker
|
||||||
fun createStarProjection(typeParameter: TypeParameterMarker): TypeArgumentMarker
|
fun createStarProjection(typeParameter: TypeParameterMarker): TypeArgumentMarker
|
||||||
|
|
||||||
|
fun createErrorType(debugName: String): SimpleTypeMarker
|
||||||
fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker
|
fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -561,6 +561,10 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
|||||||
return captureFromExpressionInternal(type as UnwrappedType)
|
return captureFromExpressionInternal(type as UnwrappedType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun createErrorType(debugName: String): SimpleTypeMarker {
|
||||||
|
return ErrorUtils.createErrorType(debugName)
|
||||||
|
}
|
||||||
|
|
||||||
override fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker {
|
override fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker {
|
||||||
require(constructor is TypeConstructor, constructor::errorMessage)
|
require(constructor is TypeConstructor, constructor::errorMessage)
|
||||||
return ErrorUtils.createErrorTypeWithCustomConstructor(debugName, constructor)
|
return ErrorUtils.createErrorTypeWithCustomConstructor(debugName, constructor)
|
||||||
|
|||||||
Reference in New Issue
Block a user