Skip to content

[CodeCompletion] Some refactorings surrounding solver-based completion #41885

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 4 commits into from
Mar 22, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Mar 18, 2022

Perform a couple of refactoring for solver-based completion, with the goal of sharing more code between the different completion kinds:

  • Sink TypeCheckCompletionCallbacks from Sema to IDE
    • That’s really where it belongs, there’s no reason for it to be in Sema
  • Unify logic to retrieve completion expr type for all completion callbacks
    • Previously, each completion kind had its own handling of UnresolvedType and some had fewer fallback mechanisms to retrieve the type, have one implementation that does everything
  • Check whether surrounding context supports async in all solver-based completion kinds
    • Previously, only ExprCompletion checked whether the surrounding context is async, I don’t have any failing test cases for the other completion kinds but it definitely makes sense for them to share the same logic to determine whether the surrounding context is async

@ahoppen ahoppen changed the title Pr/refactor solver completion [CodeCompletion] Some refactorings surrounding solver-based completion Mar 18, 2022
@ahoppen ahoppen force-pushed the pr/refactor-solver-completion branch from 3011ff6 to fe46180 Compare March 19, 2022 07:51
@ahoppen
Copy link
Member Author

ahoppen commented Mar 19, 2022

@swift-ci Please smoke test

@ahoppen
Copy link
Member Author

ahoppen commented Mar 19, 2022

@swift-ci Please SourceKit stress test

@ahoppen ahoppen force-pushed the pr/refactor-solver-completion branch from fe46180 to 03d819f Compare March 21, 2022 19:14
@ahoppen ahoppen marked this pull request as ready for review March 21, 2022 19:14
@ahoppen ahoppen requested a review from xedin March 21, 2022 19:14
@ahoppen
Copy link
Member Author

ahoppen commented Mar 21, 2022

@swift-ci Please smoke test

// func foo(fn: () async -> Void)
// foo { <HERE> }
// In this case, the closure is wrapped with a 'FunctionConversionExpr'
// which has 'async' function type.
Copy link
Contributor

Choose a reason for hiding this comment

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

This assume a type-checked version of the AST, is that always the case?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe so. The call side inside CompletionLookup is intended for the legacy code completion, which works on a type-checked AST and https://github.com/apple/swift/pull/41885/files/03d819f442f05b58f6a2b1816b2e280292db5329#diff-3088e637c4f06d0fc6cb38370068cd6fa6fe8dcaa10ec35c9086602c59eaba17R149 works on the already type-checked part of the AST to determine async-ness after failing to determine async-ness from the solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good, just double-checking! :)

/// Called for each solution produced while type-checking an expression
/// that the code completion expression participates in.
virtual void sawSolution(const constraints::Solution &solution) {
GotCallback = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks suspicious - there is no way to ensure that each override calls TypeCheckCompletionCallback::sawSolution(solution) internally. I see that they currently do but it only takes one to go unnoticed... I'd like to suggest virtual to be removed from this method, and instead be used on a protected sawSolutionImpl(const Solution &) which is going to be called from this one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds like a good idea. I’ll do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Implemented in 3597652

…mpl from subclasses

This eliminates a source of bugs if subclasses of `TypeCheckCompletionCallback` forget to call the superclass’s implementation of `sawSolution` from their overridden method.
@ahoppen
Copy link
Member Author

ahoppen commented Mar 21, 2022

@swift-ci Please smoke test

@ahoppen ahoppen merged commit 2697e96 into swiftlang:main Mar 22, 2022
@ahoppen ahoppen deleted the pr/refactor-solver-completion branch March 22, 2022 07:05
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