Skip to content

Commit 47b8b3f

Browse files
committed
[Concurrency] Use EnvVars utilities for SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE
1 parent f650dc0 commit 47b8b3f

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

include/swift/Runtime/EnvironmentVariables.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ SWIFT_RUNTIME_STDLIB_SPI bool concurrencyEnableJobDispatchIntegration();
5353
// Concurrency library can call.
5454
SWIFT_RUNTIME_STDLIB_SPI bool concurrencyValidateUncheckedContinuations();
5555

56+
// Wrapper around SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE that the
57+
// Concurrency library can call.
58+
SWIFT_RUNTIME_STDLIB_SPI const char *concurrencyIsCurrentExecutorLegacyModeOverride();
59+
5660
} // end namespace environment
5761
} // end namespace runtime
5862
} // end namespace swift

stdlib/public/Concurrency/Actor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "swift/Runtime/Bincompat.h"
3131
#include "swift/Runtime/Casting.h"
3232
#include "swift/Runtime/DispatchShims.h"
33+
#include "swift/Runtime/EnvironmentVariables.h"
3334
#include "swift/Threading/Mutex.h"
3435
#include "swift/Threading/Once.h"
3536
#include "swift/Threading/Thread.h"
@@ -352,8 +353,8 @@ static void checkIsCurrentExecutorMode(void *context) {
352353
// Potentially, override the platform detected mode, primarily used in tests.
353354
#if SWIFT_STDLIB_HAS_ENVIRON
354355
if (const char *modeStr =
355-
getenv("SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE")) {
356-
if (modeStr && *modeStr) {
356+
runtime::environment::concurrencyIsCurrentExecutorLegacyModeOverride()) {
357+
if (modeStr) {
357358
if (strcmp(modeStr, "nocrash") == 0) {
358359
useLegacyMode = true;
359360
} else if (strcmp(modeStr, "crash") == 0) {

stdlib/public/runtime/EnvironmentVariables.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,7 @@ SWIFT_RUNTIME_STDLIB_SPI bool concurrencyEnableJobDispatchIntegration() {
272272
SWIFT_RUNTIME_STDLIB_SPI bool concurrencyValidateUncheckedContinuations() {
273273
return runtime::environment::SWIFT_DEBUG_VALIDATE_UNCHECKED_CONTINUATIONS();
274274
}
275+
276+
SWIFT_RUNTIME_STDLIB_SPI const char *concurrencyIsCurrentExecutorLegacyModeOverride() {
277+
return runtime::environment::SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE();
278+
}

stdlib/public/runtime/EnvironmentVariables.def

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,17 @@ VARIABLE(SWIFT_BACKTRACE, string, "",
119119
"crash catching and backtracing support in the runtime. "
120120
"See docs/Backtracing.rst in the Swift repository for details.")
121121

122+
VARIABLE(SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE, string, "",
123+
"Allows for suppressing 'is current executor' equality check crashes. "
124+
"As since Swift 6.0 checking for current executor equality, may crash "
125+
"and will never return 'false' because we are calling into library "
126+
"implemented SerialExecutor.checkIsolation which should crash if the "
127+
"isolation is not the expected one. Some old code may rely on the "
128+
"non-crashing behavior. This flag enables temporarily restoring the "
129+
"legacy 'nocrash' behavior until adopting code has been adjusted.\n"
130+
"\n"
131+
"Legal values are: \n"
132+
" - nocrash (Legacy behavior)\n"
133+
" - crash (Swift 6.0+ behavior)")
134+
122135
#undef VARIABLE

0 commit comments

Comments
 (0)