Skip to content

Commit c3d5828

Browse files
committed
[SourceKit] Limit compiler instance reuse count for completions
1 parent fcc7e41 commit c3d5828

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

include/swift/IDE/CompletionInstance.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ makeCodeCompletionMemoryBuffer(const llvm::MemoryBuffer *origBuf,
3737
class CompletionInstance {
3838
std::unique_ptr<CompilerInstance> CachedCI = nullptr;
3939
bool EnableASTCaching = false;
40+
unsigned MaxASTReuseCount = 100;
41+
unsigned CurrentASTReuseCount = 0;
4042

4143
swift::CompilerInstance *
4244
getReusingCompilerInstance(const swift::CompilerInvocation &Invocation,

lib/IDE/CompletionInstance.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ CompilerInstance *CompletionInstance::getReusingCompilerInstance(
202202
if (!EnableASTCaching)
203203
return nullptr;
204204

205+
if (CurrentASTReuseCount >= MaxASTReuseCount) {
206+
CurrentASTReuseCount = 0;
207+
return nullptr;
208+
}
209+
205210
if (!CachedCI)
206211
return nullptr;
207212

@@ -296,6 +301,8 @@ CompilerInstance *CompletionInstance::getReusingCompilerInstance(
296301
SM.getLocForOffset(BufferID, newInfo.StartOffset),
297302
diag::completion_reusing_astcontext);
298303

304+
CurrentASTReuseCount += 1;
305+
299306
return CachedCI.get();
300307
}
301308

0 commit comments

Comments
 (0)