Skip to content

Commit 23ab43c

Browse files
committed
[sourcekitd] Change compile notifications to pass a single args string
... instead of an array of compiler arguments. This is good enough for seeing what's going on, and it saves significant time for long argument strings, because it doesn't create and destroy so many xpc strings, and more of the string copying that happens is on a large contiguous string instead of many small strings. rdar://39538847
1 parent 1d66f0a commit 23ab43c

File tree

7 files changed

+30
-14
lines changed

7 files changed

+30
-14
lines changed

test/SourceKit/CompileNotifications/args.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
// ARGS1: {
33
// ARGS1: key.notification: source.notification.compile-will-start
44
// ARGS1: key.filepath: "[[PATH:.*]]"
5-
// ARGS1: key.compilerargs: [
6-
// ARGS1-NEXT: [[PATH]]
7-
// ARGS1-NEXT: ]
5+
// ARGS1: key.compilerargs-string: "
6+
// ARGS1-LINE: [[PATH]]
87

98
// RUN: %sourcekitd-test -req=track-compiles == -req=sema %s -- %s -j 1000 | %FileCheck %s -check-prefix=ARGS2
109
// ARGS2: {
1110
// ARGS2: key.notification: source.notification.compile-will-start
1211
// ARGS2: key.filepath: "[[PATH:.*]]"
13-
// ARGS2: key.compilerargs: [
14-
// ARGS2-NEXT: [[PATH]]
15-
// ARGS2-NEXT: "-j"
16-
// ARGS2-NEXT: "1000"
17-
// ARGS2-NEXT: ]
12+
// ARGS2: key.compilerargs-string: "
13+
// ARGS2-LINE: [[PATH]]
14+
// ARGS2-LINE: -j
15+
// ARGS2-LINE: 1000

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace trace {
2828

2929
struct SwiftArguments {
3030
std::string PrimaryFile;
31-
std::vector<std::string> Args;
31+
std::string Arguments;
3232
};
3333

3434
enum class OperationKind : uint64_t {

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,8 +795,8 @@ ASTUnitRef ASTProducer::createASTUnit(SwiftASTManager::Implementation &MgrImpl,
795795
trace::TracedOperation TracedOp(trace::OperationKind::PerformSema);
796796
trace::SwiftInvocation TraceInfo;
797797
if (TracedOp.enabled()) {
798-
TraceInfo.Args.PrimaryFile = InvokRef->Impl.Opts.PrimaryFile;
799-
TraceInfo.Args.Args = InvokRef->Impl.Opts.Args;
798+
trace::initTraceInfo(TraceInfo, InvokRef->Impl.Opts.PrimaryFile,
799+
InvokRef->Impl.Opts.Args);
800800
}
801801

802802
ASTUnitRef ASTRef = new ASTUnit(++ASTUnitGeneration, MgrImpl.Stats);

tools/SourceKit/lib/SwiftLang/SwiftIndexing.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,25 @@ static void indexModule(llvm::MemoryBuffer *Input,
198198
// IndexSource
199199
//===----------------------------------------------------------------------===//
200200

201+
template <typename Str>
202+
static void initTraceInfoImpl(trace::SwiftInvocation &SwiftArgs,
203+
StringRef InputFile,
204+
ArrayRef<Str> Args) {
205+
llvm::raw_string_ostream OS(SwiftArgs.Args.Arguments);
206+
interleave(Args, [&OS](StringRef arg) { OS << arg; }, [&OS] { OS << ' '; });
207+
SwiftArgs.Args.PrimaryFile = InputFile;
208+
}
209+
201210
void trace::initTraceInfo(trace::SwiftInvocation &SwiftArgs,
202211
StringRef InputFile,
203212
ArrayRef<const char *> Args) {
204-
SwiftArgs.Args.Args.assign(Args.begin(), Args.end());
205-
SwiftArgs.Args.PrimaryFile = InputFile;
213+
initTraceInfoImpl(SwiftArgs, InputFile, Args);
214+
}
215+
216+
void trace::initTraceInfo(trace::SwiftInvocation &SwiftArgs,
217+
StringRef InputFile,
218+
ArrayRef<std::string> Args) {
219+
initTraceInfoImpl(SwiftArgs, InputFile, Args);
206220
}
207221

208222
void SwiftLangSupport::indexSource(StringRef InputFile,

tools/SourceKit/lib/SwiftLang/SwiftLangSupport.h

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

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

tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2711,7 +2711,7 @@ void CompileTrackingConsumer::operationStarted(
27112711
Dict.set(KeyCompileID, std::to_string(OpId));
27122712
Dict.set(KeyFilePath, Inv.Args.PrimaryFile);
27132713
// FIXME: OperationKind
2714-
Dict.set(KeyCompilerArgs, Inv.Args.Args);
2714+
Dict.set(KeyCompilerArgsString, Inv.Args.Arguments);
27152715
sourcekitd::postNotification(RespBuilder.createResponse());
27162716
}
27172717

utils/gyb_sourcekit_support/UIDs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def __init__(self, internal_name, external_name):
154154
KEY('ActionUID', 'key.actionuid'),
155155
KEY('ActionUnavailableReason', 'key.actionunavailablereason'),
156156
KEY('CompileID', 'key.compileid'),
157+
KEY('CompilerArgsString', 'key.compilerargs-string'),
157158
]
158159

159160

0 commit comments

Comments
 (0)