@@ -1787,10 +1787,20 @@ bool swift::isAsyncDecl(ConcreteDeclRef declRef) {
1787
1787
return false ;
1788
1788
}
1789
1789
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) {
1794
1804
auto funcTy = ty->getAs <AnyFunctionType>();
1795
1805
if (!funcTy)
1796
1806
return false ;
@@ -1813,7 +1823,7 @@ bool swift::safeToDropGlobalActor(
1813
1823
return false ;
1814
1824
1815
1825
// finally, must be in a context with matching isolation.
1816
- auto dcIsolation = getActorIsolationOfContext (dc, getClosureActorIsolation );
1826
+ auto dcIsolation = getActorIsolationOfContext (dc);
1817
1827
if (dcIsolation.isGlobalActor ())
1818
1828
if (dcIsolation.getGlobalActor ()->getCanonicalType ()
1819
1829
== globalActor->getCanonicalType ())
@@ -2100,21 +2110,13 @@ namespace {
2100
2110
2101
2111
auto dc = const_cast <DeclContext*>(getDeclContext ());
2102
2112
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 );
2118
2120
}
2119
2121
}
2120
2122
}
0 commit comments