@@ -94,39 +94,23 @@ static SILValue stripFunctionConversions(SILValue val) {
9494}
9595
9696static 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) {
11299 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);
119103}
120104
121105// / Find the most conservative diagnostic behavior by taking the max over all
122106// / DiagnosticBehavior for the captured values.
123107static std::optional<DiagnosticBehavior>
124108getDiagnosticBehaviorLimitForCapturedValues (
125- ArrayRef<CapturedValue> capturedValues) {
109+ SILFunction *fn, ArrayRef<CapturedValue> capturedValues) {
126110 std::optional<DiagnosticBehavior> diagnosticBehavior;
127111 for (auto value : capturedValues) {
128112 auto lhs = diagnosticBehavior.value_or (DiagnosticBehavior::Unspecified);
129- auto rhs = getDiagnosticBehaviorLimitForCapturedValue (value).value_or (
113+ auto rhs = getDiagnosticBehaviorLimitForCapturedValue (fn, value).value_or (
130114 DiagnosticBehavior::Unspecified);
131115 auto result = lhs.merge (rhs);
132116 if (result != DiagnosticBehavior::Unspecified)
@@ -668,8 +652,11 @@ class UseAfterTransferDiagnosticEmitter {
668652 emitUnknownPatternError ();
669653 }
670654
655+ SILFunction *getFunction () const { return transferOp->getFunction (); }
656+
671657 std::optional<DiagnosticBehavior> getBehaviorLimit () const {
672- return getDiagnosticBehaviorLimitForValue (transferOp->get ());
658+ return transferOp->get ()->getType ().getConcurrencyDiagnosticBehavior (
659+ getFunction ());
673660 }
674661
675662 // / If we can find a callee decl name, return that. None otherwise.
@@ -1329,6 +1316,8 @@ class TransferNonTransferrableDiagnosticEmitter {
13291316
13301317 Operand *getOperand () const { return info.transferredOperand ; }
13311318
1319+ SILFunction *getFunction () const { return getOperand ()->getFunction (); }
1320+
13321321 SILValue getNonTransferrableValue () const {
13331322 return info.nonTransferrable .dyn_cast <SILValue>();
13341323 }
@@ -1338,7 +1327,9 @@ class TransferNonTransferrableDiagnosticEmitter {
13381327 }
13391328
13401329 std::optional<DiagnosticBehavior> getBehaviorLimit () const {
1341- return getDiagnosticBehaviorLimitForValue (info.transferredOperand ->get ());
1330+ return info.transferredOperand ->get ()
1331+ ->getType ()
1332+ .getConcurrencyDiagnosticBehavior (getOperand ()->getFunction ());
13421333 }
13431334
13441335 // / If we can find a callee decl name, return that. None otherwise.
@@ -1460,8 +1451,8 @@ class TransferNonTransferrableDiagnosticEmitter {
14601451 diag::regionbasedisolation_typed_tns_passed_sending_closure,
14611452 descriptiveKindStr)
14621453 .highlight (loc.getSourceRange ())
1463- .limitBehaviorIf (
1464- getDiagnosticBehaviorLimitForCapturedValue ( capturedValue));
1454+ .limitBehaviorIf (getDiagnosticBehaviorLimitForCapturedValue (
1455+ getFunction (), capturedValue));
14651456
14661457 auto capturedLoc = RegularLocation (capturedValue.getLoc ());
14671458 if (getIsolationRegionInfo ().getIsolationInfo ().isTaskIsolated ()) {
@@ -1496,8 +1487,8 @@ class TransferNonTransferrableDiagnosticEmitter {
14961487 }
14971488 }
14981489
1499- auto behaviorLimit =
1500- getDiagnosticBehaviorLimitForCapturedValues ( capturedValues);
1490+ auto behaviorLimit = getDiagnosticBehaviorLimitForCapturedValues (
1491+ getFunction (), capturedValues);
15011492 diagnoseError (loc,
15021493 diag::regionbasedisolation_typed_tns_passed_sending_closure,
15031494 descriptiveKindStr)
@@ -2059,8 +2050,13 @@ class InOutSendingNotDisconnectedDiagnosticEmitter {
20592050 emitUnknownPatternError ();
20602051 }
20612052
2053+ SILFunction *getFunction () const {
2054+ return info.inoutSendingParam ->getFunction ();
2055+ }
2056+
20622057 std::optional<DiagnosticBehavior> getBehaviorLimit () const {
2063- return getDiagnosticBehaviorLimitForValue (info.inoutSendingParam );
2058+ return info.inoutSendingParam ->getType ().getConcurrencyDiagnosticBehavior (
2059+ getFunction ());
20642060 }
20652061
20662062 void emitUnknownPatternError () {
@@ -2178,8 +2174,11 @@ class AssignIsolatedIntoSendingResultDiagnosticEmitter {
21782174 emitUnknownPatternError ();
21792175 }
21802176
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 ());
21832182 }
21842183
21852184 void emitUnknownPatternError () {
@@ -2190,7 +2189,7 @@ class AssignIsolatedIntoSendingResultDiagnosticEmitter {
21902189
21912190 diagnoseError (info.srcOperand ->getUser (),
21922191 diag::regionbasedisolation_unknown_pattern)
2193- .limitBehaviorIf (getBehaviorLimit ());
2192+ .limitBehaviorIf (getConcurrencyDiagnosticBehavior ());
21942193 }
21952194
21962195 void emit ();
@@ -2326,7 +2325,7 @@ void AssignIsolatedIntoSendingResultDiagnosticEmitter::emit() {
23262325 info.srcOperand ,
23272326 diag::regionbasedisolation_out_sending_cannot_be_actor_isolated_named,
23282327 *varName, descriptiveKindStr)
2329- .limitBehaviorIf (getBehaviorLimit ());
2328+ .limitBehaviorIf (getConcurrencyDiagnosticBehavior ());
23302329
23312330 diagnoseNote (
23322331 info.srcOperand ,
@@ -2342,7 +2341,7 @@ void AssignIsolatedIntoSendingResultDiagnosticEmitter::emit() {
23422341 info.srcOperand ,
23432342 diag::regionbasedisolation_out_sending_cannot_be_actor_isolated_type,
23442343 type, descriptiveKindStr)
2345- .limitBehaviorIf (getBehaviorLimit ());
2344+ .limitBehaviorIf (getConcurrencyDiagnosticBehavior ());
23462345
23472346 diagnoseNote (
23482347 info.srcOperand ,
0 commit comments