Skip to content

Revert "[CodeComplete] Compute type relations for global cached results" #41627

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

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/IDE/CodeCompletion.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool isDynamicLookup(Type T);

void postProcessCompletionResults(
MutableArrayRef<CodeCompletionResult *> results, CompletionKind Kind,
const DeclContext *DC, CodeCompletionResultSink *Sink);
DeclContext *DC, CodeCompletionResultSink *Sink);

void deliverCompletionResults(CodeCompletionContext &CompletionContext,
CompletionLookup &Lookup, DeclContext *DC,
Expand Down
4 changes: 0 additions & 4 deletions include/swift/IDE/CodeCompletionCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ class CodeCompletionCache {

std::vector<const ContextFreeCodeCompletionResult *> Results;

/// The arena that contains the \c USRBasedTypes of the
/// \c ContextFreeCodeCompletionResult in this cache value.
USRBasedTypeArena USRTypeArena;

Value() : Allocator(std::make_shared<llvm::BumpPtrAllocator>()) {}
};
using ValueRefCntPtr = llvm::IntrusiveRefCntPtr<Value>;
Expand Down
6 changes: 2 additions & 4 deletions include/swift/IDE/CodeCompletionConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ class CodeCompletionConsumer {
virtual void
handleResultsAndModules(CodeCompletionContext &context,
ArrayRef<RequestedCachedModule> requestedModules,
const ExpectedTypeContext *TypeContext,
const DeclContext *DC) = 0;
DeclContext *DC) = 0;
};

/// A simplified code completion consumer interface that clients can use to get
Expand All @@ -41,8 +40,7 @@ struct SimpleCachingCodeCompletionConsumer : public CodeCompletionConsumer {
// Implement the CodeCompletionConsumer interface.
void handleResultsAndModules(CodeCompletionContext &context,
ArrayRef<RequestedCachedModule> requestedModules,
const ExpectedTypeContext *TypeContext,
const DeclContext *DCForModules) override;
DeclContext *DCForModules) override;

/// Clients should override this method to receive \p Results.
virtual void handleResults(CodeCompletionContext &context) = 0;
Expand Down
11 changes: 4 additions & 7 deletions include/swift/IDE/CodeCompletionResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ class ContextFreeCodeCompletionResult {
/// StringRefs outlive this result, typically by storing them in the same
/// \c CodeCompletionResultSink as the result itself.
static ContextFreeCodeCompletionResult *createPatternOrBuiltInOperatorResult(
CodeCompletionResultSink &Sink, CodeCompletionResultKind Kind,
llvm::BumpPtrAllocator &Allocator, CodeCompletionResultKind Kind,
CodeCompletionString *CompletionString,
CodeCompletionOperatorKind KnownOperatorKind,
NullTerminatedStringRef BriefDocComment,
Expand All @@ -405,7 +405,7 @@ class ContextFreeCodeCompletionResult {
/// \p BriefDocComment outlive this result, typically by storing them in
/// the same \c CodeCompletionResultSink as the result itself.
static ContextFreeCodeCompletionResult *
createKeywordResult(CodeCompletionResultSink &Sink,
createKeywordResult(llvm::BumpPtrAllocator &Allocator,
CodeCompletionKeywordKind Kind,
CodeCompletionString *CompletionString,
NullTerminatedStringRef BriefDocComment,
Expand All @@ -417,7 +417,7 @@ class ContextFreeCodeCompletionResult {
/// result, typically by storing them in the same \c CodeCompletionResultSink
/// as the result itself.
static ContextFreeCodeCompletionResult *
createLiteralResult(CodeCompletionResultSink &Sink,
createLiteralResult(llvm::BumpPtrAllocator &Allocator,
CodeCompletionLiteralKind LiteralKind,
CodeCompletionString *CompletionString,
CodeCompletionResultType ResultType);
Expand All @@ -428,7 +428,7 @@ class ContextFreeCodeCompletionResult {
/// \c StringRefs outlive this result, typically by storing them in the same
/// \c CodeCompletionResultSink as the result itself.
static ContextFreeCodeCompletionResult *createDeclResult(
CodeCompletionResultSink &Sink, CodeCompletionString *CompletionString,
llvm::BumpPtrAllocator &Allocator, CodeCompletionString *CompletionString,
const Decl *AssociatedDecl, NullTerminatedStringRef ModuleName,
NullTerminatedStringRef BriefDocComment,
ArrayRef<NullTerminatedStringRef> AssociatedUSRs,
Expand Down Expand Up @@ -566,8 +566,6 @@ class CodeCompletionResult {
/// information.
/// This computes the type relation between the completion item and its
/// expected type context.
/// See \c CodeCompletionResultType::calculateTypeRelation for documentation
/// on \p USRTypeContext.
/// The \c ContextFree result must outlive this result. Typically, this is
/// done by allocating the two in the same sink or adopting the context free
/// sink in the sink that allocates this result.
Expand All @@ -576,7 +574,6 @@ class CodeCompletionResult {
CodeCompletionFlair Flair, uint8_t NumBytesToErase,
const ExpectedTypeContext *TypeContext,
const DeclContext *DC,
const USRBasedTypeContext *USRTypeContext,
ContextualNotRecommendedReason NotRecommended,
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
NullTerminatedStringRef DiagnosticMessage);
Expand Down
32 changes: 0 additions & 32 deletions include/swift/IDE/CodeCompletionResultSink.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ struct CodeCompletionResultSink {
/// Whether to include an item without any default arguments.
bool addCallWithNoDefaultArgs = true;

private:
/// Whether the code completion results computed for this sink are intended to
/// only be stored in the cache. In this case no contextual information is
/// computed and all types in \c ContextFreeCodeCompletionResult should be
/// USR-based instead of AST-based.
USRBasedTypeArena *USRTypeArena = nullptr;

public:
std::vector<CodeCompletionResult *> Results;

/// A single-element cache for module names stored in Allocator, keyed by a
Expand All @@ -60,30 +52,6 @@ struct CodeCompletionResultSink {

CodeCompletionResultSink()
: Allocator(std::make_shared<llvm::BumpPtrAllocator>()) {}

llvm::BumpPtrAllocator &getAllocator() { return *Allocator; }

/// Marks the sink as producing results for the code completion cache.
/// In this case the produced results will not contain any contextual
/// information and all types in the \c ContextFreeCodeCompletionResult are
/// USR-based.
void setProduceContextFreeResults(USRBasedTypeArena &USRTypeArena) {
this->USRTypeArena = &USRTypeArena;
}

/// See \c setProduceContextFreeResults.
bool shouldProduceContextFreeResults() const {
return USRTypeArena != nullptr;
}

/// If \c shouldProduceContextFreeResults is \c true, returns the arena in
/// which the USR-based types of the \c ContextFreeCodeCompletionResult should
/// be stored.
USRBasedTypeArena &getUSRTypeArena() const {
assert(USRTypeArena != nullptr &&
"Must only be called if shouldProduceContextFreeResults is true");
return *USRTypeArena;
}
};

} // end namespace ide
Expand Down
Loading