Skip to content

Commit 845b2f9

Browse files
authored
Merge pull request #39386 from rintaro/ide-completion-sourcefileinfo
[CodeCompletion] Revert "Provide known module source file information"
2 parents 47e333c + 1656eed commit 845b2f9

File tree

14 files changed

+20
-338
lines changed

14 files changed

+20
-338
lines changed

include/swift/IDE/CodeCompletion.h

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,6 @@ class CodeCompletionResult {
686686
private:
687687
CodeCompletionString *CompletionString;
688688
StringRef ModuleName;
689-
StringRef SourceFilePath;
690689
StringRef BriefDocComment;
691690
ArrayRef<StringRef> AssociatedUSRs;
692691
unsigned TypeDistance : 3;
@@ -797,7 +796,7 @@ class CodeCompletionResult {
797796
CodeCompletionFlair Flair, unsigned NumBytesToErase,
798797
CodeCompletionString *CompletionString,
799798
CodeCompletionDeclKind DeclKind, bool IsSystem,
800-
StringRef ModuleName, StringRef SourceFilePath,
799+
StringRef ModuleName,
801800
CodeCompletionResult::NotRecommendedReason NotRecReason,
802801
CodeCompletionDiagnosticSeverity diagSeverity,
803802
StringRef DiagnosticMessage, StringRef BriefDocComment,
@@ -806,10 +805,10 @@ class CodeCompletionResult {
806805
CodeCompletionOperatorKind KnownOperatorKind)
807806
: Kind(ResultKind::Declaration),
808807
KnownOperatorKind(unsigned(KnownOperatorKind)),
809-
SemanticContext(unsigned(SemanticContext)), Flair(unsigned(Flair.toRaw())),
810-
NotRecommended(unsigned(NotRecReason)), IsSystem(IsSystem),
811-
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
812-
ModuleName(ModuleName), SourceFilePath(SourceFilePath),
808+
SemanticContext(unsigned(SemanticContext)),
809+
Flair(unsigned(Flair.toRaw())), NotRecommended(unsigned(NotRecReason)),
810+
IsSystem(IsSystem), NumBytesToErase(NumBytesToErase),
811+
CompletionString(CompletionString), ModuleName(ModuleName),
813812
BriefDocComment(BriefDocComment), AssociatedUSRs(AssociatedUSRs),
814813
TypeDistance(TypeDistance), DiagnosticSeverity(unsigned(diagSeverity)),
815814
DiagnosticMessage(DiagnosticMessage) {
@@ -907,10 +906,6 @@ class CodeCompletionResult {
907906
return AssociatedUSRs;
908907
}
909908

910-
void setSourceFilePath(StringRef value) {
911-
SourceFilePath = value;
912-
}
913-
914909
void setDiagnostics(CodeCompletionDiagnosticSeverity severity, StringRef message) {
915910
DiagnosticSeverity = static_cast<unsigned>(severity);
916911
DiagnosticMessage = message;
@@ -924,12 +919,6 @@ class CodeCompletionResult {
924919
return DiagnosticMessage;
925920
}
926921

927-
/// Returns the source file path where the associated decl was declared.
928-
/// Returns an empty string if the information is not available.
929-
StringRef getSourceFilePath() const {
930-
return SourceFilePath;
931-
}
932-
933922
/// Print a debug representation of the code completion result to \p OS.
934923
void printPrefix(raw_ostream &OS) const;
935924
SWIFT_DEBUG_DUMP;
@@ -942,15 +931,6 @@ class CodeCompletionResult {
942931
static bool getDeclIsSystem(const Decl *D);
943932
};
944933

945-
/// A pair of a file path and its up-to-date-ness.
946-
struct SourceFileAndUpToDate {
947-
StringRef FilePath;
948-
bool IsUpToDate;
949-
950-
SourceFileAndUpToDate(StringRef FilePath, bool IsUpToDate)
951-
: FilePath(FilePath), IsUpToDate(IsUpToDate) {}
952-
};
953-
954934
struct CodeCompletionResultSink {
955935
using AllocatorPtr = std::shared_ptr<llvm::BumpPtrAllocator>;
956936

@@ -963,13 +943,11 @@ struct CodeCompletionResultSink {
963943

964944
/// Whether to annotate the results with XML.
965945
bool annotateResult = false;
966-
bool requiresSourceFileInfo = false;
967946

968947
/// Whether to emit object literals if desired.
969948
bool includeObjectLiterals = true;
970949

971950
std::vector<CodeCompletionResult *> Results;
972-
std::vector<SourceFileAndUpToDate> SourceFiles;
973951

974952
/// A single-element cache for module names stored in Allocator, keyed by a
975953
/// clang::Module * or swift::ModuleDecl *.
@@ -1040,9 +1018,6 @@ class CodeCompletionContext {
10401018
void setAnnotateResult(bool flag) { CurrentResults.annotateResult = flag; }
10411019
bool getAnnotateResult() const { return CurrentResults.annotateResult; }
10421020

1043-
void setRequiresSourceFileInfo(bool flag) { CurrentResults.requiresSourceFileInfo = flag; }
1044-
bool requiresSourceFileInfo() const { return CurrentResults.requiresSourceFileInfo; }
1045-
10461021
void setIncludeObjectLiterals(bool flag) {
10471022
CurrentResults.includeObjectLiterals = flag;
10481023
}
@@ -1098,7 +1073,6 @@ class PrintingCodeCompletionConsumer
10981073
bool IncludeComments;
10991074
bool IncludeSourceText;
11001075
bool PrintAnnotatedDescription;
1101-
bool RequiresSourceFileInfo = false;
11021076

11031077
public:
11041078
PrintingCodeCompletionConsumer(llvm::raw_ostream &OS,

include/swift/IDE/ModuleSourceFileInfo.h

Lines changed: 0 additions & 39 deletions
This file was deleted.

lib/IDE/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ add_swift_host_library(swiftIDE STATIC
1212
FuzzyStringMatcher.cpp
1313
Refactoring.cpp
1414
ModuleInterfacePrinting.cpp
15-
ModuleSourceFileInfo.cpp
1615
REPLCodeCompletion.cpp
1716
SwiftSourceDocInfo.cpp
1817
SyntaxModel.cpp

lib/IDE/CodeCompletion.cpp

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "swift/Frontend/FrontendOptions.h"
3535
#include "swift/IDE/CodeCompletionCache.h"
3636
#include "swift/IDE/CodeCompletionResultPrinter.h"
37-
#include "swift/IDE/ModuleSourceFileInfo.h"
3837
#include "swift/IDE/Utils.h"
3938
#include "swift/Parse/CodeCompletionCallbacks.h"
4039
#include "swift/Sema/IDETypeChecking.h"
@@ -636,9 +635,9 @@ CodeCompletionResult::withFlair(CodeCompletionFlair newFlair,
636635
return new (*Sink.Allocator) CodeCompletionResult(
637636
getSemanticContext(), newFlair, getNumBytesToErase(),
638637
getCompletionString(), getAssociatedDeclKind(), isSystem(),
639-
getModuleName(), getSourceFilePath(), getNotRecommendedReason(),
640-
getDiagnosticSeverity(), getDiagnosticMessage(),
641-
getBriefDocComment(), getAssociatedUSRs(), getExpectedTypeRelation(),
638+
getModuleName(), getNotRecommendedReason(), getDiagnosticSeverity(),
639+
getDiagnosticMessage(), getBriefDocComment(), getAssociatedUSRs(),
640+
getExpectedTypeRelation(),
642641
isOperator() ? getOperatorKind() : CodeCompletionOperatorKind::None);
643642
} else {
644643
return new (*Sink.Allocator) CodeCompletionResult(
@@ -1303,8 +1302,6 @@ CodeCompletionResult *CodeCompletionResultBuilder::takeResult() {
13031302
ModuleName, NotRecReason, copyString(*Sink.Allocator, BriefDocComment),
13041303
copyAssociatedUSRs(*Sink.Allocator, AssociatedDecl),
13051304
ExpectedTypeRelation);
1306-
if (!result->isSystem())
1307-
result->setSourceFilePath(getSourceFilePathForDecl(AssociatedDecl));
13081305
if (NotRecReason != NotRecommendedReason::None) {
13091306
// FIXME: We should generate the message lazily.
13101307
if (const auto *VD = dyn_cast<ValueDecl>(AssociatedDecl)) {
@@ -6575,37 +6572,6 @@ static void postProcessResults(MutableArrayRef<CodeCompletionResult *> results,
65756572
}
65766573
}
65776574

6578-
static void copyAllKnownSourceFileInfo(
6579-
ASTContext &Ctx, CodeCompletionResultSink &Sink) {
6580-
assert(Sink.SourceFiles.empty());
6581-
6582-
SmallVector<ModuleDecl *, 8> loadedModules;
6583-
loadedModules.reserve(Ctx.getNumLoadedModules());
6584-
for (auto &entry : Ctx.getLoadedModules())
6585-
loadedModules.push_back(entry.second);
6586-
6587-
auto &result = Sink.SourceFiles;
6588-
for (auto *M : loadedModules) {
6589-
// We don't need to check system modules.
6590-
if (M->isSystemModule())
6591-
continue;
6592-
6593-
M->collectBasicSourceFileInfo([&](const BasicSourceFileInfo &info) {
6594-
if (info.getFilePath().empty())
6595-
return;
6596-
6597-
bool isUpToDate = false;
6598-
if (info.isFromSourceFile()) {
6599-
// 'SourceFile' is always "up-to-date" because we've just loaded.
6600-
isUpToDate = true;
6601-
} else {
6602-
isUpToDate = isSourceFileUpToDate(info, Ctx);
6603-
}
6604-
result.emplace_back(copyString(*Sink.Allocator, info.getFilePath()), isUpToDate);
6605-
});
6606-
}
6607-
}
6608-
66096575
static void deliverCompletionResults(CodeCompletionContext &CompletionContext,
66106576
CompletionLookup &Lookup,
66116577
DeclContext *DC,
@@ -6725,10 +6691,6 @@ static void deliverCompletionResults(CodeCompletionContext &CompletionContext,
67256691
CompletionContext.CodeCompletionKind, DC,
67266692
/*Sink=*/nullptr);
67276693

6728-
if (CompletionContext.requiresSourceFileInfo())
6729-
copyAllKnownSourceFileInfo(SF.getASTContext(),
6730-
CompletionContext.getResultSink());
6731-
67326694
Consumer.handleResultsAndModules(CompletionContext, RequestedModules, DC);
67336695
}
67346696

@@ -7447,16 +7409,6 @@ void CodeCompletionCallbacksImpl::doneParsing() {
74477409

74487410
void PrintingCodeCompletionConsumer::handleResults(
74497411
CodeCompletionContext &context) {
7450-
if (context.requiresSourceFileInfo() &&
7451-
!context.getResultSink().SourceFiles.empty()) {
7452-
OS << "Known module source files\n";
7453-
for (auto &entry : context.getResultSink().SourceFiles) {
7454-
OS << (entry.IsUpToDate ? " + " : " - ");
7455-
OS << entry.FilePath;
7456-
OS << "\n";
7457-
}
7458-
this->RequiresSourceFileInfo = true;
7459-
}
74607412
auto results = context.takeResults();
74617413
handleResults(results);
74627414
}
@@ -7503,13 +7455,6 @@ void PrintingCodeCompletionConsumer::handleResults(
75037455
OS << "; comment=" << comment;
75047456
}
75057457

7506-
if (RequiresSourceFileInfo) {
7507-
StringRef sourceFilePath = Result->getSourceFilePath();
7508-
if (!sourceFilePath.empty()) {
7509-
OS << "; source=" << sourceFilePath;
7510-
}
7511-
}
7512-
75137458
if (Result->getDiagnosticSeverity() !=
75147459
CodeCompletionDiagnosticSeverity::None) {
75157460
OS << "; diagnostics=" << comment;

lib/IDE/CodeCompletionCache.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = 2;
105+
static constexpr uint32_t onDiskCompletionCacheVersion = 3; // Removed "source file path".
106106

107107
/// Deserializes CodeCompletionResults from \p in and stores them in \p V.
108108
/// \see writeCacheModule.
@@ -209,7 +209,6 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
209209
auto numBytesToErase = static_cast<unsigned>(*cursor++);
210210
auto chunkIndex = read32le(cursor);
211211
auto moduleIndex = read32le(cursor);
212-
auto sourceFilePathIndex = read32le(cursor);
213212
auto briefDocIndex = read32le(cursor);
214213
auto diagMessageIndex = read32le(cursor);
215214

@@ -221,15 +220,14 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
221220

222221
CodeCompletionString *string = getCompletionString(chunkIndex);
223222
auto moduleName = getString(moduleIndex);
224-
auto sourceFilePath = getString(sourceFilePathIndex);
225223
auto briefDocComment = getString(briefDocIndex);
226224
auto diagMessage = getString(diagMessageIndex);
227225

228226
CodeCompletionResult *result = nullptr;
229227
if (kind == CodeCompletionResult::Declaration) {
230228
result = new (*V.Sink.Allocator) CodeCompletionResult(
231229
context, CodeCompletionFlair(), numBytesToErase, string,
232-
declKind, isSystem, moduleName, sourceFilePath, notRecommended,
230+
declKind, isSystem, moduleName, notRecommended,
233231
diagSeverity, diagMessage, briefDocComment,
234232
copyArray(*V.Sink.Allocator, ArrayRef<StringRef>(assocUSRs)),
235233
CodeCompletionResult::Unknown, opKind);
@@ -369,7 +367,6 @@ static void writeCachedModule(llvm::raw_ostream &out,
369367
LE.write(
370368
static_cast<uint32_t>(addCompletionString(R->getCompletionString())));
371369
LE.write(addString(R->getModuleName())); // index into strings
372-
LE.write(addString(R->getSourceFilePath())); // index into strings
373370
LE.write(addString(R->getBriefDocComment())); // index into strings
374371
LE.write(addString(R->getDiagnosticMessage())); // index into strings
375372

lib/IDE/CompletionInstance.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,10 @@ bool swift::ide::CompletionInstance::performOperation(
613613
std::string &Error, DiagnosticConsumer *DiagC,
614614
llvm::function_ref<void(CompilerInstance &, bool)> Callback) {
615615

616+
// Always disable source location resolutions from .swiftsourceinfo file
617+
// because they're somewhat heavy operations and aren't needed for completion.
618+
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo = true;
619+
616620
// Disable to build syntax tree because code-completion skips some portion of
617621
// source text. That breaks an invariant of syntax tree building.
618622
Invocation.getLangOptions().BuildSyntaxTree = false;

0 commit comments

Comments
 (0)