Skip to content

[IDE] Two more preparation commits for solver-based cursor info #62359

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

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Dec 2, 2022

[IDE] Make isDynamicRef take a getType function (@bnbarham)

This allows isDynamicRef to work with types from a constraint system solution


[IDE] Move getSelectedOverloadInfo to be a function on Solution (@xedin)

We will need this for solver-based cursor info.


[Sema] Add a solution callback that is called when the constraint system produces a solution (@xedin)

When doing solver-based cursor info, we’ll type check the expression in question using a normal typeCheckASTNodeAtLoc call (not in code completion mode) and listen for any solutions that were produced during the type check.

@ahoppen ahoppen requested review from xedin and bnbarham December 2, 2022 09:54
@ahoppen
Copy link
Member Author

ahoppen commented Dec 2, 2022

@swift-ci Please smoke test

Copy link
Contributor

@bnbarham bnbarham left a comment

Choose a reason for hiding this comment

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

Not sure how you're planning on using isDynamicRef, but sure 👍

@@ -746,6 +746,19 @@ struct SelectedOverload {
const Type boundType;
};

/// Information that \c getSelectedOverloadInfo gathered about a
/// \c SelectedOverload.
struct SelectedOverloadInfo {
Copy link
Contributor

@xedin xedin Dec 2, 2022

Choose a reason for hiding this comment

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

We have a representation for this already - SelectedOverload - it has all of the types plus OverloadChoice which would give you base type and kind, why not use that directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

The computation of SelectedOverloadInfo is using SelectedOverload under the hood but we need to do some more adjustments of key path overloads to get the behavior we need for code completion (see implementation of getSelectedOverloadInfo). In particular in the case of KeyPathDynamicMemberLookup we don’t return information for the subscript(keyPath:) declaration but for the key path member access itself. This requires forming a new constraint locator (https://github.com/apple/swift/pull/62359/files#diff-d57f6f2d466f1f207cdf2dbd0396a1dbb2caba7b6828ebdb9954948f0ac2b499R3876-R3891).

AFAICT we have the following options:

  • Store the types that SelectedOverloadInfo contains in SelectedOverload. I don’t really like the idea because the information seems to be IDE-specific to me and not useful for general type checking.
  • Add methods to SelectedOverload that compute the types stored in SelectedOverloadInfo. I don’t like this approach since the computation of CallBaseTy and FuncTy require the Solution in which the overload was picked as well as the ContraintLocator that referred to it.
  • Name SelectedOverloadInfo something more IDE-specific
  • Move getSelectedOverloadInfo into libIDE (where it essentially came from, previously it was a static function in ArgumentCompletion.cpp)

I think I like the last option best. WDYT @xedin?

Copy link
Contributor

Choose a reason for hiding this comment

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

I concur, let's move that functionally to libIDE and feed it information from SelectedOverload.

We will need this for solver-based cursor info.
This allows isDynamicRef to work with types from a constraint system solution
…tem produces a solution

When doing solver-based cursor info, we’ll type check the expression in question using a normal `typeCheckASTNodeAtLoc` call (not in code completion mode) and listen for any solutions that were produced during the type check.
@ahoppen ahoppen force-pushed the ahoppen/solver-based-cursor-info-prep-pt-2 branch from 35985e4 to 4b62682 Compare December 5, 2022 22:52
@ahoppen
Copy link
Member Author

ahoppen commented Dec 5, 2022

@swift-ci Please smoke test

@ahoppen ahoppen merged commit cc8e28c into swiftlang:main Dec 6, 2022
@ahoppen ahoppen deleted the ahoppen/solver-based-cursor-info-prep-pt-2 branch December 6, 2022 08: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.

3 participants