Skip to content

Commit cd3e6e3

Browse files
authored
Merge pull request #68752 from hborla/isolation-cleanup
[NFC][Concurrency] Minor cleanup for actor isolation.
2 parents 8dabec4 + 00ff491 commit cd3e6e3

File tree

2 files changed

+22
-40
lines changed

2 files changed

+22
-40
lines changed

include/swift/AST/ActorIsolation.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -240,26 +240,6 @@ bool isSameActorIsolated(ValueDecl *value, DeclContext *dc);
240240
/// Determines whether this function's body uses flow-sensitive isolation.
241241
bool usesFlowSensitiveIsolation(AbstractFunctionDecl const *fn);
242242

243-
/// Check if it is safe for the \c globalActor qualifier to be removed from
244-
/// \c ty, when the function value of that type is isolated to that actor.
245-
///
246-
/// In general this is safe in a narrow but common case: a global actor
247-
/// qualifier can be dropped from a function type while in a DeclContext
248-
/// isolated to that same actor, as long as the value is not Sendable.
249-
///
250-
/// \param dc the innermost context in which the cast to remove the global actor
251-
/// is happening.
252-
/// \param globalActor global actor that was dropped from \c ty.
253-
/// \param ty a function type where \c globalActor was removed from it.
254-
/// \param getClosureActorIsolation function that knows how to produce accurate
255-
/// information about the isolation of a closure.
256-
/// \return true if it is safe to drop the global-actor qualifier.
257-
bool safeToDropGlobalActor(
258-
DeclContext *dc, Type globalActor, Type ty,
259-
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
260-
getClosureActorIsolation =
261-
__AbstractClosureExpr_getActorIsolation);
262-
263243
void simple_display(llvm::raw_ostream &out, const ActorIsolation &state);
264244

265245
} // end namespace swift

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)