@@ -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.
12391239class 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
12521251public:
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