[NI] Fix substitution in builder-inference for empty common system

This commit is contained in:
Mikhail Zarechenskiy
2020-02-21 03:00:51 +03:00
parent c5ffbfd33c
commit 1624327ba4
12 changed files with 101 additions and 5 deletions
@@ -105,7 +105,13 @@ class CoroutineInferenceSession(
lambda: ResolvedLambdaAtom,
initialStorage: ConstraintStorage,
diagnosticsHolder: KotlinDiagnosticsHolder
): Map<TypeConstructor, UnwrappedType> {
): Map<TypeConstructor, UnwrappedType>? {
if (partiallyResolvedCallsInfo.isEmpty() && commonCalls.isEmpty()) {
val emptyCommonSystem = NewConstraintSystemImpl(callComponents.constraintInjector, builtIns)
updateCalls(lambda, emptyCommonSystem)
return null
}
val commonSystem = buildCommonSystem(initialStorage)
val context = commonSystem.asConstraintSystemCompleterContext()
@@ -281,9 +287,8 @@ class CoroutineInferenceSession(
class ComposedSubstitutor(val left: NewTypeSubstitutor, val right: NewTypeSubstitutor) : NewTypeSubstitutor {
override fun substituteNotNullTypeWithConstructor(constructor: TypeConstructor): UnwrappedType? {
return left.substituteNotNullTypeWithConstructor(
right.substituteNotNullTypeWithConstructor(constructor)?.constructor ?: constructor
)
val rightSubstitution = right.substituteNotNullTypeWithConstructor(constructor)
return left.substituteNotNullTypeWithConstructor(rightSubstitution?.constructor ?: constructor) ?: rightSubstitution
}
override val isEmpty: Boolean get() = left.isEmpty && right.isEmpty
@@ -40,7 +40,7 @@ interface InferenceSession {
lambda: ResolvedLambdaAtom,
initialStorage: ConstraintStorage,
diagnosticsHolder: KotlinDiagnosticsHolder
): Map<TypeConstructor, UnwrappedType>
): Map<TypeConstructor, UnwrappedType>?
fun writeOnlyStubs(callInfo: SingleCallResolutionResult): Boolean
fun callCompleted(resolvedAtom: ResolvedAtom): Boolean
@@ -159,6 +159,10 @@ class PostponedArgumentsAnalyzer(
val storageSnapshot = c.getBuilder().currentStorage()
val postponedVariables = inferenceSession.inferPostponedVariables(lambda, storageSnapshot, diagnosticHolder)
if (postponedVariables == null) {
c.getBuilder().removePostponedVariables()
return
}
for ((constructor, resultType) in postponedVariables) {
val variableWithConstraints = storageSnapshot.notFixedTypeVariables[constructor] ?: continue
@@ -34,6 +34,7 @@ interface ConstraintSystemOperation {
fun registerVariable(variable: TypeVariableMarker)
fun markPostponedVariable(variable: TypeVariableMarker)
fun unmarkPostponedVariable(variable: TypeVariableMarker)
fun removePostponedVariables()
fun addSubtypeConstraint(lowerType: KotlinTypeMarker, upperType: KotlinTypeMarker, position: ConstraintPosition)
fun addEqualityConstraint(a: KotlinTypeMarker, b: KotlinTypeMarker, position: ConstraintPosition)
@@ -103,6 +103,10 @@ class NewConstraintSystemImpl(
storage.postponedTypeVariables -= variable
}
override fun removePostponedVariables() {
storage.postponedTypeVariables.clear()
}
override fun addSubtypeConstraint(lowerType: KotlinTypeMarker, upperType: KotlinTypeMarker, position: ConstraintPosition) =
constraintInjector.addInitialSubtypeConstraint(
apply { checkState(State.BUILDING, State.COMPLETION, State.TRANSACTION) },
@@ -0,0 +1,52 @@
// WITH_RUNTIME
// WITH_COROUTINES
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
import kotlin.experimental.ExperimentalTypeInference
fun test() {
flow {
emit(1)
}.flatMapLatest<Int, Long> {
flow {}
}
flow {
emit(1)
}.flatMap {
if (it == 1)
flow {}
else
flow<Int> {}
}
flow {
emit(1)
}.flatMap {
if (it == 1)
flow {}
else flow {}
}
}
fun <T> Flow<T>.flatMap(mapper: suspend (T) -> Flow<T>): Flow<T> = TODO()
@OptIn(ExperimentalTypeInference::class)
fun <T> flow(@BuilderInference block: suspend FlowCollector<T>.() -> Unit): Flow<T> = TODO()
@OptIn(ExperimentalTypeInference::class)
inline fun <T, R> Flow<T>.flatMapLatest(@BuilderInference crossinline transform: suspend (value: T) -> Flow<R>): Flow<R> = TODO()
interface Flow<out T>
interface FlowCollector<in T> {
suspend fun emit(value: T)
}
fun box(): String {
return "OK"
}
@@ -6200,6 +6200,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/emptyClosure.kt", "kotlin.coroutines");
}
@TestMetadata("emptyCommonConstraintSystemForCoroutineInferenceCall.kt")
public void testEmptyCommonConstraintSystemForCoroutineInferenceCall() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/emptyCommonConstraintSystemForCoroutineInferenceCall.kt");
}
@TestMetadata("epam.kt")
public void testEpam_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/epam.kt", "kotlin.coroutines.experimental");
@@ -6200,6 +6200,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/emptyClosure.kt", "kotlin.coroutines");
}
@TestMetadata("emptyCommonConstraintSystemForCoroutineInferenceCall.kt")
public void testEmptyCommonConstraintSystemForCoroutineInferenceCall() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/emptyCommonConstraintSystemForCoroutineInferenceCall.kt");
}
@TestMetadata("epam.kt")
public void testEpam_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/epam.kt", "kotlin.coroutines.experimental");
@@ -6080,6 +6080,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/emptyClosure.kt", "kotlin.coroutines");
}
@TestMetadata("emptyCommonConstraintSystemForCoroutineInferenceCall.kt")
public void testEmptyCommonConstraintSystemForCoroutineInferenceCall() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/emptyCommonConstraintSystemForCoroutineInferenceCall.kt");
}
@TestMetadata("epam.kt")
public void testEpam_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/epam.kt", "kotlin.coroutines");
@@ -6080,6 +6080,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/emptyClosure.kt", "kotlin.coroutines");
}
@TestMetadata("emptyCommonConstraintSystemForCoroutineInferenceCall.kt")
public void testEmptyCommonConstraintSystemForCoroutineInferenceCall() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/emptyCommonConstraintSystemForCoroutineInferenceCall.kt");
}
@TestMetadata("epam.kt")
public void testEpam_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/epam.kt", "kotlin.coroutines");
@@ -5130,6 +5130,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/emptyClosure.kt", "kotlin.coroutines");
}
@TestMetadata("emptyCommonConstraintSystemForCoroutineInferenceCall.kt")
public void testEmptyCommonConstraintSystemForCoroutineInferenceCall() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/emptyCommonConstraintSystemForCoroutineInferenceCall.kt");
}
@TestMetadata("epam.kt")
public void testEpam_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/epam.kt", "kotlin.coroutines");
@@ -5130,6 +5130,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/emptyClosure.kt", "kotlin.coroutines");
}
@TestMetadata("emptyCommonConstraintSystemForCoroutineInferenceCall.kt")
public void testEmptyCommonConstraintSystemForCoroutineInferenceCall() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/emptyCommonConstraintSystemForCoroutineInferenceCall.kt");
}
@TestMetadata("epam.kt")
public void testEpam_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/epam.kt", "kotlin.coroutines");