Skip to content

Commit c22fdfc

Browse files
committed
[Concurrency] Address some review comments.
Tweaked diagnostic to use a string instead of a type. Renamed the feature in `FeatureAvailability.def` (and added the `TaskExecutor` feature to 6.2). Also fixed the `swift_getActiveExecutor()` function to return the main executor only when on the main thread. rdar://141348916
1 parent b411e23 commit c22fdfc

File tree

8 files changed

+33
-41
lines changed

8 files changed

+33
-41
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,8 @@ NOTE(rbi_add_generic_parameter_sendable_conformance,none,
11371137
ERROR(cannot_find_executor_factory_type, none,
11381138
"the specified executor factory '%0' could not be found", (StringRef))
11391139
ERROR(executor_factory_must_conform, none,
1140-
"the executor factory '%0' does not conform to 'ExecutorFactory'", (Type))
1140+
"the executor factory '%0' does not conform to 'ExecutorFactory'",
1141+
(StringRef))
11411142
ERROR(executor_factory_not_supported, none,
11421143
"deployment target too low for executor factory specification", ())
11431144

include/swift/AST/FeatureAvailability.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ FEATURE(IsolatedDeinit, (6, 1))
8080

8181
FEATURE(ValueGenericType, (6, 2))
8282
FEATURE(InitRawStructMetadata2, (6, 2))
83-
FEATURE(CustomExecutors, (6, 2))
83+
FEATURE(CustomGlobalExecutors, (6, 2))
84+
FEATURE(TaskExecutor, (6, 2))
8485

85-
FEATURE(TaskExecutor, FUTURE)
8686
FEATURE(Differentiation, FUTURE)
8787
FEATURE(ClearSensitive, FUTURE)
8888
FEATURE(UpdatePureObjCClassMetadata, FUTURE)

lib/SILGen/SILGen.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ FuncDecl *SILGenModule::getExit() {
511511
return exitFunction;
512512
}
513513

514-
Type SILGenModule::getExecutorFactory() {
514+
Type SILGenModule::getConfiguredExecutorFactory() {
515515
auto &ctx = getASTContext();
516516

517517
ModuleDecl *module;
@@ -545,12 +545,6 @@ Type SILGenModule::getDefaultExecutorFactory() {
545545
return ctx.getNamedSwiftType(module, "DefaultExecutorFactory");
546546
}
547547

548-
ProtocolDecl *SILGenModule::getExecutorFactoryProtocol() {
549-
auto &ctx = getASTContext();
550-
551-
return ctx.getProtocol(KnownProtocolKind::ExecutorFactory);
552-
}
553-
554548
ProtocolConformance *SILGenModule::getNSErrorConformanceToError() {
555549
if (NSErrorConformanceToError)
556550
return *NSErrorConformanceToError;

lib/SILGen/SILGen.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -555,15 +555,12 @@ 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();
558+
/// Get the configured ExecutorFactory type.
559+
Type getConfiguredExecutorFactory();
560560

561561
/// Get the DefaultExecutorFactory type.
562562
Type getDefaultExecutorFactory();
563563

564-
/// Get the ExecutorFactory protocol.
565-
ProtocolDecl *getExecutorFactoryProtocol();
566-
567564
/// Get the swift_createExecutors function.
568565
FuncDecl *getCreateExecutors();
569566

lib/SILGen/SILGenFunction.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,8 +1400,8 @@ static bool isCreateExecutorsFunctionAvailable(SILGenModule &SGM) {
14001400
if (!ctx.LangOpts.DisableAvailabilityChecking) {
14011401
auto deploymentAvailability = AvailabilityRange::forDeploymentTarget(ctx);
14021402
auto runtimeAvailability = AvailabilityRange::forRuntimeTarget(ctx);
1403-
auto declAvailability = ctx.getCustomExecutorsAvailability();
1404-
auto declRtAvailability = ctx.getCustomExecutorsRuntimeAvailability();
1403+
auto declAvailability = ctx.getCustomGlobalExecutorsAvailability();
1404+
auto declRtAvailability = ctx.getCustomGlobalExecutorsRuntimeAvailability();
14051405
return deploymentAvailability.isContainedIn(declAvailability)
14061406
&& runtimeAvailability.isContainedIn(declRtAvailability);
14071407
}
@@ -1429,21 +1429,23 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
14291429
if (!isCreateExecutorsFunctionAvailable(SGM)) {
14301430
ctx.Diags.diagnose(SourceLoc(), diag::executor_factory_not_supported);
14311431
} else {
1432-
CanType factoryTy = SGM.getExecutorFactory()->getCanonicalType();
1432+
CanType factoryTy = SGM.getConfiguredExecutorFactory()->getCanonicalType();
14331433

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

1439-
ProtocolDecl *executorFactoryProtocol = SGM.getExecutorFactoryProtocol();
1439+
ProtocolDecl *executorFactoryProtocol
1440+
= ctx.getProtocol(KnownProtocolKind::ExecutorFactory);
14401441
auto conformance = lookupConformance(factoryTy, executorFactoryProtocol);
14411442

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

1446-
ctx.Diags.diagnose(loc, diag::executor_factory_must_conform, factoryTy);
1447+
ctx.Diags.diagnose(loc, diag::executor_factory_must_conform,
1448+
*ctx.LangOpts.ExecutorFactory);
14471449

14481450
factoryTy = SGM.getDefaultExecutorFactory()->getCanonicalType();
14491451
conformance = lookupConformance(factoryTy, executorFactoryProtocol);
@@ -1464,7 +1466,7 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
14641466
SILValue factorySILMetaTy
14651467
= B.createMetatype(moduleLoc, getLoweredType(factoryThickMetaTy));
14661468
auto ceSubs = SubstitutionMap::getProtocolSubstitutions(
1467-
conformance.getRequirement(), factoryTy, conformance);
1469+
conformance.getProtocol(), factoryTy, conformance);
14681470
B.createApply(moduleLoc, createExecutorsFunc, ceSubs, { factorySILMetaTy });
14691471
}
14701472
}

stdlib/public/Concurrency/Actor.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,16 @@ static SerialExecutorRef swift_task_getCurrentExecutorImpl() {
290290
return result;
291291
}
292292

293+
/// Determine whether we are currently executing on the main thread
294+
/// independently of whether we know that we are on the main actor.
295+
static bool isExecutingOnMainThread() {
296+
#if SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY
297+
return true;
298+
#else
299+
return Thread::onMainThread();
300+
#endif
301+
}
302+
293303
#pragma clang diagnostic push
294304
#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
295305

@@ -303,7 +313,13 @@ SerialExecutorRef _swift_getActiveExecutor() {
303313
return SerialExecutorRef::generic();
304314
return executor;
305315
}
306-
return swift_getMainExecutor();
316+
317+
// If there's no tracking and we're on the main thread, then the main
318+
// executor is notionally active.
319+
if (isExecutingOnMainThread())
320+
return swift_getMainExecutor();
321+
322+
return SerialExecutorRef::generic();
307323
}
308324

309325
extern "C" SWIFT_CC(swift)
@@ -324,16 +340,6 @@ TaskExecutorRef _swift_getPreferredTaskExecutor() {
324340

325341
#pragma clang diagnostic pop
326342

327-
/// Determine whether we are currently executing on the main thread
328-
/// independently of whether we know that we are on the main actor.
329-
static bool isExecutingOnMainThread() {
330-
#if SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY
331-
return true;
332-
#else
333-
return Thread::onMainThread();
334-
#endif
335-
}
336-
337343
JobPriority swift::swift_task_getCurrentThreadPriority() {
338344
#if SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY
339345
return JobPriority::UserInitiated;

stdlib/public/Concurrency/PartialAsyncTask.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,7 @@ extension ExecutorJob {
470470
/// runtime.
471471
///
472472
/// N.B. Because this allocator is stack disciplined, explicitly
473-
/// deallocating memory will also deallocate all memory allocated
474-
/// after the block being deallocated.
473+
/// deallocating memory out-of-order will cause your program to abort.
475474
public struct LocalAllocator {
476475
internal var context: Builtin.Job
477476

stdlib/public/Concurrency/Task.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,6 @@ static SerialExecutorRef executorForEnqueuedJob(Job *job) {
381381
return swift_task_getMainExecutor();
382382
}
383383

384-
// It is no longer valid to return a Dispatch Queue as the "identity" here.
385-
//
386-
//if (auto identity = reinterpret_cast<HeapObject *>(jobQueue)) {
387-
// return SerialExecutorRef::forOrdinary(
388-
// identity, _swift_task_getDispatchQueueSerialExecutorWitnessTable());
389-
//}
390-
391384
return SerialExecutorRef::generic();
392385
#endif
393386
}

0 commit comments

Comments
 (0)