Skip to content

Commit 31eae36

Browse files
committed
[sourcekitd] Remove XPCTracing
This code was an experiment in how to collect information after a crash, that did not end up being used. It's unclear how much it has bitrotted at this point, since it has no tests and was not designed with automated testing in mind. Parts of it interfere with some changes I want to make to the underlying tracing mechanism, so I am finally removing it. This also lets us remove the buffer copying in the parts of tracing used by the compile notifications, improving performance. For rdar://39538847
1 parent fc7db4d commit 31eae36

File tree

16 files changed

+6
-888
lines changed

16 files changed

+6
-888
lines changed

tools/SourceKit/include/SourceKit/Support/Tracing.h

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,42 +32,18 @@ struct SwiftArguments {
3232
};
3333

3434
enum class OperationKind : uint64_t {
35-
SimpleParse = 1 << 0,
36-
PerformSema = 1 << 1,
37-
AnnotAndDiag = 1 << 2,
35+
PerformSema = 1 << 0,
36+
IndexSource = 1 << 1,
37+
CodeCompletion = 1 << 2,
3838

39-
ReadSyntaxInfo = 1 << 3,
40-
ReadDiagnostics = 1 << 4,
41-
ReadSemanticInfo = 1 << 5,
42-
43-
IndexModule = 1 << 6,
44-
IndexSource = 1 << 7,
45-
46-
CursorInfoForIFaceGen = 1 << 8,
47-
CursorInfoForSource = 1 << 9,
48-
49-
ExpandPlaceholder = 1 << 10,
50-
FormatText = 1 << 11,
51-
RelatedIdents = 1 << 12,
52-
CodeCompletion = 1 << 13,
53-
OpenInterface = 1 << 14,
54-
OpenHeaderInterface = 1 << 15,
55-
56-
CodeCompletionInit = 1 << 16,
57-
58-
Last = CodeCompletionInit,
39+
Last = CodeCompletion,
5940
All = (Last << 1) - 1
6041
};
6142

6243
typedef std::vector<std::pair<std::string, std::string>> StringPairs;
6344

6445
struct SwiftInvocation {
6546
SwiftArguments Args;
66-
StringPairs Files;
67-
68-
void addFile(std::string FileName, std::string Text) {
69-
Files.push_back(std::make_pair(std::move(FileName), std::move(Text)));
70-
}
7147
};
7248

7349
class TraceConsumer {

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -803,11 +803,6 @@ ASTUnitRef ASTProducer::createASTUnit(SwiftASTManager::Implementation &MgrImpl,
803803
for (auto &Content : Contents) {
804804
if (Content.Snapshot)
805805
ASTRef->Impl.Snapshots.push_back(Content.Snapshot);
806-
807-
if (TracedOp.enabled()) {
808-
TraceInfo.addFile(Content.Buffer->getBufferIdentifier(),
809-
Content.Buffer->getBuffer());
810-
}
811806
}
812807
auto &CompIns = ASTRef->Impl.CompInst;
813808
auto &Consumer = ASTRef->Impl.CollectDiagConsumer;

tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,6 @@ static bool swiftCodeCompleteImpl(SwiftLangSupport &Lang,
112112
ArrayRef<const char *> Args,
113113
std::string &Error) {
114114

115-
trace::TracedOperation TracedInit(trace::OperationKind::CodeCompletionInit);
116-
if (TracedInit.enabled()) {
117-
trace::SwiftInvocation SwiftArgs;
118-
trace::initTraceInfo(SwiftArgs,
119-
UnresolvedInputFile->getBufferIdentifier(),
120-
Args);
121-
SwiftArgs.addFile(UnresolvedInputFile->getBufferIdentifier(),
122-
UnresolvedInputFile->getBuffer());
123-
124-
TracedInit.start(SwiftArgs,
125-
{ std::make_pair("Offset", std::to_string(Offset)),
126-
std::make_pair("InputBufferSize",
127-
std::to_string(UnresolvedInputFile->getBufferSize()))});
128-
}
129-
130115
// Resolve symlinks for the input file; we resolve them for the input files
131116
// in the arguments as well.
132117
// FIXME: We need the Swift equivalent of Clang's FileEntry.
@@ -193,21 +178,9 @@ static bool swiftCodeCompleteImpl(SwiftLangSupport &Lang,
193178
return true;
194179
}
195180

196-
TracedInit.finish();
197-
198181
if (TracedOp.enabled()) {
199182
trace::SwiftInvocation SwiftArgs;
200183
trace::initTraceInfo(SwiftArgs, InputFile->getBufferIdentifier(), Args);
201-
trace::initTraceFiles(SwiftArgs, CI);
202-
203-
// Replace primary file with original content
204-
std::for_each(SwiftArgs.Files.begin(), SwiftArgs.Files.end(),
205-
[&] (trace::StringPairs::value_type &Pair) {
206-
if (Pair.first == InputFile->getBufferIdentifier()) {
207-
Pair.second = InputFile->getBuffer();
208-
}
209-
});
210-
211184
TracedOp.start(SwiftArgs,
212185
{std::make_pair("OriginalOffset", std::to_string(Offset)),
213186
std::make_pair("Offset",

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -681,23 +681,8 @@ class SwiftDocumentSyntaxInfo {
681681
Parser->getDiagnosticEngine().addConsumer(DiagConsumer);
682682
}
683683

684-
void initArgsAndPrimaryFile(trace::SwiftInvocation &Info) {
685-
Info.Args.PrimaryFile = PrimaryFile;
686-
Info.Args.Args = Args;
687-
}
688-
689684
void parse() {
690685
auto &P = Parser->getParser();
691-
692-
trace::TracedOperation TracedOp(trace::OperationKind::SimpleParse);
693-
if (TracedOp.enabled()) {
694-
trace::SwiftInvocation Info;
695-
initArgsAndPrimaryFile(Info);
696-
auto Text = SM.getLLVMSourceMgr().getMemoryBuffer(BufferID)->getBuffer();
697-
Info.Files.push_back(std::make_pair(PrimaryFile, Text));
698-
TracedOp.start(Info);
699-
}
700-
701686
bool Done = false;
702687
while (!Done) {
703688
P.parseTopLevel();
@@ -988,21 +973,10 @@ class AnnotAndDiagASTConsumer : public SwiftASTConsumer {
988973
}
989974
unsigned BufferID = AstUnit->getPrimarySourceFile().getBufferID().getValue();
990975

991-
trace::TracedOperation TracedOp(trace::OperationKind::AnnotAndDiag);
992-
if (TracedOp.enabled()) {
993-
trace::SwiftInvocation SwiftArgs;
994-
SemaInfoRef->getInvocation()->raw(SwiftArgs.Args.Args,
995-
SwiftArgs.Args.PrimaryFile);
996-
trace::initTraceFiles(SwiftArgs, CompIns);
997-
TracedOp.start(SwiftArgs);
998-
}
999-
1000976
SemanticAnnotator Annotator(CompIns.getSourceMgr(), BufferID);
1001977
Annotator.walk(AstUnit->getPrimarySourceFile());
1002978
SemaToks = std::move(Annotator.SemaToks);
1003979

1004-
TracedOp.finish();
1005-
1006980
SemaInfoRef->
1007981
updateSemanticInfo(std::move(SemaToks),
1008982
std::move(Consumer.getDiagnosticsForBuffer(BufferID)),
@@ -1066,23 +1040,8 @@ struct SwiftEditorDocument::Implementation {
10661040
: LangSupport(LangSupport), FilePath(FilePath), FormatOptions(options) {
10671041
SemanticInfo = new SwiftDocumentSemanticInfo(FilePath, LangSupport);
10681042
}
1069-
1070-
void buildSwiftInv(trace::SwiftInvocation &Inv);
10711043
};
10721044

1073-
void SwiftEditorDocument::Implementation::buildSwiftInv(
1074-
trace::SwiftInvocation &Inv) {
1075-
if (SemanticInfo->getInvocation()) {
1076-
std::string PrimaryFile; // Ignored, FilePath will be used
1077-
SemanticInfo->getInvocation()->raw(Inv.Args.Args, PrimaryFile);
1078-
}
1079-
Inv.Args.PrimaryFile = FilePath;
1080-
auto &SM = SyntaxInfo->getSourceManager();
1081-
auto ID = SyntaxInfo->getBufferID();
1082-
auto Text = SM.getLLVMSourceMgr().getMemoryBuffer(ID)->getBuffer();
1083-
Inv.Files.push_back(std::make_pair(FilePath, Text));
1084-
}
1085-
10861045
namespace {
10871046

10881047
static UIdent getAccessLevelUID(AccessLevel Access) {
@@ -1816,13 +1775,6 @@ void SwiftEditorDocument::parse(ImmutableTextSnapshotRef Snapshot,
18161775
void SwiftEditorDocument::readSyntaxInfo(EditorConsumer &Consumer) {
18171776
llvm::sys::ScopedLock L(Impl.AccessMtx);
18181777

1819-
trace::TracedOperation TracedOp(trace::OperationKind::ReadSyntaxInfo);
1820-
if (TracedOp.enabled()) {
1821-
trace::SwiftInvocation Info;
1822-
Impl.buildSwiftInv(Info);
1823-
TracedOp.start(Info);
1824-
}
1825-
18261778
Impl.ParserDiagnostics = Impl.SyntaxInfo->getDiagnostics();
18271779

18281780
ide::SyntaxModelContext ModelContext(Impl.SyntaxInfo->getSourceFile());
@@ -1868,13 +1820,6 @@ void SwiftEditorDocument::readSyntaxInfo(EditorConsumer &Consumer) {
18681820

18691821
void SwiftEditorDocument::readSemanticInfo(ImmutableTextSnapshotRef Snapshot,
18701822
EditorConsumer& Consumer) {
1871-
trace::TracedOperation TracedOp(trace::OperationKind::ReadSemanticInfo);
1872-
if (TracedOp.enabled()) {
1873-
trace::SwiftInvocation Info;
1874-
Impl.buildSwiftInv(Info);
1875-
TracedOp.start(Info);
1876-
}
1877-
18781823
std::vector<SwiftSemanticToken> SemaToks;
18791824
Optional<std::vector<DiagnosticEntryInfo>> SemaDiags;
18801825
Impl.SemanticInfo->readSemanticInfo(Snapshot, SemaToks, SemaDiags,
@@ -1929,26 +1874,6 @@ void SwiftEditorDocument::formatText(unsigned Line, unsigned Length,
19291874
auto SyntaxInfo = Impl.getSyntaxInfo();
19301875
SourceFile &SF = SyntaxInfo->getSourceFile();
19311876
SourceManager &SM = SyntaxInfo->getSourceManager();
1932-
unsigned BufID = SyntaxInfo->getBufferID();
1933-
1934-
trace::TracedOperation TracedOp(trace::OperationKind::FormatText);
1935-
if (TracedOp.enabled()) {
1936-
trace::SwiftInvocation SwiftArgs;
1937-
// Compiler arguments do not matter
1938-
auto Buf = SM.getLLVMSourceMgr().getMemoryBuffer(BufID);
1939-
SwiftArgs.Args.PrimaryFile = Buf->getBufferIdentifier();
1940-
SwiftArgs.addFile(SwiftArgs.Args.PrimaryFile, Buf->getBuffer());
1941-
trace::StringPairs OpArgs = {
1942-
std::make_pair("Line", std::to_string(Line)),
1943-
std::make_pair("Length", std::to_string(Length)),
1944-
std::make_pair("IndentWidth",
1945-
std::to_string(Impl.FormatOptions.IndentWidth)),
1946-
std::make_pair("TabWidth",
1947-
std::to_string(Impl.FormatOptions.TabWidth)),
1948-
std::make_pair("UseTabs",
1949-
std::to_string(Impl.FormatOptions.UseTabs))};
1950-
TracedOp.start(SwiftArgs, OpArgs);
1951-
}
19521877

19531878
LineRange inputRange = LineRange(Line, Length);
19541879
CodeFormatOptions Options = getFormatOptions();
@@ -1981,18 +1906,6 @@ void SwiftEditorDocument::expandPlaceholder(unsigned Offset, unsigned Length,
19811906
return;
19821907
}
19831908

1984-
trace::TracedOperation TracedOp(trace::OperationKind::ExpandPlaceholder);
1985-
if (TracedOp.enabled()) {
1986-
trace::SwiftInvocation SwiftArgs;
1987-
SyntaxInfo->initArgsAndPrimaryFile(SwiftArgs);
1988-
auto Buf = SM.getLLVMSourceMgr().getMemoryBuffer(BufID);
1989-
SwiftArgs.addFile(Buf->getBufferIdentifier(), Buf->getBuffer());
1990-
trace::StringPairs OpArgs = {
1991-
std::make_pair("Offset", std::to_string(Offset)),
1992-
std::make_pair("Length", std::to_string(Length))};
1993-
TracedOp.start(SwiftArgs, OpArgs);
1994-
}
1995-
19961909
PlaceholderExpansionScanner Scanner(SM);
19971910
SourceFile &SF = SyntaxInfo->getSourceFile();
19981911

tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -707,17 +707,6 @@ void SwiftLangSupport::editorOpenInterface(EditorConsumer &Consumer,
707707
return;
708708
}
709709

710-
trace::TracedOperation TracedOp(trace::OperationKind::OpenInterface);
711-
if (TracedOp.enabled()) {
712-
trace::SwiftInvocation SwiftArgs;
713-
SwiftArgs.Args.Args.assign(Args.begin(), Args.end());
714-
// NOTE: do not use primary file
715-
// NOTE: do not use files
716-
TracedOp.start(SwiftArgs,
717-
{std::make_pair("Name", Name),
718-
std::make_pair("ModuleName", ModuleName)});
719-
}
720-
721710
Invocation.getClangImporterOptions().ImportForwardDeclarations = true;
722711

723712
std::string ErrMsg;
@@ -783,16 +772,6 @@ void SwiftLangSupport::editorOpenSwiftSourceInterface(StringRef Name,
783772
Consumer->handleRequestError(Error.c_str());
784773
return;
785774
}
786-
trace::TracedOperation TracedOp(trace::OperationKind::OpenInterface);
787-
if (TracedOp.enabled()) {
788-
trace::SwiftInvocation SwiftArgs;
789-
SwiftArgs.Args.Args.assign(Args.begin(), Args.end());
790-
// NOTE: do not use primary file
791-
// NOTE: do not use files
792-
TracedOp.start(SwiftArgs,
793-
{std::make_pair("Name", Name),
794-
std::make_pair("SourceName", SourceName)});
795-
}
796775
auto AstConsumer = std::make_shared<PrimaryFileInterfaceConsumer>(Name,
797776
SourceName, IFaceGenContexts, Consumer, Invocation);
798777
static const char OncePerASTToken = 0;
@@ -826,17 +805,6 @@ void SwiftLangSupport::editorOpenHeaderInterface(EditorConsumer &Consumer,
826805
return;
827806
}
828807

829-
trace::TracedOperation TracedOp(trace::OperationKind::OpenHeaderInterface);
830-
if (TracedOp.enabled()) {
831-
trace::SwiftInvocation SwiftArgs;
832-
SwiftArgs.Args.Args.assign(Args.begin(), Args.end());
833-
// NOTE: do not use primary file
834-
// NOTE: do not use files
835-
TracedOp.start(SwiftArgs,
836-
{std::make_pair("Name", Name),
837-
std::make_pair("HeaderName", HeaderName)});
838-
}
839-
840808
Invocation.getClangImporterOptions().ImportForwardDeclarations = true;
841809
if (!swiftVersion.empty()) {
842810
auto swiftVer = version::Version::parseVersionString(swiftVersion,

tools/SourceKit/lib/SwiftLang/SwiftIndexing.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,6 @@ static void indexModule(llvm::MemoryBuffer *Input,
158158
IndexingConsumer &IdxConsumer,
159159
CompilerInstance &CI,
160160
ArrayRef<const char *> Args) {
161-
trace::TracedOperation TracedOp(trace::OperationKind::IndexModule);
162-
if (TracedOp.enabled()) {
163-
trace::SwiftInvocation SwiftArgs;
164-
SwiftArgs.Args.Args.assign(Args.begin(), Args.end());
165-
SwiftArgs.Args.PrimaryFile = Input->getBufferIdentifier();
166-
SwiftArgs.addFile(Input->getBufferIdentifier(), Input->getBuffer());
167-
trace::StringPairs OpArgs;
168-
OpArgs.push_back(std::make_pair("ModuleName", ModuleName));
169-
OpArgs.push_back(std::make_pair("Hash", Hash));
170-
TracedOp.start(SwiftArgs, OpArgs);
171-
}
172-
173161
ASTContext &Ctx = CI.getASTContext();
174162
std::unique_ptr<SerializedModuleLoader> Loader;
175163
ModuleDecl *Mod = nullptr;
@@ -217,18 +205,6 @@ void trace::initTraceInfo(trace::SwiftInvocation &SwiftArgs,
217205
SwiftArgs.Args.PrimaryFile = InputFile;
218206
}
219207

220-
void trace::initTraceFiles(trace::SwiftInvocation &SwiftArgs,
221-
swift::CompilerInstance &CI) {
222-
auto &SM = CI.getSourceMgr();
223-
auto Ids = CI.getInputBufferIDs();
224-
std::for_each(Ids.begin(), Ids.end(),
225-
[&] (unsigned Id) {
226-
auto Buf = SM.getLLVMSourceMgr().getMemoryBuffer(Id);
227-
SwiftArgs.addFile(Buf->getBufferIdentifier(),
228-
Buf->getBuffer());
229-
});
230-
}
231-
232208
void SwiftLangSupport::indexSource(StringRef InputFile,
233209
IndexingConsumer &IdxConsumer,
234210
ArrayRef<const char *> OrigArgs,
@@ -296,7 +272,6 @@ void SwiftLangSupport::indexSource(StringRef InputFile,
296272
if (TracedOp.enabled()) {
297273
trace::SwiftInvocation SwiftArgs;
298274
trace::initTraceInfo(SwiftArgs, InputFile, Args);
299-
trace::initTraceFiles(SwiftArgs, CI);
300275
TracedOp.start(SwiftArgs);
301276
}
302277

tools/SourceKit/lib/SwiftLang/SwiftLangSupport.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,6 @@ namespace trace {
516516
void initTraceInfo(trace::SwiftInvocation &SwiftArgs,
517517
StringRef InputFile,
518518
ArrayRef<const char *> Args);
519-
520-
void initTraceFiles(trace::SwiftInvocation &SwiftArgs,
521-
swift::CompilerInstance &CI);
522519
}
523520

524521
/// When we cannot build any more clang modules, close the .pcm / files to

0 commit comments

Comments
 (0)