Skip to content

[5.4][CodeCompletion][Sema] Don't filter out any viable solutions when solving for code completion #35746

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

Conversation

nathawes
Copy link
Contributor

@nathawes nathawes commented Feb 3, 2021

Cherry-pick of #35535 for 5.4

  • Explanation: When type checking expressions there are sometimes multiple viable solutions. The constraint solver has some logic to pick a “best” solution in these cases and filter out the rest (e.g. choosing a more-specialized non-generic function or operator overload over purely generic one). This makes sense during regular compilation, but failing to consider the removed solutions made us miss valid code completion results that once inserted into the code would have made those solutions become the "best" solution. In the code below, for example, we would fail to suggest the members of Optional and MyEnum, instead just offering static members of Int:

    enum MyEnum { case first, second }
    func foo(a: Int, b: Int)-> Int { return 42 }
    func foo<T:Equatable>(a: T, b: T) -> MyEnum? { return nil }
    
    foo(a: 42, b: 4) != .<COMPLETE-HERE> 
    

    This patch resolves this issue by not filtering out any viable solutions when solving for code completion.

  • Scope of issue: This can cause us to offer only a small subset of valid code completions in expressions involving multiple components and generic overloads.

  • Origination: Introduced when code completion was switched over to use the new solver-based implementation.

  • Risk: Low. The change only affects the behavior of code completion – not the compiler – and is small.

  • Testing: Added a regression test for this case, checked it had no noticeable impact on code completion performance in small and complex expressions, and the existing regression tests pass.

  • Reviewer: Pavel Yaskevich (@xedin) reviewed on the main branch PR

Resolves rdar://problem/73282163

…ving for code completion

Resolves rdar://problem/73282163
@nathawes
Copy link
Contributor Author

nathawes commented Feb 3, 2021

@swift-ci please test

@nathawes
Copy link
Contributor Author

nathawes commented Feb 4, 2021

@swift-ci please test Windows

@nathawes
Copy link
Contributor Author

nathawes commented Feb 4, 2021

@swift-ci please nominate

@nathawes nathawes marked this pull request as ready for review February 4, 2021 08:42
@nathawes nathawes requested a review from a team as a code owner February 4, 2021 08:42
@nathawes nathawes added the r5.4 label Feb 4, 2021
@nathawes nathawes requested a review from akyrtzi February 4, 2021 08:43
@akyrtzi akyrtzi merged commit 82e559e into swiftlang:release/5.4 Feb 4, 2021
@nathawes nathawes deleted the dont-filter-out-non-best-solutions-for-completion-5.4 branch February 4, 2021 22:07
@AnthonyLatsis AnthonyLatsis added swift 5.4 🍒 release cherry pick Flag: Release branch cherry picks labels Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants