Use the same temporary trace for analyzing all candidate calls
Otherwise, when completing all the unsuccessfull candiates, resolution of each lambda-arguments starts repeatedly for each candidate that leads to exponential time NB: Changes in `completeArguments` are necessary because otherwise nested lambdas will be analyzed twice: once for the main resolved call, and then for all candidates that again leads to exponential complexity #KT-16672 Fixed #KT-19457 Fixed
This commit is contained in:
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType
|
import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType
|
||||||
import org.jetbrains.kotlin.builtins.getValueParameterTypesFromFunctionType
|
import org.jetbrains.kotlin.builtins.getValueParameterTypesFromFunctionType
|
||||||
import org.jetbrains.kotlin.builtins.isFunctionType
|
import org.jetbrains.kotlin.builtins.isFunctionType
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
|
||||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
@@ -75,10 +74,10 @@ class CallCompleter(
|
|||||||
// it's completed when the outer (variable as function call) is completed
|
// it's completed when the outer (variable as function call) is completed
|
||||||
if (!isInvokeCallOnVariable(context.call)) {
|
if (!isInvokeCallOnVariable(context.call)) {
|
||||||
val temporaryTrace = TemporaryBindingTrace.create(context.trace, "Trace to complete a resulting call")
|
val temporaryTrace = TemporaryBindingTrace.create(context.trace, "Trace to complete a resulting call")
|
||||||
|
val contextWithTemporaryTrace = context.replaceBindingTrace(temporaryTrace)
|
||||||
|
|
||||||
completeResolvedCallAndArguments(resolvedCall, results, context.replaceBindingTrace(temporaryTrace), tracing)
|
completeResolvedCallAndArguments(resolvedCall, results, contextWithTemporaryTrace, tracing)
|
||||||
|
completeAllCandidates(contextWithTemporaryTrace, results)
|
||||||
completeAllCandidates(context, results)
|
|
||||||
|
|
||||||
temporaryTrace.commit()
|
temporaryTrace.commit()
|
||||||
}
|
}
|
||||||
@@ -120,10 +119,10 @@ class CallCompleter(
|
|||||||
results.resultingCalls
|
results.resultingCalls
|
||||||
}) as Collection<MutableResolvedCall<D>>
|
}) as Collection<MutableResolvedCall<D>>
|
||||||
|
|
||||||
|
val temporaryBindingTrace = TemporaryBindingTrace.create(context.trace, "Trace to complete a candidate that is not a resulting call")
|
||||||
candidates.filterNot { resolvedCall -> resolvedCall.isCompleted }.forEach {
|
candidates.filterNot { resolvedCall -> resolvedCall.isCompleted }.forEach {
|
||||||
resolvedCall ->
|
resolvedCall ->
|
||||||
|
|
||||||
val temporaryBindingTrace = TemporaryBindingTrace.create(context.trace, "Trace to complete a candidate that is not a resulting call")
|
|
||||||
completeResolvedCallAndArguments(resolvedCall, results, context.replaceBindingTrace(temporaryBindingTrace), TracingStrategy.EMPTY)
|
completeResolvedCallAndArguments(resolvedCall, results, context.replaceBindingTrace(temporaryBindingTrace), TracingStrategy.EMPTY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+53
@@ -0,0 +1,53 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
|
||||||
|
class A
|
||||||
|
class B
|
||||||
|
class C
|
||||||
|
class D
|
||||||
|
|
||||||
|
fun A.bar(x: Int = 0) = ""
|
||||||
|
fun A.bar(x: Int = 0, y: D.() -> Unit) = ""
|
||||||
|
|
||||||
|
fun B.bar(x: Int = 0) = ""
|
||||||
|
fun B.bar(x: Int = 0, y: D.() -> Unit) = ""
|
||||||
|
|
||||||
|
fun C.bar(x: Int = 0) = ""
|
||||||
|
fun C.bar(x: Int = 0, y: D.() -> Unit) = ""
|
||||||
|
|
||||||
|
class E {
|
||||||
|
fun foo() {
|
||||||
|
// `bar` calls are inapplicable since both E nor D aren't proper receivers
|
||||||
|
// But prior to this change, every lambda was analyzed repeatedly for every candidate
|
||||||
|
// Thus, the resulting time was exponential
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Vendored
+44
@@ -0,0 +1,44 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun A.bar(/*0*/ x: kotlin.Int = ...): kotlin.String
|
||||||
|
public fun A.bar(/*0*/ x: kotlin.Int = ..., /*1*/ y: D.() -> kotlin.Unit): kotlin.String
|
||||||
|
public fun B.bar(/*0*/ x: kotlin.Int = ...): kotlin.String
|
||||||
|
public fun B.bar(/*0*/ x: kotlin.Int = ..., /*1*/ y: D.() -> kotlin.Unit): kotlin.String
|
||||||
|
public fun C.bar(/*0*/ x: kotlin.Int = ...): kotlin.String
|
||||||
|
public fun C.bar(/*0*/ x: kotlin.Int = ..., /*1*/ y: D.() -> kotlin.Unit): kotlin.String
|
||||||
|
|
||||||
|
public final class A {
|
||||||
|
public constructor A()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class B {
|
||||||
|
public constructor B()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class C {
|
||||||
|
public constructor C()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class D {
|
||||||
|
public constructor D()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class E {
|
||||||
|
public constructor E()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public final fun foo(): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
class A {
|
||||||
|
fun bar() {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>div<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE!>+<!>(<!UNRESOLVED_REFERENCE!>foo<!> ?: "")
|
||||||
|
<!UNRESOLVED_REFERENCE!>+<!>(<!UNRESOLVED_REFERENCE!>foo<!> ?: "")
|
||||||
|
<!UNRESOLVED_REFERENCE!>+<!>(<!UNRESOLVED_REFERENCE!>foo<!> ?: "")
|
||||||
|
<!UNRESOLVED_REFERENCE!>+<!>(<!UNRESOLVED_REFERENCE!>foo<!> ?: "")
|
||||||
|
<!UNRESOLVED_REFERENCE!>+<!>(<!UNRESOLVED_REFERENCE!>foo<!> ?: "")
|
||||||
|
<!UNRESOLVED_REFERENCE!>+<!>(<!UNRESOLVED_REFERENCE!>foo<!> ?: "")
|
||||||
|
<!UNRESOLVED_REFERENCE!>+<!>(<!UNRESOLVED_REFERENCE!>foo<!> ?: "")
|
||||||
|
<!UNRESOLVED_REFERENCE!>+<!>(<!UNRESOLVED_REFERENCE!>foo<!> ?: "")
|
||||||
|
<!UNRESOLVED_REFERENCE!>+<!>(<!UNRESOLVED_REFERENCE!>foo<!> ?: "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public final class A {
|
||||||
|
public constructor A()
|
||||||
|
public final fun bar(): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
@@ -18123,6 +18123,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("manyInapplicableCandidatesWithLambdas.kt")
|
||||||
|
public void testManyInapplicableCandidatesWithLambdas() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/nestedCalls/manyInapplicableCandidatesWithLambdas.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("twoTypeParameters.kt")
|
@TestMetadata("twoTypeParameters.kt")
|
||||||
public void testTwoTypeParameters() throws Exception {
|
public void testTwoTypeParameters() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/nestedCalls/twoTypeParameters.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/nestedCalls/twoTypeParameters.kt");
|
||||||
|
|||||||
@@ -78,6 +78,12 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("hugeUnresolvedKotlinxHtml.kt")
|
||||||
|
public void testHugeUnresolvedKotlinxHtml() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/hugeUnresolvedKotlinxHtml.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ifElseJavaList.kt")
|
@TestMetadata("ifElseJavaList.kt")
|
||||||
public void testIfElseJavaList() throws Exception {
|
public void testIfElseJavaList() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/ifElseJavaList.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/ifElseJavaList.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user