@@ -1787,10 +1787,20 @@ bool swift::isAsyncDecl(ConcreteDeclRef declRef) {
17871787 return false ;
17881788}
17891789
1790- bool swift::safeToDropGlobalActor (
1791- DeclContext *dc, Type globalActor, Type ty,
1792- llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
1793- getClosureActorIsolation) {
1790+ // / Check if it is safe for the \c globalActor qualifier to be removed from
1791+ // / \c ty, when the function value of that type is isolated to that actor.
1792+ // /
1793+ // / In general this is safe in a narrow but common case: a global actor
1794+ // / qualifier can be dropped from a function type while in a DeclContext
1795+ // / isolated to that same actor, as long as the value is not Sendable.
1796+ // /
1797+ // / \param dc the innermost context in which the cast to remove the global actor
1798+ // / is happening.
1799+ // / \param globalActor global actor that was dropped from \c ty.
1800+ // / \param ty a function type where \c globalActor was removed from it.
1801+ // / \return true if it is safe to drop the global-actor qualifier.
1802+ static bool safeToDropGlobalActor (
1803+ DeclContext *dc, Type globalActor, Type ty) {
17941804 auto funcTy = ty->getAs <AnyFunctionType>();
17951805 if (!funcTy)
17961806 return false ;
@@ -1813,7 +1823,7 @@ bool swift::safeToDropGlobalActor(
18131823 return false ;
18141824
18151825 // finally, must be in a context with matching isolation.
1816- auto dcIsolation = getActorIsolationOfContext (dc, getClosureActorIsolation );
1826+ auto dcIsolation = getActorIsolationOfContext (dc);
18171827 if (dcIsolation.isGlobalActor ())
18181828 if (dcIsolation.getGlobalActor ()->getCanonicalType ()
18191829 == globalActor->getCanonicalType ())
@@ -2100,21 +2110,13 @@ namespace {
21002110
21012111 auto dc = const_cast <DeclContext*>(getDeclContext ());
21022112 if (!safeToDropGlobalActor (dc, fromActor, toType)) {
2103- // FIXME: this diagnostic is sometimes a duplicate of one emitted
2104- // by the constraint solver. Difference is the solver doesn't use
2105- // warnUntilSwiftVersion, which appends extra text on the end.
2106- // So, I'm making the messages exactly the same so IDEs will
2107- // hopefully ignore the second diagnostic!
2108-
2109- // otherwise, it's not a safe cast.
2110- dc->getASTContext ()
2111- .Diags
2112- .diagnose (funcConv->getLoc (),
2113- diag::converting_func_loses_global_actor, fromType,
2114- toType, fromActor)
2115- .limitBehavior (dc->getASTContext ().isSwiftVersionAtLeast (6 )
2116- ? DiagnosticBehavior::Error
2117- : DiagnosticBehavior::Warning);
2113+ // otherwise, it's not a safe cast.
2114+ dc->getASTContext ()
2115+ .Diags
2116+ .diagnose (funcConv->getLoc (),
2117+ diag::converting_func_loses_global_actor, fromType,
2118+ toType, fromActor)
2119+ .warnUntilSwiftVersion (6 );
21182120 }
21192121 }
21202122 }
0 commit comments