@@ -94,39 +94,23 @@ static SILValue stripFunctionConversions(SILValue val) {
94
94
}
95
95
96
96
static std::optional<DiagnosticBehavior>
97
- getDiagnosticBehaviorLimitForValue (SILValue value) {
98
- auto *nom = value->getType ().getNominalOrBoundGenericNominal ();
99
- if (!nom)
100
- return {};
101
-
102
- auto declRef = value->getFunction ()->getDeclRef ();
103
- if (!declRef)
104
- return {};
105
-
106
- auto *fromDC = declRef.getInnermostDeclContext ();
107
- return getConcurrencyDiagnosticBehaviorLimit (nom, fromDC);
108
- }
109
-
110
- static std::optional<DiagnosticBehavior>
111
- getDiagnosticBehaviorLimitForCapturedValue (CapturedValue value) {
97
+ getDiagnosticBehaviorLimitForCapturedValue (SILFunction *fn,
98
+ CapturedValue value) {
112
99
ValueDecl *decl = value.getDecl ();
113
- auto *nom = decl->getInterfaceType ()->getNominalOrBoundGenericNominal ();
114
- if (!nom)
115
- return {};
116
-
117
- auto *fromDC = decl->getInnermostDeclContext ();
118
- return getConcurrencyDiagnosticBehaviorLimit (nom, fromDC);
100
+ auto *ctx = decl->getInnermostDeclContext ();
101
+ auto type = fn->mapTypeIntoContext (decl->getInterfaceType ());
102
+ return type->getConcurrencyDiagnosticBehaviorLimit (ctx);
119
103
}
120
104
121
105
// / Find the most conservative diagnostic behavior by taking the max over all
122
106
// / DiagnosticBehavior for the captured values.
123
107
static std::optional<DiagnosticBehavior>
124
108
getDiagnosticBehaviorLimitForCapturedValues (
125
- ArrayRef<CapturedValue> capturedValues) {
109
+ SILFunction *fn, ArrayRef<CapturedValue> capturedValues) {
126
110
std::optional<DiagnosticBehavior> diagnosticBehavior;
127
111
for (auto value : capturedValues) {
128
112
auto lhs = diagnosticBehavior.value_or (DiagnosticBehavior::Unspecified);
129
- auto rhs = getDiagnosticBehaviorLimitForCapturedValue (value).value_or (
113
+ auto rhs = getDiagnosticBehaviorLimitForCapturedValue (fn, value).value_or (
130
114
DiagnosticBehavior::Unspecified);
131
115
auto result = lhs.merge (rhs);
132
116
if (result != DiagnosticBehavior::Unspecified)
@@ -668,8 +652,11 @@ class UseAfterTransferDiagnosticEmitter {
668
652
emitUnknownPatternError ();
669
653
}
670
654
655
+ SILFunction *getFunction () const { return transferOp->getFunction (); }
656
+
671
657
std::optional<DiagnosticBehavior> getBehaviorLimit () const {
672
- return getDiagnosticBehaviorLimitForValue (transferOp->get ());
658
+ return transferOp->get ()->getType ().getConcurrencyDiagnosticBehavior (
659
+ getFunction ());
673
660
}
674
661
675
662
// / If we can find a callee decl name, return that. None otherwise.
@@ -1329,6 +1316,8 @@ class TransferNonTransferrableDiagnosticEmitter {
1329
1316
1330
1317
Operand *getOperand () const { return info.transferredOperand ; }
1331
1318
1319
+ SILFunction *getFunction () const { return getOperand ()->getFunction (); }
1320
+
1332
1321
SILValue getNonTransferrableValue () const {
1333
1322
return info.nonTransferrable .dyn_cast <SILValue>();
1334
1323
}
@@ -1338,7 +1327,9 @@ class TransferNonTransferrableDiagnosticEmitter {
1338
1327
}
1339
1328
1340
1329
std::optional<DiagnosticBehavior> getBehaviorLimit () const {
1341
- return getDiagnosticBehaviorLimitForValue (info.transferredOperand ->get ());
1330
+ return info.transferredOperand ->get ()
1331
+ ->getType ()
1332
+ .getConcurrencyDiagnosticBehavior (getOperand ()->getFunction ());
1342
1333
}
1343
1334
1344
1335
// / If we can find a callee decl name, return that. None otherwise.
@@ -1460,8 +1451,8 @@ class TransferNonTransferrableDiagnosticEmitter {
1460
1451
diag::regionbasedisolation_typed_tns_passed_sending_closure,
1461
1452
descriptiveKindStr)
1462
1453
.highlight (loc.getSourceRange ())
1463
- .limitBehaviorIf (
1464
- getDiagnosticBehaviorLimitForCapturedValue ( capturedValue));
1454
+ .limitBehaviorIf (getDiagnosticBehaviorLimitForCapturedValue (
1455
+ getFunction (), capturedValue));
1465
1456
1466
1457
auto capturedLoc = RegularLocation (capturedValue.getLoc ());
1467
1458
if (getIsolationRegionInfo ().getIsolationInfo ().isTaskIsolated ()) {
@@ -1496,8 +1487,8 @@ class TransferNonTransferrableDiagnosticEmitter {
1496
1487
}
1497
1488
}
1498
1489
1499
- auto behaviorLimit =
1500
- getDiagnosticBehaviorLimitForCapturedValues ( capturedValues);
1490
+ auto behaviorLimit = getDiagnosticBehaviorLimitForCapturedValues (
1491
+ getFunction (), capturedValues);
1501
1492
diagnoseError (loc,
1502
1493
diag::regionbasedisolation_typed_tns_passed_sending_closure,
1503
1494
descriptiveKindStr)
@@ -2059,8 +2050,13 @@ class InOutSendingNotDisconnectedDiagnosticEmitter {
2059
2050
emitUnknownPatternError ();
2060
2051
}
2061
2052
2053
+ SILFunction *getFunction () const {
2054
+ return info.inoutSendingParam ->getFunction ();
2055
+ }
2056
+
2062
2057
std::optional<DiagnosticBehavior> getBehaviorLimit () const {
2063
- return getDiagnosticBehaviorLimitForValue (info.inoutSendingParam );
2058
+ return info.inoutSendingParam ->getType ().getConcurrencyDiagnosticBehavior (
2059
+ getFunction ());
2064
2060
}
2065
2061
2066
2062
void emitUnknownPatternError () {
@@ -2178,8 +2174,11 @@ class AssignIsolatedIntoSendingResultDiagnosticEmitter {
2178
2174
emitUnknownPatternError ();
2179
2175
}
2180
2176
2181
- std::optional<DiagnosticBehavior> getBehaviorLimit () const {
2182
- return getDiagnosticBehaviorLimitForValue (info.outSendingResult );
2177
+ SILFunction *getFunction () const { return info.srcOperand ->getFunction (); }
2178
+
2179
+ std::optional<DiagnosticBehavior> getConcurrencyDiagnosticBehavior () const {
2180
+ return info.outSendingResult ->getType ().getConcurrencyDiagnosticBehavior (
2181
+ getFunction ());
2183
2182
}
2184
2183
2185
2184
void emitUnknownPatternError () {
@@ -2190,7 +2189,7 @@ class AssignIsolatedIntoSendingResultDiagnosticEmitter {
2190
2189
2191
2190
diagnoseError (info.srcOperand ->getUser (),
2192
2191
diag::regionbasedisolation_unknown_pattern)
2193
- .limitBehaviorIf (getBehaviorLimit ());
2192
+ .limitBehaviorIf (getConcurrencyDiagnosticBehavior ());
2194
2193
}
2195
2194
2196
2195
void emit ();
@@ -2326,7 +2325,7 @@ void AssignIsolatedIntoSendingResultDiagnosticEmitter::emit() {
2326
2325
info.srcOperand ,
2327
2326
diag::regionbasedisolation_out_sending_cannot_be_actor_isolated_named,
2328
2327
*varName, descriptiveKindStr)
2329
- .limitBehaviorIf (getBehaviorLimit ());
2328
+ .limitBehaviorIf (getConcurrencyDiagnosticBehavior ());
2330
2329
2331
2330
diagnoseNote (
2332
2331
info.srcOperand ,
@@ -2342,7 +2341,7 @@ void AssignIsolatedIntoSendingResultDiagnosticEmitter::emit() {
2342
2341
info.srcOperand ,
2343
2342
diag::regionbasedisolation_out_sending_cannot_be_actor_isolated_type,
2344
2343
type, descriptiveKindStr)
2345
- .limitBehaviorIf (getBehaviorLimit ());
2344
+ .limitBehaviorIf (getConcurrencyDiagnosticBehavior ());
2346
2345
2347
2346
diagnoseNote (
2348
2347
info.srcOperand ,
0 commit comments