[NI] Fix construction of common system for builder inference

This commit is contained in:
Mikhail Zarechenskiy
2020-01-28 14:09:09 +03:00
parent e3b6104489
commit e42f16c95c
8 changed files with 53 additions and 15 deletions
@@ -111,9 +111,11 @@ class KotlinToResolvedCallTransformer(
context.trace.record(BindingContext.ONLY_RESOLVED_CALL, psiCall, PartialCallContainer(baseResolvedCall)) context.trace.record(BindingContext.ONLY_RESOLVED_CALL, psiCall, PartialCallContainer(baseResolvedCall))
context.trace.record(BindingContext.PARTIAL_CALL_RESOLUTION_CONTEXT, psiCall, context) context.trace.record(BindingContext.PARTIAL_CALL_RESOLUTION_CONTEXT, psiCall, context)
context.inferenceSession.addPartialCallInfo( if (baseResolvedCall.forwardToInferenceSession) {
PSIPartialCallInfo(baseResolvedCall, context, tracingStrategy) context.inferenceSession.addPartialCallInfo(
) PSIPartialCallInfo(baseResolvedCall, context, tracingStrategy),
)
}
createStubResolvedCallAndWriteItToTrace(candidate, context.trace, baseResolvedCall.diagnostics, substitutor = null) createStubResolvedCallAndWriteItToTrace(candidate, context.trace, baseResolvedCall.diagnostics, substitutor = null)
} }
@@ -51,14 +51,22 @@ class KotlinCallCompleter(
candidate.addExpectedTypeFromCastConstraint(returnType, resolutionCallbacks) candidate.addExpectedTypeFromCastConstraint(returnType, resolutionCallbacks)
candidate.checkSamWithVararg(diagnosticHolder) candidate.checkSamWithVararg(diagnosticHolder)
return if (resolutionCallbacks.inferenceSession.shouldRunCompletion(candidate)) val completionMode =
candidate.runCompletion( CompletionModeCalculator.computeCompletionMode(candidate, expectedType, returnType, trivialConstraintTypeInferenceOracle)
CompletionModeCalculator.computeCompletionMode(candidate, expectedType, returnType, trivialConstraintTypeInferenceOracle),
diagnosticHolder, return when (completionMode) {
resolutionCallbacks ConstraintSystemCompletionMode.FULL -> {
) if (resolutionCallbacks.inferenceSession.shouldRunCompletion(candidate)) {
else candidate.runCompletion(completionMode, diagnosticHolder, resolutionCallbacks)
candidate.asCallResolutionResult(ConstraintSystemCompletionMode.PARTIAL, diagnosticHolder) } else {
candidate.asCallResolutionResult(
ConstraintSystemCompletionMode.PARTIAL, diagnosticHolder, forwardToInferenceSession = true
)
}
}
ConstraintSystemCompletionMode.PARTIAL ->
candidate.runCompletion(completionMode, diagnosticHolder, resolutionCallbacks)
}
} }
private fun KotlinResolutionCandidate.checkSamWithVararg(diagnosticHolder: KotlinDiagnosticsHolder.SimpleHolder) { private fun KotlinResolutionCandidate.checkSamWithVararg(diagnosticHolder: KotlinDiagnosticsHolder.SimpleHolder) {
@@ -210,7 +218,8 @@ class KotlinCallCompleter(
fun KotlinResolutionCandidate.asCallResolutionResult( fun KotlinResolutionCandidate.asCallResolutionResult(
type: ConstraintSystemCompletionMode, type: ConstraintSystemCompletionMode,
diagnosticsHolder: KotlinDiagnosticsHolder.SimpleHolder diagnosticsHolder: KotlinDiagnosticsHolder.SimpleHolder,
forwardToInferenceSession: Boolean = false
): CallResolutionResult { ): CallResolutionResult {
val systemStorage = getSystem().asReadOnlyStorage() val systemStorage = getSystem().asReadOnlyStorage()
val allDiagnostics = diagnosticsHolder.getDiagnostics() + this.diagnosticsFromResolutionParts val allDiagnostics = diagnosticsHolder.getDiagnostics() + this.diagnosticsFromResolutionParts
@@ -222,7 +231,7 @@ class KotlinCallCompleter(
return if (type == ConstraintSystemCompletionMode.FULL) { return if (type == ConstraintSystemCompletionMode.FULL) {
CompletedCallResolutionResult(resolvedCall, allDiagnostics, systemStorage) CompletedCallResolutionResult(resolvedCall, allDiagnostics, systemStorage)
} else { } else {
PartialCallResolutionResult(resolvedCall, allDiagnostics, systemStorage) PartialCallResolutionResult(resolvedCall, allDiagnostics, systemStorage, forwardToInferenceSession)
} }
} }
@@ -225,7 +225,8 @@ open class SingleCallResolutionResult(
class PartialCallResolutionResult( class PartialCallResolutionResult(
resultCallAtom: ResolvedCallAtom, resultCallAtom: ResolvedCallAtom,
diagnostics: List<KotlinCallDiagnostic>, diagnostics: List<KotlinCallDiagnostic>,
constraintSystem: ConstraintStorage constraintSystem: ConstraintStorage,
val forwardToInferenceSession: Boolean = false
) : SingleCallResolutionResult(resultCallAtom, diagnostics, constraintSystem) ) : SingleCallResolutionResult(resultCallAtom, diagnostics, constraintSystem)
class CompletedCallResolutionResult( class CompletedCallResolutionResult(
@@ -0,0 +1,11 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
fun foo(x: List<String>) {}
fun <K> materialize(): K = TODO()
fun test() {
val x: Sequence<String> = sequence {
foo(materialize())
}
}
@@ -0,0 +1,5 @@
package
public fun foo(/*0*/ x: kotlin.collections.List<kotlin.String>): kotlin.Unit
public fun </*0*/ K> materialize(): K
public fun test(): kotlin.Unit
@@ -14,7 +14,7 @@ fun test_1() {
fun test_2() { fun test_2() {
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>sequence<!> { <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>sequence<!> {
yield(<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>materialize<!>()) <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>yield<!>(<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>materialize<!>())
} }
} }
@@ -1882,6 +1882,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/applyInsideCoroutine.kt"); runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/applyInsideCoroutine.kt");
} }
@TestMetadata("builderInferenceForMaterializeWithExpectedType.kt")
public void testBuilderInferenceForMaterializeWithExpectedType() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/builderInferenceForMaterializeWithExpectedType.kt");
}
@TestMetadata("callableReferenceToASuspendFunction.kt") @TestMetadata("callableReferenceToASuspendFunction.kt")
public void testCallableReferenceToASuspendFunction() throws Exception { public void testCallableReferenceToASuspendFunction() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/callableReferenceToASuspendFunction.kt"); runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/callableReferenceToASuspendFunction.kt");
@@ -1882,6 +1882,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/applyInsideCoroutine.kt"); runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/applyInsideCoroutine.kt");
} }
@TestMetadata("builderInferenceForMaterializeWithExpectedType.kt")
public void testBuilderInferenceForMaterializeWithExpectedType() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/builderInferenceForMaterializeWithExpectedType.kt");
}
@TestMetadata("callableReferenceToASuspendFunction.kt") @TestMetadata("callableReferenceToASuspendFunction.kt")
public void testCallableReferenceToASuspendFunction() throws Exception { public void testCallableReferenceToASuspendFunction() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/callableReferenceToASuspendFunction.kt"); runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/callableReferenceToASuspendFunction.kt");