1
- // ===--- SendNonSendable .cpp ---- ------------------------------------------===//
1
+ // ===--- TransferNonSendable .cpp ------------------------------------------===//
2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
27
27
#include " llvm/ADT/DenseMap.h"
28
28
#include " llvm/Support/Debug.h"
29
29
30
- #define DEBUG_TYPE " send -non-sendable"
30
+ #define DEBUG_TYPE " transfer -non-sendable"
31
31
32
32
using namespace swift ;
33
33
@@ -709,7 +709,8 @@ class PartitionOpTranslator {
709
709
if (auto cast = dyn_cast<TryApplyInst>(applyInst))
710
710
return translateIsolationCrossingSILApply (cast);
711
711
712
- llvm_unreachable (" Only ApplyInst, BeginApplyInst, and TryApplyInst should cross isolation domains" );
712
+ llvm_unreachable (" Only ApplyInst, BeginApplyInst, and TryApplyInst should "
713
+ " cross isolation domains" );
713
714
}
714
715
715
716
// handles the semantics for SIL applies that cross isolation
@@ -731,7 +732,8 @@ class PartitionOpTranslator {
731
732
732
733
auto getSourceSelf = [&]() {
733
734
if (auto callExpr = dyn_cast<CallExpr>(sourceApply))
734
- if (auto calledExpr = dyn_cast<DotSyntaxCallExpr>(callExpr->getDirectCallee ()))
735
+ if (auto calledExpr =
736
+ dyn_cast<DotSyntaxCallExpr>(callExpr->getDirectCallee ()))
735
737
return calledExpr->getBase ();
736
738
return (Expr *)nullptr ;
737
739
};
@@ -814,7 +816,7 @@ class PartitionOpTranslator {
814
816
// an enum select is just a multi assign
815
817
void translateSILSelectEnum (SelectEnumOperation selectEnumInst) {
816
818
SmallVector<SILValue, 8 > enumOperands;
817
- for (unsigned i = 0 ; i < selectEnumInst.getNumCases (); i ++)
819
+ for (unsigned i = 0 ; i < selectEnumInst.getNumCases (); i++)
818
820
enumOperands.push_back (selectEnumInst.getCase (i).second );
819
821
if (selectEnumInst.hasDefault ())
820
822
enumOperands.push_back (selectEnumInst.getDefaultResult ());
@@ -829,8 +831,8 @@ class PartitionOpTranslator {
829
831
for (unsigned i = 0 ; i < switchEnumInst->getNumCases (); i++) {
830
832
SILBasicBlock *dest = switchEnumInst->getCase (i).second ;
831
833
if (dest->getNumArguments () > 0 ) {
832
- assert (dest->getNumArguments () == 1
833
- && " expected at most one bb arg in dest of enum switch" );
834
+ assert (dest->getNumArguments () == 1 &&
835
+ " expected at most one bb arg in dest of enum switch" );
834
836
argSources.addValues ({switchEnumInst->getOperand ()}, dest);
835
837
}
836
838
}
@@ -992,7 +994,8 @@ class PartitionOpTranslator {
992
994
// argument passing
993
995
case SILInstructionKind::BranchInst: {
994
996
auto *branchInst = cast<BranchInst>(inst);
995
- assert (branchInst->getNumArgs () == branchInst->getDestBB ()->getNumArguments ());
997
+ assert (branchInst->getNumArgs () ==
998
+ branchInst->getDestBB ()->getNumArguments ());
996
999
TermArgSources argSources;
997
1000
argSources.addValues (branchInst->getArgs (), branchInst->getDestBB ());
998
1001
return translateSILPhi (argSources);
@@ -1256,18 +1259,16 @@ class BlockPartitionState {
1256
1259
public:
1257
1260
// run the passed action on each partitionOp in this block. Action should
1258
1261
// return true iff iteration should continue
1259
- void forEachPartitionOp (llvm::function_ref<bool (const PartitionOp&)> action) const {
1262
+ void forEachPartitionOp (
1263
+ llvm::function_ref<bool (const PartitionOp &)> action) const {
1260
1264
for (const PartitionOp &partitionOp : blockPartitionOps)
1261
- if (!action (partitionOp)) break ;
1265
+ if (!action (partitionOp))
1266
+ break ;
1262
1267
}
1263
1268
1264
- const Partition& getEntryPartition () const {
1265
- return entryPartition;
1266
- }
1269
+ const Partition &getEntryPartition () const { return entryPartition; }
1267
1270
1268
- const Partition& getExitPartition () const {
1269
- return exitPartition;
1270
- }
1271
+ const Partition &getExitPartition () const { return exitPartition; }
1271
1272
1272
1273
SWIFT_DEBUG_DUMP { print (llvm::dbgs ()); }
1273
1274
@@ -1352,7 +1353,7 @@ class TransferredReason {
1352
1353
1353
1354
friend class TransferRequireAccumulator ;
1354
1355
1355
- bool containsOp (const PartitionOp& op) {
1356
+ bool containsOp (const PartitionOp & op) {
1356
1357
return llvm::any_of (transferOps,
1357
1358
[&](const std::pair<unsigned , PartitionOp> &pair) {
1358
1359
return pair.second == op;
@@ -1404,7 +1405,7 @@ class TransferRequireAccumulator {
1404
1405
PartitionOpAtDistance (PartitionOp partitionOp, unsigned distance)
1405
1406
: partitionOp(partitionOp), distance(distance) {}
1406
1407
1407
- bool operator <(const PartitionOpAtDistance& other) const {
1408
+ bool operator <(const PartitionOpAtDistance & other) const {
1408
1409
if (distance != other.distance )
1409
1410
return distance < other.distance ;
1410
1411
return partitionOp < other.partitionOp ;
@@ -1516,7 +1517,7 @@ class TransferRequireAccumulator {
1516
1517
// and traces those facts to the Transfer operations that could have been
1517
1518
// responsible.
1518
1519
class RaceTracer {
1519
- const BasicBlockData<BlockPartitionState>& blockStates;
1520
+ const BasicBlockData<BlockPartitionState> & blockStates;
1520
1521
1521
1522
std::map<std::pair<SILBasicBlock *, TrackableValueID>, TransferredReason>
1522
1523
transferredAtEntryReasons;
@@ -1596,7 +1597,8 @@ class RaceTracer {
1596
1597
for (SILBasicBlock *pred : SILBlock->getPredecessorBlocks ())
1597
1598
for (std::vector<TrackableValueID> region :
1598
1599
blockStates[pred].getExitPartition ().getNonTransferredRegions ()) {
1599
- for (TrackableValueID fst : region) for (TrackableValueID snd : region)
1600
+ for (TrackableValueID fst : region)
1601
+ for (TrackableValueID snd : region)
1600
1602
if (fst != snd && entryTracks (fst) && entryTracks (snd))
1601
1603
singleStepJoins[fst].insert (snd);
1602
1604
}
@@ -1668,9 +1670,9 @@ class RaceTracer {
1668
1670
workingPartition.apply (PartitionOp::AssignFresh (transferredVal));
1669
1671
1670
1672
int i = 0 ;
1671
- block.forEachPartitionOp ([&](const PartitionOp& partitionOp) {
1673
+ block.forEachPartitionOp ([&](const PartitionOp & partitionOp) {
1672
1674
if (targetOp == partitionOp)
1673
- return false ; // break
1675
+ return false ; // break
1674
1676
workingPartition.apply (partitionOp);
1675
1677
if (workingPartition.isTransferred (transferredVal) &&
1676
1678
!transferredReason) {
@@ -1880,7 +1882,8 @@ class PartitionAnalysis {
1880
1882
if (auto castExpr = dyn_cast<ImplicitConversionExpr>(expr))
1881
1883
return hasBeenEmitted (castExpr->getSubExpr ());
1882
1884
1883
- if (emittedExprs.contains (expr)) return true ;
1885
+ if (emittedExprs.contains (expr))
1886
+ return true ;
1884
1887
emittedExprs.insert (expr);
1885
1888
return false ;
1886
1889
}
@@ -1891,9 +1894,8 @@ class PartitionAnalysis {
1891
1894
void diagnose () {
1892
1895
assert (solved && " diagnose should not be called before solve" );
1893
1896
1894
- LLVM_DEBUG (
1895
- llvm::dbgs () << " Emitting diagnostics for function "
1896
- << function->getName () << " \n " );
1897
+ LLVM_DEBUG (llvm::dbgs () << " Emitting diagnostics for function "
1898
+ << function->getName () << " \n " );
1897
1899
RaceTracer tracer (function, blockStates);
1898
1900
1899
1901
for (auto [block, blockState] : blockStates) {
@@ -1960,7 +1962,8 @@ class PartitionAnalysis {
1960
1962
}
1961
1963
auto argExpr = transferOp.getSourceExpr ();
1962
1964
if (!argExpr)
1963
- assert (false && " sourceExpr should be populated for ApplyExpr consumptions" );
1965
+ assert (false &&
1966
+ " sourceExpr should be populated for ApplyExpr consumptions" );
1964
1967
1965
1968
function->getASTContext ()
1966
1969
.Diags
@@ -2003,14 +2006,14 @@ namespace {
2003
2006
// this class is the entry point to the region-based Sendable analysis,
2004
2007
// after certain checks are performed to ensure the analysis can be completed
2005
2008
// a PartitionAnalysis object is created and used to run the analysis.
2006
- class SendNonSendable : public SILFunctionTransform {
2009
+ class TransferNonSendable : public SILFunctionTransform {
2007
2010
// find any ApplyExprs in this function, and check if any of them make an
2008
2011
// unsatisfied isolation jump, emitting appropriate diagnostics if so
2009
2012
void run () override {
2010
2013
SILFunction *function = getFunction ();
2011
2014
2012
2015
if (!function->getASTContext ().LangOpts .hasFeature (
2013
- Feature::SendNonSendable ))
2016
+ Feature::TransferNonSendable ))
2014
2017
return ;
2015
2018
2016
2019
LLVM_DEBUG (llvm::dbgs ()
@@ -2024,9 +2027,9 @@ class SendNonSendable : public SILFunctionTransform {
2024
2027
return ;
2025
2028
}
2026
2029
2027
- // The sendable protocol should /always/ be available if SendNonSendable is
2028
- // enabled. If not, there is a major bug in the compiler and we should fail
2029
- // loudly.
2030
+ // The sendable protocol should /always/ be available if TransferNonSendable
2031
+ // is enabled. If not, there is a major bug in the compiler and we should
2032
+ // fail loudly.
2030
2033
if (!function->getASTContext ().getProtocol (KnownProtocolKind::Sendable))
2031
2034
llvm::report_fatal_error (" Sendable protocol not available!" );
2032
2035
@@ -2038,6 +2041,6 @@ class SendNonSendable : public SILFunctionTransform {
2038
2041
2039
2042
// / This pass is known to depend on the following passes having run before it:
2040
2043
// / none so far.
2041
- SILTransform *swift::createSendNonSendable () {
2042
- return new SendNonSendable ();
2044
+ SILTransform *swift::createTransferNonSendable () {
2045
+ return new TransferNonSendable ();
2043
2046
}
0 commit comments