-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SourceKit] Preparation for solver-based cursor info #62292
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
[SourceKit] Preparation for solver-based cursor info #62292
Conversation
@swift-ci Please smoke test |
@swift-ci Please SourceKit stress test |
lib/IDE/IDETypeChecking.cpp
Outdated
Expr *Init = Capture.PBD->getInit(0); | ||
if (!Init) { | ||
continue; | ||
} | ||
if (isa<UnresolvedDeclRefExpr>(Init) && DC) { | ||
// Type check Init to resolve the decl ref. | ||
typeCheckExpression(DC, Init); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems very error prone to me, but adding getResolvedInit
doesn't seem great to me either. Plus we'd be re-running this every time since the expression isn't stored anywhere. Any thoughts @slavapestov?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing some more work on this, I changed this to
Init = resolveDeclRefExpr(UDRE, DC, /*replaceInvalidRefsWithErrors=*/false);
which should be a lot faster and seems reasonable to me. I’ll update the PR tomorrow.
/// Subclasses of \c ResolvedCursorInfo cannot add new stored properies because | ||
/// \c ResolvedCursorInfo is being passed around as its base class and thus any | ||
/// properties in subclasses would get lost. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should just fix wherever we're doing copies if you want to model this as a class hierarchy. It's a fairly large structure in the ValueRefInfo
case, so that sounds reasonable to me. So the resolution should return a std::unique_ptr<ResolvedCursorInfo>
instead.
That would also avoid all the property -> getter/setter changes and given these are pure data structures I personally prefer direct access over getter/setters here. I don't feel super strongly about that though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ll try to do that in a follow-up PR if I’ve got time. Filed rdar://102853071 for now.
This way, each kind of `ResolvedCursorInfo` can define its own set of properties and it’s obvious which properties are used for which kind. Also switch to getters and setters because that makes it easier to search for usages of properties by looking at the call hierarchy of the getter / setter.
This will be necessary to make cursor info completion like to inspect the just parsed source file because the callback from parsing the code completion token won’t be called.
We will be using the string serialized results to verify that solver-based cursor info results match the old implementation. This is necessary because cursor info results on their own contain stack references that cannot be stored.
…ting a code completion token into the buffer We will use this for solver-based cursor info, which doesn’t use code completion tokens.
c65b4bd
to
8af4db2
Compare
@swift-ci Please smoke test |
This PR contains multiple, more or less independent commits that are required to implement cursor info using the solver-based / completion-like design that doesn’t type check the entire file but only those parts that are necessary to server the request and which will allow cursor info to return ambiguous results.
If any of these changes is controversial, I can split it into a separate PR.