Skip to content

Remove unused functions from 5.6 backdeploy #61643

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 1 commit into from
Oct 20, 2022
Merged
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
154 changes: 0 additions & 154 deletions stdlib/toolchain/Compatibility56/Concurrency/TaskLocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,85 +77,6 @@ SWIFT_RUNTIME_DECLARE_THREAD_LOCAL(
Pointer<TaskLocal::Storage>, FallbackTaskLocalStorage::Value,
SWIFT_CONCURRENCY_FALLBACK_TASK_LOCAL_STORAGE_KEY);

// ==== ABI --------------------------------------------------------------------

SWIFT_CC(swift)
static void swift_task_localValuePushImpl(const HeapObject *key,
/* +1 */ OpaqueValue *value,
const Metadata *valueType) {
if (AsyncTask *task = swift_task_getCurrent()) {
task->localValuePush(key, value, valueType);
return;
}

// no AsyncTask available so we must check the fallback
TaskLocal::Storage *Local = nullptr;
if (auto storage = FallbackTaskLocalStorage::get()) {
Local = storage;
} else {
void *allocation = malloc(sizeof(TaskLocal::Storage));
auto *freshStorage = new(allocation) TaskLocal::Storage();

FallbackTaskLocalStorage::set(freshStorage);
Local = freshStorage;
}

Local->pushValue(/*task=*/nullptr, key, value, valueType);
}

SWIFT_CC(swift)
static OpaqueValue* swift_task_localValueGetImpl(const HeapObject *key) {
if (AsyncTask *task = swift_task_getCurrent()) {
// we're in the context of a task and can use the task's storage
return task->localValueGet(key);
}

// no AsyncTask available so we must check the fallback
if (auto Local = FallbackTaskLocalStorage::get()) {
return Local->getValue(/*task*/nullptr, key);
}

// no value found in task-local or fallback thread-local storage.
return nullptr;
}

SWIFT_CC(swift)
static void swift_task_localValuePopImpl() {
if (AsyncTask *task = swift_task_getCurrent()) {
task->localValuePop();
return;
}

if (TaskLocal::Storage *Local = FallbackTaskLocalStorage::get()) {
bool hasRemainingBindings = Local->popValue(nullptr);
if (!hasRemainingBindings) {
// We clean up eagerly, it may be that this non-swift-concurrency thread
// never again will use task-locals, and as such we better remove the storage.
FallbackTaskLocalStorage::set(nullptr);
free(Local);
}
return;
}

assert(false && "Attempted to pop value but no task or thread-local storage available!");
}

SWIFT_CC(swift)
static void swift_task_localsCopyToImpl(AsyncTask *task) {
TaskLocal::Storage *Local = nullptr;

if (AsyncTask *task = swift_task_getCurrent()) {
Local = &task->_private().Local;
} else if (auto *storage = FallbackTaskLocalStorage::get()) {
Local = storage;
} else {
// bail out, there are no values to copy
return;
}

Local->copyTo(task);
}

// =============================================================================
// ==== Initialization ---------------------------------------------------------

Expand Down Expand Up @@ -241,81 +162,6 @@ void TaskLocal::Item::copyTo(AsyncTask *target) {
target->_private().Local.head = item;
}

// =============================================================================
// ==== checks -----------------------------------------------------------------

SWIFT_CC(swift)
static void swift_task_reportIllegalTaskLocalBindingWithinWithTaskGroupImpl(
const unsigned char *file, uintptr_t fileLength,
bool fileIsASCII, uintptr_t line) {

char *message;
swift_asprintf(
&message,
"error: task-local: detected illegal task-local value binding at %.*s:%d.\n"
"Task-local values must only be set in a structured-context, such as: "
"around any (synchronous or asynchronous function invocation), "
"around an 'async let' declaration, or around a 'with(Throwing)TaskGroup(...){ ... }' "
"invocation. Notably, binding a task-local value is illegal *within the body* "
"of a withTaskGroup invocation.\n"
"\n"
"The following example is illegal:\n\n"
" await withTaskGroup(...) { group in \n"
" await <task-local>.withValue(1234) {\n"
" group.spawn { ... }\n"
" }\n"
" }\n"
"\n"
"And should be replaced by, either: setting the value for the entire group:\n"
"\n"
" // bind task-local for all tasks spawned within the group\n"
" await <task-local>.withValue(1234) {\n"
" await withTaskGroup(...) { group in\n"
" group.spawn { ... }\n"
" }\n"
" }\n"
"\n"
"or, inside the specific task-group child task:\n"
"\n"
" // bind-task-local for only specific child-task\n"
" await withTaskGroup(...) { group in\n"
" group.spawn {\n"
" await <task-local>.withValue(1234) {\n"
" ... \n"
" }\n"
" }\n"
"\n"
" group.spawn { ... }\n"
" }\n",
(int)fileLength, file,
(int)line);

if (_swift_shouldReportFatalErrorsToDebugger()) {
RuntimeErrorDetails details = {
.version = RuntimeErrorDetails::currentVersion,
.errorType = "task-local-violation",
.currentStackDescription = "Task-local bound in illegal context",
.framesToSkip = 1,
};
_swift_reportToDebugger(RuntimeErrorFlagFatal, message, &details);
}

#if defined(_WIN32)
#define STDERR_FILENO 2
_write(STDERR_FILENO, message, strlen(message));
#else
write(STDERR_FILENO, message, strlen(message));
#endif
#if defined(__APPLE__)
asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", message);
#elif defined(__ANDROID__)
__android_log_print(ANDROID_LOG_FATAL, "SwiftRuntime", "%s", message);
#endif

free(message);
abort();
}

// =============================================================================
// ==== destroy ----------------------------------------------------------------

Expand Down