@@ -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,21 +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) {
200- auto kind = static_cast <CodeCompletionResult::ResultKind >(*cursor++);
201- auto declKind = static_cast <CodeCompletionDeclKind >(*cursor++);
200+ auto kind = static_cast <CodeCompletionResultKind >(*cursor++);
201+ auto associatedKind = static_cast <uint8_t >(*cursor++);
202202 auto opKind = static_cast <CodeCompletionOperatorKind>(*cursor++);
203- auto context = static_cast <SemanticContextKind>(*cursor++);
204203 auto notRecommended =
205- static_cast <CodeCompletionResult::NotRecommendedReason >(*cursor++);
204+ static_cast <ContextFreeNotRecommendedReason >(*cursor++);
206205 auto diagSeverity =
207206 static_cast <CodeCompletionDiagnosticSeverity>(*cursor++);
208207 auto isSystem = static_cast <bool >(*cursor++);
209- auto numBytesToErase = static_cast <unsigned >(*cursor++);
210208 auto chunkIndex = read32le (cursor);
211209 auto moduleIndex = read32le (cursor);
212210 auto briefDocIndex = read32le (cursor);
@@ -223,21 +221,14 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
223221 auto briefDocComment = getString (briefDocIndex);
224222 auto diagMessage = getString (diagMessageIndex);
225223
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);
234- } else {
235- result = new (*V.Sink .Allocator ) CodeCompletionResult (
236- kind, context, CodeCompletionFlair (), numBytesToErase, string,
237- CodeCompletionResult::ExpectedTypeRelation::NotApplicable, opKind);
238- }
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);
239230
240- V.Sink . Results .push_back (result);
231+ V.Results .push_back (result);
241232 }
242233
243234 return true ;
@@ -343,27 +334,18 @@ static void writeCachedModule(llvm::raw_ostream &out,
343334 // RESULTS
344335 {
345336 endian::Writer LE (results, little);
346- for (CodeCompletionResult *R : V.Sink .Results ) {
347- assert (!R->getFlair ().toRaw () && " Any flairs should not be cached" );
348- assert (R->getNotRecommendedReason () !=
349- CodeCompletionResult::NotRecommendedReason::InvalidAsyncContext &&
350- " InvalidAsyncContext is decl context specific, cannot be cached" );
351-
337+ for (const ContextFreeCodeCompletionResult *R : V.Results ) {
352338 // FIXME: compress bitfield
353339 LE.write (static_cast <uint8_t >(R->getKind ()));
354- if (R->getKind () == CodeCompletionResult::ResultKind::Declaration)
355- LE.write (static_cast <uint8_t >(R->getAssociatedDeclKind ()));
356- else
357- LE.write (static_cast <uint8_t >(~0u ));
358- if (R->isOperator ())
359- LE.write (static_cast <uint8_t >(R->getOperatorKind ()));
360- 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 {
361344 LE.write (static_cast <uint8_t >(CodeCompletionOperatorKind::None));
362- LE. write ( static_cast < uint8_t >(R-> getSemanticContext ()));
345+ }
363346 LE.write (static_cast <uint8_t >(R->getNotRecommendedReason ()));
364347 LE.write (static_cast <uint8_t >(R->getDiagnosticSeverity ()));
365348 LE.write (static_cast <uint8_t >(R->isSystem ()));
366- LE.write (static_cast <uint8_t >(R->getNumBytesToErase ()));
367349 LE.write (
368350 static_cast <uint32_t >(addCompletionString (R->getCompletionString ())));
369351 LE.write (addString (R->getModuleName ())); // index into strings
0 commit comments