@@ -337,13 +337,14 @@ static IsCurrentExecutorCheckMode isCurrentExecutorMode =
337
337
338
338
339
339
// Shimming call to Swift runtime because Swift Embedded does not have
340
- // these symbols defined
340
+ // these symbols defined.
341
341
bool swift_bincompat_useLegacyNonCrashingExecutorChecks () {
342
342
#if !SWIFT_CONCURRENCY_EMBEDDED
343
343
return swift::runtime::bincompat::
344
344
swift_bincompat_useLegacyNonCrashingExecutorChecks ();
345
- #endif
345
+ #else
346
346
return false ;
347
+ #endif
347
348
}
348
349
349
350
// Check override of executor checking mode.
@@ -353,17 +354,15 @@ static void checkIsCurrentExecutorMode(void *context) {
353
354
354
355
// Potentially, override the platform detected mode, primarily used in tests.
355
356
#if SWIFT_STDLIB_HAS_ENVIRON
356
- if (const char *modeStr =
357
- runtime::environment::concurrencyIsCurrentExecutorLegacyModeOverride ()) {
358
- if (modeStr) {
359
- if (strcmp (modeStr, " nocrash" ) == 0 ) {
360
- useLegacyMode = true ;
361
- } else if (strcmp (modeStr, " crash" ) == 0 ) {
362
- useLegacyMode = false ;
363
- } // else, just use the platform detected mode
364
- }
357
+ if (const char *modeStr = runtime::environment::concurrencyIsCurrentExecutorLegacyModeOverride ()) {
358
+ if (strcmp (modeStr, " nocrash" ) == 0 || strcmp (modeStr, " legacy" ) == 0 ) {
359
+ useLegacyMode = true ;
360
+ } else if (strcmp (modeStr, " crash" ) == 0 || strcmp (modeStr, " swift6" ) == 0 ) {
361
+ useLegacyMode = false ;
362
+ } // else, just use the platform detected mode
365
363
}
366
364
#endif // SWIFT_STDLIB_HAS_ENVIRON
365
+
367
366
isCurrentExecutorMode = useLegacyMode ? Legacy_NoCheckIsolated_NonCrashing
368
367
: Default_UseCheckIsolated_AllowCrash;
369
368
}
@@ -425,32 +424,6 @@ static bool swift_task_isCurrentExecutorImpl(SerialExecutorRef expectedExecutor)
425
424
return true ;
426
425
}
427
426
428
- // If the expected executor is "default" then we should have matched
429
- // by pointer equality already with the current executor.
430
- if (expectedExecutor.isDefaultActor ()) {
431
- // If the expected executor is a default actor, it makes no sense to try
432
- // the 'checkIsolated' call, it must be equal to the other actor, or it is
433
- // not the same isolation domain.
434
- if (isCurrentExecutorMode == Default_UseCheckIsolated_AllowCrash) {
435
- swift_Concurrency_fatalError (0 , " Incorrect actor executor assumption" );
436
- }
437
- return false ;
438
- }
439
-
440
- if (expectedExecutor.isMainExecutor () && !currentExecutor.isMainExecutor ()) {
441
- if (isCurrentExecutorMode == Default_UseCheckIsolated_AllowCrash) {
442
- // TODO: Invoke checkIsolated() on "main" SerialQueue once it implements `checkIsolated`, for potentially better/more consistent error messages
443
- swift_Concurrency_fatalError (0 , " Incorrect actor executor assumption; Expected MainActor executor" );
444
- }
445
- return false ;
446
- } else if (!expectedExecutor.isMainExecutor () && currentExecutor.isMainExecutor ()) {
447
- if (isCurrentExecutorMode == Default_UseCheckIsolated_AllowCrash) {
448
- // TODO: Invoke checkIsolated() on "main" SerialQueue once it implements `checkIsolated`, for potentially better/more consistent error messages
449
- swift_Concurrency_fatalError (0 , " Incorrect actor executor assumption; Expected not-MainActor executor" );
450
- }
451
- return false ;
452
- }
453
-
454
427
if (expectedExecutor.isComplexEquality ()) {
455
428
if (currentExecutor.getIdentity () && expectedExecutor.getIdentity () &&
456
429
swift_compareWitnessTables (
@@ -470,7 +443,7 @@ static bool swift_task_isCurrentExecutorImpl(SerialExecutorRef expectedExecutor)
470
443
// chance to check.
471
444
if (isSameExclusiveExecutionContextResult) {
472
445
return true ;
473
- }
446
+ } // else, we must give 'checkIsolated' a last chance to verify isolation
474
447
}
475
448
}
476
449
@@ -497,11 +470,11 @@ static bool swift_task_isCurrentExecutorImpl(SerialExecutorRef expectedExecutor)
497
470
// compat_invoke_swift_task_checkIsolated(expectedExecutor);
498
471
if (isCurrentExecutorMode == Default_UseCheckIsolated_AllowCrash) {
499
472
swift_task_checkIsolated (expectedExecutor);
473
+
500
474
// The checkIsolated call did not crash, so we are on the right executor.
501
475
return true ;
502
476
}
503
477
504
- assert (isCurrentExecutorMode == Legacy_NoCheckIsolated_NonCrashing);
505
478
return false ;
506
479
}
507
480
@@ -524,9 +497,30 @@ static void checkUnexpectedExecutorLogLevel(void *context) {
524
497
if (!levelStr)
525
498
return ;
526
499
500
+ auto isSameExecutorLegacyMode =
501
+ swift_bincompat_useLegacyNonCrashingExecutorChecks ();
502
+
527
503
long level = strtol (levelStr, nullptr , 0 );
528
- if (level >= 0 && level < 3 )
529
- unexpectedExecutorLogLevel = level;
504
+ if (level >= 0 && level < 3 ) {
505
+ if (isSameExecutorLegacyMode) {
506
+ // legacy mode permits doing nothing or just logging, since the method
507
+ // used to perform the check itself is not going to crash:
508
+ unexpectedExecutorLogLevel = level;
509
+ } else {
510
+ // We are in swift6/crash mode of isSameExecutor... which means that
511
+ // rather than returning false, that method will always CRASH when an
512
+ // executor mismatch is discovered. This means that it is not possible
513
+ // to support logging or warning 'unexpected executor log level' in this mode.
514
+ if (level > 1 ) {
515
+ fprintf (stderr, " [%s:%d](%s) [unexpected executor] ONLY CRASH MODE IS OK\n " , __FILE_NAME__, __LINE__, __FUNCTION__);
516
+ unexpectedExecutorLogLevel = level;
517
+ } else {
518
+ fprintf (stderr,
519
+ " [%s:%d](%s) [unexpected executor] HAD TO IGNORE LEVEL [%s] CRASH MODE IS OK\n " ,
520
+ level, __FILE_NAME__, __LINE__, __FUNCTION__);
521
+ }
522
+ }
523
+ }
530
524
#endif // SWIFT_STDLIB_HAS_ENVIRON
531
525
}
532
526
0 commit comments