Skip to content

Commit bef90eb

Browse files
committed
[Concurrency] Reshape initial values of executor checking so tests pass on Linux
1 parent 55ce24e commit bef90eb

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,9 @@ enum IsCurrentExecutorCheckMode: unsigned {
335335
static IsCurrentExecutorCheckMode isCurrentExecutorMode =
336336
Swift6_UseCheckIsolated_AllowCrash;
337337

338-
339338
// Shimming call to Swift runtime because Swift Embedded does not have
340339
// these symbols defined.
341-
bool swift_bincompat_useLegacyNonCrashingExecutorChecks() {
340+
bool __swift_bincompat_useLegacyNonCrashingExecutorChecks() {
342341
#if !SWIFT_CONCURRENCY_EMBEDDED
343342
return swift::runtime::bincompat::
344343
swift_bincompat_useLegacyNonCrashingExecutorChecks();
@@ -347,22 +346,30 @@ bool swift_bincompat_useLegacyNonCrashingExecutorChecks() {
347346
#endif
348347
}
349348

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();
354353

355354
// Potentially, override the platform detected mode, primarily used in tests.
356355
#if SWIFT_STDLIB_HAS_ENVIRON
357-
if (const char *modeStr = runtime::environment::concurrencyIsCurrentExecutorLegacyModeOverride()) {
356+
if (const char *modeStr = runtime::environment::
357+
concurrencyIsCurrentExecutorLegacyModeOverride()) {
358358
if (strcmp(modeStr, "nocrash") == 0 || strcmp(modeStr, "legacy") == 0) {
359-
useLegacyMode = true;
359+
return true;
360360
} else if (strcmp(modeStr, "crash") == 0 || strcmp(modeStr, "swift6") == 0) {
361-
useLegacyMode = false;
361+
return false; // don't use the legacy mode
362362
} // else, just use the platform detected mode
363-
}
363+
} // no override, use the default mode
364364
#endif // SWIFT_STDLIB_HAS_ENVIRON
365365

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();
366373
isCurrentExecutorMode = useLegacyMode ? Legacy_NoCheckIsolated_NonCrashing
367374
: Swift6_UseCheckIsolated_AllowCrash;
368375
}
@@ -382,6 +389,11 @@ static bool swift_task_isCurrentExecutorImpl(SerialExecutorRef expectedExecutor)
382389
static swift::once_t checkModeToken;
383390
swift::once(checkModeToken, checkIsCurrentExecutorMode, nullptr);
384391

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+
385397
if (!current) {
386398
// We have no current executor, i.e. we are running "outside" of Swift
387399
// Concurrency. We could still be running on a thread/queue owned by
@@ -521,12 +533,9 @@ static void checkUnexpectedExecutorLogLevel(void *context) {
521533
if (!levelStr)
522534
return;
523535

524-
auto isCurrentExecutorLegacyMode =
525-
swift_bincompat_useLegacyNonCrashingExecutorChecks();
526-
527536
long level = strtol(levelStr, nullptr, 0);
528537
if (level >= 0 && level < 3) {
529-
if (isCurrentExecutorLegacyMode) {
538+
if (swift_bincompat_useLegacyNonCrashingExecutorChecks()) {
530539
// legacy mode permits doing nothing or just logging, since the method
531540
// used to perform the check itself is not going to crash:
532541
unexpectedExecutorLogLevel = level;

test/Concurrency/Runtime/actor_assert_precondition_executor_default_mode.swift renamed to test/Concurrency/Runtime/actor_assert_precondition_executor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-build-swift -Xfrontend -disable-availability-checking -parse-as-library %s -o %t/a.out
33
// RUN: %target-codesign %t/a.out
4-
// RUN: %target-run %t/a.out
4+
// RUN: %env-SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=swift6 %target-run %t/a.out
55

66
// REQUIRES: executable_test
77
// REQUIRES: concurrency
@@ -12,7 +12,7 @@
1212
// UNSUPPORTED: use_os_stdlib
1313
// UNSUPPORTED: freestanding
1414

15-
// rdar://119743909 fails in optimze tests.
15+
// rdar://119743909 fails in optimize tests.
1616
// UNSUPPORTED: swift_test_mode_optimize
1717
// UNSUPPORTED: swift_test_mode_optimize_size
1818

test/Concurrency/Runtime/actor_assume_executor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-build-swift -Xfrontend -disable-availability-checking -parse-as-library %s -o %t/a.out
33
// RUN: %target-codesign %t/a.out
4-
// RUN: %target-run %t/a.out
4+
// RUN: %env-SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=legacy %target-run %t/a.out
55

66
// REQUIRES: executable_test
77
// REQUIRES: concurrency

test/Concurrency/Runtime/data_race_detection_legacy_warning.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// will be able to have this behavior, however new apps will not. We use the
77
// overrides to test the logic for legacy code remains functional.
88
//
9-
// RUN: env %env-SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=1 %env-SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=nocrash %target-run %t/a.out 2>&1 | %FileCheck %s
9+
// RUN: %env-SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=1 %env-SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE=legacy %target-run %t/a.out 2>&1 | %FileCheck %s
1010

1111
// REQUIRES: executable_test
1212
// REQUIRES: concurrency
@@ -66,14 +66,14 @@ actor MyActor {
6666
struct Runner {
6767
static func main() async {
6868
print("Launching a main-actor task")
69-
// CHECK: warning: data race detected: @MainActor function at main/data_race_detection_legacy_warning.swift:30 was not called on the main thread
69+
// CHECK: data race detected: @MainActor function at main/data_race_detection_legacy_warning.swift:30 was not called on the main thread
7070
launchFromMainThread()
7171
sleep(1)
7272

7373
let actor = MyActor()
7474
let actorFn = await actor.getTaskOnMyActor()
7575
print("Launching an actor-instance task")
76-
// CHECK: warning: data race detected: actor-isolated function at main/data_race_detection_legacy_warning.swift:59 was not called on the same actor
76+
// CHECK: data race detected: actor-isolated function at main/data_race_detection_legacy_warning.swift:59 was not called on the same actor
7777
launchTask(actorFn)
7878

7979
sleep(1)

0 commit comments

Comments
 (0)