[API Usage] Add refinement to ConstraintInjector (NI)
This commit is contained in:
committed by
Dmitry Savvinov
parent
6c44b6b859
commit
9add14a2a1
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.ResultTypeResolve
|
|||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.TrivialConstraintTypeInferenceOracle
|
import org.jetbrains.kotlin.resolve.calls.inference.components.TrivialConstraintTypeInferenceOracle
|
||||||
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.model.SimpleTypeMarker
|
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
|
||||||
import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContextDelegate
|
import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContextDelegate
|
||||||
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
||||||
@@ -66,7 +67,7 @@ class InferenceComponents(
|
|||||||
}
|
}
|
||||||
val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle(ctx)
|
val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle(ctx)
|
||||||
private val incorporator = ConstraintIncorporator(approximator, trivialConstraintTypeInferenceOracle)
|
private val incorporator = ConstraintIncorporator(approximator, trivialConstraintTypeInferenceOracle)
|
||||||
private val injector = ConstraintInjector(incorporator, approximator)
|
private val injector = ConstraintInjector(incorporator, approximator, KotlinTypeRefiner.Default)
|
||||||
val resultTypeResolver = ResultTypeResolver(approximator, trivialConstraintTypeInferenceOracle)
|
val resultTypeResolver = ResultTypeResolver(approximator, trivialConstraintTypeInferenceOracle)
|
||||||
|
|
||||||
fun createConstraintSystem(): NewConstraintSystemImpl {
|
fun createConstraintSystem(): NewConstraintSystemImpl {
|
||||||
|
|||||||
+18
-5
@@ -21,15 +21,18 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
|||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind.LOWER
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind.LOWER
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind.UPPER
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind.UPPER
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
|
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
|
||||||
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
||||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
|
||||||
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
|
||||||
import org.jetbrains.kotlin.types.model.*
|
import org.jetbrains.kotlin.types.model.*
|
||||||
|
import org.jetbrains.kotlin.types.refinement.TypeRefinement
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
|
||||||
class ConstraintInjector(val constraintIncorporator: ConstraintIncorporator, val typeApproximator: AbstractTypeApproximator) {
|
class ConstraintInjector(
|
||||||
|
val constraintIncorporator: ConstraintIncorporator,
|
||||||
|
val typeApproximator: AbstractTypeApproximator,
|
||||||
|
val kotlinTypeRefiner: KotlinTypeRefiner
|
||||||
|
) {
|
||||||
private val ALLOWED_DEPTH_DELTA_FOR_INCORPORATION = 1
|
private val ALLOWED_DEPTH_DELTA_FOR_INCORPORATION = 1
|
||||||
|
|
||||||
interface Context : TypeSystemInferenceExtensionContext {
|
interface Context : TypeSystemInferenceExtensionContext {
|
||||||
@@ -137,10 +140,20 @@ class ConstraintInjector(val constraintIncorporator: ConstraintIncorporator, val
|
|||||||
return baseContext.prepareType(type)
|
return baseContext.prepareType(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseExperimental(TypeRefinement::class)
|
||||||
|
override fun refineType(type: KotlinTypeMarker): KotlinTypeMarker {
|
||||||
|
return if (type is KotlinType) {
|
||||||
|
kotlinTypeRefiner.refineType(type)
|
||||||
|
} else {
|
||||||
|
type
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun runIsSubtypeOf(lowerType: KotlinTypeMarker, upperType: KotlinTypeMarker) {
|
fun runIsSubtypeOf(lowerType: KotlinTypeMarker, upperType: KotlinTypeMarker) {
|
||||||
if (!AbstractTypeChecker.isSubtypeOf(this@TypeCheckerContext as AbstractTypeCheckerContext, lowerType, upperType)) {
|
if (!AbstractTypeChecker.isSubtypeOf(this@TypeCheckerContext as AbstractTypeCheckerContext, lowerType, upperType)) {
|
||||||
// todo improve error reporting -- add information about base types
|
// todo improve error reporting -- add information about base types
|
||||||
c.addError(NewConstraintError(lowerType, upperType, position))
|
c.addError(NewConstraintError(lowerType, upperType, position))
|
||||||
|
AbstractTypeChecker.isSubtypeOf(this@TypeCheckerContext as AbstractTypeCheckerContext, lowerType, upperType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user