Skip to content

[6.0][Concurrency] Use EnvVars utilities for SWIFT_IS_CURRENT_EXECUTOR_LEG… #73509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/Runtime/EnvironmentVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ SWIFT_RUNTIME_STDLIB_SPI bool concurrencyEnableJobDispatchIntegration();
// Concurrency library can call.
SWIFT_RUNTIME_STDLIB_SPI bool concurrencyValidateUncheckedContinuations();

// Wrapper around SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE that the
// Concurrency library can call.
SWIFT_RUNTIME_STDLIB_SPI const char *concurrencyIsCurrentExecutorLegacyModeOverride();

} // end namespace environment
} // end namespace runtime
} // end namespace swift
5 changes: 3 additions & 2 deletions stdlib/public/Concurrency/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "swift/Runtime/Bincompat.h"
#include "swift/Runtime/Casting.h"
#include "swift/Runtime/DispatchShims.h"
#include "swift/Runtime/EnvironmentVariables.h"
#include "swift/Threading/Mutex.h"
#include "swift/Threading/Once.h"
#include "swift/Threading/Thread.h"
Expand Down Expand Up @@ -352,8 +353,8 @@ static void checkIsCurrentExecutorMode(void *context) {
// Potentially, override the platform detected mode, primarily used in tests.
#if SWIFT_STDLIB_HAS_ENVIRON
if (const char *modeStr =
getenv("SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE")) {
if (modeStr && *modeStr) {
runtime::environment::concurrencyIsCurrentExecutorLegacyModeOverride()) {
if (modeStr) {
if (strcmp(modeStr, "nocrash") == 0) {
useLegacyMode = true;
} else if (strcmp(modeStr, "crash") == 0) {
Expand Down
4 changes: 4 additions & 0 deletions stdlib/public/runtime/EnvironmentVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,7 @@ SWIFT_RUNTIME_STDLIB_SPI bool concurrencyEnableJobDispatchIntegration() {
SWIFT_RUNTIME_STDLIB_SPI bool concurrencyValidateUncheckedContinuations() {
return runtime::environment::SWIFT_DEBUG_VALIDATE_UNCHECKED_CONTINUATIONS();
}

SWIFT_RUNTIME_STDLIB_SPI const char *concurrencyIsCurrentExecutorLegacyModeOverride() {
return runtime::environment::SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE();
}
12 changes: 12 additions & 0 deletions stdlib/public/runtime/EnvironmentVariables.def
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,16 @@ VARIABLE(SWIFT_BACKTRACE, string, "",
"crash catching and backtracing support in the runtime. "
"See docs/Backtracing.rst in the Swift repository for details.")

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

#undef VARIABLE
3 changes: 3 additions & 0 deletions test/abi/macOS/arm64/stdlib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -565,3 +565,6 @@ Added: __swift_enableSwizzlingOfAllocationAndRefCountingFunctions_forInstruments

// Runtime bincompat functions for Concurrency runtime to detect legacy mode
Added: _swift_bincompat_useLegacyNonCrashingExecutorChecks

// Add add SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE
Added: _concurrencyIsCurrentExecutorLegacyModeOverride
3 changes: 3 additions & 0 deletions test/abi/macOS/x86_64/stdlib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -565,3 +565,6 @@ Added: __swift_enableSwizzlingOfAllocationAndRefCountingFunctions_forInstruments

// Runtime bincompat functions for Concurrency runtime to detect legacy mode
Added: _swift_bincompat_useLegacyNonCrashingExecutorChecks

// Add add SWIFT_IS_CURRENT_EXECUTOR_LEGACY_MODE_OVERRIDE
Added: _concurrencyIsCurrentExecutorLegacyModeOverride