Skip to content

Commit 1086264

Browse files
committed
[region-isolation] Stub out PartitionOpEvaluator::doesFunctionHaveSendingResult() so that the unittests can override it.
The unittests for PartitionUtils pass in mocked operands and instructions that cannot be dereferenced. Adding this static CRTP helper allows for the unittest PartitionOpEvaluator subclass to just return false for it instead of dereferencing operands or instructions. The rest of the evaluators just get to use the default "normal" implementation that actually accesses program state.
1 parent bcbf5c5 commit 1086264

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,14 @@ struct PartitionOpEvaluator {
10871087
return Impl::getIsolationInfo(partitionOp);
10881088
}
10891089

1090+
/// Some evaluators do not support accessing fields on their SILInstruction
1091+
/// since they just pass in "mocked" SILInstruction. We allow for them to just
1092+
/// return false for this case to prevent dereference issues.
1093+
static bool
1094+
doesParentFunctionHaveSendingResult(const PartitionOp &partitionOp) {
1095+
return Impl::doesFunctionHaveSendingResult(partitionOp);
1096+
}
1097+
10901098
std::optional<Element> getElement(SILValue value) const {
10911099
return asImpl().getElement(value);
10921100
}
@@ -1130,10 +1138,7 @@ struct PartitionOpEvaluator {
11301138

11311139
// See if we are assigning an a non-disconnected value into a 'out
11321140
// sending' parameter. In such a case, we emit a diagnostic.
1133-
if (op.getSourceInst()
1134-
->getFunction()
1135-
->getLoweredFunctionType()
1136-
->hasSendingResult()) {
1141+
if (doesParentFunctionHaveSendingResult(op)) {
11371142
if (auto instance = getRepresentativeValue(op.getOpArgs()[0])) {
11381143
if (auto value = instance.maybeGetValue()) {
11391144
if (auto *fArg = dyn_cast<SILFunctionArgument>(value)) {
@@ -1246,10 +1251,7 @@ struct PartitionOpEvaluator {
12461251

12471252
// See if we are assigning an a non-disconnected value into a 'out
12481253
// sending' parameter. In such a case, we emit a diagnostic.
1249-
if (op.getSourceInst()
1250-
->getFunction()
1251-
->getLoweredFunctionType()
1252-
->hasSendingResult()) {
1254+
if (doesParentFunctionHaveSendingResult(op)) {
12531255
if (auto instance = getRepresentativeValue(op.getOpArgs()[0])) {
12541256
if (auto value = instance.maybeGetValue()) {
12551257
if (auto *fArg = dyn_cast<SILFunctionArgument>(value)) {
@@ -1571,6 +1573,12 @@ struct PartitionOpEvaluatorBaseImpl : PartitionOpEvaluator<Subclass> {
15711573
static SILIsolationInfo getIsolationInfo(const PartitionOp &partitionOp) {
15721574
return SILIsolationInfo::get(partitionOp.getSourceInst());
15731575
}
1576+
static bool doesFunctionHaveSendingResult(const PartitionOp &partitionOp) {
1577+
return partitionOp.getSourceInst()
1578+
->getFunction()
1579+
->getLoweredFunctionType()
1580+
->hasSendingResult();
1581+
}
15741582
};
15751583

15761584
/// A subclass of PartitionOpEvaluatorBaseImpl that doesn't have any special

unittests/SILOptimizer/PartitionUtilsTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ struct MockedPartitionOpEvaluator final
6161
static SILIsolationInfo getIsolationInfo(const PartitionOp &partitionOp) {
6262
return {};
6363
}
64+
65+
static bool doesFunctionHaveSendingResult(const PartitionOp &partitionOp) {
66+
return false;
67+
}
6468
};
6569

6670
} // namespace

0 commit comments

Comments
 (0)