Skip to content

Commit d887827

Browse files
authored
Merge pull request #73509 from ktoso/pick-wip-fix-checkIsCurrentExecutorMode
2 parents 21b30a7 + 599b3f9 commit d887827

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,16 @@ 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. "
130+
"Legal values are: "
131+
" 'nocrash' (Legacy behavior), "
132+
" 'crash' (Swift 6.0+ behavior)")
133+
122134
#undef VARIABLE

test/abi/macOS/arm64/stdlib.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,6 @@ Added: __swift_enableSwizzlingOfAllocationAndRefCountingFunctions_forInstruments
565565

566566
// Runtime bincompat functions for Concurrency runtime to detect legacy mode
567567
Added: _swift_bincompat_useLegacyNonCrashingExecutorChecks
568+
569+
// Add add SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE
570+
Added: _concurrencyIsCurrentExecutorLegacyModeOverride

test/abi/macOS/x86_64/stdlib.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,6 @@ Added: __swift_enableSwizzlingOfAllocationAndRefCountingFunctions_forInstruments
565565

566566
// Runtime bincompat functions for Concurrency runtime to detect legacy mode
567567
Added: _swift_bincompat_useLegacyNonCrashingExecutorChecks
568+
569+
// Add add SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE
570+
Added: _concurrencyIsCurrentExecutorLegacyModeOverride

0 commit comments

Comments
 (0)