Skip to content

Commit a5b2615

Browse files
committed
---
yaml --- r: 341743 b: refs/heads/rxwei-patch-1 c: 2c5d880 h: refs/heads/master i: 341741: 2dc4870 341739: 899f26d 341735: 5ba6c91 341727: 01d02b2
1 parent ecdb3bb commit a5b2615

38 files changed

+338
-156
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: a030e6190ab98b4076474353407a0ed01d4e884b
1018+
refs/heads/rxwei-patch-1: 2c5d8804925a94f2ae064f8a0d87b66dc9aab865
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/AST/SimpleRequest.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ namespace detail {
113113

114114
/// Extract the first, nearest source location from a tuple.
115115
template<unsigned Index, typename ...Types,
116-
typename = typename std::enable_if<sizeof...(Types) - Index
117-
? true
118-
: false>::type>
116+
typename = typename std::enable_if<(Index < sizeof...(Types))>::type>
119117
SourceLoc extractNearestSourceLocTuple(const std::tuple<Types...> &value) {
120118
SourceLoc loc = maybeExtractNearestSourceLoc(std::get<Index>(value));
121119
if (loc.isValid())

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/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,

branches/rxwei-patch-1/lib/Frontend/ParseableInterfaceModuleLoader.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ class swift::ParseableInterfaceBuilder {
504504
// Note that we don't assume cachePath is the same as the Clang
505505
// module cache path at this point.
506506
if (!moduleCachePath.empty())
507-
(void)llvm::sys::fs::create_directories(moduleCachePath);
507+
(void)llvm::sys::fs::create_directory(moduleCachePath);
508508

509509
configureSubInvocationInputsAndOutputs(OutPath);
510510

@@ -1267,10 +1267,6 @@ class ParseableInterfaceModuleLoaderImpl {
12671267
depsAdjustedToMTime.push_back(adjustedDep);
12681268
}
12691269

1270-
// Create the module cache if we haven't created it yet.
1271-
StringRef parentDir = path::parent_path(outputPath);
1272-
(void)llvm::sys::fs::create_directories(parentDir);
1273-
12741270
auto hadError = withOutputFile(diags, outputPath,
12751271
[&](llvm::raw_pwrite_stream &out) {
12761272
llvm::yaml::Output yamlWriter(out);

branches/rxwei-patch-1/lib/SIL/DynamicCasts.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,10 @@ CanType swift::getNSBridgedClassOfCFClass(ModuleDecl *M, CanType type) {
292292

293293
static bool isCFBridgingConversion(ModuleDecl *M, SILType sourceType,
294294
SILType targetType) {
295-
if (auto bridgedTarget =
296-
getNSBridgedClassOfCFClass(M, targetType.getASTType())) {
297-
return bridgedTarget->isExactSuperclassOf(sourceType.getASTType());
298-
}
299-
if (auto bridgedSource =
300-
getNSBridgedClassOfCFClass(M, sourceType.getASTType())) {
301-
return targetType.getASTType()->isExactSuperclassOf(bridgedSource);
302-
}
303-
304-
return false;
295+
return (sourceType.getASTType() ==
296+
getNSBridgedClassOfCFClass(M, targetType.getASTType()) ||
297+
targetType.getASTType() ==
298+
getNSBridgedClassOfCFClass(M, sourceType.getASTType()));
305299
}
306300

307301
/// Try to classify the dynamic-cast relationship between two types.
@@ -874,7 +868,7 @@ namespace {
874868
value = getOwnedScalar(source, srcTL);
875869
}
876870
auto targetTy = target.LoweredType;
877-
if (isCFBridgingConversion(SwiftModule, value->getType(), targetTy)) {
871+
if (isCFBridgingConversion(SwiftModule, targetTy, value->getType())) {
878872
value = B.createUncheckedRefCast(Loc, value, targetTy.getObjectType());
879873
} else {
880874
value = B.createUpcast(Loc, value, targetTy.getObjectType());

branches/rxwei-patch-1/stdlib/public/SwiftShims/RefCount.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,6 @@ _Static_assert(_Alignof(InlineRefCounts) == _Alignof(__swift_uintptr_t),
14961496
#endif
14971497

14981498
#if defined(_WIN32) && defined(_M_ARM64)
1499-
#if defined(__cplusplus)
15001499
namespace std {
15011500
template <>
15021501
inline void _Atomic_storage<swift::SideTableRefCountBits, 16>::_Unlock() const noexcept {
@@ -1506,6 +1505,5 @@ inline void _Atomic_storage<swift::SideTableRefCountBits, 16>::_Unlock() const n
15061505
}
15071506
}
15081507
#endif
1509-
#endif
15101508

15111509
#endif

branches/rxwei-patch-1/stdlib/public/core/Assert.swift

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public func _overflowChecked<T>(
236236
let (result, error) = args
237237
if _isDebugAssertConfiguration() {
238238
if _slowPath(error) {
239-
_fatalErrorMessage("Fatal error", "Overflow/underflow",
239+
_fatalErrorMessage("Fatal error", "Overflow/underflow",
240240
file: file, line: line, flags: _fatalErrorFlags())
241241
}
242242
} else {
@@ -297,22 +297,6 @@ internal func _internalInvariant(
297297
#endif
298298
}
299299

300-
// Only perform the invariant check on Swift 5.1 and later
301-
@_alwaysEmitIntoClient // Swift 5.1
302-
@_transparent
303-
internal func _internalInvariant_5_1(
304-
_ condition: @autoclosure () -> Bool, _ message: StaticString = StaticString(),
305-
file: StaticString = #file, line: UInt = #line
306-
) {
307-
#if INTERNAL_CHECKS_ENABLED
308-
// FIXME: The below won't run the assert on 5.1 stdlib if testing on older
309-
// OSes, which means that testing may not test the assertion. We need a real
310-
// solution to this.
311-
guard #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) else { return }
312-
_internalInvariant(condition(), message, file: file, line: line)
313-
#endif
314-
}
315-
316300
@usableFromInline @_transparent
317301
internal func _internalInvariantFailure(
318302
_ message: StaticString = StaticString(),

branches/rxwei-patch-1/stdlib/public/core/ContiguousArrayBuffer.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ internal final class __EmptyArrayStorage
4040
return try body(UnsafeBufferPointer(start: nil, count: 0))
4141
}
4242

43+
@nonobjc
44+
override internal func _getNonVerbatimBridgedCount() -> Int {
45+
return 0
46+
}
47+
4348
override internal func _getNonVerbatimBridgingBuffer() -> _BridgingBuffer {
4449
return _BridgingBuffer(0)
4550
}
@@ -106,6 +111,17 @@ internal final class _ContiguousArrayStorage<
106111
}
107112
}
108113

114+
/// Returns the number of elements in the array.
115+
///
116+
/// - Precondition: `Element` is bridged non-verbatim.
117+
@nonobjc
118+
override internal func _getNonVerbatimBridgedCount() -> Int {
119+
_internalInvariant(
120+
!_isBridgedVerbatimToObjectiveC(Element.self),
121+
"Verbatim bridging should be handled separately")
122+
return countAndCapacity.count
123+
}
124+
109125
/// Bridge array elements and return a new buffer that owns them.
110126
///
111127
/// - Precondition: `Element` is bridged non-verbatim.

0 commit comments

Comments
 (0)