[5.4][CodeCompletion][Sema] Don't filter out any viable solutions when solving for code completion #35746
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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