Skip to content

Commit 0ce84dc

Browse files
committed
[Concurrency] Reshape initial values of executor checking so tests pass on Linux
1 parent 61e29ec commit 0ce84dc

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

stdlib/public/Concurrency/Actor.cpp

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

337-
338337
// Shimming call to Swift runtime because Swift Embedded does not have
339338
// these symbols defined.
340-
bool swift_bincompat_useLegacyNonCrashingExecutorChecks() {
339+
bool __swift_bincompat_useLegacyNonCrashingExecutorChecks() {
341340
#if !SWIFT_CONCURRENCY_EMBEDDED
342341
return swift::runtime::bincompat::
343342
swift_bincompat_useLegacyNonCrashingExecutorChecks();
@@ -346,22 +345,30 @@ bool swift_bincompat_useLegacyNonCrashingExecutorChecks() {
346345
#endif
347346
}
348347

349-
// Check override of executor checking mode.
350-
static void checkIsCurrentExecutorMode(void *context) {
351-
auto useLegacyMode =
352-
swift_bincompat_useLegacyNonCrashingExecutorChecks();
348+
// Done this way because of the interaction with the initial value of
349+
// 'unexpectedExecutorLogLevel'
350+
bool swift_bincompat_useLegacyNonCrashingExecutorChecks() {
351+
bool legacyMode = __swift_bincompat_useLegacyNonCrashingExecutorChecks();
353352

354353
// Potentially, override the platform detected mode, primarily used in tests.
355354
#if SWIFT_STDLIB_HAS_ENVIRON
356-
if (const char *modeStr = runtime::environment::concurrencyIsCurrentExecutorLegacyModeOverride()) {
355+
if (const char *modeStr = runtime::environment::
356+
concurrencyIsCurrentExecutorLegacyModeOverride()) {
357357
if (strcmp(modeStr, "nocrash") == 0 || strcmp(modeStr, "legacy") == 0) {
358-
useLegacyMode = true;
358+
return true;
359359
} else if (strcmp(modeStr, "crash") == 0 || strcmp(modeStr, "swift6") == 0) {
360-
useLegacyMode = false;
360+
return false; // don't use the legacy mode
361361
} // else, just use the platform detected mode
362-
}
362+
} // no override, use the default mode
363363
#endif // SWIFT_STDLIB_HAS_ENVIRON
364364

365+
return legacyMode;
366+
}
367+
368+
// Check override of executor checking mode.
369+
static void checkIsCurrentExecutorMode(void *context) {
370+
bool useLegacyMode =
371+
swift_bincompat_useLegacyNonCrashingExecutorChecks();
365372
isCurrentExecutorMode = useLegacyMode ? Legacy_NoCheckIsolated_NonCrashing
366373
: Swift6_UseCheckIsolated_AllowCrash;
367374
}
@@ -520,12 +527,9 @@ static void checkUnexpectedExecutorLogLevel(void *context) {
520527
if (!levelStr)
521528
return;
522529

523-
auto isCurrentExecutorLegacyMode =
524-
swift_bincompat_useLegacyNonCrashingExecutorChecks();
525-
526530
long level = strtol(levelStr, nullptr, 0);
527531
if (level >= 0 && level < 3) {
528-
if (isCurrentExecutorLegacyMode) {
532+
if (swift_bincompat_useLegacyNonCrashingExecutorChecks()) {
529533
// legacy mode permits doing nothing or just logging, since the method
530534
// used to perform the check itself is not going to crash:
531535
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=legacy %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)