@@ -410,9 +410,6 @@ static void _swift_task_debug_dumpIsCurrentExecutorFlags(
410
410
if (options.contains (swift_task_is_current_executor_flag::Assert))
411
411
SWIFT_TASK_DEBUG_LOG (" %s swift_task_is_current_executor_flag::%s" ,
412
412
hint, " Assert" );
413
- if (options.contains (swift_task_is_current_executor_flag::UseIsIsolatingCurrentContext))
414
- SWIFT_TASK_DEBUG_LOG (" %s swift_task_is_current_executor_flag::%s" ,
415
- hint, " UseIsIsolatingCurrentContext" );
416
413
}
417
414
418
415
// Shimming call to Swift runtime because Swift Embedded does not have
@@ -470,13 +467,6 @@ swift_task_is_current_executor_flag swift_bincompat_selectDefaultIsCurrentExecut
470
467
// Remove the assert option which is what would cause the "crash" mode
471
468
options = swift_task_is_current_executor_flag (
472
469
options & ~swift_task_is_current_executor_flag::Assert);
473
- } else if (strcmp (modeStr, " isIsolatingCurrentContext" ) == 0 ) {
474
- options = swift_task_is_current_executor_flag (
475
- options | swift_task_is_current_executor_flag::UseIsIsolatingCurrentContext);
476
- // When we're using the isIsolatingCurrentContext we don't want to use crashing APIs,
477
- // so disable it explicitly.
478
- options = swift_task_is_current_executor_flag (
479
- options & ~swift_task_is_current_executor_flag::Assert);
480
470
} else if (strcmp (modeStr, " crash" ) == 0 ||
481
471
strcmp (modeStr, " swift6" ) == 0 ) {
482
472
options = swift_task_is_current_executor_flag (
@@ -501,43 +491,11 @@ extern "C" SWIFT_CC(swift) void _swift_task_enqueueOnExecutor(
501
491
Job *job, HeapObject *executor, const Metadata *executorType,
502
492
const SerialExecutorWitnessTable *wtable);
503
493
504
- // / Check the executor's witness table for specific information about e.g.
505
- // / being able ignore `checkIsolated` and only call `isIsolatingCurrentContext`.
506
- static swift_task_is_current_executor_flag
507
- _getIsolationCheckingOptionsFromExecutorWitnessTable (const SerialExecutorWitnessTable *_wtable) {
508
- const WitnessTable* wtable = reinterpret_cast <const WitnessTable*>(_wtable);
509
- #if SWIFT_STDLIB_USE_RELATIVE_PROTOCOL_WITNESS_TABLES
510
- auto description = lookThroughOptionalConditionalWitnessTable (
511
- reinterpret_cast <const RelativeWitnessTable*>(wtable))
512
- ->getDescription ();
513
- #else
514
- auto description = wtable->getDescription ();
515
- #endif
516
- if (!description) {
517
- return swift_task_is_current_executor_flag::None;
518
- }
519
-
520
- if (description->hasNonDefaultSerialExecutorIsIsolatingCurrentContext ()) {
521
- // The specific executor has implemented `isIsolatingCurrentContext` and
522
- // we do not have to call `checkIsolated`.
523
- return swift_task_is_current_executor_flag::UseIsIsolatingCurrentContext;
524
- }
525
-
526
- // No changes to the checking mode.
527
- return swift_task_is_current_executor_flag::None;
528
- }
529
-
530
494
SWIFT_CC (swift)
531
495
static bool swift_task_isCurrentExecutorWithFlagsImpl (
532
496
SerialExecutorRef expectedExecutor,
533
497
swift_task_is_current_executor_flag flags) {
534
498
auto current = ExecutorTrackingInfo::current ();
535
- if (expectedExecutor.getIdentity () && expectedExecutor.hasSerialExecutorWitnessTable ()) {
536
- if (auto *wtable = expectedExecutor.getSerialExecutorWitnessTable ()) {
537
- auto executorSpecificMode = _getIsolationCheckingOptionsFromExecutorWitnessTable (wtable);
538
- flags = swift_task_is_current_executor_flag (flags | executorSpecificMode);
539
- }
540
- }
541
499
542
500
auto options = SwiftTaskIsCurrentExecutorOptions (flags);
543
501
_swift_task_debug_dumpIsCurrentExecutorFlags (__FUNCTION__, flags);
@@ -557,16 +515,26 @@ static bool swift_task_isCurrentExecutorWithFlagsImpl(
557
515
// We cannot use 'complexEquality' as it requires two executor instances,
558
516
// and we do not have a 'current' executor here.
559
517
560
- if (options.contains (swift_task_is_current_executor_flag::UseIsIsolatingCurrentContext)) {
561
- SWIFT_TASK_DEBUG_LOG (" executor checking mode option: UseIsIsolatingCurrentContext; invoke (%p).isIsolatingCurrentContext" ,
562
- expectedExecutor.getIdentity ());
563
- // The executor has the most recent 'isIsolatingCurrentContext' API
564
- // so available so we prefer calling that to 'checkIsolated'.
565
- auto result = swift_task_isIsolatingCurrentContext (expectedExecutor);
566
-
567
- SWIFT_TASK_DEBUG_LOG (" executor checking mode option: UseIsIsolatingCurrentContext; invoke (%p).isIsolatingCurrentContext => %s" ,
568
- expectedExecutor.getIdentity (), result ? " pass" : " fail" );
569
- return result;
518
+ // Invoke the 'isIsolatingCurrentContext', if "undecided" (i.e. nil), we need to make further calls
519
+ SWIFT_TASK_DEBUG_LOG (" executor checking, invoke (%p).isIsolatingCurrentContext" ,
520
+ expectedExecutor.getIdentity ());
521
+ // The executor has the most recent 'isIsolatingCurrentContext' API
522
+ // so available so we prefer calling that to 'checkIsolated'.
523
+ auto isIsolatingCurrentContextDecision = swift_task_isIsolatingCurrentContext (expectedExecutor);
524
+
525
+ SWIFT_TASK_DEBUG_LOG (" executor checking mode option: UseIsIsolatingCurrentContext; invoke (%p).isIsolatingCurrentContext => %s" ,
526
+ expectedExecutor.getIdentity (), getIsIsolatingCurrentContextDecisionNameStr (isIsolatingCurrentContextDecision));
527
+ switch (isIsolatingCurrentContextDecision) {
528
+ case IsIsolatingCurrentContextDecision::Isolated:
529
+ // We know for sure that this serial executor is isolating this context, return the decision.
530
+ return true ;
531
+ case IsIsolatingCurrentContextDecision::NotIsolated:
532
+ // We know for sure that this serial executor is NOT isolating this context, return this decision.
533
+ return false ;
534
+ case IsIsolatingCurrentContextDecision::Unknown:
535
+ // We don't know, so we have to continue trying to check using other methods.
536
+ // This most frequently would happen if a serial executor did not implement isIsolatingCurrentContext.
537
+ break ;
570
538
}
571
539
572
540
// Otherwise, as last resort, let the expected executor check using
@@ -675,18 +643,20 @@ static bool swift_task_isCurrentExecutorWithFlagsImpl(
675
643
676
644
// Invoke the 'isIsolatingCurrentContext' function if we can; If so, we can
677
645
// avoid calling the `checkIsolated` because their result will be the same.
678
- if (options.contains (swift_task_is_current_executor_flag::UseIsIsolatingCurrentContext)) {
679
- SWIFT_TASK_DEBUG_LOG (" executor checking: can call (%p).isIsolatingCurrentContext" ,
680
- expectedExecutor.getIdentity ());
646
+ SWIFT_TASK_DEBUG_LOG (" executor checking: call (%p).isIsolatingCurrentContext" ,
647
+ expectedExecutor.getIdentity ());
681
648
682
- bool checkResult = swift_task_isIsolatingCurrentContext (expectedExecutor);
649
+ const auto isIsolatingCurrentContextDecision = swift_task_isIsolatingCurrentContext (expectedExecutor);
683
650
684
- SWIFT_TASK_DEBUG_LOG (" executor checking: can call (%p).isIsolatingCurrentContext => %p" ,
685
- expectedExecutor.getIdentity (), checkResult ? " pass" : " fail" );
686
- return checkResult;
687
- } else {
688
- SWIFT_TASK_DEBUG_LOG (" executor checking: can NOT call (%p).isIsolatingCurrentContext" ,
689
- expectedExecutor.getIdentity ());
651
+ SWIFT_TASK_DEBUG_LOG (" executor checking: can call (%p).isIsolatingCurrentContext => %p" ,
652
+ expectedExecutor.getIdentity (), getIsIsolatingCurrentContextDecisionNameStr (isIsolatingCurrentContextDecision));
653
+ switch (isIsolatingCurrentContextDecision) {
654
+ case IsIsolatingCurrentContextDecision::Isolated:
655
+ return true ;
656
+ case IsIsolatingCurrentContextDecision::NotIsolated:
657
+ return false ;
658
+ case IsIsolatingCurrentContextDecision::Unknown:
659
+ break ;
690
660
}
691
661
692
662
// This provides a last-resort check by giving the expected SerialExecutor the
0 commit comments