Skip to content

[CodeCompletion] Filter overloads if their function application doesn't contain the code completion token #41917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Mar 21, 2022

When solving for code completion, we weren't disabling overloads because the call might be malfored in the presence of a code completion token (because the user is only now writing the function call). But this logic doesn't apply to function calls that don't even involve the code completion token, which happens if completing in result builders.

I am hoping that this significantly improves code completion performance inside result builders.

@ahoppen ahoppen requested a review from xedin March 21, 2022 11:58
@ahoppen
Copy link
Member Author

ahoppen commented Mar 21, 2022

@swift-ci Please smoke test

@ahoppen
Copy link
Member Author

ahoppen commented Mar 21, 2022

@swift-ci Please SourceKit stress test

};
CodeCompletionTypeFinder CompletionTypeFinder;
type.walk(CompletionTypeFinder);
return CompletionTypeFinder.ContainsCodeCompletionTypeVar;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The easier way of doing this would be to use type.findIf([&](Type type) { return isCodeCompetionTypeVar(type); });

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doing it think way you wouldn't need an additional isCodeCompletionTypeVar(fnTypeVar) in your condition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it's fnTypeVar, never mind

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that’s definitely cleaner

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this makes sense, this is what I have advocated for at some point but the counter here is that some of the results are going to be lost because not all of the overloads of the chained members are going to be attempted...

@ahoppen
Copy link
Member Author

ahoppen commented Mar 21, 2022

IHMO this makes sense, this is what I have advocated for at some point but the counter here is that some of the results are going to be lost because not all of the overloads of the chained members are going to be attempted…

I think this trade-off is reasonable. This change eliminates all timeouts in the stress tester + fixes some other expression to complex issues while barely introducing any new issues (I still need to investigate what the two unexpected failures are).

@xedin
Copy link
Contributor

xedin commented Mar 21, 2022

Sounds good then :)

@ahoppen ahoppen force-pushed the pr/filter-overloads-if-no-cc-token branch from 4f0a0fa to 99cc75b Compare March 21, 2022 18:16
@ahoppen
Copy link
Member Author

ahoppen commented Mar 21, 2022

@swift-ci Please smoke test

@ahoppen
Copy link
Member Author

ahoppen commented Mar 21, 2022

@swift-ci Please smoke test Windows

if (isForCodeCompletion())
return false;
if (isForCodeCompletion()) {
bool ArgContainsCCTypeVar = Type(argFnType).findIf(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that this could be simplified down to Type(argFnType).findIf(isCodeCompletionTypeVar);

…'t contain the code completion token

When solving for code completion, we weren't disabling overloads because the call might be malfored in the presence of a code completion token (because the user is only now writing the function call). But this logic doesn't apply to function calls that don't even involve the code completion token, which happens if completing in result builders.

I am hoping that this significantly improves code completion performance inside result builders.
@ahoppen ahoppen force-pushed the pr/filter-overloads-if-no-cc-token branch from 99cc75b to 045302b Compare March 22, 2022 07:07
@ahoppen
Copy link
Member Author

ahoppen commented Mar 22, 2022

@swift-ci Please smoke test

@ahoppen ahoppen merged commit 1ef2c59 into swiftlang:main Mar 22, 2022
@ahoppen ahoppen deleted the pr/filter-overloads-if-no-cc-token branch March 22, 2022 11:11
ahoppen added a commit to ahoppen/swift-source-compat-suite that referenced this pull request Mar 23, 2022
- SR-14694: A few timeout issues were resolved by swiftlang/swift#41917 and others were introduced by swiftlang/swift#41633.

- SR-16012: A couple more cases were caused by migrating expression completions to solver-based swiftlang/swift#41633
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants