Skip to content

Commit 01d02b2

Browse files
authored
---
yaml --- r: 341727 b: refs/heads/rxwei-patch-1 c: 675141b h: refs/heads/master i: 341725: 25e5ad8 341723: c61910d 341719: 5d98fd0 341711: 5be83fe 341695: 2266551
1 parent 1ff2977 commit 01d02b2

28 files changed

+388
-123
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: 5022d8be5dc0527429785c6d6543bd6555550d1c
1018+
refs/heads/rxwei-patch-1: 675141b5530c339f66f2ac7a6196047e23c24a39
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/include/swift/Basic/SourceManager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,14 @@ class SourceManager {
231231
void verifyAllBuffers() const;
232232

233233
/// Translate line and column pair to the offset.
234+
/// If the column number is the maximum unsinged int, return the offset of the end of the line.
234235
llvm::Optional<unsigned> resolveFromLineCol(unsigned BufferId, unsigned Line,
235236
unsigned Col) const;
236237

238+
/// Translate the end position of the given line to the offset.
239+
llvm::Optional<unsigned> resolveOffsetForEndOfLine(unsigned BufferId,
240+
unsigned Line) const;
241+
237242
SourceLoc getLocForLineCol(unsigned BufferId, unsigned Line, unsigned Col) const {
238243
auto Offset = resolveFromLineCol(BufferId, Line, Col);
239244
return Offset.hasValue() ? getLocForOffset(BufferId, Offset.getValue()) :

branches/rxwei-patch-1/include/swift/Driver/Action.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ class Action {
5252
GenerateDSYMJob,
5353
VerifyDebugInfoJob,
5454
GeneratePCHJob,
55+
LoadModuleJob,
5556

5657
JobFirst = CompileJob,
57-
JobLast = GeneratePCHJob
58+
JobLast = LoadModuleJob
5859
};
5960

6061
static const char *getClassName(Kind AC);
@@ -338,6 +339,24 @@ class StaticLinkJobAction : public JobAction {
338339
}
339340
};
340341

342+
/// An action that will attempt to load a specific module before any other
343+
/// actions.
344+
class LoadModuleJobAction : public JobAction {
345+
virtual void anchor();
346+
std::string moduleName;
347+
348+
public:
349+
LoadModuleJobAction(StringRef moduleName)
350+
: JobAction(Action::Kind::LoadModuleJob, {}, file_types::TY_Nothing),
351+
moduleName(moduleName) {}
352+
353+
StringRef getModuleName() const { return moduleName; }
354+
355+
static bool classof(const Action *A) {
356+
return A->getKind() == Action::Kind::LoadModuleJob;
357+
}
358+
};
359+
341360
} // end namespace driver
342361
} // end namespace swift
343362

branches/rxwei-patch-1/include/swift/Driver/ToolChain.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ class ToolChain {
164164
virtual InvocationInfo constructInvocation(const StaticLinkJobAction &job,
165165
const JobContext &context) const;
166166

167+
virtual InvocationInfo constructInvocation(const LoadModuleJobAction &job,
168+
const JobContext &context) const;
169+
167170
/// Searches for the given executable in appropriate paths relative to the
168171
/// Swift binary.
169172
///

branches/rxwei-patch-1/lib/Basic/SourceLoc.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,19 @@ void CharSourceRange::dump(const SourceManager &SM) const {
310310
print(llvm::errs(), SM);
311311
}
312312

313+
llvm::Optional<unsigned>
314+
SourceManager::resolveOffsetForEndOfLine(unsigned BufferId,
315+
unsigned Line) const {
316+
return resolveFromLineCol(BufferId, Line, ~0u);
317+
}
318+
313319
llvm::Optional<unsigned> SourceManager::resolveFromLineCol(unsigned BufferId,
314320
unsigned Line,
315321
unsigned Col) const {
316322
if (Line == 0 || Col == 0) {
317323
return None;
318324
}
325+
const bool LineEnd = Col == ~0u;
319326
auto InputBuf = getLLVMSourceMgr().getMemoryBuffer(BufferId);
320327
const char *Ptr = InputBuf->getBufferStart();
321328
const char *End = InputBuf->getBufferEnd();
@@ -331,14 +338,18 @@ llvm::Optional<unsigned> SourceManager::resolveFromLineCol(unsigned BufferId,
331338
return None;
332339
}
333340
Ptr = LineStart;
334-
335341
// The <= here is to allow for non-inclusive range end positions at EOF
336-
for (; Ptr <= End; ++Ptr) {
342+
for (; ; ++Ptr) {
337343
--Col;
338344
if (Col == 0)
339345
return Ptr - InputBuf->getBufferStart();
340-
if (*Ptr == '\n')
341-
break;
346+
if (*Ptr == '\n' || Ptr == End) {
347+
if (LineEnd) {
348+
return Ptr - InputBuf->getBufferStart();
349+
} else {
350+
break;
351+
}
352+
}
342353
}
343354
return None;
344355
}

branches/rxwei-patch-1/lib/Driver/Action.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const char *Action::getClassName(Kind AC) {
3333
case Kind::GenerateDSYMJob: return "generate-dSYM";
3434
case Kind::VerifyDebugInfoJob: return "verify-debug-info";
3535
case Kind::GeneratePCHJob: return "generate-pch";
36+
case Kind::LoadModuleJob: return "load-module";
3637
}
3738

3839
llvm_unreachable("invalid class");
@@ -65,3 +66,5 @@ void GenerateDSYMJobAction::anchor() {}
6566
void VerifyDebugInfoJobAction::anchor() {}
6667

6768
void GeneratePCHJobAction::anchor() {}
69+
70+
void LoadModuleJobAction::anchor() {}

branches/rxwei-patch-1/lib/Driver/Driver.cpp

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,25 @@ Driver::computeCompilerMode(const DerivedArgList &Args,
17311731
return OutputInfo::Mode::SingleCompile;
17321732
}
17331733

1734+
/// Determines whether the given set of inputs has multiple .swift, .sil, or
1735+
/// .sib inputs, which will require loading the standard library.
1736+
static bool hasMultipleSourceFileInputs(ArrayRef<InputPair> inputs) {
1737+
bool hasFoundOneSourceFileAlready = false;
1738+
for (const InputPair &input : inputs) {
1739+
switch (input.first) {
1740+
case file_types::TY_Swift:
1741+
case file_types::TY_SIL:
1742+
case file_types::TY_SIB:
1743+
if (hasFoundOneSourceFileAlready)
1744+
return true;
1745+
hasFoundOneSourceFileAlready = true;
1746+
break;
1747+
default: break;
1748+
}
1749+
}
1750+
return false;
1751+
}
1752+
17341753
void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
17351754
const ToolChain &TC, const OutputInfo &OI,
17361755
const InputInfoMap *OutOfDateMap,
@@ -1749,6 +1768,18 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
17491768
switch (OI.CompilerMode) {
17501769
case OutputInfo::Mode::StandardCompile: {
17511770

1771+
// If we're not compiling the standard library, and we're going to schedule
1772+
// multiple parallel compile jobs, add an action before any others that
1773+
// will quickly load the standard library module.
1774+
// This will ensure that, if we need to build the standard library from
1775+
// a module interface, it happens once, rather than once per parallel
1776+
// invocation.
1777+
LoadModuleJobAction *preLoadStdlib = nullptr;
1778+
if (!Args.hasArg(options::OPT_parse_stdlib) &&
1779+
hasMultipleSourceFileInputs(Inputs)) {
1780+
preLoadStdlib = C.createAction<LoadModuleJobAction>(STDLIB_NAME);
1781+
}
1782+
17521783
// If the user is importing a textual (.h) bridging header and we're in
17531784
// standard-compile (non-WMO) mode, we take the opportunity to precompile
17541785
// the header into a temporary PCH, and replace the import argument with the
@@ -1772,6 +1803,15 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
17721803
}
17731804
}
17741805

1806+
// Adds the implicit dependencies for this job action, either generating
1807+
// a PCH, or pre-loading the standard library, or both.
1808+
auto addImplicitDeps = [&](Action *action) {
1809+
if (PCH)
1810+
cast<JobAction>(action)->addInput(PCH);
1811+
if (preLoadStdlib)
1812+
cast<JobAction>(action)->addInput(preLoadStdlib);
1813+
};
1814+
17751815
for (const InputPair &Input : Inputs) {
17761816
file_types::ID InputType = Input.first;
17771817
const Arg *InputArg = Input.second;
@@ -1793,17 +1833,15 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
17931833
if (Args.hasArg(options::OPT_embed_bitcode)) {
17941834
Current = C.createAction<CompileJobAction>(
17951835
Current, file_types::TY_LLVM_BC, previousBuildState);
1796-
if (PCH)
1797-
cast<JobAction>(Current)->addInput(PCH);
1836+
addImplicitDeps(Current);
17981837
AllModuleInputs.push_back(Current);
17991838
Current = C.createAction<BackendJobAction>(Current,
18001839
OI.CompilerOutputType, 0);
18011840
} else {
18021841
Current = C.createAction<CompileJobAction>(Current,
18031842
OI.CompilerOutputType,
18041843
previousBuildState);
1805-
if (PCH)
1806-
cast<JobAction>(Current)->addInput(PCH);
1844+
addImplicitDeps(Current);
18071845
AllModuleInputs.push_back(Current);
18081846
}
18091847
AllLinkerInputs.push_back(Current);

branches/rxwei-patch-1/lib/Driver/Job.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,14 @@ void Job::printSummary(raw_ostream &os) const {
383383
if (const auto *IA = dyn_cast<InputAction>(A))
384384
Inputs.push_back(IA->getInputArg().getValue());
385385

386-
for (const Job *J : getInputs())
386+
for (const Job *J : getInputs()) {
387+
// Some jobs might produce no output, so don't include them in the
388+
// list of inputs.
389+
if (J->getOutput().getPrimaryOutputType() == file_types::TY_Nothing)
390+
continue;
387391
for (StringRef f : J->getOutput().getPrimaryOutputFilenames())
388392
Inputs.push_back(f);
393+
}
389394

390395
size_t limit = 3;
391396
size_t actual_in = Inputs.size();

branches/rxwei-patch-1/lib/Driver/ParseableOutput.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,27 @@ class DetailedCommandBasedMessage : public CommandBasedMessage {
146146
});
147147
}
148148

149+
/// Subclasses can override this to determine if they should print empty
150+
/// arrays for `inputs` and `output`, or if they can omit them.
151+
virtual bool requireInputsAndOutputs() {
152+
return false;
153+
}
154+
149155
void provideMapping(swift::json::Output &out) override {
150156
Message::provideMapping(out);
151157
out.mapRequired("command", CommandLine); // Deprecated, do not document
152158
out.mapRequired("command_executable", Executable);
153159
out.mapRequired("command_arguments", Arguments);
154-
out.mapOptional("inputs", Inputs);
155-
out.mapOptional("outputs", Outputs);
160+
161+
// Some commands can choose to print empty arrays if their inputs and
162+
// outputs are empty.
163+
if (requireInputsAndOutputs()) {
164+
out.mapRequired("inputs", Inputs);
165+
out.mapRequired("outputs", Outputs);
166+
} else {
167+
out.mapOptional("inputs", Inputs);
168+
out.mapOptional("outputs", Outputs);
169+
}
156170
}
157171
};
158172

@@ -177,6 +191,12 @@ class BeganMessage : public DetailedCommandBasedMessage {
177191
: DetailedCommandBasedMessage("began", Cmd), Pid(Pid),
178192
ProcInfo(ProcInfo) {}
179193

194+
bool requireInputsAndOutputs() override {
195+
/// `began` messages should always print inputs and outputs, even if they
196+
/// are empty.
197+
return true;
198+
}
199+
180200
void provideMapping(swift::json::Output &out) override {
181201
DetailedCommandBasedMessage::provideMapping(out);
182202
out.mapRequired("pid", Pid);

branches/rxwei-patch-1/lib/Driver/ToolChain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ std::unique_ptr<Job> ToolChain::constructJob(
106106
CASE(GeneratePCHJob)
107107
CASE(AutolinkExtractJob)
108108
CASE(REPLJob)
109+
CASE(LoadModuleJob)
109110
#undef CASE
110111
case Action::Kind::Input:
111112
llvm_unreachable("not a JobAction");

branches/rxwei-patch-1/lib/Driver/ToolChains.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,40 @@ ToolChain::constructInvocation(const StaticLinkJobAction &job,
11131113
llvm_unreachable("archiving not implemented for this toolchain");
11141114
}
11151115

1116+
ToolChain::InvocationInfo
1117+
ToolChain::constructInvocation(const LoadModuleJobAction &job,
1118+
const JobContext &context) const {
1119+
1120+
// Invoke the frontend, passing `-import-module ModuleName` for whatever
1121+
// module the job is supposed to load.
1122+
1123+
InvocationInfo II{SWIFT_EXECUTABLE_NAME};
1124+
ArgStringList &Arguments = II.Arguments;
1125+
II.allowsResponseFiles = true;
1126+
1127+
for (auto &s : getDriver().getSwiftProgramArgs())
1128+
Arguments.push_back(s.c_str());
1129+
1130+
Arguments.push_back("-frontend");
1131+
Arguments.push_back("-typecheck");
1132+
1133+
// Force importing the module that this job specifies.
1134+
1135+
Arguments.push_back("-import-module");
1136+
Arguments.push_back(context.Args.MakeArgString(job.getModuleName()));
1137+
1138+
// Pass along the relevant arguments to the frontend invocation.
1139+
1140+
addCommonFrontendArgs(*this, context.OI, context.Output, context.Args,
1141+
Arguments);
1142+
1143+
// Create an empty temporary file to typecheck.
1144+
auto tempFile = context.getTemporaryFilePath("tmp", "swift");
1145+
Arguments.push_back(context.Args.MakeArgString(tempFile));
1146+
1147+
return II;
1148+
}
1149+
11161150
void ToolChain::addPathEnvironmentVariableIfNeeded(
11171151
Job::EnvironmentVector &env, const char *name, const char *separator,
11181152
options::ID optionID, const ArgList &args,

0 commit comments

Comments
 (0)