Skip to content

Commit 241fca5

Browse files
committed
[region-isolation] Stub out getIsolationInfo so the mocking unit tests succeed.
Specifically, the partition unit tests pass in bogus instructions/operands so we cannot call /any/ methods on them. So I created stubed out helpers on the evaluator that in the case of mocking just return a default initialized SILIsolationInfo(). (cherry picked from commit 1113a61)
1 parent 9892543 commit 241fca5

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,13 @@ struct PartitionOpEvaluator {
11211121
/// if they need to.
11221122
static SILLocation getLoc(Operand *op) { return Impl::getLoc(op); }
11231123

1124+
/// Some evaluators pass in mock operands that one cannot call getUser()
1125+
/// upon. So to allow for this, provide a routine that our impl can override
1126+
/// if they need to.
1127+
static SILIsolationInfo getIsolationInfo(const PartitionOp &partitionOp) {
1128+
return Impl::getIsolationInfo(partitionOp);
1129+
}
1130+
11241131
/// Apply \p op to the partition op.
11251132
void apply(const PartitionOp &op) const {
11261133
if (shouldEmitVerboseLogging()) {
@@ -1192,8 +1199,7 @@ struct PartitionOpEvaluator {
11921199
//
11931200
// DISCUSSION: We couldn't not emit this earlier since we needed the
11941201
// dynamic isolation info of our value.
1195-
if (auto calleeIsolationInfo =
1196-
SILIsolationInfo::get(op.getSourceInst())) {
1202+
if (auto calleeIsolationInfo = getIsolationInfo(op)) {
11971203
if (transferredRegionIsolation.hasSameIsolation(calleeIsolationInfo)) {
11981204
return;
11991205
}
@@ -1288,7 +1294,7 @@ struct PartitionOpEvaluator {
12881294
void handleLocalUseAfterTransferHelper(const PartitionOp &op, Element elt,
12891295
Operand *transferringOp) const {
12901296
if (shouldTryToSquelchErrors()) {
1291-
if (auto isolationInfo = SILIsolationInfo::get(op.getSourceInst())) {
1297+
if (auto isolationInfo = getIsolationInfo(op)) {
12921298
if (isolationInfo.isActorIsolated() &&
12931299
isolationInfo.hasSameIsolation(
12941300
SILIsolationInfo::get(transferringOp->getUser())))
@@ -1386,6 +1392,9 @@ struct PartitionOpEvaluatorBaseImpl : PartitionOpEvaluator<Subclass> {
13861392

13871393
static SILLocation getLoc(SILInstruction *inst) { return inst->getLoc(); }
13881394
static SILLocation getLoc(Operand *op) { return op->getUser()->getLoc(); }
1395+
static SILIsolationInfo getIsolationInfo(const PartitionOp &partitionOp) {
1396+
return SILIsolationInfo::get(partitionOp.getSourceInst());
1397+
}
13891398
};
13901399

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

unittests/SILOptimizer/PartitionUtilsTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ struct MockedPartitionOpEvaluator final
5757
}
5858

5959
static SILLocation getLoc(Operand *op) { return SILLocation::invalid(); }
60+
61+
static SILIsolationInfo getIsolationInfo(const PartitionOp &partitionOp) {
62+
return {};
63+
}
6064
};
6165

6266
} // namespace
@@ -95,6 +99,10 @@ struct MockedPartitionOpEvaluatorWithFailureCallback final
9599
}
96100

97101
static SILLocation getLoc(Operand *op) { return SILLocation::invalid(); }
102+
103+
static SILIsolationInfo getIsolationInfo(const PartitionOp &partitionOp) {
104+
return {};
105+
}
98106
};
99107

100108
} // namespace

0 commit comments

Comments
 (0)