@@ -1947,6 +1947,15 @@ static void noteGlobalActorOnContext(DeclContext *dc, Type globalActor) {
19471947 }
19481948}
19491949
1950+ static bool shouldCheckSendable (Expr *expr) {
1951+ if (auto *declRef = dyn_cast<DeclRefExpr>(expr->findOriginalValue ())) {
1952+ auto isolation = getActorIsolation (declRef->getDecl ());
1953+ return isolation != ActorIsolation::NonisolatedUnsafe;
1954+ }
1955+
1956+ return true ;
1957+ }
1958+
19501959bool swift::diagnoseApplyArgSendability (ApplyExpr *apply, const DeclContext *declContext) {
19511960 auto isolationCrossing = apply->getIsolationCrossing ();
19521961 if (!isolationCrossing.has_value ())
@@ -1959,7 +1968,9 @@ bool swift::diagnoseApplyArgSendability(ApplyExpr *apply, const DeclContext *dec
19591968 // Check the 'self' argument.
19601969 if (auto *selfApply = dyn_cast<SelfApplyExpr>(apply->getFn ())) {
19611970 auto *base = selfApply->getBase ();
1962- if (diagnoseNonSendableTypes (
1971+
1972+ if (shouldCheckSendable (base) &&
1973+ diagnoseNonSendableTypes (
19631974 base->getType (),
19641975 declContext, base->getStartLoc (),
19651976 diag::non_sendable_call_argument,
@@ -1979,6 +1990,7 @@ bool swift::diagnoseApplyArgSendability(ApplyExpr *apply, const DeclContext *dec
19791990 // Dig out the location of the argument.
19801991 SourceLoc argLoc = apply->getLoc ();
19811992 Type argType;
1993+ bool checkSendable = true ;
19821994 if (auto argList = apply->getArgs ()) {
19831995 auto arg = argList->get (paramIdx);
19841996 if (arg.getStartLoc ().isValid ())
@@ -1987,11 +1999,13 @@ bool swift::diagnoseApplyArgSendability(ApplyExpr *apply, const DeclContext *dec
19871999 // Determine the type of the argument, ignoring any implicit
19882000 // conversions that could have stripped sendability.
19892001 if (Expr *argExpr = arg.getExpr ()) {
1990- argType = argExpr->findOriginalType ();
2002+ checkSendable = shouldCheckSendable (argExpr);
2003+ argType = argExpr->findOriginalType ();
19912004 }
19922005 }
19932006
1994- if (diagnoseNonSendableTypes (
2007+ if (checkSendable &&
2008+ diagnoseNonSendableTypes (
19952009 argType ? argType : param.getParameterType (),
19962010 declContext, argLoc, diag::non_sendable_call_argument,
19972011 isolationCrossing.value ().exitsIsolation (),
@@ -2812,6 +2826,11 @@ namespace {
28122826 if (getActorIsolation (value).isActorIsolated ())
28132827 return false ;
28142828
2829+ if (auto attr = value->getAttrs ().getAttribute <NonisolatedAttr>();
2830+ attr && attr->isUnsafe ()) {
2831+ return false ;
2832+ }
2833+
28152834 ctx.Diags .diagnose (loc, diag::shared_mutable_state_access, value);
28162835 value->diagnose (diag::kind_declared_here, value->getDescriptiveKind ());
28172836 return true ;
@@ -3275,6 +3294,11 @@ namespace {
32753294 }
32763295 }
32773296
3297+ if (auto attr = var->getAttrs ().getAttribute <NonisolatedAttr>();
3298+ attr && attr->isUnsafe ()) {
3299+ return false ;
3300+ }
3301+
32783302 // Otherwise, we have concurrent access. Complain.
32793303 bool preconcurrencyContext =
32803304 getActorIsolationOfContext (
0 commit comments