Skip to content

[CodeComplete] Make SourceKit::CodeCompletion::Completion store a reference to the underlying swift result instead of extending that type #40724

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

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jan 4, 2022

Previously, when creating a SourceKit::CodeCompletion::Completion, we needed to copy all fields from the underlying SwiftResult (aka swift::ide::CodeCompletionResult). The arena in which the SwiftResult was allocated still needed to be kept alive for the references stored in the SwiftResult.

To avoid this unnecessary copy, make SourceKit::CodeCompletion::Completion store a reference to the underlying SwiftResult.

While making this change, I also noticed that the innerSink created by transformAndForwardResults did not adopt the sink of the outer results, but was still referencing e.g. strings stored in it. The first commit in this PR makes sure that we retain outer sink from the inner sink.

@ahoppen ahoppen requested a review from rintaro January 4, 2022 11:26
@ahoppen
Copy link
Member Author

ahoppen commented Jan 4, 2022

@swift-ci Please smoke test

@ahoppen
Copy link
Member Author

ahoppen commented Jan 5, 2022

@swift-ci Please smoke test Linux

assert(SwiftContext.swiftASTContext);
Callback(ResultType::success({Results, SwiftContext}));
Callback(ResultType::success({context.getResultSink(), SwiftContext}));
Copy link
Member

Choose a reason for hiding this comment

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

This copies CodeCompletionResultSink object which has std::vector<CodeCompletionResult *> Results etc. Copying it sounds heavy. Do we really want that? If so could you explain why?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch CodeCompleteResult should store CodeCompletionResultSink by reference. Updated it.

Previously the code completion methods just returned an `ArrayRef` that pointed into the result sink that contained the results but no effort was made to actually keep that that result sink alive, e.g. when transforming results in `transformAndForwardResults`.

Instead, return the `CodeCompletionResultSink` from the code compleiton methods now and adopt that sink from the inner results created in `transformAndForwardResults`.
…erence to the underlying swift result instead of extending that type

Previously, when creating a `SourceKit::CodeCompletion::Completion`, we needed to copy all fields from the underlying `SwiftResult` (aka `swift::ide::CodeCompletionResult`). The arena in which the `SwiftResult` was allocated still needed to be kept alive for the references stored in the `SwiftResult`.

To avoid this unnecessary copy, make `SourceKit::CodeCompletion::Completion` store a reference to the underlying `SwiftResult`.
@ahoppen
Copy link
Member Author

ahoppen commented Jan 11, 2022

@swift-ci Please smoke test

@ahoppen ahoppen force-pushed the pr/sourcekit-completion-reference-to-swift-result branch from cb3e662 to 520c41a Compare January 11, 2022 14:36
@ahoppen
Copy link
Member Author

ahoppen commented Jan 12, 2022

@swift-ci Please smoke test Linux

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