Skip to content

[SourceKit] Refactor main 'handleRequestImpl' function #63090

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 1 commit into from
Jan 19, 2023

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Jan 18, 2023

Previously, SourceKit requests are handled in a single handleRequestImpl/handleSemanticRequest with, basically, a giant if (ReqUID == RequstXXX) branches. Some request parameters are extracted at the top of the function, but not all request kind used all of them.

Factor out each handling logic to its own function, and check/extract request parameters in it. This makes it clear that which request uses what parameters, and how they are handled.

This is mostly a mechanical change, and mostly NFC.

@rintaro
Copy link
Member Author

rintaro commented Jan 18, 2023

@swift-ci Please smoke test

handleRequestGlobalConfiguration(const RequestDict &Req,
SourceKitCancellationToken CancellationToken,
ResponseReceiver Rec) {
{
Copy link
Member Author

Choose a reason for hiding this comment

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

This block for non-semantic request is for minimizing diff.
Also, I have a plan to wrapping these in a function, just like the handleSemanticRequest in this PR.

SourceKitCancellationToken CancellationToken,
ResponseReceiver Rec) {
if (checkVFSNotSupported(Req, Rec))
return;
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously, rejecting VFS options is done by "allow" list at the top of handleRequestImpl and allowed only 4 request kinds, that was often overlooked. Even if the request allowed VFS options, the request failed.

Now it's an opt-out option handled in each request handling function.

@rintaro rintaro marked this pull request as draft January 18, 2023 20:50
Previously, SourceKit requests are handled in a single
'handleRequestImpl'/'handleSemanticRequest' with basically a giant
'if (ReqUID == RequstXXX)' branches. Some request parameters are
extracted at the top of the function, but not all request kind used all
of them.

Factor out each handling logic to its own function, and check/extract
request parameters in it. This makes it clear that which request uses
what parameters, and how they are handled.
@rintaro
Copy link
Member Author

rintaro commented Jan 18, 2023

@swift-ci Please smoke test

@rintaro rintaro force-pushed the sourcekit-async-refactor1 branch from 8d01639 to d4a757b Compare January 18, 2023 21:41
@rintaro
Copy link
Member Author

rintaro commented Jan 18, 2023

@swift-ci Please smoke test

Comment on lines +131 to +137
explicit RequestDict(sourcekitd_object_t Dict) : Dict(Dict) {
sourcekitd_request_retain(Dict);
}
RequestDict(const RequestDict &other) : RequestDict(other.Dict) {}
~RequestDict() {
sourcekitd_request_release(Dict);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This may trigger unnecessary retain/release traffic, but this should make the request dictionary handling safer.

@rintaro rintaro marked this pull request as ready for review January 18, 2023 22:43
@rintaro rintaro requested a review from bnbarham January 18, 2023 22:43
@@ -661,7 +740,13 @@ void handleRequestImpl(sourcekitd_object_t ReqObj,
Opts.SyntacticOnly = SyntacticOnly;
return Rec(editorOpen(*Name, InputBuf.get(), Opts, Args, std::move(vfsOptions)));
Copy link
Member Author

Choose a reason for hiding this comment

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

Existing request handling functions, like this editorOpen, will be inlined in this main request handling function in follow-ups.

@rintaro rintaro merged commit 560781b into swiftlang:main Jan 19, 2023
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