Skip to content

Commit 8d46cc8

Browse files
committed
[isolation-regions] Rename Consume to Transfer.
Transfer is the terminology that we are using for something be transferred across an isolation boundary, not consume. This also eliminates confusion with consume which is a term being used around ownership.
1 parent a9e8baa commit 8d46cc8

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
lines changed

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,25 @@ struct Region {
4444

4545
using namespace PartitionPrimitives;
4646

47-
// PartitionOpKind represents the different kinds of PartitionOps that
48-
// SILInstructions can be translated to
47+
/// PartitionOpKind represents the different kinds of PartitionOps that
48+
/// SILInstructions can be translated to
4949
enum class PartitionOpKind : uint8_t {
50-
// Assign one value to the region of another, takes two args, second arg
51-
// must already be tracked with a non-consumed region
50+
/// Assign one value to the region of another, takes two args, second arg
51+
/// must already be tracked with a non-consumed region
5252
Assign,
5353

54-
// Assign one value to a fresh region, takes one arg.
54+
/// Assign one value to a fresh region, takes one arg.
5555
AssignFresh,
5656

57-
// Consume the region of a value if not already consumed, takes one arg.
58-
Consume,
59-
60-
// Merge the regions of two values, takes two args, both must be from
61-
// non-consumed regions.
57+
/// Merge the regions of two values, takes two args, both must be from
58+
/// non-consumed regions.
6259
Merge,
6360

64-
// Require the region of a value to be non-consumed, takes one arg.
65-
Require
61+
/// Consume the region of a value if not already consumed, takes one arg.
62+
Transfer,
63+
64+
/// Require the region of a value to be non-consumed, takes one arg.
65+
Require,
6666
};
6767

6868
// PartitionOp represents a primitive operation that can be performed on
@@ -108,11 +108,9 @@ class PartitionOp {
108108
return PartitionOp(PartitionOpKind::AssignFresh, tgt, sourceInst);
109109
}
110110

111-
static PartitionOp Consume(Element tgt,
112-
SILInstruction *sourceInst = nullptr,
113-
Expr *sourceExpr = nullptr) {
114-
return PartitionOp(PartitionOpKind::Consume, tgt,
115-
sourceInst, sourceExpr);
111+
static PartitionOp Transfer(Element tgt, SILInstruction *sourceInst = nullptr,
112+
Expr *sourceExpr = nullptr) {
113+
return PartitionOp(PartitionOpKind::Transfer, tgt, sourceInst, sourceExpr);
116114
}
117115

118116
static PartitionOp Merge(Element tgt1, Element tgt2,
@@ -164,7 +162,7 @@ class PartitionOp {
164162
case PartitionOpKind::AssignFresh:
165163
os << "assign_fresh %%" << OpArgs[0] << "\n";
166164
break;
167-
case PartitionOpKind::Consume:
165+
case PartitionOpKind::Transfer:
168166
os << "consume %%" << OpArgs[0] << "\n";
169167
break;
170168
case PartitionOpKind::Merge:
@@ -425,7 +423,7 @@ class Partition {
425423
fresh_label = Region(fresh_label + 1);
426424
canonical = false;
427425
break;
428-
case PartitionOpKind::Consume:
426+
case PartitionOpKind::Transfer:
429427
assert(op.OpArgs.size() == 1 &&
430428
"Consume PartitionOp should be passed 1 argument");
431429
assert(labels.count(op.OpArgs[0]) &&

lib/SILOptimizer/Mandatory/SendNonSendable.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,12 @@ struct PartitionOpBuilder {
239239
lookupValueID(tgt), lookupValueID(src), currentInst));
240240
}
241241

242-
void addConsume(SILValue value, Expr *sourceExpr = nullptr) {
242+
void addTransfer(SILValue value, Expr *sourceExpr = nullptr) {
243243
assert(valueHasID(value) &&
244244
"consumed value should already have been encountered");
245245

246246
currentInstPartitionOps.emplace_back(
247-
PartitionOp::Consume(lookupValueID(value), currentInst, sourceExpr));
247+
PartitionOp::Transfer(lookupValueID(value), currentInst, sourceExpr));
248248
}
249249

250250
void addMerge(SILValue fst, SILValue snd) {
@@ -655,14 +655,14 @@ class PartitionOpTranslator {
655655
int argNum = 0;
656656
for (auto arg : ops) {
657657
if (auto value = trackIfNonSendable(arg))
658-
builder.addConsume(value->getRepresentative(), getSourceArg(argNum));
658+
builder.addTransfer(value->getRepresentative(), getSourceArg(argNum));
659659
argNum++;
660660
}
661661
};
662662

663663
auto handleSILSelf = [&](SILValue self) {
664664
if (auto value = trackIfNonSendable(self))
665-
builder.addConsume(value->getRepresentative(), getSourceSelf());
665+
builder.addTransfer(value->getRepresentative(), getSourceSelf());
666666
};
667667

668668
if (applySite.hasSelfArgument()) {
@@ -1201,7 +1201,7 @@ struct LocalConsumedReason {
12011201
std::optional<PartitionOp> localInst;
12021202

12031203
static LocalConsumedReason ConsumeInst(PartitionOp localInst) {
1204-
assert(localInst.getKind() == PartitionOpKind::Consume);
1204+
assert(localInst.getKind() == PartitionOpKind::Transfer);
12051205
return LocalConsumedReason(LocalConsumedReasonKind::LocalConsumeInst, localInst);
12061206
}
12071207

@@ -1262,7 +1262,7 @@ class ConsumedReason {
12621262
}
12631263

12641264
void addConsumeOp(PartitionOp consumeOp, unsigned distance) {
1265-
assert(consumeOp.getKind() == PartitionOpKind::Consume);
1265+
assert(consumeOp.getKind() == PartitionOpKind::Transfer);
12661266
// duplicates should not arise
12671267
if (!containsOp(consumeOp))
12681268
consumeOps[distance].push_back(consumeOp);
@@ -1509,7 +1509,7 @@ class RaceTracer {
15091509
workingPartition.apply(partitionOp);
15101510
if (workingPartition.isConsumed(consumedVal) && !consumedReason) {
15111511
// this partitionOp consumes the target value
1512-
if (partitionOp.getKind() == PartitionOpKind::Consume)
1512+
if (partitionOp.getKind() == PartitionOpKind::Transfer)
15131513
consumedReason = LocalConsumedReason::ConsumeInst(partitionOp);
15141514
else
15151515
// a merge or assignment invalidated this, but that will be a separate

unittests/SIL/PartitionUtilsTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ TEST(PartitionUtilsTest, TestConsumeAndRequire) {
194194

195195
//expected: p: ((0 1 2) (3 4 5) (6 7) (8 9) (Element(10)) (Element(11)))
196196

197-
p.apply(PartitionOp::Consume(Element(2)));
198-
p.apply(PartitionOp::Consume(Element(7)));
199-
p.apply(PartitionOp::Consume(Element(10)));
197+
p.apply(PartitionOp::Transfer(Element(2)));
198+
p.apply(PartitionOp::Transfer(Element(7)));
199+
p.apply(PartitionOp::Transfer(Element(10)));
200200

201201
// expected: p: ({0 1 2 6 7 10} (3 4 5) (8 9) (Element(11)))
202202

@@ -236,7 +236,7 @@ TEST(PartitionUtilsTest, TestCopyConstructor) {
236236
Partition p1;
237237
p1.apply(PartitionOp::AssignFresh(Element(0)));
238238
Partition p2 = p1;
239-
p1.apply(PartitionOp::Consume(Element(0)));
239+
p1.apply(PartitionOp::Transfer(Element(0)));
240240
bool failure = false;
241241
p1.apply(PartitionOp::Require(Element(0)), [&](const PartitionOp &, unsigned) {
242242
failure = true;

0 commit comments

Comments
 (0)