Skip to content

[6.2][Frontend] Promote AsyncCallerExecution to an upcoming feature #80982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2025
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
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticGroups.def
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
GROUP(no_group, "")

GROUP(ActorIsolatedCall, "actor-isolated-call")
GROUP(AsyncCallerExecution, "async-caller-execution")
GROUP(NonisolatedNonsendingByDefault, "nonisolated-nonsending-by-default")
GROUP(ConformanceIsolation, "conformance-isolation")
GROUP(DeprecatedDeclaration, "deprecated-declaration")
GROUP(DynamicCallable, "dynamic-callable-requirements")
Expand Down
6 changes: 3 additions & 3 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -8592,22 +8592,22 @@ NOTE(type_does_not_conform_to_Sendable,none,
"type %0 does not conform to 'Sendable' protocol", (Type))

GROUPED_WARNING(
attr_execution_nonisolated_behavior_will_change_decl, AsyncCallerExecution,
attr_execution_nonisolated_behavior_will_change_decl, NonisolatedNonsendingByDefault,
none,
"feature '%0' will cause nonisolated async %kindbase1 to run on the "
"caller's actor; use %2 to preserve behavior",
(StringRef, const AbstractFunctionDecl *, DeclAttribute))

GROUPED_WARNING(
attr_execution_nonisolated_behavior_will_change_closure,
AsyncCallerExecution, none,
NonisolatedNonsendingByDefault, none,
"feature '%0' will cause nonisolated async closure to run on the caller's "
"actor; use %1 to preserve behavior",
(StringRef, DeclAttribute))

GROUPED_WARNING(
attr_execution_nonisolated_behavior_will_change_typerepr,
AsyncCallerExecution, none,
NonisolatedNonsendingByDefault, none,
"feature '%0' will cause nonisolated async function type to be treated as "
"specified to run on the caller's actor; use %1 to preserve "
"behavior",
Expand Down
5 changes: 1 addition & 4 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ ADOPTABLE_UPCOMING_FEATURE(ExistentialAny, 335, 7)
UPCOMING_FEATURE(InternalImportsByDefault, 409, 7)
UPCOMING_FEATURE(MemberImportVisibility, 444, 7)
UPCOMING_FEATURE(InferIsolatedConformances, 470, 7)
ADOPTABLE_UPCOMING_FEATURE(NonisolatedNonsendingByDefault, 461, 7)

// Optional language features / modes

Expand Down Expand Up @@ -487,10 +488,6 @@ SUPPRESSIBLE_EXPERIMENTAL_FEATURE(AddressableTypes, true)
/// Allow the @abi attribute.
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(ABIAttribute, true)

/// Functions with nonisolated isolation inherit their isolation from the
/// calling context.
ADOPTABLE_EXPERIMENTAL_FEATURE(AsyncCallerExecution, false)

/// Allow custom availability domains to be defined and referenced.
EXPERIMENTAL_FEATURE(CustomAvailability, true)

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/FeatureSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ UNINTERESTING_FEATURE(Volatile)
UNINTERESTING_FEATURE(SuppressedAssociatedTypes)
UNINTERESTING_FEATURE(StructLetDestructuring)
UNINTERESTING_FEATURE(MacrosOnImports)
UNINTERESTING_FEATURE(AsyncCallerExecution)
UNINTERESTING_FEATURE(ExtensibleEnums)
UNINTERESTING_FEATURE(NonisolatedNonsendingByDefault)
UNINTERESTING_FEATURE(KeyPathWithMethodMembers)

static bool usesFeatureNonescapableTypes(Decl *decl) {
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/IR/SILFunctionType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1705,7 +1705,7 @@ class DestructureInputs {
}

// If we are an async function that is unspecified or nonisolated, insert an
// isolated parameter if AsyncCallerExecution is enabled.
// isolated parameter if NonisolatedNonsendingByDefault is enabled.
//
// NOTE: The parameter is not inserted for async functions imported
// from ObjC because they are handled in a special way that doesn't
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

add_swift_host_library(swiftSema STATIC
AssociatedTypeInference.cpp
AsyncCallerExecutionMigration.cpp
NonisolatedNonsendingByDefaultMigration.cpp
BuilderTransform.cpp
Comment.cpp
CSApply.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- Sema/AsyncCallerExecutionMigration.cpp ------------------*- C++ -*-===//
//===-- Sema/NonisolatedNonsendingByDefaultMigration.cpp --------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
Expand All @@ -11,12 +11,12 @@
//===----------------------------------------------------------------------===//
///
/// \file
/// This file implements code migration support for the `AsyncCallerExecution`
/// feature.
/// This file implements code migration support for the
/// `NonisolatedNonsendingByDefault` feature.
///
//===----------------------------------------------------------------------===//

#include "AsyncCallerExecutionMigration.h"
#include "NonisolatedNonsendingByDefaultMigration.h"
#include "swift/AST/ASTContext.h"
#include "swift/AST/Decl.h"
#include "swift/AST/DiagnosticsSema.h"
Expand All @@ -30,34 +30,34 @@
using namespace swift;

namespace {
class AsyncCallerExecutionMigrationTarget {
class NonisolatedNonsendingByDefaultMigrationTarget {
ASTContext &ctx;
PointerUnion<ValueDecl *, AbstractClosureExpr *, FunctionTypeRepr *> node;
TaggedUnion<ActorIsolation, FunctionTypeIsolation> isolation;

public:
AsyncCallerExecutionMigrationTarget(ASTContext &ctx, ValueDecl *decl,
NonisolatedNonsendingByDefaultMigrationTarget(ASTContext &ctx, ValueDecl *decl,
ActorIsolation isolation)
: ctx(ctx), node(decl), isolation(isolation) {}

AsyncCallerExecutionMigrationTarget(ASTContext &ctx,
NonisolatedNonsendingByDefaultMigrationTarget(ASTContext &ctx,
AbstractClosureExpr *closure,
ActorIsolation isolation)
: ctx(ctx), node(closure), isolation(isolation) {}

AsyncCallerExecutionMigrationTarget(ASTContext &ctx, FunctionTypeRepr *repr,
NonisolatedNonsendingByDefaultMigrationTarget(ASTContext &ctx, FunctionTypeRepr *repr,
FunctionTypeIsolation isolation)
: ctx(ctx), node(repr), isolation(isolation) {}

/// Warns that the behavior of nonisolated async functions will change under
/// `AsyncCallerExecution` and suggests `@concurrent` to preserve the current
/// `NonisolatedNonsendingByDefault` and suggests `@concurrent` to preserve the current
/// behavior.
void diagnose() const;
};
} // end anonymous namespace

void AsyncCallerExecutionMigrationTarget::diagnose() const {
const auto feature = Feature::AsyncCallerExecution;
void NonisolatedNonsendingByDefaultMigrationTarget::diagnose() const {
const auto feature = Feature::NonisolatedNonsendingByDefault;

ASSERT(node);
ASSERT(ctx.LangOpts.getFeatureState(feature).isEnabledForAdoption());
Expand Down Expand Up @@ -189,15 +189,15 @@ void AsyncCallerExecutionMigrationTarget::diagnose() const {

void swift::warnAboutNewNonisolatedAsyncExecutionBehavior(
ASTContext &ctx, FunctionTypeRepr *repr, FunctionTypeIsolation isolation) {
AsyncCallerExecutionMigrationTarget(ctx, repr, isolation).diagnose();
NonisolatedNonsendingByDefaultMigrationTarget(ctx, repr, isolation).diagnose();
}

void swift::warnAboutNewNonisolatedAsyncExecutionBehavior(
ASTContext &ctx, ValueDecl *decl, ActorIsolation isolation) {
AsyncCallerExecutionMigrationTarget(ctx, decl, isolation).diagnose();
NonisolatedNonsendingByDefaultMigrationTarget(ctx, decl, isolation).diagnose();
}

void swift::warnAboutNewNonisolatedAsyncExecutionBehavior(
ASTContext &ctx, AbstractClosureExpr *closure, ActorIsolation isolation) {
AsyncCallerExecutionMigrationTarget(ctx, closure, isolation).diagnose();
NonisolatedNonsendingByDefaultMigrationTarget(ctx, closure, isolation).diagnose();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- Sema/AsyncCallerExecutionMigration.h --------------------*- C++ -*-===//
//===-- Sema/NonisolatedNonsendingByDefaultMigration.h ----------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
Expand All @@ -11,13 +11,13 @@
//===----------------------------------------------------------------------===//
///
/// \file
/// This file provides code migration support for the `AsyncCallerExecution`
/// feature.
/// This file provides code migration support for the
/// `NonisolatedNonsendingByDefault` feature.
///
//===----------------------------------------------------------------------===//

#ifndef SWIFT_SEMA_ASYNCCALLEREXECUTIONMIGRATION_H
#define SWIFT_SEMA_ASYNCCALLEREXECUTIONMIGRATION_H
#ifndef SWIFT_SEMA_NONISOLATEDNONSENDINGBYDEFAULTMIGRATION_H
#define SWIFT_SEMA_NONISOLATEDNONSENDINGBYDEFAULTMIGRATION_H

#include "swift/AST/ActorIsolation.h"
#include "swift/AST/ExtInfo.h"
Expand All @@ -29,25 +29,25 @@ class ValueDecl;
class AbstractClosureExpr;

/// Warns that the behavior of nonisolated async functions will change under
/// `AsyncCallerExecution` and suggests `@concurrent` to preserve the current
/// `NonisolatedNonsendingByDefault` and suggests `@concurrent` to preserve the current
/// behavior.
void warnAboutNewNonisolatedAsyncExecutionBehavior(
ASTContext &ctx, FunctionTypeRepr *node, FunctionTypeIsolation isolation);

/// Warns that the behavior of nonisolated async functions will change under
/// `AsyncCallerExecution` and suggests `@concurrent` to preserve the current
/// `NonisolatedNonsendingByDefault` and suggests `@concurrent` to preserve the current
/// behavior.
void warnAboutNewNonisolatedAsyncExecutionBehavior(ASTContext &ctx,
ValueDecl *node,
ActorIsolation isolation);

/// Warns that the behavior of nonisolated async functions will change under
/// `AsyncCallerExecution` and suggests `@concurrent` to preserve the current
/// `NonisolatedNonsendingByDefault` and suggests `@concurrent` to preserve the current
/// behavior.
void warnAboutNewNonisolatedAsyncExecutionBehavior(ASTContext &ctx,
AbstractClosureExpr *node,
ActorIsolation isolation);

} // end namespace swift

#endif /* SWIFT_SEMA_ASYNCCALLEREXECUTIONMIGRATION_H */
#endif /* SWIFT_SEMA_NONISOLATEDNONSENDINGBYDEFAULTMIGRATION_H */
14 changes: 7 additions & 7 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//===----------------------------------------------------------------------===//

#include "TypeCheckConcurrency.h"
#include "AsyncCallerExecutionMigration.h"
#include "NonisolatedNonsendingByDefaultMigration.h"
#include "MiscDiagnostics.h"
#include "TypeCheckDistributed.h"
#include "TypeCheckInvertible.h"
Expand Down Expand Up @@ -4767,7 +4767,7 @@ ActorIsolation ActorIsolationChecker::determineClosureIsolation(
// Apply computed preconcurrency.
isolation = isolation.withPreconcurrency(preconcurrency);

if (ctx.LangOpts.getFeatureState(Feature::AsyncCallerExecution)
if (ctx.LangOpts.getFeatureState(Feature::NonisolatedNonsendingByDefault)
.isEnabledForAdoption()) {
warnAboutNewNonisolatedAsyncExecutionBehavior(ctx, closure, isolation);
}
Expand Down Expand Up @@ -4948,7 +4948,7 @@ getIsolationFromAttributes(const Decl *decl, bool shouldDiagnose = true,
// If the nonisolated async inherits isolation from context,
// return caller isolation inheriting.
if (decl->getASTContext().LangOpts.hasFeature(
Feature::AsyncCallerExecution)) {
Feature::NonisolatedNonsendingByDefault)) {
if (auto *func = dyn_cast<AbstractFunctionDecl>(decl);
func && func->hasAsync() &&
func->getModuleContext() == decl->getASTContext().MainModule) {
Expand Down Expand Up @@ -5814,7 +5814,7 @@ computeDefaultInferredActorIsolation(ValueDecl *value) {
}

// If we have an async function... by default we inherit isolation.
if (ctx.LangOpts.hasFeature(Feature::AsyncCallerExecution)) {
if (ctx.LangOpts.hasFeature(Feature::NonisolatedNonsendingByDefault)) {
if (auto *func = dyn_cast<AbstractFunctionDecl>(value);
func && func->hasAsync() &&
func->getModuleContext() == ctx.MainModule) {
Expand Down Expand Up @@ -5931,7 +5931,7 @@ static InferredActorIsolation computeActorIsolation(Evaluator &evaluator,
// did not have an ExecutionKind::Caller attached to it.
//
// DISCUSSION: This occurs when we have a value decl that is explicitly marked
// as nonisolated but since AsyncCallerExecution is enabled, we return
// as nonisolated but since NonisolatedNonsendingByDefault is enabled, we return
// CallerIsolationInheriting.
if (isolationFromAttr && isolationFromAttr->getKind() ==
ActorIsolation::CallerIsolationInheriting) {
Expand Down Expand Up @@ -6232,7 +6232,7 @@ static InferredActorIsolation computeActorIsolation(Evaluator &evaluator,

if (auto *func = dyn_cast<AbstractFunctionDecl>(value);
ctx.LangOpts.hasFeature(
Feature::AsyncCallerExecution) &&
Feature::NonisolatedNonsendingByDefault) &&
func && func->hasAsync() &&
func->getModuleContext() == ctx.MainModule &&
isolation.isNonisolated()) {
Expand Down Expand Up @@ -6277,7 +6277,7 @@ InferredActorIsolation ActorIsolationRequest::evaluate(Evaluator &evaluator,
const auto inferredIsolation = computeActorIsolation(evaluator, value);

auto &ctx = value->getASTContext();
if (ctx.LangOpts.getFeatureState(Feature::AsyncCallerExecution)
if (ctx.LangOpts.getFeatureState(Feature::NonisolatedNonsendingByDefault)
.isEnabledForAdoption()) {
warnAboutNewNonisolatedAsyncExecutionBehavior(ctx, value,
inferredIsolation.isolation);
Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//===----------------------------------------------------------------------===//

#include "TypeCheckType.h"
#include "AsyncCallerExecutionMigration.h"
#include "NonisolatedNonsendingByDefaultMigration.h"
#include "TypeCheckAvailability.h"
#include "TypeCheckConcurrency.h"
#include "TypeCheckInvertible.h"
Expand Down Expand Up @@ -4251,7 +4251,7 @@ NeverNullType TypeResolver::resolveASTFunctionType(
if (!repr->isInvalid())
isolation = FunctionTypeIsolation::forNonIsolated();
} else {
if (ctx.LangOpts.getFeatureState(Feature::AsyncCallerExecution)
if (ctx.LangOpts.getFeatureState(Feature::NonisolatedNonsendingByDefault)
.isEnabledForAdoption()) {
// Diagnose only in the interface stage, which is run once.
if (inStage(TypeResolutionStage::Interface)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// RUN: %target-run-simple-swift( -swift-version 6 -g %import-libdispatch -import-objc-header %S/Inputs/RunOnMainActor.h -enable-experimental-feature AsyncCallerExecution )
// RUN: %target-run-simple-swift( -swift-version 6 -g %import-libdispatch -import-objc-header %S/Inputs/RunOnMainActor.h -enable-upcoming-feature NonisolatedNonsendingByDefault )

// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: concurrency_runtime
// REQUIRES: libdispatch
// REQUIRES: asserts

// REQUIRES: swift_feature_AsyncCallerExecution
// REQUIRES: swift_feature_NonisolatedNonsendingByDefault

// UNSUPPORTED: freestanding

Expand Down
Loading