Skip to content

Commit 0b8beea

Browse files
committed
IDE: Add CodeCompleteInitsInPostfixExpr to completion cache key
This fixes a source of non-determinism. The IDE/complete_constructor test would sometimes fail depending on the order in which prior tests ran, since those prior tests might populate the code completion cache.
1 parent 7af5238 commit 0b8beea

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

include/swift/IDE/CodeCompletionCache.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ class CodeCompletionCache {
3939
std::vector<std::string> AccessPath;
4040
bool ResultsHaveLeadingDot;
4141
bool ForTestableLookup;
42+
bool CodeCompleteInitsInPostfixExpr;
4243

4344
friend bool operator==(const Key &LHS, const Key &RHS) {
4445
return LHS.ModuleFilename == RHS.ModuleFilename &&
45-
LHS.ModuleName == RHS.ModuleName &&
46-
LHS.AccessPath == RHS.AccessPath &&
47-
LHS.ResultsHaveLeadingDot == RHS.ResultsHaveLeadingDot &&
48-
LHS.ForTestableLookup == RHS.ForTestableLookup;
46+
LHS.ModuleName == RHS.ModuleName &&
47+
LHS.AccessPath == RHS.AccessPath &&
48+
LHS.ResultsHaveLeadingDot == RHS.ResultsHaveLeadingDot &&
49+
LHS.ForTestableLookup == RHS.ForTestableLookup &&
50+
LHS.CodeCompleteInitsInPostfixExpr == RHS.CodeCompleteInitsInPostfixExpr;
4951
}
5052
};
5153

@@ -101,10 +103,10 @@ template<>
101103
struct DenseMapInfo<swift::ide::CodeCompletionCache::Key> {
102104
using KeyTy = swift::ide::CodeCompletionCache::Key;
103105
static inline KeyTy getEmptyKey() {
104-
return KeyTy{"", "", {}, false, false};
106+
return KeyTy{"", "", {}, false, false, false};
105107
}
106108
static inline KeyTy getTombstoneKey() {
107-
return KeyTy{"", "", {}, true, false};
109+
return KeyTy{"", "", {}, true, false, false};
108110
}
109111
static unsigned getHashValue(const KeyTy &Val) {
110112
size_t H = 0;

lib/IDE/CodeCompletion.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5377,9 +5377,11 @@ void CodeCompletionCallbacksImpl::doneParsing() {
53775377
// ModuleFilename can be empty if something strange happened during
53785378
// module loading, for example, the module file is corrupted.
53795379
if (!ModuleFilename.empty()) {
5380+
auto &Ctx = TheModule->getASTContext();
53805381
CodeCompletionCache::Key K{ModuleFilename, TheModule->getName().str(),
53815382
AccessPath, Request.NeedLeadingDot,
5382-
SF.hasTestableImport(TheModule)};
5383+
SF.hasTestableImport(TheModule),
5384+
Ctx.LangOpts.CodeCompleteInitsInPostfixExpr};
53835385
std::pair<decltype(ImportsSeen)::iterator, bool>
53845386
Result = ImportsSeen.insert(K);
53855387
if (!Result.second)

lib/IDE/CodeCompletionCache.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ CodeCompletionCache::~CodeCompletionCache() {}
8888
///
8989
/// This should be incremented any time we commit a change to the format of the
9090
/// cached results. This isn't expected to change very often.
91-
static constexpr uint32_t onDiskCompletionCacheVersion = 0;
91+
static constexpr uint32_t onDiskCompletionCacheVersion = 1;
9292

9393
static StringRef copyString(llvm::BumpPtrAllocator &Allocator, StringRef Str) {
9494
char *Mem = Allocator.Allocate<char>(Str.size());
@@ -297,6 +297,7 @@ static void writeCachedModule(llvm::raw_ostream &out,
297297
OSS << p << "\0";
298298
OSSLE.write(K.ResultsHaveLeadingDot);
299299
OSSLE.write(K.ForTestableLookup);
300+
OSSLE.write(K.CodeCompleteInitsInPostfixExpr);
300301
LE.write(static_cast<uint32_t>(OSS.tell())); // Size of debug info
301302
out.write(OSS.str().data(), OSS.str().size()); // Debug info blob
302303
}
@@ -404,9 +405,10 @@ static std::string getName(StringRef cacheDirectory,
404405
llvm::sys::path::append(name, K.ModuleName);
405406
llvm::raw_svector_ostream OSS(name);
406407

407-
// name[-dot][-testable]
408+
// name[-dot][-testable][-inits]
408409
OSS << (K.ResultsHaveLeadingDot ? "-dot" : "")
409-
<< (K.ForTestableLookup ? "-testable" : "");
410+
<< (K.ForTestableLookup ? "-testable" : "")
411+
<< (K.CodeCompleteInitsInPostfixExpr ? "-inits" : "");
410412

411413
// name[-access-path-components]
412414
for (StringRef component : K.AccessPath)
@@ -471,7 +473,7 @@ OnDiskCodeCompletionCache::getFromFile(StringRef filename) {
471473
return None;
472474

473475
// Make up a key for readCachedModule.
474-
CodeCompletionCache::Key K{filename, "<module-name>", {}, false, false};
476+
CodeCompletionCache::Key K{filename, "<module-name>", {}, false, false, false};
475477

476478
// Read the cached results.
477479
auto V = CodeCompletionCache::createValue();

0 commit comments

Comments
 (0)