@@ -139,21 +139,23 @@ bool CompletionInstance::performCachedOperaitonIfPossible(
139
139
return false ;
140
140
141
141
// Temporary move the CI so other threads don't use the same instance.
142
- std::shared_ptr<CompilerInstance> CI ;
143
- CI .swap (CachedCI );
142
+ std::shared_ptr<CachedInstance> CachedI ( nullptr ) ;
143
+ CachedInst .swap (CachedI );
144
144
145
- if (!CI )
145
+ if (!CachedI )
146
146
return false ;
147
- if (CurrentASTReuseCount >= MaxASTReuseCount)
147
+ if (CachedI-> ReuseCound >= MaxASTReuseCount)
148
148
return false ;
149
- if (ArgsHash != CachedArgsHash )
149
+ if (CachedI-> ArgHash != ArgsHash )
150
150
return false ;
151
151
152
- auto &oldState = CI->getPersistentParserState ();
152
+ auto &CI = CachedI->CI ;
153
+
154
+ auto &oldState = CachedI->CI .getPersistentParserState ();
153
155
if (!oldState.hasCodeCompletionDelayedDeclState ())
154
156
return false ;
155
157
156
- auto &SM = CI-> getSourceMgr ();
158
+ auto &SM = CI. getSourceMgr ();
157
159
if (SM.getIdentifierForBuffer (SM.getCodeCompletionBufferID ()) !=
158
160
completionBuffer->getBufferIdentifier ())
159
161
return false ;
@@ -230,19 +232,18 @@ bool CompletionInstance::performCachedOperaitonIfPossible(
230
232
if (AFD->isBodySkipped ())
231
233
AFD->setBodyDelayed (AFD->getBodySourceRange ());
232
234
if (DiagC)
233
- CI-> addDiagnosticConsumer (DiagC);
235
+ CI. addDiagnosticConsumer (DiagC);
234
236
235
- CI-> getDiags ().diagnose (SM.getLocForOffset (BufferID, newInfo.StartOffset ),
237
+ CI. getDiags ().diagnose (SM.getLocForOffset (BufferID, newInfo.StartOffset ),
236
238
diag::completion_reusing_astcontext);
237
239
238
- Callback (* CI);
240
+ Callback (CI);
239
241
240
242
if (DiagC)
241
- CI-> removeDiagnosticConsumer (DiagC);
243
+ CI. removeDiagnosticConsumer (DiagC);
242
244
243
- CachedCI.swap (CI);
244
- CachedArgsHash = ArgsHash;
245
- CurrentASTReuseCount += 1 ;
245
+ CachedI->ReuseCound += 1 ;
246
+ CachedInst.swap (CachedI);
246
247
247
248
return true ;
248
249
}
@@ -253,32 +254,32 @@ bool CompletionInstance::performNewOperation(
253
254
llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
254
255
std::string &Error, DiagnosticConsumer *DiagC,
255
256
llvm::function_ref<void (CompilerInstance &)> Callback) {
256
- CachedCI.reset ();
257
- auto CI = std::make_shared<CompilerInstance>();
257
+ CachedInst.reset ();
258
+ auto TheInstance = std::make_shared<CachedInstance>();
259
+ auto &CI = TheInstance->CI ;
258
260
if (DiagC)
259
- CI-> addDiagnosticConsumer (DiagC);
261
+ CI. addDiagnosticConsumer (DiagC);
260
262
261
263
if (FileSystem != llvm::vfs::getRealFileSystem ())
262
- CI-> getSourceMgr ().setFileSystem (FileSystem);
264
+ CI. getSourceMgr ().setFileSystem (FileSystem);
263
265
264
266
Invocation.setCodeCompletionPoint (completionBuffer, Offset);
265
267
266
- if (CI-> setup (Invocation)) {
268
+ if (CI. setup (Invocation)) {
267
269
Error = " failed to setup compiler instance" ;
268
270
return false ;
269
271
}
270
- registerIDERequestFunctions (CI-> getASTContext ().evaluator );
272
+ registerIDERequestFunctions (CI. getASTContext ().evaluator );
271
273
272
- CI-> performParseAndResolveImportsOnly ();
273
- Callback (* CI);
274
+ CI. performParseAndResolveImportsOnly ();
275
+ Callback (CI);
274
276
275
277
if (DiagC)
276
- CI-> removeDiagnosticConsumer (DiagC);
278
+ CI. removeDiagnosticConsumer (DiagC);
277
279
278
280
if (EnableASTCaching) {
279
- CachedCI.swap (CI);
280
- CachedArgsHash = ArgsHash;
281
- CurrentASTReuseCount = 0 ;
281
+ TheInstance->ArgHash = ArgsHash;
282
+ CachedInst.swap (TheInstance);
282
283
}
283
284
284
285
return true ;
0 commit comments