@@ -94,77 +94,77 @@ static InFlightDiagnostic diagnose(const SILInstruction *inst, Diag<T...> diag,
94
94
95
95
namespace {
96
96
97
- enum class UseDiagnosticInfoKind {
98
- Invalid = 0 ,
97
+ class UseAfterTransferDiagnosticInferrer {
98
+ public:
99
+ enum class UseDiagnosticInfoKind {
100
+ Invalid = 0 ,
99
101
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 ,
102
104
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 ,
107
109
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 ,
111
113
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 ,
115
117
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
+ };
119
121
120
- class UseDiagnosticInfo {
121
- UseDiagnosticInfoKind kind;
122
- std::optional<ApplyIsolationCrossing> isolationCrossing;
122
+ class UseDiagnosticInfo {
123
+ UseDiagnosticInfoKind kind;
124
+ std::optional<ApplyIsolationCrossing> isolationCrossing;
123
125
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
+ }
130
132
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
+ }
137
139
138
- static UseDiagnosticInfo forIsolationCrossingWithUnknownIsolation () {
139
- return UseDiagnosticInfo (
140
- UseDiagnosticInfoKind::RaceWithoutKnownIsolationCrossing, {});
141
- }
140
+ static UseDiagnosticInfo forIsolationCrossingWithUnknownIsolation () {
141
+ return UseDiagnosticInfo (
142
+ UseDiagnosticInfoKind::RaceWithoutKnownIsolationCrossing, {});
143
+ }
142
144
143
- static UseDiagnosticInfo forAssignmentIntoTransferringParameter () {
144
- return UseDiagnosticInfo (
145
- UseDiagnosticInfoKind::AssignmentIntoTransferringParameter, {});
146
- }
145
+ static UseDiagnosticInfo forAssignmentIntoTransferringParameter () {
146
+ return UseDiagnosticInfo (
147
+ UseDiagnosticInfoKind::AssignmentIntoTransferringParameter, {});
148
+ }
147
149
148
- static UseDiagnosticInfo forUseOfStronglyTransferredValue () {
149
- return UseDiagnosticInfo (
150
- UseDiagnosticInfoKind::UseOfStronglyTransferredValue, {});
151
- }
150
+ static UseDiagnosticInfo forUseOfStronglyTransferredValue () {
151
+ return UseDiagnosticInfo (
152
+ UseDiagnosticInfoKind::UseOfStronglyTransferredValue, {});
153
+ }
152
154
153
- UseDiagnosticInfoKind getKind () const { return kind; }
155
+ UseDiagnosticInfoKind getKind () const { return kind; }
154
156
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
+ }
159
161
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
+ };
165
167
166
- class InferredCallerArgumentTypeInfo {
167
- public:
168
168
struct ApplyUse {
169
169
SILLocation loc;
170
170
Type inferredType;
@@ -183,8 +183,10 @@ class InferredCallerArgumentTypeInfo {
183
183
// / baseInferredType.
184
184
SmallVector<ApplyUse, 4 > applyUses;
185
185
186
+ struct Walker ;
187
+
186
188
public:
187
- InferredCallerArgumentTypeInfo (RegionAnalysisValueMap &valueMap)
189
+ UseAfterTransferDiagnosticInferrer (RegionAnalysisValueMap &valueMap)
188
190
: valueMap(valueMap) {}
189
191
void init (const Operand *op);
190
192
@@ -247,7 +249,7 @@ class InferredCallerArgumentTypeInfo {
247
249
248
250
} // namespace
249
251
250
- bool InferredCallerArgumentTypeInfo ::initForIsolatedPartialApply (
252
+ bool UseAfterTransferDiagnosticInferrer ::initForIsolatedPartialApply (
251
253
Operand *op, AbstractClosureExpr *ace) {
252
254
SmallVector<std::tuple<CapturedValue, unsigned , ApplyIsolationCrossing>, 8 >
253
255
foundCapturedIsolationCrossing;
@@ -268,13 +270,13 @@ bool InferredCallerArgumentTypeInfo::initForIsolatedPartialApply(
268
270
return false ;
269
271
}
270
272
271
- void InferredCallerArgumentTypeInfo ::initForApply (
273
+ void UseAfterTransferDiagnosticInferrer ::initForApply (
272
274
ApplyIsolationCrossing isolationCrossing) {
273
275
addApplyUse (UseDiagnosticInfo::forIsolationCrossing (isolationCrossing));
274
276
}
275
277
276
- void InferredCallerArgumentTypeInfo ::initForApply (const Operand *op,
277
- ApplyExpr *sourceApply) {
278
+ void UseAfterTransferDiagnosticInferrer ::initForApply (const Operand *op,
279
+ ApplyExpr *sourceApply) {
278
280
auto isolationCrossing = sourceApply->getIsolationCrossing ().value ();
279
281
280
282
// Grab out full apply site and see if we can find a better expr.
@@ -303,14 +305,13 @@ void InferredCallerArgumentTypeInfo::initForApply(const Operand *op,
303
305
UseDiagnosticInfo::forIsolationCrossing (isolationCrossing));
304
306
}
305
307
306
- namespace {
307
-
308
- struct Walker : ASTWalker {
309
- InferredCallerArgumentTypeInfo &foundTypeInfo;
308
+ struct UseAfterTransferDiagnosticInferrer ::Walker : ASTWalker {
309
+ UseAfterTransferDiagnosticInferrer &foundTypeInfo;
310
310
ValueDecl *targetDecl;
311
311
SmallPtrSet<Expr *, 8 > visitedCallExprDeclRefExprs;
312
312
313
- Walker (InferredCallerArgumentTypeInfo &foundTypeInfo, ValueDecl *targetDecl)
313
+ Walker (UseAfterTransferDiagnosticInferrer &foundTypeInfo,
314
+ ValueDecl *targetDecl)
314
315
: foundTypeInfo(foundTypeInfo), targetDecl(targetDecl) {}
315
316
316
317
Expr *lookThroughExpr (Expr *expr) {
@@ -378,8 +379,6 @@ struct Walker : ASTWalker {
378
379
}
379
380
};
380
381
381
- } // namespace
382
-
383
382
static SILValue getDestOfStoreOrCopyAddr (Operand *op) {
384
383
if (auto *si = dyn_cast<StoreInst>(op->getUser ()))
385
384
return si->getDest ();
@@ -390,7 +389,7 @@ static SILValue getDestOfStoreOrCopyAddr(Operand *op) {
390
389
return SILValue ();
391
390
}
392
391
393
- void InferredCallerArgumentTypeInfo ::init (const Operand *op) {
392
+ void UseAfterTransferDiagnosticInferrer ::init (const Operand *op) {
394
393
baseLoc = op->getUser ()->getLoc ();
395
394
baseInferredType = op->get ()->getType ().getASTType ();
396
395
auto *nonConstOp = const_cast <Operand *>(op);
@@ -807,21 +806,24 @@ void TransferNonSendableImpl::emitUseAfterTransferDiagnostics() {
807
806
++blockLivenessInfoGeneration;
808
807
liveness.process (requireInsts);
809
808
810
- InferredCallerArgumentTypeInfo argTypeInfo (regionInfo->getValueMap ());
811
- argTypeInfo.init (transferOp);
809
+ UseAfterTransferDiagnosticInferrer diagnosticInferrer (
810
+ regionInfo->getValueMap ());
811
+ diagnosticInferrer.init (transferOp);
812
812
813
813
// If we were supposed to emit an error and we failed to do so, emit a
814
814
// hard error so that the user knows to file a bug.
815
815
//
816
816
// DISCUSSION: We do this rather than asserting since users often times do
817
817
// not know what to do if the compiler crashes. This at least shows up in
818
818
// editor UIs providing a more actionable error message.
819
- auto applyUses = argTypeInfo .getApplyUses ();
819
+ auto applyUses = diagnosticInferrer .getApplyUses ();
820
820
if (applyUses.empty ()) {
821
821
diagnose (transferOp, diag::regionbasedisolation_unknown_pattern);
822
822
continue ;
823
823
}
824
824
825
+ using UseDiagnosticInfoKind =
826
+ UseAfterTransferDiagnosticInferrer::UseDiagnosticInfoKind;
825
827
for (auto &info : applyUses) {
826
828
switch (info.diagInfo .getKind ()) {
827
829
case UseDiagnosticInfoKind::Invalid:
0 commit comments