@@ -41,7 +41,7 @@ namespace swift {
4141 struct CacheValueCostInfo <swift::ide::CodeCompletionCacheImpl::Value> {
4242 static size_t
4343 getCost (const swift::ide::CodeCompletionCacheImpl::Value &V) {
44- return V.Sink . Allocator ->getTotalMemory ();
44+ return V.Allocator ->getTotalMemory ();
4545 }
4646 };
4747 } // namespace sys
@@ -102,7 +102,7 @@ CodeCompletionCache::~CodeCompletionCache() {}
102102// /
103103// / This should be incremented any time we commit a change to the format of the
104104// / 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 = 4 ; // Store ContextFreeCodeCompletionResults in cache
106106
107107// / Deserializes CodeCompletionResults from \p in and stores them in \p V.
108108// / \see writeCacheModule.
@@ -166,7 +166,7 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
166166
167167 const char *p = strings + index;
168168 auto size = read32le (p);
169- auto str = copyString (*V.Sink . Allocator , StringRef (p, size));
169+ auto str = copyString (*V.Allocator , StringRef (p, size));
170170 knownStrings[index] = str;
171171 return str;
172172 };
@@ -192,20 +192,19 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
192192 }
193193 }
194194
195- return CodeCompletionString::create (*V.Sink . Allocator , chunkList);
195+ return CodeCompletionString::create (*V.Allocator , chunkList);
196196 };
197197
198198 // RESULTS
199199 while (cursor != resultEnd) {
200200 auto kind = static_cast <CodeCompletionResultKind>(*cursor++);
201- auto declKind = static_cast <CodeCompletionDeclKind >(*cursor++);
201+ auto associatedKind = static_cast <uint8_t >(*cursor++);
202202 auto opKind = static_cast <CodeCompletionOperatorKind>(*cursor++);
203- auto context = static_cast <SemanticContextKind>(*cursor++);
204- auto notRecommended = static_cast <NotRecommendedReason >(*cursor++);
203+ auto notRecommended =
204+ static_cast <ContextFreeNotRecommendedReason >(*cursor++);
205205 auto diagSeverity =
206206 static_cast <CodeCompletionDiagnosticSeverity>(*cursor++);
207207 auto isSystem = static_cast <bool >(*cursor++);
208- auto numBytesToErase = static_cast <unsigned >(*cursor++);
209208 auto chunkIndex = read32le (cursor);
210209 auto moduleIndex = read32le (cursor);
211210 auto briefDocIndex = read32le (cursor);
@@ -222,21 +221,14 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
222221 auto briefDocComment = getString (briefDocIndex);
223222 auto diagMessage = getString (diagMessageIndex);
224223
225- CodeCompletionResult *result = nullptr ;
226- if (kind == CodeCompletionResultKind::Declaration) {
227- result = new (*V.Sink .Allocator ) CodeCompletionResult (
228- context, CodeCompletionFlair (), numBytesToErase, string, declKind,
229- isSystem, moduleName, notRecommended, diagSeverity, diagMessage,
230- briefDocComment,
231- copyArray (*V.Sink .Allocator , ArrayRef<StringRef>(assocUSRs)),
232- CodeCompletionResult::ExpectedTypeRelation::Unknown, opKind);
233- } else {
234- result = new (*V.Sink .Allocator ) CodeCompletionResult (
235- kind, context, CodeCompletionFlair (), numBytesToErase, string,
236- CodeCompletionResult::ExpectedTypeRelation::NotApplicable, opKind);
237- }
224+ ContextFreeCodeCompletionResult *result =
225+ new (*V.Allocator ) ContextFreeCodeCompletionResult (
226+ kind, associatedKind, opKind, isSystem, string, moduleName,
227+ briefDocComment,
228+ copyArray (*V.Allocator , ArrayRef<StringRef>(assocUSRs)),
229+ notRecommended, diagSeverity, diagMessage);
238230
239- V.Sink . Results .push_back (result);
231+ V.Results .push_back (result);
240232 }
241233
242234 return true ;
@@ -342,27 +334,18 @@ static void writeCachedModule(llvm::raw_ostream &out,
342334 // RESULTS
343335 {
344336 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- NotRecommendedReason::InvalidAsyncContext &&
349- " InvalidAsyncContext is decl context specific, cannot be cached" );
350-
337+ for (const ContextFreeCodeCompletionResult *R : V.Results ) {
351338 // FIXME: compress bitfield
352339 LE.write (static_cast <uint8_t >(R->getKind ()));
353- if (R->getKind () == CodeCompletionResultKind::Declaration)
354- LE.write (static_cast <uint8_t >(R->getAssociatedDeclKind ()));
355- else
356- LE.write (static_cast <uint8_t >(~0u ));
357- if (R->isOperator ())
358- LE.write (static_cast <uint8_t >(R->getOperatorKind ()));
359- else
340+ LE.write (static_cast <uint8_t >(R->getOpaqueAssociatedKind ()));
341+ if (R->isOperator ()) {
342+ LE.write (static_cast <uint8_t >(R->getKnownOperatorKind ()));
343+ } else {
360344 LE.write (static_cast <uint8_t >(CodeCompletionOperatorKind::None));
361- LE. write ( static_cast < uint8_t >(R-> getSemanticContext ()));
345+ }
362346 LE.write (static_cast <uint8_t >(R->getNotRecommendedReason ()));
363347 LE.write (static_cast <uint8_t >(R->getDiagnosticSeverity ()));
364348 LE.write (static_cast <uint8_t >(R->isSystem ()));
365- LE.write (static_cast <uint8_t >(R->getNumBytesToErase ()));
366349 LE.write (
367350 static_cast <uint32_t >(addCompletionString (R->getCompletionString ())));
368351 LE.write (addString (R->getModuleName ())); // index into strings
0 commit comments