Skip to content

Commit 60afe4f

Browse files
committed
Merge remote-tracking branch 'origin/main' into next
2 parents f47ef26 + 5b6c814 commit 60afe4f

File tree

1 file changed

+0
-154
lines changed

1 file changed

+0
-154
lines changed

stdlib/toolchain/Compatibility56/Concurrency/TaskLocal.cpp

Lines changed: 0 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -77,85 +77,6 @@ SWIFT_RUNTIME_DECLARE_THREAD_LOCAL(
7777
Pointer<TaskLocal::Storage>, FallbackTaskLocalStorage::Value,
7878
SWIFT_CONCURRENCY_FALLBACK_TASK_LOCAL_STORAGE_KEY);
7979

80-
// ==== ABI --------------------------------------------------------------------
81-
82-
SWIFT_CC(swift)
83-
static void swift_task_localValuePushImpl(const HeapObject *key,
84-
/* +1 */ OpaqueValue *value,
85-
const Metadata *valueType) {
86-
if (AsyncTask *task = swift_task_getCurrent()) {
87-
task->localValuePush(key, value, valueType);
88-
return;
89-
}
90-
91-
// no AsyncTask available so we must check the fallback
92-
TaskLocal::Storage *Local = nullptr;
93-
if (auto storage = FallbackTaskLocalStorage::get()) {
94-
Local = storage;
95-
} else {
96-
void *allocation = malloc(sizeof(TaskLocal::Storage));
97-
auto *freshStorage = new(allocation) TaskLocal::Storage();
98-
99-
FallbackTaskLocalStorage::set(freshStorage);
100-
Local = freshStorage;
101-
}
102-
103-
Local->pushValue(/*task=*/nullptr, key, value, valueType);
104-
}
105-
106-
SWIFT_CC(swift)
107-
static OpaqueValue* swift_task_localValueGetImpl(const HeapObject *key) {
108-
if (AsyncTask *task = swift_task_getCurrent()) {
109-
// we're in the context of a task and can use the task's storage
110-
return task->localValueGet(key);
111-
}
112-
113-
// no AsyncTask available so we must check the fallback
114-
if (auto Local = FallbackTaskLocalStorage::get()) {
115-
return Local->getValue(/*task*/nullptr, key);
116-
}
117-
118-
// no value found in task-local or fallback thread-local storage.
119-
return nullptr;
120-
}
121-
122-
SWIFT_CC(swift)
123-
static void swift_task_localValuePopImpl() {
124-
if (AsyncTask *task = swift_task_getCurrent()) {
125-
task->localValuePop();
126-
return;
127-
}
128-
129-
if (TaskLocal::Storage *Local = FallbackTaskLocalStorage::get()) {
130-
bool hasRemainingBindings = Local->popValue(nullptr);
131-
if (!hasRemainingBindings) {
132-
// We clean up eagerly, it may be that this non-swift-concurrency thread
133-
// never again will use task-locals, and as such we better remove the storage.
134-
FallbackTaskLocalStorage::set(nullptr);
135-
free(Local);
136-
}
137-
return;
138-
}
139-
140-
assert(false && "Attempted to pop value but no task or thread-local storage available!");
141-
}
142-
143-
SWIFT_CC(swift)
144-
static void swift_task_localsCopyToImpl(AsyncTask *task) {
145-
TaskLocal::Storage *Local = nullptr;
146-
147-
if (AsyncTask *task = swift_task_getCurrent()) {
148-
Local = &task->_private().Local;
149-
} else if (auto *storage = FallbackTaskLocalStorage::get()) {
150-
Local = storage;
151-
} else {
152-
// bail out, there are no values to copy
153-
return;
154-
}
155-
156-
Local->copyTo(task);
157-
}
158-
15980
// =============================================================================
16081
// ==== Initialization ---------------------------------------------------------
16182

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

244-
// =============================================================================
245-
// ==== checks -----------------------------------------------------------------
246-
247-
SWIFT_CC(swift)
248-
static void swift_task_reportIllegalTaskLocalBindingWithinWithTaskGroupImpl(
249-
const unsigned char *file, uintptr_t fileLength,
250-
bool fileIsASCII, uintptr_t line) {
251-
252-
char *message;
253-
swift_asprintf(
254-
&message,
255-
"error: task-local: detected illegal task-local value binding at %.*s:%d.\n"
256-
"Task-local values must only be set in a structured-context, such as: "
257-
"around any (synchronous or asynchronous function invocation), "
258-
"around an 'async let' declaration, or around a 'with(Throwing)TaskGroup(...){ ... }' "
259-
"invocation. Notably, binding a task-local value is illegal *within the body* "
260-
"of a withTaskGroup invocation.\n"
261-
"\n"
262-
"The following example is illegal:\n\n"
263-
" await withTaskGroup(...) { group in \n"
264-
" await <task-local>.withValue(1234) {\n"
265-
" group.spawn { ... }\n"
266-
" }\n"
267-
" }\n"
268-
"\n"
269-
"And should be replaced by, either: setting the value for the entire group:\n"
270-
"\n"
271-
" // bind task-local for all tasks spawned within the group\n"
272-
" await <task-local>.withValue(1234) {\n"
273-
" await withTaskGroup(...) { group in\n"
274-
" group.spawn { ... }\n"
275-
" }\n"
276-
" }\n"
277-
"\n"
278-
"or, inside the specific task-group child task:\n"
279-
"\n"
280-
" // bind-task-local for only specific child-task\n"
281-
" await withTaskGroup(...) { group in\n"
282-
" group.spawn {\n"
283-
" await <task-local>.withValue(1234) {\n"
284-
" ... \n"
285-
" }\n"
286-
" }\n"
287-
"\n"
288-
" group.spawn { ... }\n"
289-
" }\n",
290-
(int)fileLength, file,
291-
(int)line);
292-
293-
if (_swift_shouldReportFatalErrorsToDebugger()) {
294-
RuntimeErrorDetails details = {
295-
.version = RuntimeErrorDetails::currentVersion,
296-
.errorType = "task-local-violation",
297-
.currentStackDescription = "Task-local bound in illegal context",
298-
.framesToSkip = 1,
299-
};
300-
_swift_reportToDebugger(RuntimeErrorFlagFatal, message, &details);
301-
}
302-
303-
#if defined(_WIN32)
304-
#define STDERR_FILENO 2
305-
_write(STDERR_FILENO, message, strlen(message));
306-
#else
307-
write(STDERR_FILENO, message, strlen(message));
308-
#endif
309-
#if defined(__APPLE__)
310-
asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", message);
311-
#elif defined(__ANDROID__)
312-
__android_log_print(ANDROID_LOG_FATAL, "SwiftRuntime", "%s", message);
313-
#endif
314-
315-
free(message);
316-
abort();
317-
}
318-
319165
// =============================================================================
320166
// ==== destroy ----------------------------------------------------------------
321167

0 commit comments

Comments
 (0)