Skip to content

Commit 28eb77f

Browse files
Merge remote-tracking branch 'origin/release/5.7' into katei/merge-5.7-2022-05-06
2 parents ea514a5 + 5aa05b2 commit 28eb77f

24 files changed

+547
-127
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4544,6 +4544,7 @@ class ConstraintSystem {
45444544
/// Generate constraints for the given solution target.
45454545
///
45464546
/// \returns true if an error occurred, false otherwise.
4547+
LLVM_NODISCARD
45474548
bool generateConstraints(SolutionApplicationTarget &target,
45484549
FreeTypeVariableBinding allowFreeTypeVariables);
45494550

@@ -4552,18 +4553,21 @@ class ConstraintSystem {
45524553
/// \param closure the closure expression
45534554
///
45544555
/// \returns \c true if constraint generation failed, \c false otherwise
4556+
LLVM_NODISCARD
45554557
bool generateConstraints(ClosureExpr *closure);
45564558

45574559
/// Generate constraints for the given (unchecked) expression.
45584560
///
45594561
/// \returns a possibly-sanitized expression, or null if an error occurred.
4562+
LLVM_NODISCARD
45604563
Expr *generateConstraints(Expr *E, DeclContext *dc,
45614564
bool isInputExpression = true);
45624565

45634566
/// Generate constraints for binding the given pattern to the
45644567
/// value of the given expression.
45654568
///
45664569
/// \returns a possibly-sanitized initializer, or null if an error occurred.
4570+
LLVM_NODISCARD
45674571
Type generateConstraints(Pattern *P, ConstraintLocatorBuilder locator,
45684572
bool bindPatternVarsOneWay,
45694573
PatternBindingDecl *patternBinding,
@@ -4573,6 +4577,7 @@ class ConstraintSystem {
45734577
///
45744578
/// \returns true if there was an error in constraint generation, false
45754579
/// if generation succeeded.
4580+
LLVM_NODISCARD
45764581
bool generateConstraints(StmtCondition condition, DeclContext *dc);
45774582

45784583
/// Generate constraints for a case statement.
@@ -4582,6 +4587,7 @@ class ConstraintSystem {
45824587
///
45834588
/// \returns true if there was an error in constraint generation, false
45844589
/// if generation succeeded.
4590+
LLVM_NODISCARD
45854591
bool generateConstraints(CaseStmt *caseStmt, DeclContext *dc,
45864592
Type subjectType, ConstraintLocator *locator);
45874593

@@ -4625,6 +4631,7 @@ class ConstraintSystem {
46254631
/// \param propertyType The type of the wrapped property.
46264632
///
46274633
/// \returns true if there is an error.
4634+
LLVM_NODISCARD
46284635
bool generateWrappedPropertyTypeConstraints(VarDecl *wrappedVar,
46294636
Type initializerType,
46304637
Type propertyType);

lib/AST/Type.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4115,7 +4115,6 @@ CanType ProtocolCompositionType::getMinimalCanonicalType(
41154115
return Reqs.front().getSecondType()->getCanonicalType();
41164116
}
41174117

4118-
Type superclass;
41194118
llvm::SmallVector<Type, 2> MinimalMembers;
41204119
bool MinimalHasExplicitAnyObject = false;
41214120
auto ifaceTy = Sig.getGenericParams().back();
@@ -4126,10 +4125,6 @@ CanType ProtocolCompositionType::getMinimalCanonicalType(
41264125

41274126
switch (Req.getKind()) {
41284127
case RequirementKind::Superclass:
4129-
assert((!superclass || superclass->isEqual(Req.getSecondType()))
4130-
&& "Multiple distinct superclass constraints!");
4131-
superclass = Req.getSecondType();
4132-
break;
41334128
case RequirementKind::Conformance:
41344129
MinimalMembers.push_back(Req.getSecondType());
41354130
break;
@@ -4141,10 +4136,16 @@ CanType ProtocolCompositionType::getMinimalCanonicalType(
41414136
}
41424137
}
41434138

4144-
// Ensure superclass bounds appear first regardless of their order among
4145-
// the signature's requirements.
4146-
if (superclass)
4147-
MinimalMembers.insert(MinimalMembers.begin(), superclass->getCanonicalType());
4139+
// A superclass constraint is always retained and must appear first in the
4140+
// members list.
4141+
assert(Composition->getMembers().front()->getClassOrBoundGenericClass() ==
4142+
MinimalMembers.front()->getClassOrBoundGenericClass());
4143+
4144+
// If we are left with a single member and no layout constraint, the member
4145+
// is the minimal type. Also, note that a protocol composition cannot be
4146+
// constructed with a single member unless there is a layout constraint.
4147+
if (MinimalMembers.size() == 1 && !MinimalHasExplicitAnyObject)
4148+
return CanType(MinimalMembers.front());
41484149

41494150
// The resulting composition is necessarily canonical.
41504151
return CanType(build(Ctx, MinimalMembers, MinimalHasExplicitAnyObject));

lib/FrontendTool/FrontendTool.cpp

Lines changed: 72 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ mapFrontendInvocationToAction(const CompilerInvocation &Invocation) {
590590

591591
static DetailedTaskDescription
592592
constructDetailedTaskDescription(const CompilerInvocation &Invocation,
593-
const InputFile &PrimaryInput,
593+
ArrayRef<InputFile> PrimaryInputs,
594594
ArrayRef<const char *> Args) {
595595
// Command line and arguments
596596
std::string Executable = Invocation.getFrontendOptions().MainExecutablePath;
@@ -604,24 +604,30 @@ constructDetailedTaskDescription(const CompilerInvocation &Invocation,
604604
CommandLine += std::string(" ") + A;
605605
}
606606

607-
// Primary Input only
608-
Inputs.push_back(CommandInput(PrimaryInput.getFileName()));
607+
// Primary Inputs
608+
for (const auto &input : PrimaryInputs) {
609+
Inputs.push_back(CommandInput(input.getFileName()));
610+
}
609611

610-
// Output for this Primary
611-
auto OutputFile = PrimaryInput.outputFilename();
612-
Outputs.push_back(OutputPair(file_types::lookupTypeForExtension(
613-
llvm::sys::path::extension(OutputFile)),
614-
OutputFile));
612+
for (const auto &input : PrimaryInputs) {
613+
// Main outputs
614+
auto OutputFile = input.outputFilename();
615+
if (!OutputFile.empty()) {
616+
Outputs.push_back(OutputPair(file_types::lookupTypeForExtension(
617+
llvm::sys::path::extension(OutputFile)),
618+
OutputFile));
619+
}
615620

616-
// Supplementary outputs
617-
const auto &primarySpecificFiles = PrimaryInput.getPrimarySpecificPaths();
618-
const auto &supplementaryOutputPaths =
619-
primarySpecificFiles.SupplementaryOutputs;
620-
supplementaryOutputPaths.forEachSetOutput([&](const std::string &output) {
621-
Outputs.push_back(OutputPair(
622-
file_types::lookupTypeForExtension(llvm::sys::path::extension(output)),
623-
output));
624-
});
621+
// Supplementary outputs
622+
const auto &primarySpecificFiles = input.getPrimarySpecificPaths();
623+
const auto &supplementaryOutputPaths =
624+
primarySpecificFiles.SupplementaryOutputs;
625+
supplementaryOutputPaths.forEachSetOutput([&](const std::string &output) {
626+
Outputs.push_back(OutputPair(file_types::lookupTypeForExtension(
627+
llvm::sys::path::extension(output)),
628+
output));
629+
});
630+
}
625631
return DetailedTaskDescription{Executable, Arguments, CommandLine, Inputs,
626632
Outputs};
627633
}
@@ -2125,15 +2131,26 @@ int swift::performFrontend(ArrayRef<const char *> Args,
21252131
// making sure it cannot collide with a real PID (always positive). Non-batch
21262132
// compilation gets a real OS PID.
21272133
int64_t Pid = IO.hasUniquePrimaryInput() ? OSPid : QUASI_PID_START;
2128-
IO.forEachPrimaryInputWithIndex([&](const InputFile &Input,
2129-
unsigned idx) -> bool {
2130-
emitBeganMessage(
2131-
llvm::errs(),
2132-
mapFrontendInvocationToAction(Invocation),
2133-
constructDetailedTaskDescription(Invocation, Input, Args), Pid - idx,
2134-
ProcInfo);
2135-
return false;
2136-
});
2134+
2135+
if (IO.hasPrimaryInputs()) {
2136+
IO.forEachPrimaryInputWithIndex([&](const InputFile &Input,
2137+
unsigned idx) -> bool {
2138+
ArrayRef<InputFile> Inputs(Input);
2139+
emitBeganMessage(llvm::errs(),
2140+
mapFrontendInvocationToAction(Invocation),
2141+
constructDetailedTaskDescription(Invocation,
2142+
Inputs,
2143+
Args), Pid - idx,
2144+
ProcInfo);
2145+
return false;
2146+
});
2147+
} else {
2148+
// If no primary inputs are present, we are in WMO.
2149+
emitBeganMessage(llvm::errs(),
2150+
mapFrontendInvocationToAction(Invocation),
2151+
constructDetailedTaskDescription(Invocation, IO.getAllInputs(), Args),
2152+
OSPid, ProcInfo);
2153+
}
21372154
}
21382155

21392156
int ReturnValue = 0;
@@ -2164,23 +2181,41 @@ int swift::performFrontend(ArrayRef<const char *> Args,
21642181
// making sure it cannot collide with a real PID (always positive). Non-batch
21652182
// compilation gets a real OS PID.
21662183
int64_t Pid = IO.hasUniquePrimaryInput() ? OSPid : QUASI_PID_START;
2167-
IO.forEachPrimaryInputWithIndex([&](const InputFile &Input,
2168-
unsigned idx) -> bool {
2169-
assert(FileSpecificDiagnostics.count(Input.getFileName()) != 0 &&
2170-
"Expected diagnostic collection for input.");
21712184

2172-
// Join all diagnostics produced for this file into a single output.
2173-
auto PrimaryDiags = FileSpecificDiagnostics.lookup(Input.getFileName());
2185+
if (IO.hasPrimaryInputs()) {
2186+
IO.forEachPrimaryInputWithIndex([&](const InputFile &Input,
2187+
unsigned idx) -> bool {
2188+
assert(FileSpecificDiagnostics.count(Input.getFileName()) != 0 &&
2189+
"Expected diagnostic collection for input.");
2190+
2191+
// Join all diagnostics produced for this file into a single output.
2192+
auto PrimaryDiags = FileSpecificDiagnostics.lookup(Input.getFileName());
2193+
const char *const Delim = "";
2194+
std::ostringstream JoinedDiags;
2195+
std::copy(PrimaryDiags.begin(), PrimaryDiags.end(),
2196+
std::ostream_iterator<std::string>(JoinedDiags, Delim));
2197+
2198+
emitFinishedMessage(llvm::errs(),
2199+
mapFrontendInvocationToAction(Invocation),
2200+
JoinedDiags.str(), r, Pid - idx, ProcInfo);
2201+
return false;
2202+
});
2203+
} else {
2204+
// If no primary inputs are present, we are in WMO.
2205+
std::vector<std::string> AllDiagnostics;
2206+
for (const auto &FileDiagnostics : FileSpecificDiagnostics) {
2207+
AllDiagnostics.insert(AllDiagnostics.end(),
2208+
FileDiagnostics.getValue().begin(),
2209+
FileDiagnostics.getValue().end());
2210+
}
21742211
const char *const Delim = "";
21752212
std::ostringstream JoinedDiags;
2176-
std::copy(PrimaryDiags.begin(), PrimaryDiags.end(),
2213+
std::copy(AllDiagnostics.begin(), AllDiagnostics.end(),
21772214
std::ostream_iterator<std::string>(JoinedDiags, Delim));
2178-
21792215
emitFinishedMessage(llvm::errs(),
21802216
mapFrontendInvocationToAction(Invocation),
2181-
JoinedDiags.str(), r, Pid - idx, ProcInfo);
2182-
return false;
2183-
});
2217+
JoinedDiags.str(), r, OSPid, ProcInfo);
2218+
}
21842219
}
21852220

21862221
return r;

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ static bool mayAccessPointer(SILInstruction *instruction) {
420420
static bool mayLoadWeakOrUnowned(SILInstruction *instruction) {
421421
// TODO: It is possible to do better here by looking at the address that is
422422
// being loaded.
423-
return isa<LoadWeakInst>(instruction) || isa<LoadUnownedInst>(instruction);
423+
return isa<LoadWeakInst>(instruction) || isa<LoadUnownedInst>(instruction)
424+
|| isa<StrongCopyUnownedValueInst>(instruction)
425+
|| isa<StrongCopyUnmanagedValueInst>(instruction);
424426
}
425427

426428
bool swift::isDeinitBarrier(SILInstruction *instruction) {
@@ -1398,6 +1400,11 @@ void swift::visitProductLeafAccessPathNodes(
13981400
worklist.push_back({silType.getTupleElementType(index), elementNode});
13991401
}
14001402
} else if (auto *decl = silType.getStructOrBoundGenericStruct()) {
1403+
if (decl->isResilient(tec.getContext()->getParentModule(),
1404+
tec.getResilienceExpansion())) {
1405+
visitor(AccessPath::PathNode(node), silType);
1406+
continue;
1407+
}
14011408
unsigned index = 0;
14021409
for (auto *field : decl->getStoredProperties()) {
14031410
auto *fieldNode = node->getChild(index);

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,8 +1319,14 @@ TrampolineDest::TrampolineDest(SILBasicBlock *sourceBB,
13191319
return;
13201320
}
13211321
}
1322+
SILBasicBlock *destBlock = targetBranch->getDestBB();
13221323
newSourceBranchArgs.reserve(targetBranch->getArgs().size());
13231324
for (SILValue branchArg : targetBranch->getArgs()) {
1325+
if (branchArg->getParentBlock() == destBlock) {
1326+
// This can happen if the involved blocks are part of an unreachable CFG
1327+
// cycle (dominance is not meaningful in such a case).
1328+
return;
1329+
}
13241330
if (branchArg->getParentBlock() == targetBB) {
13251331
auto *phi = dyn_cast<SILPhiArgument>(branchArg);
13261332
if (!phi || !phi->isPhi()) {
@@ -1331,7 +1337,7 @@ TrampolineDest::TrampolineDest(SILBasicBlock *sourceBB,
13311337
newSourceBranchArgs.push_back(branchArg);
13321338
}
13331339
// Setting destBB constructs a valid TrampolineDest.
1334-
destBB = targetBranch->getDestBB();
1340+
destBB = destBlock;
13351341
}
13361342

13371343
#ifndef NDEBUG

lib/Sema/CSSimplify.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3467,8 +3467,11 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
34673467
if (!req)
34683468
return getTypeMatchFailure(locator);
34693469

3470-
if (type1->isPlaceholder() ||
3471-
req->getRequirementKind() == RequirementKind::Superclass)
3470+
// Superclass constraints are never satisfied by existentials,
3471+
// even those that contain the superclass a la `any C & P`.
3472+
if (!type1->isExistentialType() &&
3473+
(type1->isPlaceholder() ||
3474+
req->getRequirementKind() == RequirementKind::Superclass))
34723475
return getTypeMatchSuccess();
34733476

34743477
auto *fix = fixRequirementFailure(*this, type1, type2, locator);
@@ -8971,7 +8974,8 @@ static bool inferEnumMemberThroughTildeEqualsOperator(
89718974
}
89728975
}
89738976

8974-
cs.generateConstraints(target, FreeTypeVariableBinding::Disallow);
8977+
if (cs.generateConstraints(target, FreeTypeVariableBinding::Disallow))
8978+
return true;
89758979

89768980
// Sub-expression associated with expression pattern is the enum element
89778981
// access which needs to be connected to the provided element type.
@@ -9907,8 +9911,9 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
99079911
}
99089912

99099913
if (!paramDecl->getName().hasDollarPrefix()) {
9910-
generateWrappedPropertyTypeConstraints(paramDecl, backingType,
9911-
param.getParameterType());
9914+
if (generateWrappedPropertyTypeConstraints(paramDecl, backingType,
9915+
param.getParameterType()))
9916+
return false;
99129917
}
99139918

99149919
auto result = applyPropertyWrapperToParameter(backingType, param.getParameterType(),

stdlib/public/Concurrency/Actor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ void swift::runJobInEstablishedExecutorContext(Job *job) {
232232
// it afterwards.
233233
task->flagAsRunning();
234234

235+
auto traceHandle = concurrency::trace::job_run_begin(job);
235236
task->runInFullyEstablishedContext();
237+
concurrency::trace::job_run_end(traceHandle);
236238

237239
assert(ActiveTask::get() == nullptr &&
238240
"active task wasn't cleared before susspending?");
@@ -1505,12 +1507,10 @@ static void swift_job_runImpl(Job *job, ExecutorRef executor) {
15051507
if (!executor.isGeneric()) trackingInfo.disallowSwitching();
15061508

15071509
trackingInfo.enterAndShadow(executor);
1508-
auto traceHandle = concurrency::trace::job_run_begin(job, &executor);
15091510

15101511
SWIFT_TASK_DEBUG_LOG("job %p", job);
15111512
runJobInEstablishedExecutorContext(job);
15121513

1513-
concurrency::trace::job_run_end(&executor, traceHandle);
15141514
trackingInfo.leave();
15151515

15161516
// Give up the current executor if this is a switching context

stdlib/public/Concurrency/Clock.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ void swift_get_time(
3737
clock_gettime(CLOCK_BOOTTIME, &continuous);
3838
*seconds = continuous.tv_sec;
3939
*nanoseconds = continuous.tv_nsec;
40-
#elif (defined(__APPLE__) || defined(__wasi__) || defined(__OpenBSD__)) && HAS_TIME
40+
#elif defined(__APPLE__) && HAS_TIME
41+
struct timespec continuous;
42+
clock_gettime(CLOCK_MONOTONIC_RAW, &continuous);
43+
*seconds = continuous.tv_sec;
44+
*nanoseconds = continuous.tv_nsec;
45+
#elif (defined(__OpenBSD__) || defined(__wasi__)) && HAS_TIME
4146
struct timespec continuous;
4247
clock_gettime(CLOCK_MONOTONIC, &continuous);
4348
*seconds = continuous.tv_sec;
@@ -63,7 +68,7 @@ void swift_get_time(
6368
case swift_clock_id_suspending: {
6469
#if defined(__linux__) && HAS_TIME
6570
struct timespec suspending;
66-
clock_gettime(CLOCK_MONOTONIC_RAW, &suspending);
71+
clock_gettime(CLOCK_MONOTONIC, &suspending);
6772
*seconds = suspending.tv_sec;
6873
*nanoseconds = suspending.tv_nsec;
6974
#elif defined(__APPLE__) && HAS_TIME
@@ -116,7 +121,12 @@ switch (clock_id) {
116121
clock_getres(CLOCK_BOOTTIME, &continuous);
117122
*seconds = continuous.tv_sec;
118123
*nanoseconds = continuous.tv_nsec;
119-
#elif (defined(__APPLE__) || defined(__wasi__) || defined(__OpenBSD__)) && HAS_TIME
124+
#elif defined(__APPLE__) && HAS_TIME
125+
struct timespec continuous;
126+
clock_getres(CLOCK_MONOTONIC_RAW, &continuous);
127+
*seconds = continuous.tv_sec;
128+
*nanoseconds = continuous.tv_nsec;
129+
#elif (defined(__wasi__) || defined(__OpenBSD__)) && HAS_TIME
120130
struct timespec continuous;
121131
clock_getres(CLOCK_MONOTONIC, &continuous);
122132
*seconds = continuous.tv_sec;

0 commit comments

Comments
 (0)