Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions include/swift/AST/ActorIsolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,26 +240,6 @@ bool isSameActorIsolated(ValueDecl *value, DeclContext *dc);
/// Determines whether this function's body uses flow-sensitive isolation.
bool usesFlowSensitiveIsolation(AbstractFunctionDecl const *fn);

/// Check if it is safe for the \c globalActor qualifier to be removed from
/// \c ty, when the function value of that type is isolated to that actor.
///
/// In general this is safe in a narrow but common case: a global actor
/// qualifier can be dropped from a function type while in a DeclContext
/// isolated to that same actor, as long as the value is not Sendable.
///
/// \param dc the innermost context in which the cast to remove the global actor
/// is happening.
/// \param globalActor global actor that was dropped from \c ty.
/// \param ty a function type where \c globalActor was removed from it.
/// \param getClosureActorIsolation function that knows how to produce accurate
/// information about the isolation of a closure.
/// \return true if it is safe to drop the global-actor qualifier.
bool safeToDropGlobalActor(
DeclContext *dc, Type globalActor, Type ty,
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
getClosureActorIsolation =
__AbstractClosureExpr_getActorIsolation);

void simple_display(llvm::raw_ostream &out, const ActorIsolation &state);

} // end namespace swift
Expand Down
17 changes: 0 additions & 17 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2938,23 +2938,6 @@ bool ConstraintSystem::hasPreconcurrencyCallee(
return calleeOverload->choice.getDecl()->preconcurrency();
}

/// Determines whether a DeclContext is preconcurrency, using information
/// tracked by the solver to aid in answering that.
static bool isPreconcurrency(ConstraintSystem &cs, DeclContext *dc) {
if (auto *decl = dc->getAsDecl())
return decl->preconcurrency();

if (auto *ce = dyn_cast<ClosureExpr>(dc)) {
return ClosureIsolatedByPreconcurrency{cs}(ce);
}

if (auto *autoClos = dyn_cast<AutoClosureExpr>(dc)) {
return isPreconcurrency(cs, autoClos->getParent());
}

llvm_unreachable("unhandled DeclContext kind in isPreconcurrency");
}

ConstraintSystem::TypeMatchResult
ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
ConstraintKind kind, TypeMatchOptions flags,
Expand Down
42 changes: 22 additions & 20 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1787,10 +1787,20 @@ bool swift::isAsyncDecl(ConcreteDeclRef declRef) {
return false;
}

bool swift::safeToDropGlobalActor(
DeclContext *dc, Type globalActor, Type ty,
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
getClosureActorIsolation) {
/// Check if it is safe for the \c globalActor qualifier to be removed from
/// \c ty, when the function value of that type is isolated to that actor.
///
/// In general this is safe in a narrow but common case: a global actor
/// qualifier can be dropped from a function type while in a DeclContext
/// isolated to that same actor, as long as the value is not Sendable.
///
/// \param dc the innermost context in which the cast to remove the global actor
/// is happening.
/// \param globalActor global actor that was dropped from \c ty.
/// \param ty a function type where \c globalActor was removed from it.
/// \return true if it is safe to drop the global-actor qualifier.
static bool safeToDropGlobalActor(
DeclContext *dc, Type globalActor, Type ty) {
auto funcTy = ty->getAs<AnyFunctionType>();
if (!funcTy)
return false;
Expand All @@ -1813,7 +1823,7 @@ bool swift::safeToDropGlobalActor(
return false;

// finally, must be in a context with matching isolation.
auto dcIsolation = getActorIsolationOfContext(dc, getClosureActorIsolation);
auto dcIsolation = getActorIsolationOfContext(dc);
if (dcIsolation.isGlobalActor())
if (dcIsolation.getGlobalActor()->getCanonicalType()
== globalActor->getCanonicalType())
Expand Down Expand Up @@ -2100,21 +2110,13 @@ namespace {

auto dc = const_cast<DeclContext*>(getDeclContext());
if (!safeToDropGlobalActor(dc, fromActor, toType)) {
// FIXME: this diagnostic is sometimes a duplicate of one emitted
// by the constraint solver. Difference is the solver doesn't use
// warnUntilSwiftVersion, which appends extra text on the end.
// So, I'm making the messages exactly the same so IDEs will
// hopefully ignore the second diagnostic!

// otherwise, it's not a safe cast.
dc->getASTContext()
.Diags
.diagnose(funcConv->getLoc(),
diag::converting_func_loses_global_actor, fromType,
toType, fromActor)
.limitBehavior(dc->getASTContext().isSwiftVersionAtLeast(6)
? DiagnosticBehavior::Error
: DiagnosticBehavior::Warning);
// otherwise, it's not a safe cast.
dc->getASTContext()
.Diags
.diagnose(funcConv->getLoc(),
diag::converting_func_loses_global_actor, fromType,
toType, fromActor)
.warnUntilSwiftVersion(6);
}
}
}
Expand Down