[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
@@ -158,9 +158,8 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext,
}
*/
val simpleType = this.asSimpleType() ?: return false
repeat(simpleType.argumentsCount()) { index ->
val argument = simpleType.getArgument(index)
repeat(argumentsCount()) { index ->
val argument = getArgument(index)
if (!argument.isStarProjection() && argument.getType().containsInternal(predicate, visited)) return true
}
@@ -144,13 +144,13 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext {
return typeConstructor
}
override fun SimpleTypeMarker.argumentsCount(): Int {
override fun KotlinTypeMarker.argumentsCount(): Int {
require(this is ConeKotlinType)
return this.typeArguments.size
}
override fun SimpleTypeMarker.getArgument(index: Int): TypeArgumentMarker {
override fun KotlinTypeMarker.getArgument(index: Int): TypeArgumentMarker {
require(this is ConeKotlinType)
return this.typeArguments.getOrNull(index)
@@ -10059,6 +10059,16 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
runTest("compiler/testData/diagnostics/tests/inference/constraints/kt8879.kt");
}
@TestMetadata("manyConstraintsDueToFlexibleRawTypes.kt")
public void testManyConstraintsDueToFlexibleRawTypes() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/constraints/manyConstraintsDueToFlexibleRawTypes.kt");
}
@TestMetadata("manyConstraintsDueToRecursiveFlexibleTypesWithWildcards.kt")
public void testManyConstraintsDueToRecursiveFlexibleTypesWithWildcards() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/constraints/manyConstraintsDueToRecursiveFlexibleTypesWithWildcards.kt");
}
@TestMetadata("notNullConstraintOnNullableType.kt")
public void testNotNullConstraintOnNullableType() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/constraints/notNullConstraintOnNullableType.kt");