@@ -335,10 +335,9 @@ enum IsCurrentExecutorCheckMode: unsigned {
335
335
static IsCurrentExecutorCheckMode isCurrentExecutorMode =
336
336
Swift6_UseCheckIsolated_AllowCrash;
337
337
338
-
339
338
// Shimming call to Swift runtime because Swift Embedded does not have
340
339
// these symbols defined.
341
- bool swift_bincompat_useLegacyNonCrashingExecutorChecks () {
340
+ bool __swift_bincompat_useLegacyNonCrashingExecutorChecks () {
342
341
#if !SWIFT_CONCURRENCY_EMBEDDED
343
342
return swift::runtime::bincompat::
344
343
swift_bincompat_useLegacyNonCrashingExecutorChecks ();
@@ -347,22 +346,30 @@ bool swift_bincompat_useLegacyNonCrashingExecutorChecks() {
347
346
#endif
348
347
}
349
348
350
- // Check override of executor checking mode.
351
- static void checkIsCurrentExecutorMode ( void *context) {
352
- auto useLegacyMode =
353
- swift_bincompat_useLegacyNonCrashingExecutorChecks ();
349
+ // Done this way because of the interaction with the initial value of
350
+ // 'unexpectedExecutorLogLevel'
351
+ bool swift_bincompat_useLegacyNonCrashingExecutorChecks () {
352
+ bool legacyMode = __swift_bincompat_useLegacyNonCrashingExecutorChecks ();
354
353
355
354
// Potentially, override the platform detected mode, primarily used in tests.
356
355
#if SWIFT_STDLIB_HAS_ENVIRON
357
- if (const char *modeStr = runtime::environment::concurrencyIsCurrentExecutorLegacyModeOverride ()) {
356
+ if (const char *modeStr = runtime::environment::
357
+ concurrencyIsCurrentExecutorLegacyModeOverride ()) {
358
358
if (strcmp (modeStr, " nocrash" ) == 0 || strcmp (modeStr, " legacy" ) == 0 ) {
359
- useLegacyMode = true ;
359
+ return true ;
360
360
} else if (strcmp (modeStr, " crash" ) == 0 || strcmp (modeStr, " swift6" ) == 0 ) {
361
- useLegacyMode = false ;
361
+ return false ; // don't use the legacy mode
362
362
} // else, just use the platform detected mode
363
- }
363
+ } // no override, use the default mode
364
364
#endif // SWIFT_STDLIB_HAS_ENVIRON
365
365
366
+ return legacyMode;
367
+ }
368
+
369
+ // Check override of executor checking mode.
370
+ static void checkIsCurrentExecutorMode (void *context) {
371
+ bool useLegacyMode =
372
+ swift_bincompat_useLegacyNonCrashingExecutorChecks ();
366
373
isCurrentExecutorMode = useLegacyMode ? Legacy_NoCheckIsolated_NonCrashing
367
374
: Swift6_UseCheckIsolated_AllowCrash;
368
375
}
@@ -382,6 +389,11 @@ static bool swift_task_isCurrentExecutorImpl(SerialExecutorRef expectedExecutor)
382
389
static swift::once_t checkModeToken;
383
390
swift::once (checkModeToken, checkIsCurrentExecutorMode, nullptr );
384
391
392
+ fprintf (stderr, " [%s:%d](%s) MODE = %s\n " , __FILE_NAME__, __LINE__, __FUNCTION__,
393
+ isCurrentExecutorMode == Swift6_UseCheckIsolated_AllowCrash
394
+ ? " Swift6_UseCheckIsolated_AllowCrash"
395
+ : " Legacy_NoCheckIsolated_NonCrashing" );
396
+
385
397
if (!current) {
386
398
// We have no current executor, i.e. we are running "outside" of Swift
387
399
// Concurrency. We could still be running on a thread/queue owned by
@@ -521,12 +533,9 @@ static void checkUnexpectedExecutorLogLevel(void *context) {
521
533
if (!levelStr)
522
534
return ;
523
535
524
- auto isCurrentExecutorLegacyMode =
525
- swift_bincompat_useLegacyNonCrashingExecutorChecks ();
526
-
527
536
long level = strtol (levelStr, nullptr , 0 );
528
537
if (level >= 0 && level < 3 ) {
529
- if (isCurrentExecutorLegacyMode ) {
538
+ if (swift_bincompat_useLegacyNonCrashingExecutorChecks () ) {
530
539
// legacy mode permits doing nothing or just logging, since the method
531
540
// used to perform the check itself is not going to crash:
532
541
unexpectedExecutorLogLevel = level;
0 commit comments