@@ -41,7 +41,7 @@ namespace swift {
41
41
struct CacheValueCostInfo <swift::ide::CodeCompletionCacheImpl::Value> {
42
42
static size_t
43
43
getCost (const swift::ide::CodeCompletionCacheImpl::Value &V) {
44
- return V.Sink . Allocator ->getTotalMemory ();
44
+ return V.Allocator ->getTotalMemory ();
45
45
}
46
46
};
47
47
} // namespace sys
@@ -102,7 +102,8 @@ CodeCompletionCache::~CodeCompletionCache() {}
102
102
// /
103
103
// / This should be incremented any time we commit a change to the format of the
104
104
// / cached results. This isn't expected to change very often.
105
- static constexpr uint32_t onDiskCompletionCacheVersion = 3 ; // Removed "source file path".
105
+ static constexpr uint32_t onDiskCompletionCacheVersion =
106
+ 4 ; // Store ContextFreeCodeCompletionResults in cache
106
107
107
108
// / Deserializes CodeCompletionResults from \p in and stores them in \p V.
108
109
// / \see writeCacheModule.
@@ -166,7 +167,7 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
166
167
167
168
const char *p = strings + index;
168
169
auto size = read32le (p);
169
- auto str = copyString (*V.Sink . Allocator , StringRef (p, size));
170
+ auto str = copyString (*V.Allocator , StringRef (p, size));
170
171
knownStrings[index] = str;
171
172
return str;
172
173
};
@@ -192,21 +193,19 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
192
193
}
193
194
}
194
195
195
- return CodeCompletionString::create (*V.Sink . Allocator , chunkList);
196
+ return CodeCompletionString::create (*V.Allocator , chunkList);
196
197
};
197
198
198
199
// RESULTS
199
200
while (cursor != resultEnd) {
200
- auto kind = static_cast <CodeCompletionResult::ResultKind >(*cursor++);
201
+ auto kind = static_cast <CodeCompletionResultKind >(*cursor++);
201
202
auto declKind = static_cast <CodeCompletionDeclKind>(*cursor++);
202
203
auto opKind = static_cast <CodeCompletionOperatorKind>(*cursor++);
203
- auto context = static_cast <SemanticContextKind>(*cursor++);
204
204
auto notRecommended =
205
- static_cast <CodeCompletionResult::NotRecommendedReason >(*cursor++);
205
+ static_cast <ContextFreeNotRecommendedReason >(*cursor++);
206
206
auto diagSeverity =
207
207
static_cast <CodeCompletionDiagnosticSeverity>(*cursor++);
208
208
auto isSystem = static_cast <bool >(*cursor++);
209
- auto numBytesToErase = static_cast <unsigned >(*cursor++);
210
209
auto chunkIndex = read32le (cursor);
211
210
auto moduleIndex = read32le (cursor);
212
211
auto briefDocIndex = read32le (cursor);
@@ -223,21 +222,20 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
223
222
auto briefDocComment = getString (briefDocIndex);
224
223
auto diagMessage = getString (diagMessageIndex);
225
224
226
- CodeCompletionResult *result = nullptr ;
227
- if (kind == CodeCompletionResult::ResultKind::Declaration) {
228
- result = new (*V.Sink .Allocator ) CodeCompletionResult (
229
- context, CodeCompletionFlair (), numBytesToErase, string, declKind,
230
- isSystem, moduleName, notRecommended, diagSeverity, diagMessage,
231
- briefDocComment,
232
- copyArray (*V.Sink .Allocator , ArrayRef<StringRef>(assocUSRs)),
233
- CodeCompletionResult::ExpectedTypeRelation::Unknown, opKind);
225
+ ContextFreeCodeCompletionResult *result = nullptr ;
226
+ if (kind == CodeCompletionResultKind::Declaration) {
227
+ result = new (*V.Allocator ) ContextFreeCodeCompletionResult (
228
+ CodeCompletionResultKind::Declaration, static_cast <uint8_t >(declKind),
229
+ opKind, isSystem, string, moduleName, briefDocComment,
230
+ copyArray (*V.Allocator , ArrayRef<StringRef>(assocUSRs)),
231
+ notRecommended, diagSeverity, diagMessage);
234
232
} else {
235
- result = new (*V.Sink . Allocator ) CodeCompletionResult (
236
- kind, context, CodeCompletionFlair (), numBytesToErase, string ,
237
- CodeCompletionResult::ExpectedTypeRelation::NotApplicable, opKind );
233
+ result = new (*V.Allocator ) ContextFreeCodeCompletionResult (
234
+ kind, string, opKind, /* BriefDocComment= */ " " , notRecommended ,
235
+ diagSeverity, diagMessage );
238
236
}
239
237
240
- V.Sink . Results .push_back (result);
238
+ V.Results .push_back (result);
241
239
}
242
240
243
241
return true ;
@@ -342,27 +340,22 @@ static void writeCachedModule(llvm::raw_ostream &out,
342
340
// RESULTS
343
341
{
344
342
endian::Writer LE (results, little);
345
- for (CodeCompletionResult *R : V.Sink .Results ) {
346
- assert (!R->getFlair ().toRaw () && " Any flairs should not be cached" );
347
- assert (R->getNotRecommendedReason () !=
348
- CodeCompletionResult::NotRecommendedReason::InvalidAsyncContext &&
349
- " InvalidAsyncContext is decl context specific, cannot be cached" );
350
-
343
+ for (ContextFreeCodeCompletionResult *R : V.Results ) {
351
344
// FIXME: compress bitfield
352
345
LE.write (static_cast <uint8_t >(R->getKind ()));
353
- if (R->getKind () == CodeCompletionResult::ResultKind:: Declaration)
346
+ if (R->getKind () == CodeCompletionResultKind:: Declaration) {
354
347
LE.write (static_cast <uint8_t >(R->getAssociatedDeclKind ()));
355
- else
348
+ } else {
356
349
LE.write (static_cast <uint8_t >(~0u ));
357
- if (R->isOperator ())
358
- LE.write (static_cast <uint8_t >(R->getOperatorKind ()));
359
- else
350
+ }
351
+ if (R->isOperator ()) {
352
+ LE.write (static_cast <uint8_t >(R->getKnownOperatorKind ()));
353
+ } else {
360
354
LE.write (static_cast <uint8_t >(CodeCompletionOperatorKind::None));
361
- LE. write ( static_cast < uint8_t >(R-> getSemanticContext ()));
355
+ }
362
356
LE.write (static_cast <uint8_t >(R->getNotRecommendedReason ()));
363
357
LE.write (static_cast <uint8_t >(R->getDiagnosticSeverity ()));
364
358
LE.write (static_cast <uint8_t >(R->isSystem ()));
365
- LE.write (static_cast <uint8_t >(R->getNumBytesToErase ()));
366
359
LE.write (
367
360
static_cast <uint32_t >(addCompletionString (R->getCompletionString ())));
368
361
LE.write (addString (R->getModuleName ())); // index into strings
0 commit comments