Skip to content

Commit c5b1ada

Browse files
committed
[SourceKit] Hold CompletionInstance with std::shared_ptr
So we can pin it on the threads.
1 parent f2466de commit c5b1ada

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ static bool swiftCodeCompleteImpl(
172172
Error = "no input filenames specified";
173173
return false;
174174
}
175-
CompilerInstance *CI = Lang.getCompletionInstance().getCompilerInstance(
175+
176+
// Pin completion instance.
177+
auto CompletionInst = Lang.getCompletionInstance();
178+
CompilerInstance *CI = CompletionInst->getCompilerInstance(
176179
Invocation, FileSystem, newBuffer.get(), Offset, Error, &CIDiags);
177180
if (!CI)
178181
return false;

tools/SourceKit/lib/SwiftLang/SwiftConformingMethodList.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ static bool swiftConformingMethodListImpl(
7676
Error = "no input filenames specified";
7777
return false;
7878
}
79-
CompilerInstance *CI = Lang.getCompletionInstance().getCompilerInstance(
79+
80+
// Pin completion instance.
81+
auto CompletionInst = Lang.getCompletionInstance();
82+
CompilerInstance *CI = CompletionInst->getCompilerInstance(
8083
Invocation, FileSystem, newBuffer.get(), Offset, Error, &CIDiags);
8184
if (!CI)
8285
return false;

tools/SourceKit/lib/SwiftLang/SwiftLangSupport.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class SwiftLangSupport : public LangSupport {
295295
ThreadSafeRefCntPtr<SwiftCustomCompletions> CustomCompletions;
296296
std::shared_ptr<SwiftStatistics> Stats;
297297
llvm::StringMap<std::unique_ptr<FileSystemProvider>> FileSystemProviders;
298-
std::unique_ptr<swift::ide::CompletionInstance> CompletionInst;
298+
std::shared_ptr<swift::ide::CompletionInstance> CompletionInst;
299299

300300
public:
301301
explicit SwiftLangSupport(SourceKit::Context &SKCtx);
@@ -315,8 +315,8 @@ class SwiftLangSupport : public LangSupport {
315315
return CCCache;
316316
}
317317

318-
swift::ide::CompletionInstance &getCompletionInstance() {
319-
return *CompletionInst;
318+
std::shared_ptr<swift::ide::CompletionInstance> getCompletionInstance() {
319+
return CompletionInst;
320320
}
321321

322322
/// Returns the FileSystemProvider registered under Name, or nullptr if not

tools/SourceKit/lib/SwiftLang/SwiftTypeContextInfo.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ static bool swiftTypeContextInfoImpl(
7474
Error = "no input filenames specified";
7575
return false;
7676
}
77-
CompilerInstance *CI = Lang.getCompletionInstance().getCompilerInstance(
77+
78+
// Pin completion instance.
79+
auto CompletionInst = Lang.getCompletionInstance();
80+
CompilerInstance *CI = CompletionInst->getCompilerInstance(
7881
Invocation, FileSystem, newBuffer.get(), Offset, Error, &CIDiags);
7982
if (!CI)
8083
return false;

0 commit comments

Comments
 (0)