Skip to content

[SourceKit] Compute type relations for global code completion items from the cache #40399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
833 changes: 604 additions & 229 deletions include/swift/IDE/CodeCompletion.h

Large diffs are not rendered by default.

27 changes: 23 additions & 4 deletions include/swift/IDE/CodeCompletionCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class OnDiskCodeCompletionCache;
class CodeCompletionCache {
std::unique_ptr<CodeCompletionCacheImpl> Impl;
OnDiskCodeCompletionCache *nextCache;
/// The arena in which the types for the completion results cached by this
/// \c CodeCompletionCache are stored.
CodeCompletionResultTypeArenaRef ResultTypeArena;

public:
/// Cache key.
Expand All @@ -58,18 +61,31 @@ class CodeCompletionCache {
};

struct Value : public llvm::ThreadSafeRefCountedBase<Value> {
using AllocatorPtr = std::shared_ptr<llvm::BumpPtrAllocator>;

/// The allocator used to allocate the results stored in this cache.
AllocatorPtr Allocator;

llvm::sys::TimePoint<> ModuleModificationTime;
CodeCompletionResultSink Sink;

std::vector<ContextFreeCodeCompletionResult *> Results;

Value() : Allocator(std::make_shared<llvm::BumpPtrAllocator>()) {}
};
using ValueRefCntPtr = llvm::IntrusiveRefCntPtr<Value>;

CodeCompletionCache(OnDiskCodeCompletionCache *nextCache = nullptr);
CodeCompletionCache(const CodeCompletionResultTypeArenaRef &ResultTypeArena,
OnDiskCodeCompletionCache *nextCache = nullptr);
~CodeCompletionCache();

static ValueRefCntPtr createValue();
Optional<ValueRefCntPtr> get(const Key &K);
void set(const Key &K, ValueRefCntPtr V) { setImpl(K, V, /*setChain*/ true); }

const CodeCompletionResultTypeArenaRef &getResultTypeArena() const {
return ResultTypeArena;
}

private:
void setImpl(const Key &K, ValueRefCntPtr V, bool setChain);
};
Expand All @@ -89,10 +105,13 @@ class OnDiskCodeCompletionCache {
OnDiskCodeCompletionCache(Twine cacheDirectory);
~OnDiskCodeCompletionCache();

Optional<ValueRefCntPtr> get(const Key &K);
Optional<ValueRefCntPtr>
get(const Key &K, const CodeCompletionResultTypeArenaRef &ResultTypeArena);
std::error_code set(const Key &K, ValueRefCntPtr V);

static Optional<ValueRefCntPtr> getFromFile(StringRef filename);
static Optional<ValueRefCntPtr>
getFromFile(StringRef filename,
const CodeCompletionResultTypeArenaRef &ResultTypeArena);
};

struct RequestedCachedModule {
Expand Down
2 changes: 1 addition & 1 deletion include/swift/IDE/REPLCodeCompletion.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class REPLCompletions {

public:
/// Create an invalid completion set.
REPLCompletions();
REPLCompletions(const ide::CodeCompletionResultTypeArenaRef &ResultTypeArena);

/// Create completion results for the given string.
void populate(SourceFile &SF, StringRef EnteredCode);
Expand Down
Loading