Skip to content

Commit cc1a873

Browse files
committed
Fix another mocking issue with PartitionUtils unittest.
1 parent 6844b99 commit cc1a873

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,8 @@ class PartitionOp {
655655
return source.get<SILInstruction *>();
656656
}
657657

658+
bool hasSourceInst() const { return source.is<SILInstruction *>(); }
659+
658660
Operand *getSourceOp() const { return source.get<Operand *>(); }
659661

660662
SILLocation getSourceLoc() const { return getSourceInst()->getLoc(); }
@@ -1095,6 +1097,11 @@ struct PartitionOpEvaluator {
10951097
/// if they need to.
10961098
static SILLocation getLoc(SILInstruction *inst) { return Impl::getLoc(inst); }
10971099

1100+
/// Some evaluators pass in mock operands that one cannot call getLoc()
1101+
/// upon. So to allow for this, provide a routine that our impl can override
1102+
/// if they need to.
1103+
static SILLocation getLoc(Operand *op) { return Impl::getLoc(op); }
1104+
10981105
/// Apply \p op to the partition op.
10991106
void apply(const PartitionOp &op) const {
11001107
if (shouldEmitVerboseLogging()) {
@@ -1113,7 +1120,9 @@ struct PartitionOpEvaluator {
11131120

11141121
// Set the boundary so that as we push, this shows when to stop processing
11151122
// for this PartitionOp.
1116-
p.pushHistorySequenceBoundary(getLoc(op.getSourceInst()));
1123+
SILLocation loc = op.hasSourceInst() ? getLoc(op.getSourceInst())
1124+
: getLoc(op.getSourceOp());
1125+
p.pushHistorySequenceBoundary(loc);
11171126

11181127
switch (op.getKind()) {
11191128
case PartitionOpKind::Assign:
@@ -1356,6 +1365,7 @@ struct PartitionOpEvaluatorBaseImpl : PartitionOpEvaluator<Subclass> {
13561365
bool shouldTryToSquelchErrors() const { return true; }
13571366

13581367
static SILLocation getLoc(SILInstruction *inst) { return inst->getLoc(); }
1368+
static SILLocation getLoc(Operand *op) { return op->getUser()->getLoc(); }
13591369
};
13601370

13611371
/// 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
@@ -53,6 +53,8 @@ struct MockedPartitionOpEvaluator final
5353
static SILLocation getLoc(SILInstruction *inst) {
5454
return SILLocation::invalid();
5555
}
56+
57+
static SILLocation getLoc(Operand *op) { return SILLocation::invalid(); }
5658
};
5759

5860
} // namespace
@@ -87,6 +89,8 @@ struct MockedPartitionOpEvaluatorWithFailureCallback final
8789
static SILLocation getLoc(SILInstruction *inst) {
8890
return SILLocation::invalid();
8991
}
92+
93+
static SILLocation getLoc(Operand *op) { return SILLocation::invalid(); }
9094
};
9195

9296
} // namespace

0 commit comments

Comments
 (0)