-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Concurrency] Provide a Swift interface for custom main and global executors. #79789
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
Changes from all commits
090c375
55afa47
d89ea19
5ae6de2
2298651
3a7fc7c
ef0e09d
d14b937
b33666c
fc67cc3
23d0ca7
444bbd5
00e7ef2
d197f38
f782499
ff0ce62
869622f
8caa5c5
a4f79f3
14b0e73
f0defd8
ed08858
ad5b76a
167449f
4576d53
60fb31c
fb0396c
0da95eb
c20aa66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,7 @@ FEATURE(IsolatedDeinit, (6, 1)) | |
|
||
FEATURE(ValueGenericType, (6, 2)) | ||
FEATURE(InitRawStructMetadata2, (6, 2)) | ||
FEATURE(CustomExecutors, (6, 2)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this is CustomGlobalExecutors? Custom executor sounds like the actor ones hm... Btw, i noticed TaskExecutor is FUTURE...? That's not right is it? 🤔 |
||
|
||
FEATURE(TaskExecutor, FUTURE) | ||
FEATURE(Differentiation, FUTURE) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -458,6 +458,10 @@ FuncDecl *SILGenModule::getDeinitOnExecutor() { | |
return lookupConcurrencyIntrinsic(getASTContext(), "_deinitOnExecutor"); | ||
} | ||
|
||
FuncDecl *SILGenModule::getCreateExecutors() { | ||
return lookupConcurrencyIntrinsic(getASTContext(), "_createExecutors"); | ||
} | ||
|
||
FuncDecl *SILGenModule::getExit() { | ||
ASTContext &C = getASTContext(); | ||
|
||
|
@@ -507,6 +511,46 @@ FuncDecl *SILGenModule::getExit() { | |
return exitFunction; | ||
} | ||
|
||
Type SILGenModule::getExecutorFactory() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this maybe |
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this func? There should be |
||
} | ||
|
||
ProtocolConformance *SILGenModule::getNSErrorConformanceToError() { | ||
if (NSErrorConformanceToError) | ||
return *NSErrorConformanceToError; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
#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" | ||
|
@@ -289,6 +290,40 @@ 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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this really right? if yes, can you add a comment? Say we're just on some random thread, there's no executor tracking, we're not on the main executor though -- this seems a bit off? |
||
} | ||
|
||
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() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, your call: Maybe better to get the type name passed in?