Skip to content

Commit 84075fb

Browse files
committed
[Concurrency] More work on the custom executor implementation.
Added an `-executor-factory` argument to the compiler to let you safely specify the executors you wish to use (by naming a type that returns them). Also added some tests of the new functionality. rdar://141348916
1 parent d8aaa78 commit 84075fb

26 files changed

+709
-183
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,14 @@ 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+
11361144
//===----------------------------------------------------------------------===//
11371145
// MARK: Misc Diagnostics
11381146
//===----------------------------------------------------------------------===//

include/swift/AST/FeatureAvailability.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ FEATURE(IsolatedDeinit, (6, 1))
8080

8181
FEATURE(ValueGenericType, (6, 2))
8282
FEATURE(InitRawStructMetadata2, (6, 2))
83+
FEATURE(CustomExecutors, (6, 2))
8384

8485
FEATURE(TaskExecutor, FUTURE)
8586
FEATURE(Differentiation, FUTURE)

include/swift/AST/KnownProtocols.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ PROTOCOL(Executor)
9797
PROTOCOL(SerialExecutor)
9898
PROTOCOL(TaskExecutor)
9999
PROTOCOL(GlobalActor)
100+
PROTOCOL(ExecutorFactory)
100101

101102
PROTOCOL_(BridgedNSError)
102103
PROTOCOL_(BridgedStoredNSError)

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ namespace swift {
396396
/// Specifies how strict concurrency checking will be.
397397
StrictConcurrency StrictConcurrencyLevel = StrictConcurrency::Minimal;
398398

399+
/// Specifies the name of the executor factory to use to create the
400+
/// default executors for Swift Concurrency.
401+
std::optional<std::string> ExecutorFactory;
402+
399403
/// Enable experimental concurrency model.
400404
bool EnableExperimentalConcurrency = false;
401405

include/swift/Option/Options.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,16 @@ 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+
988998
def enable_experimental_feature :
989999
Separate<["-"], "enable-experimental-feature">,
9901000
Flags<[FrontendOption, ModuleInterfaceOption]>,

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,7 @@ ProtocolDecl *ASTContext::getProtocol(KnownProtocolKind kind) const {
14381438
case KnownProtocolKind::Executor:
14391439
case KnownProtocolKind::TaskExecutor:
14401440
case KnownProtocolKind::SerialExecutor:
1441+
case KnownProtocolKind::ExecutorFactory:
14411442
M = getLoadedModule(Id_Concurrency);
14421443
break;
14431444
case KnownProtocolKind::DistributedActor:

lib/ClangImporter/SortedCFDatabase.def.gyb

Lines changed: 1 addition & 1 deletion
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('^\w+\((\w+)\)', line)
42+
m = re.match(r'^\w+\((\w+)\)', line)
4343
if m:
4444
lineForName[m.group(1)] = line
4545
}%

lib/Driver/ToolChains.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ 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+
380384
// Pass through the values passed to -Xfrontend.
381385
inputArgs.AddAllArgValues(arguments, options::OPT_Xfrontend);
382386

lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,12 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
13141314
Opts.enableFeature(Feature::RegionBasedIsolation);
13151315
}
13161316

1317+
// Get the executor factory name
1318+
if (const Arg *A = Args.getLastArg(OPT_executor_factory)) {
1319+
printf("Got executor-factory option\n");
1320+
Opts.ExecutorFactory = A->getValue();
1321+
}
1322+
13171323
Opts.WarnImplicitOverrides =
13181324
Args.hasArg(OPT_warn_implicit_overrides);
13191325

lib/IRGen/GenMeta.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7045,6 +7045,7 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
70457045
case KnownProtocolKind::Executor:
70467046
case KnownProtocolKind::SerialExecutor:
70477047
case KnownProtocolKind::TaskExecutor:
7048+
case KnownProtocolKind::ExecutorFactory:
70487049
case KnownProtocolKind::Sendable:
70497050
case KnownProtocolKind::UnsafeSendable:
70507051
case KnownProtocolKind::RangeReplaceableCollection:

0 commit comments

Comments
 (0)