Skip to content

Commit 06f6358

Browse files
authored
Merge pull request #80224 from glessard/revert-79789-custom-executors
Revert "[Concurrency] Provide a Swift interface for custom main and global executors."
2 parents 033f667 + 8b15b05 commit 06f6358

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+426
-3611
lines changed

include/swift/AST/DiagnosticsSIL.def

-8
Original file line numberDiff line numberDiff line change
@@ -1133,14 +1133,6 @@ NOTE(rbi_add_generic_parameter_sendable_conformance,none,
11331133
"consider making generic parameter %0 conform to the 'Sendable' protocol",
11341134
(Type))
11351135

1136-
// Concurrency related diagnostics
1137-
ERROR(cannot_find_executor_factory_type, none,
1138-
"the specified executor factory '%0' could not be found", (StringRef))
1139-
ERROR(executor_factory_must_conform, none,
1140-
"the executor factory '%0' does not conform to 'ExecutorFactory'", (Type))
1141-
ERROR(executor_factory_not_supported, none,
1142-
"deployment target too low for executor factory specification", ())
1143-
11441136
//===----------------------------------------------------------------------===//
11451137
// MARK: Misc Diagnostics
11461138
//===----------------------------------------------------------------------===//

include/swift/AST/FeatureAvailability.def

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ FEATURE(IsolatedDeinit, (6, 1))
8080

8181
FEATURE(ValueGenericType, (6, 2))
8282
FEATURE(InitRawStructMetadata2, (6, 2))
83-
FEATURE(CustomExecutors, (6, 2))
8483

8584
FEATURE(TaskExecutor, FUTURE)
8685
FEATURE(Differentiation, FUTURE)

include/swift/AST/KnownProtocols.def

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ PROTOCOL(Executor)
9797
PROTOCOL(SerialExecutor)
9898
PROTOCOL(TaskExecutor)
9999
PROTOCOL(GlobalActor)
100-
PROTOCOL(ExecutorFactory)
101100

102101
PROTOCOL_(BridgedNSError)
103102
PROTOCOL_(BridgedStoredNSError)

include/swift/Basic/LangOptions.h

-4
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,6 @@ namespace swift {
401401
/// Specifies how strict concurrency checking will be.
402402
StrictConcurrency StrictConcurrencyLevel = StrictConcurrency::Minimal;
403403

404-
/// Specifies the name of the executor factory to use to create the
405-
/// default executors for Swift Concurrency.
406-
std::optional<std::string> ExecutorFactory;
407-
408404
/// Enable experimental concurrency model.
409405
bool EnableExperimentalConcurrency = false;
410406

include/swift/Option/Options.td

-10
Original file line numberDiff line numberDiff line change
@@ -985,16 +985,6 @@ def strict_concurrency : Joined<["-"], "strict-concurrency=">,
985985
"concurrency model, or 'complete' ('Sendable' and other checking is "
986986
"enabled for all code in the module)">;
987987

988-
def executor_factory : JoinedOrSeparate<["-"], "executor-factory">,
989-
Flags<[FrontendOption]>,
990-
HelpText<"Specify the factory to use to create the default executors for "
991-
"Swift Concurrency. This must be a type conforming to the "
992-
"'ExecutorFactory' protocol.">,
993-
MetaVarName<"<factory-type>">;
994-
def executor_factory_EQ : Joined<["-"], "executor-factory=">,
995-
Flags<[FrontendOption]>,
996-
Alias<executor_factory>;
997-
998988
def enable_experimental_feature :
999989
Separate<["-"], "enable-experimental-feature">,
1000990
Flags<[FrontendOption, ModuleInterfaceOption]>,

include/swift/Runtime/Concurrency.h

-23
Original file line numberDiff line numberDiff line change
@@ -149,29 +149,6 @@ SWIFT_EXPORT_FROM(swift_Concurrency)
149149
CoroAllocator *const _swift_coro_malloc_allocator;
150150
// }} TODO: CoroutineAccessors
151151

152-
/// Deallocate memory in a task.
153-
///
154-
/// The pointer provided must be the last pointer allocated on
155-
/// this task that has not yet been deallocated; that is, memory
156-
/// must be allocated and deallocated in a strict stack discipline.
157-
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
158-
void swift_task_dealloc(void *ptr);
159-
160-
/// Allocate memory in a job.
161-
///
162-
/// All allocations will be rounded to a multiple of MAX_ALIGNMENT;
163-
/// if the job does not support allocation, this will return NULL.
164-
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
165-
void *swift_job_allocate(Job *job, size_t size);
166-
167-
/// Deallocate memory in a job.
168-
///
169-
/// The pointer provided must be the last pointer allocated on
170-
/// this task that has not yet been deallocated; that is, memory
171-
/// must be allocated and deallocated in a strict stack discipline.
172-
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
173-
void swift_job_deallocate(Job *job, void *ptr);
174-
175152
/// Cancel a task and all of its child tasks.
176153
///
177154
/// This can be called from any thread.

lib/AST/ASTContext.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,6 @@ ProtocolDecl *ASTContext::getProtocol(KnownProtocolKind kind) const {
14471447
case KnownProtocolKind::Executor:
14481448
case KnownProtocolKind::TaskExecutor:
14491449
case KnownProtocolKind::SerialExecutor:
1450-
case KnownProtocolKind::ExecutorFactory:
14511450
M = getLoadedModule(Id_Concurrency);
14521451
break;
14531452
case KnownProtocolKind::DistributedActor:

lib/ClangImporter/SortedCFDatabase.def.gyb

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ with codecs.open(CFDatabaseFile, encoding='utf-8', errors='strict') as f:
3939
continue
4040

4141
# Otherwise, check for lines like FOO(BAR)
42-
m = re.match(r'^\w+\((\w+)\)', line)
42+
m = re.match('^\w+\((\w+)\)', line)
4343
if m:
4444
lineForName[m.group(1)] = line
4545
}%

lib/Driver/ToolChains.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,6 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
377377
arguments.push_back(inputArgs.MakeArgString(globalRemapping));
378378
}
379379

380-
if (inputArgs.hasArg(options::OPT_executor_factory)) {
381-
inputArgs.AddLastArg(arguments, options::OPT_executor_factory);
382-
}
383-
384380
// Pass through the values passed to -Xfrontend.
385381
inputArgs.AddAllArgValues(arguments, options::OPT_Xfrontend);
386382

lib/Frontend/CompilerInvocation.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -1364,12 +1364,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
13641364
Opts.enableFeature(Feature::RegionBasedIsolation);
13651365
}
13661366

1367-
// Get the executor factory name
1368-
if (const Arg *A = Args.getLastArg(OPT_executor_factory)) {
1369-
printf("Got executor-factory option\n");
1370-
Opts.ExecutorFactory = A->getValue();
1371-
}
1372-
13731367
Opts.WarnImplicitOverrides =
13741368
Args.hasArg(OPT_warn_implicit_overrides);
13751369

lib/IRGen/GenMeta.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -7066,7 +7066,6 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
70667066
case KnownProtocolKind::Executor:
70677067
case KnownProtocolKind::SerialExecutor:
70687068
case KnownProtocolKind::TaskExecutor:
7069-
case KnownProtocolKind::ExecutorFactory:
70707069
case KnownProtocolKind::Sendable:
70717070
case KnownProtocolKind::UnsafeSendable:
70727071
case KnownProtocolKind::RangeReplaceableCollection:

lib/SILGen/SILGen.cpp

-44
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,6 @@ FuncDecl *SILGenModule::getDeinitOnExecutor() {
458458
return lookupConcurrencyIntrinsic(getASTContext(), "_deinitOnExecutor");
459459
}
460460

461-
FuncDecl *SILGenModule::getCreateExecutors() {
462-
return lookupConcurrencyIntrinsic(getASTContext(), "_createExecutors");
463-
}
464-
465461
FuncDecl *SILGenModule::getExit() {
466462
ASTContext &C = getASTContext();
467463

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

514-
Type SILGenModule::getExecutorFactory() {
515-
auto &ctx = getASTContext();
516-
517-
ModuleDecl *module;
518-
519-
// Parse the executor factory name
520-
StringRef qualifiedName = *ctx.LangOpts.ExecutorFactory;
521-
StringRef typeName;
522-
523-
auto parts = qualifiedName.split('.');
524-
525-
if (parts.second.empty()) {
526-
// This was an unqualified name; assume it's relative to the main module
527-
module = ctx.MainModule;
528-
typeName = qualifiedName;
529-
} else {
530-
Identifier moduleName = ctx.getIdentifier(parts.first);
531-
module = ctx.getModuleByIdentifier(moduleName);
532-
typeName = parts.second;
533-
}
534-
535-
return ctx.getNamedSwiftType(module, typeName);
536-
}
537-
538-
Type SILGenModule::getDefaultExecutorFactory() {
539-
auto &ctx = getASTContext();
540-
541-
ModuleDecl *module = ctx.getModuleByIdentifier(ctx.Id_Concurrency);
542-
if (!module)
543-
return Type();
544-
545-
return ctx.getNamedSwiftType(module, "DefaultExecutorFactory");
546-
}
547-
548-
ProtocolDecl *SILGenModule::getExecutorFactoryProtocol() {
549-
auto &ctx = getASTContext();
550-
551-
return ctx.getProtocol(KnownProtocolKind::ExecutorFactory);
552-
}
553-
554510
ProtocolConformance *SILGenModule::getNSErrorConformanceToError() {
555511
if (NSErrorConformanceToError)
556512
return *NSErrorConformanceToError;

lib/SILGen/SILGen.h

-12
Original file line numberDiff line numberDiff line change
@@ -555,18 +555,6 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
555555
// Retrieve the _SwiftConcurrencyShims.exit intrinsic.
556556
FuncDecl *getExit();
557557

558-
/// Get the ExecutorFactory type.
559-
Type getExecutorFactory();
560-
561-
/// Get the DefaultExecutorFactory type.
562-
Type getDefaultExecutorFactory();
563-
564-
/// Get the ExecutorFactory protocol.
565-
ProtocolDecl *getExecutorFactoryProtocol();
566-
567-
/// Get the swift_createExecutors function.
568-
FuncDecl *getCreateExecutors();
569-
570558
SILFunction *getKeyPathProjectionCoroutine(bool isReadAccess,
571559
KeyPathTypeKind typeKind);
572560

lib/SILGen/SILGenFunction.cpp

+1-68
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ SILGenFunction::getOrCreateScope(const ast_scope::ASTScopeImpl *ASTScope,
486486
// Collapse BraceStmtScopes whose parent is a .*BodyScope.
487487
if (auto Parent = ASTScope->getParent().getPtrOrNull())
488488
if (Parent->getSourceRangeOfThisASTNode() ==
489-
ASTScope->getSourceRangeOfThisASTNode())
489+
ASTScope->getSourceRangeOfThisASTNode())
490490
return cache(getOrCreateScope(Parent, FnScope, InlinedAt));
491491

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

1390-
static bool isCreateExecutorsFunctionAvailable(SILGenModule &SGM) {
1391-
FuncDecl *createExecutorsFuncDecl = SGM.getCreateExecutors();
1392-
if (!createExecutorsFuncDecl)
1393-
return false;
1394-
1395-
auto &ctx = createExecutorsFuncDecl->getASTContext();
1396-
1397-
if (ctx.LangOpts.hasFeature(Feature::Embedded))
1398-
return true;
1399-
1400-
if (!ctx.LangOpts.DisableAvailabilityChecking) {
1401-
auto deploymentAvailability = AvailabilityRange::forDeploymentTarget(ctx);
1402-
auto runtimeAvailability = AvailabilityRange::forRuntimeTarget(ctx);
1403-
auto declAvailability = ctx.getCustomExecutorsAvailability();
1404-
auto declRtAvailability = ctx.getCustomExecutorsRuntimeAvailability();
1405-
return deploymentAvailability.isContainedIn(declAvailability)
1406-
&& runtimeAvailability.isContainedIn(declRtAvailability);
1407-
}
1408-
1409-
return true;
1410-
}
1411-
14121390
void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
14131391
auto moduleLoc = entryPoint.getAsRegularLocation();
14141392
auto *entryBlock = B.getInsertionBB();
@@ -1424,51 +1402,6 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
14241402

14251403
B.setInsertionPoint(entryBlock);
14261404

1427-
// If we're using a new enough deployment target, call swift_createExecutors()
1428-
if (ctx.LangOpts.ExecutorFactory) {
1429-
if (!isCreateExecutorsFunctionAvailable(SGM)) {
1430-
ctx.Diags.diagnose(SourceLoc(), diag::executor_factory_not_supported);
1431-
} else {
1432-
CanType factoryTy = SGM.getExecutorFactory()->getCanonicalType();
1433-
1434-
if (!factoryTy) {
1435-
ctx.Diags.diagnose(SourceLoc(), diag::cannot_find_executor_factory_type,
1436-
*ctx.LangOpts.ExecutorFactory);
1437-
}
1438-
1439-
ProtocolDecl *executorFactoryProtocol = SGM.getExecutorFactoryProtocol();
1440-
auto conformance = lookupConformance(factoryTy, executorFactoryProtocol);
1441-
1442-
if (conformance.isInvalid()) {
1443-
// If this type doesn't conform, ignore it and use the default factory
1444-
SourceLoc loc = extractNearestSourceLoc(factoryTy);
1445-
1446-
ctx.Diags.diagnose(loc, diag::executor_factory_must_conform, factoryTy);
1447-
1448-
factoryTy = SGM.getDefaultExecutorFactory()->getCanonicalType();
1449-
conformance = lookupConformance(factoryTy, executorFactoryProtocol);
1450-
1451-
assert(!conformance.isInvalid());
1452-
}
1453-
1454-
FuncDecl *createExecutorsFuncDecl = SGM.getCreateExecutors();
1455-
assert(createExecutorsFuncDecl
1456-
&& "Failed to find swift_createExecutors function decl");
1457-
SILFunction *createExecutorsSILFunc =
1458-
SGM.getFunction(SILDeclRef(createExecutorsFuncDecl, SILDeclRef::Kind::Func),
1459-
NotForDefinition);
1460-
SILValue createExecutorsFunc =
1461-
B.createFunctionRefFor(moduleLoc, createExecutorsSILFunc);
1462-
MetatypeType *factoryThickMetaTy
1463-
= MetatypeType::get(factoryTy, MetatypeRepresentation::Thick);
1464-
SILValue factorySILMetaTy
1465-
= B.createMetatype(moduleLoc, getLoweredType(factoryThickMetaTy));
1466-
auto ceSubs = SubstitutionMap::getProtocolSubstitutions(
1467-
conformance.getRequirement(), factoryTy, conformance);
1468-
B.createApply(moduleLoc, createExecutorsFunc, ceSubs, { factorySILMetaTy });
1469-
}
1470-
}
1471-
14721405
auto wrapCallArgs = [this, &moduleLoc](SILValue originalValue, FuncDecl *fd,
14731406
uint32_t paramIndex) -> SILValue {
14741407
Type parameterType = fd->getParameters()->get(paramIndex)->getTypeInContext();

stdlib/public/Concurrency/Actor.cpp

-35
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "../CompatibilityOverride/CompatibilityOverride.h"
2626
#include "swift/ABI/Actor.h"
2727
#include "swift/ABI/Task.h"
28-
#include "ExecutorBridge.h"
2928
#include "TaskPrivate.h"
3029
#include "swift/Basic/HeaderFooterLayout.h"
3130
#include "swift/Basic/PriorityQueue.h"
@@ -290,40 +289,6 @@ static SerialExecutorRef swift_task_getCurrentExecutorImpl() {
290289
return result;
291290
}
292291

293-
#pragma clang diagnostic push
294-
#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
295-
296-
extern "C" SWIFT_CC(swift)
297-
SerialExecutorRef _swift_getActiveExecutor() {
298-
auto currentTracking = ExecutorTrackingInfo::current();
299-
if (currentTracking) {
300-
SerialExecutorRef executor = currentTracking->getActiveExecutor();
301-
// This might be an actor, in which case return nil ("generic")
302-
if (executor.isDefaultActor())
303-
return SerialExecutorRef::generic();
304-
return executor;
305-
}
306-
return swift_getMainExecutor();
307-
}
308-
309-
extern "C" SWIFT_CC(swift)
310-
TaskExecutorRef _swift_getCurrentTaskExecutor() {
311-
auto currentTracking = ExecutorTrackingInfo::current();
312-
if (currentTracking)
313-
return currentTracking->getTaskExecutor();
314-
return TaskExecutorRef::undefined();
315-
}
316-
317-
extern "C" SWIFT_CC(swift)
318-
TaskExecutorRef _swift_getPreferredTaskExecutor() {
319-
AsyncTask *task = swift_task_getCurrent();
320-
if (!task)
321-
return TaskExecutorRef::undefined();
322-
return task->getPreferredTaskExecutor();
323-
}
324-
325-
#pragma clang diagnostic pop
326-
327292
/// Determine whether we are currently executing on the main thread
328293
/// independently of whether we know that we are on the main actor.
329294
static bool isExecutingOnMainThread() {

0 commit comments

Comments
 (0)