@@ -410,9 +410,6 @@ static void _swift_task_debug_dumpIsCurrentExecutorFlags(
410410 if (options.contains (swift_task_is_current_executor_flag::Assert))
411411 SWIFT_TASK_DEBUG_LOG (" %s swift_task_is_current_executor_flag::%s" ,
412412 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" );
416413}
417414
418415// Shimming call to Swift runtime because Swift Embedded does not have
@@ -470,13 +467,6 @@ swift_task_is_current_executor_flag swift_bincompat_selectDefaultIsCurrentExecut
470467 // Remove the assert option which is what would cause the "crash" mode
471468 options = swift_task_is_current_executor_flag (
472469 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);
480470 } else if (strcmp (modeStr, " crash" ) == 0 ||
481471 strcmp (modeStr, " swift6" ) == 0 ) {
482472 options = swift_task_is_current_executor_flag (
@@ -501,43 +491,11 @@ extern "C" SWIFT_CC(swift) void _swift_task_enqueueOnExecutor(
501491 Job *job, HeapObject *executor, const Metadata *executorType,
502492 const SerialExecutorWitnessTable *wtable);
503493
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-
530494SWIFT_CC (swift)
531495static bool swift_task_isCurrentExecutorWithFlagsImpl (
532496 SerialExecutorRef expectedExecutor,
533497 swift_task_is_current_executor_flag flags) {
534498 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- }
541499
542500 auto options = SwiftTaskIsCurrentExecutorOptions (flags);
543501 _swift_task_debug_dumpIsCurrentExecutorFlags (__FUNCTION__, flags);
@@ -557,16 +515,28 @@ static bool swift_task_isCurrentExecutorWithFlagsImpl(
557515 // We cannot use 'complexEquality' as it requires two executor instances,
558516 // and we do not have a 'current' executor here.
559517
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 =
524+ getIsIsolatingCurrentContextDecisionFromInt (
525+ swift_task_isIsolatingCurrentContext (expectedExecutor));
526+
527+ SWIFT_TASK_DEBUG_LOG (" executor checking mode option: UseIsIsolatingCurrentContext; invoke (%p).isIsolatingCurrentContext => %s" ,
528+ expectedExecutor.getIdentity (), getIsIsolatingCurrentContextDecisionNameStr (isIsolatingCurrentContextDecision));
529+ switch (isIsolatingCurrentContextDecision) {
530+ case IsIsolatingCurrentContextDecision::Isolated:
531+ // We know for sure that this serial executor is isolating this context, return the decision.
532+ return true ;
533+ case IsIsolatingCurrentContextDecision::NotIsolated:
534+ // We know for sure that this serial executor is NOT isolating this context, return this decision.
535+ return false ;
536+ case IsIsolatingCurrentContextDecision::Unknown:
537+ // We don't know, so we have to continue trying to check using other methods.
538+ // This most frequently would happen if a serial executor did not implement isIsolatingCurrentContext.
539+ break ;
570540 }
571541
572542 // Otherwise, as last resort, let the expected executor check using
@@ -675,18 +645,21 @@ static bool swift_task_isCurrentExecutorWithFlagsImpl(
675645
676646 // Invoke the 'isIsolatingCurrentContext' function if we can; If so, we can
677647 // 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 ());
648+ SWIFT_TASK_DEBUG_LOG (" executor checking: call (%p).isIsolatingCurrentContext" ,
649+ expectedExecutor.getIdentity ());
681650
682- bool checkResult = swift_task_isIsolatingCurrentContext (expectedExecutor);
651+ const auto isIsolatingCurrentContextDecision =
652+ getIsIsolatingCurrentContextDecisionFromInt (swift_task_isIsolatingCurrentContext (expectedExecutor));
683653
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 ());
654+ SWIFT_TASK_DEBUG_LOG (" executor checking: can call (%p).isIsolatingCurrentContext => %p" ,
655+ expectedExecutor.getIdentity (), getIsIsolatingCurrentContextDecisionNameStr (isIsolatingCurrentContextDecision));
656+ switch (isIsolatingCurrentContextDecision) {
657+ case IsIsolatingCurrentContextDecision::Isolated:
658+ return true ;
659+ case IsIsolatingCurrentContextDecision::NotIsolated:
660+ return false ;
661+ case IsIsolatingCurrentContextDecision::Unknown:
662+ break ;
690663 }
691664
692665 // This provides a last-resort check by giving the expected SerialExecutor the
0 commit comments