[NI] Implement various optimizations for incorporation algorithm

Mostly, these optimisations are picked from the old inference.
 Also, remove exponential complexity for flexible types in approximation,
 note that more correct fix for this would be to introduce new types
 that corresponds just to platform types to avoid nullability problems,
 but due to complexity it will be done later

 #KT-31415 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2019-05-24 14:58:59 +03:00
parent bbec3bf001
commit 8910859fd1
22 changed files with 239 additions and 48 deletions
@@ -127,12 +127,12 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext {
return this.constructor
}
override fun SimpleTypeMarker.argumentsCount(): Int {
require(this is SimpleType, this::errorMessage)
override fun KotlinTypeMarker.argumentsCount(): Int {
require(this is KotlinType, this::errorMessage)
return this.arguments.size
}
override fun SimpleTypeMarker.getArgument(index: Int): TypeArgumentMarker {
override fun KotlinTypeMarker.getArgument(index: Int): TypeArgumentMarker {
require(this is SimpleType, this::errorMessage)
return this.arguments[index]
}
@@ -167,8 +167,8 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
fun SimpleTypeMarker.withNullability(nullable: Boolean): SimpleTypeMarker
fun SimpleTypeMarker.typeConstructor(): TypeConstructorMarker
fun SimpleTypeMarker.argumentsCount(): Int
fun SimpleTypeMarker.getArgument(index: Int): TypeArgumentMarker
fun KotlinTypeMarker.argumentsCount(): Int
fun KotlinTypeMarker.getArgument(index: Int): TypeArgumentMarker
fun SimpleTypeMarker.getArgumentOrNull(index: Int): TypeArgumentMarker? {
if (index in 0 until argumentsCount()) return getArgument(index)