@@ -94,77 +94,77 @@ static InFlightDiagnostic diagnose(const SILInstruction *inst, Diag<T...> diag,
9494
9595namespace {
9696
97- enum class UseDiagnosticInfoKind {
98- Invalid = 0 ,
97+ class UseAfterTransferDiagnosticInferrer {
98+ public:
99+ enum class UseDiagnosticInfoKind {
100+ Invalid = 0 ,
99101
100- // / Used if we have an isolation crossing for our error.
101- IsolationCrossing = 1 ,
102+ // / Used if we have an isolation crossing for our error.
103+ IsolationCrossing = 1 ,
102104
103- // / In certain cases, we think a race can happen, but we couldn't find the
104- // / isolation crossing specifically to emit a better error. Still emit an
105- // / error though.
106- RaceWithoutKnownIsolationCrossing = 2 ,
105+ // / In certain cases, we think a race can happen, but we couldn't find the
106+ // / isolation crossing specifically to emit a better error. Still emit an
107+ // / error though.
108+ RaceWithoutKnownIsolationCrossing = 2 ,
107109
108- // / Used if the error is due to a transfer into an assignment into a
109- // / transferring parameter.
110- AssignmentIntoTransferringParameter = 3 ,
110+ // / Used if the error is due to a transfer into an assignment into a
111+ // / transferring parameter.
112+ AssignmentIntoTransferringParameter = 3 ,
111113
112- // / Set to true if this is a use of a normal value that was strongly
113- // / transferred.
114- UseOfStronglyTransferredValue = 4 ,
114+ // / Set to true if this is a use of a normal value that was strongly
115+ // / transferred.
116+ UseOfStronglyTransferredValue = 4 ,
115117
116- // / We transferred the value by capturing the value in an isolated closure.
117- IsolationCrossingDueToCapture = 5 ,
118- };
118+ // / We transferred the value by capturing the value in an isolated closure.
119+ IsolationCrossingDueToCapture = 5 ,
120+ };
119121
120- class UseDiagnosticInfo {
121- UseDiagnosticInfoKind kind;
122- std::optional<ApplyIsolationCrossing> isolationCrossing;
122+ class UseDiagnosticInfo {
123+ UseDiagnosticInfoKind kind;
124+ std::optional<ApplyIsolationCrossing> isolationCrossing;
123125
124- public:
125- static UseDiagnosticInfo
126- forIsolationCrossing (ApplyIsolationCrossing isolationCrossing) {
127- return UseDiagnosticInfo (UseDiagnosticInfoKind::IsolationCrossing,
128- isolationCrossing);
129- }
126+ public:
127+ static UseDiagnosticInfo
128+ forIsolationCrossing (ApplyIsolationCrossing isolationCrossing) {
129+ return UseDiagnosticInfo (UseDiagnosticInfoKind::IsolationCrossing,
130+ isolationCrossing);
131+ }
130132
131- static UseDiagnosticInfo
132- forIsolationCrossingDueToCapture (ApplyIsolationCrossing isolationCrossing) {
133- return UseDiagnosticInfo (
134- UseDiagnosticInfoKind::IsolationCrossingDueToCapture,
135- isolationCrossing);
136- }
133+ static UseDiagnosticInfo
134+ forIsolationCrossingDueToCapture (ApplyIsolationCrossing isolationCrossing) {
135+ return UseDiagnosticInfo (
136+ UseDiagnosticInfoKind::IsolationCrossingDueToCapture,
137+ isolationCrossing);
138+ }
137139
138- static UseDiagnosticInfo forIsolationCrossingWithUnknownIsolation () {
139- return UseDiagnosticInfo (
140- UseDiagnosticInfoKind::RaceWithoutKnownIsolationCrossing, {});
141- }
140+ static UseDiagnosticInfo forIsolationCrossingWithUnknownIsolation () {
141+ return UseDiagnosticInfo (
142+ UseDiagnosticInfoKind::RaceWithoutKnownIsolationCrossing, {});
143+ }
142144
143- static UseDiagnosticInfo forAssignmentIntoTransferringParameter () {
144- return UseDiagnosticInfo (
145- UseDiagnosticInfoKind::AssignmentIntoTransferringParameter, {});
146- }
145+ static UseDiagnosticInfo forAssignmentIntoTransferringParameter () {
146+ return UseDiagnosticInfo (
147+ UseDiagnosticInfoKind::AssignmentIntoTransferringParameter, {});
148+ }
147149
148- static UseDiagnosticInfo forUseOfStronglyTransferredValue () {
149- return UseDiagnosticInfo (
150- UseDiagnosticInfoKind::UseOfStronglyTransferredValue, {});
151- }
150+ static UseDiagnosticInfo forUseOfStronglyTransferredValue () {
151+ return UseDiagnosticInfo (
152+ UseDiagnosticInfoKind::UseOfStronglyTransferredValue, {});
153+ }
152154
153- UseDiagnosticInfoKind getKind () const { return kind; }
155+ UseDiagnosticInfoKind getKind () const { return kind; }
154156
155- ApplyIsolationCrossing getIsolationCrossing () const {
156- // assert(isolationCrossing && "Isolation crossing must be non-null");
157- return isolationCrossing.value ();
158- }
157+ ApplyIsolationCrossing getIsolationCrossing () const {
158+ // assert(isolationCrossing && "Isolation crossing must be non-null");
159+ return isolationCrossing.value ();
160+ }
159161
160- private:
161- UseDiagnosticInfo (UseDiagnosticInfoKind kind,
162- std::optional<ApplyIsolationCrossing> isolationCrossing)
163- : kind(kind), isolationCrossing(isolationCrossing) {}
164- };
162+ private:
163+ UseDiagnosticInfo (UseDiagnosticInfoKind kind,
164+ std::optional<ApplyIsolationCrossing> isolationCrossing)
165+ : kind(kind), isolationCrossing(isolationCrossing) {}
166+ };
165167
166- class InferredCallerArgumentTypeInfo {
167- public:
168168 struct ApplyUse {
169169 SILLocation loc;
170170 Type inferredType;
@@ -183,8 +183,10 @@ class InferredCallerArgumentTypeInfo {
183183 // / baseInferredType.
184184 SmallVector<ApplyUse, 4 > applyUses;
185185
186+ struct Walker ;
187+
186188public:
187- InferredCallerArgumentTypeInfo (RegionAnalysisValueMap &valueMap)
189+ UseAfterTransferDiagnosticInferrer (RegionAnalysisValueMap &valueMap)
188190 : valueMap(valueMap) {}
189191 void init (const Operand *op);
190192
@@ -247,7 +249,7 @@ class InferredCallerArgumentTypeInfo {
247249
248250} // namespace
249251
250- bool InferredCallerArgumentTypeInfo ::initForIsolatedPartialApply (
252+ bool UseAfterTransferDiagnosticInferrer ::initForIsolatedPartialApply (
251253 Operand *op, AbstractClosureExpr *ace) {
252254 SmallVector<std::tuple<CapturedValue, unsigned , ApplyIsolationCrossing>, 8 >
253255 foundCapturedIsolationCrossing;
@@ -268,13 +270,13 @@ bool InferredCallerArgumentTypeInfo::initForIsolatedPartialApply(
268270 return false ;
269271}
270272
271- void InferredCallerArgumentTypeInfo ::initForApply (
273+ void UseAfterTransferDiagnosticInferrer ::initForApply (
272274 ApplyIsolationCrossing isolationCrossing) {
273275 addApplyUse (UseDiagnosticInfo::forIsolationCrossing (isolationCrossing));
274276}
275277
276- void InferredCallerArgumentTypeInfo ::initForApply (const Operand *op,
277- ApplyExpr *sourceApply) {
278+ void UseAfterTransferDiagnosticInferrer ::initForApply (const Operand *op,
279+ ApplyExpr *sourceApply) {
278280 auto isolationCrossing = sourceApply->getIsolationCrossing ().value ();
279281
280282 // Grab out full apply site and see if we can find a better expr.
@@ -303,14 +305,13 @@ void InferredCallerArgumentTypeInfo::initForApply(const Operand *op,
303305 UseDiagnosticInfo::forIsolationCrossing (isolationCrossing));
304306}
305307
306- namespace {
307-
308- struct Walker : ASTWalker {
309- InferredCallerArgumentTypeInfo &foundTypeInfo;
308+ struct UseAfterTransferDiagnosticInferrer ::Walker : ASTWalker {
309+ UseAfterTransferDiagnosticInferrer &foundTypeInfo;
310310 ValueDecl *targetDecl;
311311 SmallPtrSet<Expr *, 8 > visitedCallExprDeclRefExprs;
312312
313- Walker (InferredCallerArgumentTypeInfo &foundTypeInfo, ValueDecl *targetDecl)
313+ Walker (UseAfterTransferDiagnosticInferrer &foundTypeInfo,
314+ ValueDecl *targetDecl)
314315 : foundTypeInfo(foundTypeInfo), targetDecl(targetDecl) {}
315316
316317 Expr *lookThroughExpr (Expr *expr) {
@@ -378,8 +379,6 @@ struct Walker : ASTWalker {
378379 }
379380};
380381
381- } // namespace
382-
383382static SILValue getDestOfStoreOrCopyAddr (Operand *op) {
384383 if (auto *si = dyn_cast<StoreInst>(op->getUser ()))
385384 return si->getDest ();
@@ -390,7 +389,7 @@ static SILValue getDestOfStoreOrCopyAddr(Operand *op) {
390389 return SILValue ();
391390}
392391
393- void InferredCallerArgumentTypeInfo ::init (const Operand *op) {
392+ void UseAfterTransferDiagnosticInferrer ::init (const Operand *op) {
394393 baseLoc = op->getUser ()->getLoc ();
395394 baseInferredType = op->get ()->getType ().getASTType ();
396395 auto *nonConstOp = const_cast <Operand *>(op);
@@ -807,21 +806,24 @@ void TransferNonSendableImpl::emitUseAfterTransferDiagnostics() {
807806 ++blockLivenessInfoGeneration;
808807 liveness.process (requireInsts);
809808
810- InferredCallerArgumentTypeInfo argTypeInfo (regionInfo->getValueMap ());
811- argTypeInfo.init (transferOp);
809+ UseAfterTransferDiagnosticInferrer diagnosticInferrer (
810+ regionInfo->getValueMap ());
811+ diagnosticInferrer.init (transferOp);
812812
813813 // If we were supposed to emit an error and we failed to do so, emit a
814814 // hard error so that the user knows to file a bug.
815815 //
816816 // DISCUSSION: We do this rather than asserting since users often times do
817817 // not know what to do if the compiler crashes. This at least shows up in
818818 // editor UIs providing a more actionable error message.
819- auto applyUses = argTypeInfo .getApplyUses ();
819+ auto applyUses = diagnosticInferrer .getApplyUses ();
820820 if (applyUses.empty ()) {
821821 diagnose (transferOp, diag::regionbasedisolation_unknown_pattern);
822822 continue ;
823823 }
824824
825+ using UseDiagnosticInfoKind =
826+ UseAfterTransferDiagnosticInferrer::UseDiagnosticInfoKind;
825827 for (auto &info : applyUses) {
826828 switch (info.diagInfo .getKind ()) {
827829 case UseDiagnosticInfoKind::Invalid:
0 commit comments