Skip to content

Revert "[Concurrency] Provide a Swift interface for custom main and global executors." #80224

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 1 commit into from
Mar 22, 2025
Merged
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
8 changes: 0 additions & 8 deletions include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
@@ -1133,14 +1133,6 @@ NOTE(rbi_add_generic_parameter_sendable_conformance,none,
"consider making generic parameter %0 conform to the 'Sendable' protocol",
(Type))

// Concurrency related diagnostics
ERROR(cannot_find_executor_factory_type, none,
"the specified executor factory '%0' could not be found", (StringRef))
ERROR(executor_factory_must_conform, none,
"the executor factory '%0' does not conform to 'ExecutorFactory'", (Type))
ERROR(executor_factory_not_supported, none,
"deployment target too low for executor factory specification", ())

//===----------------------------------------------------------------------===//
// MARK: Misc Diagnostics
//===----------------------------------------------------------------------===//
1 change: 0 additions & 1 deletion include/swift/AST/FeatureAvailability.def
Original file line number Diff line number Diff line change
@@ -80,7 +80,6 @@ FEATURE(IsolatedDeinit, (6, 1))

FEATURE(ValueGenericType, (6, 2))
FEATURE(InitRawStructMetadata2, (6, 2))
FEATURE(CustomExecutors, (6, 2))

FEATURE(TaskExecutor, FUTURE)
FEATURE(Differentiation, FUTURE)
1 change: 0 additions & 1 deletion include/swift/AST/KnownProtocols.def
Original file line number Diff line number Diff line change
@@ -97,7 +97,6 @@ PROTOCOL(Executor)
PROTOCOL(SerialExecutor)
PROTOCOL(TaskExecutor)
PROTOCOL(GlobalActor)
PROTOCOL(ExecutorFactory)

PROTOCOL_(BridgedNSError)
PROTOCOL_(BridgedStoredNSError)
4 changes: 0 additions & 4 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
@@ -401,10 +401,6 @@ namespace swift {
/// Specifies how strict concurrency checking will be.
StrictConcurrency StrictConcurrencyLevel = StrictConcurrency::Minimal;

/// Specifies the name of the executor factory to use to create the
/// default executors for Swift Concurrency.
std::optional<std::string> ExecutorFactory;

/// Enable experimental concurrency model.
bool EnableExperimentalConcurrency = false;

10 changes: 0 additions & 10 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
@@ -985,16 +985,6 @@ def strict_concurrency : Joined<["-"], "strict-concurrency=">,
"concurrency model, or 'complete' ('Sendable' and other checking is "
"enabled for all code in the module)">;

def executor_factory : JoinedOrSeparate<["-"], "executor-factory">,
Flags<[FrontendOption]>,
HelpText<"Specify the factory to use to create the default executors for "
"Swift Concurrency. This must be a type conforming to the "
"'ExecutorFactory' protocol.">,
MetaVarName<"<factory-type>">;
def executor_factory_EQ : Joined<["-"], "executor-factory=">,
Flags<[FrontendOption]>,
Alias<executor_factory>;

def enable_experimental_feature :
Separate<["-"], "enable-experimental-feature">,
Flags<[FrontendOption, ModuleInterfaceOption]>,
23 changes: 0 additions & 23 deletions include/swift/Runtime/Concurrency.h
Original file line number Diff line number Diff line change
@@ -149,29 +149,6 @@ SWIFT_EXPORT_FROM(swift_Concurrency)
CoroAllocator *const _swift_coro_malloc_allocator;
// }} TODO: CoroutineAccessors

/// Deallocate memory in a task.
///
/// The pointer provided must be the last pointer allocated on
/// this task that has not yet been deallocated; that is, memory
/// must be allocated and deallocated in a strict stack discipline.
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
void swift_task_dealloc(void *ptr);

/// Allocate memory in a job.
///
/// All allocations will be rounded to a multiple of MAX_ALIGNMENT;
/// if the job does not support allocation, this will return NULL.
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
void *swift_job_allocate(Job *job, size_t size);

/// Deallocate memory in a job.
///
/// The pointer provided must be the last pointer allocated on
/// this task that has not yet been deallocated; that is, memory
/// must be allocated and deallocated in a strict stack discipline.
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
void swift_job_deallocate(Job *job, void *ptr);

/// Cancel a task and all of its child tasks.
///
/// This can be called from any thread.
1 change: 0 additions & 1 deletion lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
@@ -1447,7 +1447,6 @@ ProtocolDecl *ASTContext::getProtocol(KnownProtocolKind kind) const {
case KnownProtocolKind::Executor:
case KnownProtocolKind::TaskExecutor:
case KnownProtocolKind::SerialExecutor:
case KnownProtocolKind::ExecutorFactory:
M = getLoadedModule(Id_Concurrency);
break;
case KnownProtocolKind::DistributedActor:
2 changes: 1 addition & 1 deletion lib/ClangImporter/SortedCFDatabase.def.gyb
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ with codecs.open(CFDatabaseFile, encoding='utf-8', errors='strict') as f:
continue

# Otherwise, check for lines like FOO(BAR)
m = re.match(r'^\w+\((\w+)\)', line)
m = re.match('^\w+\((\w+)\)', line)
if m:
lineForName[m.group(1)] = line
}%
4 changes: 0 additions & 4 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
@@ -377,10 +377,6 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
arguments.push_back(inputArgs.MakeArgString(globalRemapping));
}

if (inputArgs.hasArg(options::OPT_executor_factory)) {
inputArgs.AddLastArg(arguments, options::OPT_executor_factory);
}

// Pass through the values passed to -Xfrontend.
inputArgs.AddAllArgValues(arguments, options::OPT_Xfrontend);

6 changes: 0 additions & 6 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
@@ -1364,12 +1364,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.enableFeature(Feature::RegionBasedIsolation);
}

// Get the executor factory name
if (const Arg *A = Args.getLastArg(OPT_executor_factory)) {
printf("Got executor-factory option\n");
Opts.ExecutorFactory = A->getValue();
}

Opts.WarnImplicitOverrides =
Args.hasArg(OPT_warn_implicit_overrides);

1 change: 0 additions & 1 deletion lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
@@ -7066,7 +7066,6 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
case KnownProtocolKind::Executor:
case KnownProtocolKind::SerialExecutor:
case KnownProtocolKind::TaskExecutor:
case KnownProtocolKind::ExecutorFactory:
case KnownProtocolKind::Sendable:
case KnownProtocolKind::UnsafeSendable:
case KnownProtocolKind::RangeReplaceableCollection:
44 changes: 0 additions & 44 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
@@ -458,10 +458,6 @@ FuncDecl *SILGenModule::getDeinitOnExecutor() {
return lookupConcurrencyIntrinsic(getASTContext(), "_deinitOnExecutor");
}

FuncDecl *SILGenModule::getCreateExecutors() {
return lookupConcurrencyIntrinsic(getASTContext(), "_createExecutors");
}

FuncDecl *SILGenModule::getExit() {
ASTContext &C = getASTContext();

@@ -511,46 +507,6 @@ FuncDecl *SILGenModule::getExit() {
return exitFunction;
}

Type SILGenModule::getExecutorFactory() {
auto &ctx = getASTContext();

ModuleDecl *module;

// Parse the executor factory name
StringRef qualifiedName = *ctx.LangOpts.ExecutorFactory;
StringRef typeName;

auto parts = qualifiedName.split('.');

if (parts.second.empty()) {
// This was an unqualified name; assume it's relative to the main module
module = ctx.MainModule;
typeName = qualifiedName;
} else {
Identifier moduleName = ctx.getIdentifier(parts.first);
module = ctx.getModuleByIdentifier(moduleName);
typeName = parts.second;
}

return ctx.getNamedSwiftType(module, typeName);
}

Type SILGenModule::getDefaultExecutorFactory() {
auto &ctx = getASTContext();

ModuleDecl *module = ctx.getModuleByIdentifier(ctx.Id_Concurrency);
if (!module)
return Type();

return ctx.getNamedSwiftType(module, "DefaultExecutorFactory");
}

ProtocolDecl *SILGenModule::getExecutorFactoryProtocol() {
auto &ctx = getASTContext();

return ctx.getProtocol(KnownProtocolKind::ExecutorFactory);
}

ProtocolConformance *SILGenModule::getNSErrorConformanceToError() {
if (NSErrorConformanceToError)
return *NSErrorConformanceToError;
12 changes: 0 additions & 12 deletions lib/SILGen/SILGen.h
Original file line number Diff line number Diff line change
@@ -555,18 +555,6 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
// Retrieve the _SwiftConcurrencyShims.exit intrinsic.
FuncDecl *getExit();

/// Get the ExecutorFactory type.
Type getExecutorFactory();

/// Get the DefaultExecutorFactory type.
Type getDefaultExecutorFactory();

/// Get the ExecutorFactory protocol.
ProtocolDecl *getExecutorFactoryProtocol();

/// Get the swift_createExecutors function.
FuncDecl *getCreateExecutors();

SILFunction *getKeyPathProjectionCoroutine(bool isReadAccess,
KeyPathTypeKind typeKind);

69 changes: 1 addition & 68 deletions lib/SILGen/SILGenFunction.cpp
Original file line number Diff line number Diff line change
@@ -486,7 +486,7 @@ SILGenFunction::getOrCreateScope(const ast_scope::ASTScopeImpl *ASTScope,
// Collapse BraceStmtScopes whose parent is a .*BodyScope.
if (auto Parent = ASTScope->getParent().getPtrOrNull())
if (Parent->getSourceRangeOfThisASTNode() ==
ASTScope->getSourceRangeOfThisASTNode())
ASTScope->getSourceRangeOfThisASTNode())
return cache(getOrCreateScope(Parent, FnScope, InlinedAt));

// The calls to defer closures have cleanup source locations pointing to the
@@ -1387,28 +1387,6 @@ void SILGenFunction::emitArtificialTopLevel(Decl *mainDecl) {
}
}

static bool isCreateExecutorsFunctionAvailable(SILGenModule &SGM) {
FuncDecl *createExecutorsFuncDecl = SGM.getCreateExecutors();
if (!createExecutorsFuncDecl)
return false;

auto &ctx = createExecutorsFuncDecl->getASTContext();

if (ctx.LangOpts.hasFeature(Feature::Embedded))
return true;

if (!ctx.LangOpts.DisableAvailabilityChecking) {
auto deploymentAvailability = AvailabilityRange::forDeploymentTarget(ctx);
auto runtimeAvailability = AvailabilityRange::forRuntimeTarget(ctx);
auto declAvailability = ctx.getCustomExecutorsAvailability();
auto declRtAvailability = ctx.getCustomExecutorsRuntimeAvailability();
return deploymentAvailability.isContainedIn(declAvailability)
&& runtimeAvailability.isContainedIn(declRtAvailability);
}

return true;
}

void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
auto moduleLoc = entryPoint.getAsRegularLocation();
auto *entryBlock = B.getInsertionBB();
@@ -1424,51 +1402,6 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {

B.setInsertionPoint(entryBlock);

// If we're using a new enough deployment target, call swift_createExecutors()
if (ctx.LangOpts.ExecutorFactory) {
if (!isCreateExecutorsFunctionAvailable(SGM)) {
ctx.Diags.diagnose(SourceLoc(), diag::executor_factory_not_supported);
} else {
CanType factoryTy = SGM.getExecutorFactory()->getCanonicalType();

if (!factoryTy) {
ctx.Diags.diagnose(SourceLoc(), diag::cannot_find_executor_factory_type,
*ctx.LangOpts.ExecutorFactory);
}

ProtocolDecl *executorFactoryProtocol = SGM.getExecutorFactoryProtocol();
auto conformance = lookupConformance(factoryTy, executorFactoryProtocol);

if (conformance.isInvalid()) {
// If this type doesn't conform, ignore it and use the default factory
SourceLoc loc = extractNearestSourceLoc(factoryTy);

ctx.Diags.diagnose(loc, diag::executor_factory_must_conform, factoryTy);

factoryTy = SGM.getDefaultExecutorFactory()->getCanonicalType();
conformance = lookupConformance(factoryTy, executorFactoryProtocol);

assert(!conformance.isInvalid());
}

FuncDecl *createExecutorsFuncDecl = SGM.getCreateExecutors();
assert(createExecutorsFuncDecl
&& "Failed to find swift_createExecutors function decl");
SILFunction *createExecutorsSILFunc =
SGM.getFunction(SILDeclRef(createExecutorsFuncDecl, SILDeclRef::Kind::Func),
NotForDefinition);
SILValue createExecutorsFunc =
B.createFunctionRefFor(moduleLoc, createExecutorsSILFunc);
MetatypeType *factoryThickMetaTy
= MetatypeType::get(factoryTy, MetatypeRepresentation::Thick);
SILValue factorySILMetaTy
= B.createMetatype(moduleLoc, getLoweredType(factoryThickMetaTy));
auto ceSubs = SubstitutionMap::getProtocolSubstitutions(
conformance.getRequirement(), factoryTy, conformance);
B.createApply(moduleLoc, createExecutorsFunc, ceSubs, { factorySILMetaTy });
}
}

auto wrapCallArgs = [this, &moduleLoc](SILValue originalValue, FuncDecl *fd,
uint32_t paramIndex) -> SILValue {
Type parameterType = fd->getParameters()->get(paramIndex)->getTypeInContext();
35 changes: 0 additions & 35 deletions stdlib/public/Concurrency/Actor.cpp
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@
#include "../CompatibilityOverride/CompatibilityOverride.h"
#include "swift/ABI/Actor.h"
#include "swift/ABI/Task.h"
#include "ExecutorBridge.h"
#include "TaskPrivate.h"
#include "swift/Basic/HeaderFooterLayout.h"
#include "swift/Basic/PriorityQueue.h"
@@ -290,40 +289,6 @@ static SerialExecutorRef swift_task_getCurrentExecutorImpl() {
return result;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"

extern "C" SWIFT_CC(swift)
SerialExecutorRef _swift_getActiveExecutor() {
auto currentTracking = ExecutorTrackingInfo::current();
if (currentTracking) {
SerialExecutorRef executor = currentTracking->getActiveExecutor();
// This might be an actor, in which case return nil ("generic")
if (executor.isDefaultActor())
return SerialExecutorRef::generic();
return executor;
}
return swift_getMainExecutor();
}

extern "C" SWIFT_CC(swift)
TaskExecutorRef _swift_getCurrentTaskExecutor() {
auto currentTracking = ExecutorTrackingInfo::current();
if (currentTracking)
return currentTracking->getTaskExecutor();
return TaskExecutorRef::undefined();
}

extern "C" SWIFT_CC(swift)
TaskExecutorRef _swift_getPreferredTaskExecutor() {
AsyncTask *task = swift_task_getCurrent();
if (!task)
return TaskExecutorRef::undefined();
return task->getPreferredTaskExecutor();
}

#pragma clang diagnostic pop

/// Determine whether we are currently executing on the main thread
/// independently of whether we know that we are on the main actor.
static bool isExecutingOnMainThread() {
Loading