Skip to content

Commit b67fc90

Browse files
authored
Merge pull request #69378 from gottesmm/pr-cef756d1ce1215ea9d5eeb3500d87d1532aff686
[region-isolation] Follow up changes to #69342
2 parents df58c43 + d069169 commit b67fc90

File tree

2 files changed

+25
-36
lines changed

2 files changed

+25
-36
lines changed

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,14 @@ class Partition {
394394
return fst_reduced;
395395
}
396396

397-
// Apply the passed PartitionOp to this partition, performing its action.
398-
// A `handleFailure` closure can optionally be passed in that will be called
399-
// if a transferred region is required. The closure is given the PartitionOp
400-
// that failed, and the index of the SIL value that was required but
397+
// Apply the passed PartitionOp to this partition, performing its action. A
398+
// `handleFailure` closure can optionally be passed in that will be called if
399+
// a transferred region is required. The closure is given the PartitionOp that
400+
// failed, and the index of the SIL value that was required but
401401
// transferred. Additionally, a list of "nonconsumable" indices can be passed
402402
// in along with a handleConsumeNonConsumable closure. In the event that a
403403
// region containing one of the nonconsumable indices is transferred, the
404-
// closure will be called with the offending Consume.
404+
// closure will be called with the offending transfer.
405405
void apply(
406406
PartitionOp op,
407407
llvm::function_ref<void(const PartitionOp &, Element)> handleFailure =

lib/SILOptimizer/Mandatory/SendNonSendable.cpp

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ struct PartitionOpBuilder {
246246

247247
void addTransfer(SILValue value, Expr *sourceExpr = nullptr) {
248248
assert(valueHasID(value) &&
249-
"transfered value should already have been encountered");
249+
"transferred value should already have been encountered");
250250

251251
currentInstPartitionOps.emplace_back(
252252
PartitionOp::Transfer(lookupValueID(value), currentInst, sourceExpr));
@@ -1237,50 +1237,43 @@ struct LocalTransferredReason {
12371237
// to be informative, so distance is used as a heuristic to choose which
12381238
// access sites to display in diagnostics given a racy consumption.
12391239
class TransferredReason {
1240-
std::map<unsigned, std::vector<PartitionOp>> transferOps;
1240+
std::multimap<unsigned, PartitionOp> transferOps;
12411241

12421242
friend class TransferRequireAccumulator;
12431243

12441244
bool containsOp(const PartitionOp& op) {
1245-
for (auto [_, vec] : transferOps)
1246-
for (auto vecOp : vec)
1247-
if (op == vecOp)
1248-
return true;
1249-
return false;
1245+
return llvm::any_of(transferOps,
1246+
[&](const std::pair<unsigned, PartitionOp> &pair) {
1247+
return pair.second == op;
1248+
});
12501249
}
12511250

12521251
public:
1253-
// a TransferredReason is valid if it contains at least one transfer
1254-
// instruction
1255-
bool isValid() {
1256-
for (auto [_, vec] : transferOps)
1257-
if (!vec.empty())
1258-
return true;
1259-
return false;
1260-
}
1252+
// A TransferredReason is valid if it contains at least one transfer
1253+
// instruction.
1254+
bool isValid() { return transferOps.size(); }
12611255

12621256
TransferredReason() {}
12631257

12641258
TransferredReason(LocalTransferredReason localReason) {
12651259
assert(localReason.kind == LocalTransferredReasonKind::LocalTransferInst);
1266-
transferOps[0] = {localReason.localInst.value()};
1260+
transferOps.emplace(0, localReason.localInst.value());
12671261
}
12681262

12691263
void addTransferOp(PartitionOp transferOp, unsigned distance) {
12701264
assert(transferOp.getKind() == PartitionOpKind::Transfer);
12711265
// duplicates should not arise
12721266
if (!containsOp(transferOp))
1273-
transferOps[distance].push_back(transferOp);
1267+
transferOps.emplace(distance, transferOp);
12741268
}
12751269

12761270
// merge in another transferredReason, adding the specified distane to all its
12771271
// ops
12781272
void addOtherReasonAtDistance(const TransferredReason &otherReason,
12791273
unsigned distance) {
1280-
for (auto &[otherDistance, otherTransferOpsAtDistance] :
1274+
for (auto &[otherDistance, otherTransferOpAtDistance] :
12811275
otherReason.transferOps)
1282-
for (auto otherTransferOp : otherTransferOpsAtDistance)
1283-
addTransferOp(otherTransferOp, distance + otherDistance);
1276+
addTransferOp(otherTransferOpAtDistance, distance + otherDistance);
12841277
}
12851278
};
12861279

@@ -1319,9 +1312,8 @@ class TransferRequireAccumulator {
13191312

13201313
void accumulateTransferredReason(PartitionOp requireOp,
13211314
const TransferredReason &transferredReason) {
1322-
for (auto [distance, transferOps] : transferredReason.transferOps)
1323-
for (auto transferOp : transferOps)
1324-
requirementsForTransfers[transferOp].insert({requireOp, distance});
1315+
for (auto [distance, transferOp] : transferredReason.transferOps)
1316+
requirementsForTransfers[transferOp].insert({requireOp, distance});
13251317
}
13261318

13271319
void emitErrorsForTransferRequire(
@@ -1387,15 +1379,12 @@ class TransferRequireAccumulator {
13871379
// consumption does not correspond to an apply expression
13881380
return false;
13891381
auto isolationCrossing = apply->getIsolationCrossing();
1390-
if (!isolationCrossing) {
1391-
assert(false && "ApplyExprs should be transferring only if"
1392-
" they are isolation crossing");
1393-
return false;
1394-
}
1382+
assert(isolationCrossing && "ApplyExprs should be transferring only if "
1383+
"they are isolation crossing");
1384+
13951385
auto argExpr = transferOp.getSourceExpr();
1396-
if (!argExpr)
1397-
assert(false &&
1398-
"sourceExpr should be populated for ApplyExpr consumptions");
1386+
assert(argExpr &&
1387+
"sourceExpr should be populated for ApplyExpr consumptions");
13991388

14001389
sourceInst->getFunction()
14011390
->getASTContext()

0 commit comments

Comments
 (0)