Skip to content

Runtime: split out extern "C" marker from SWIFT_RUNTIME_EXPORT #61476

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

Closed
wants to merge 1 commit into from
Closed
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/Casting.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

namespace swift {

SWIFT_BEGIN_DECLS

/// Perform a checked dynamic cast of a value to a target type.
///
/// \param dest A buffer into which to write the destination value.
Expand Down Expand Up @@ -244,6 +246,8 @@ SWIFT_RUNTIME_EXPORT
const WitnessTable *swift_conformsToProtocol(const Metadata *type,
const ProtocolDescriptor *protocol);

SWIFT_END_DECLS

} // end namespace swift

#endif // SWIFT_RUNTIME_CASTING_H
139 changes: 97 additions & 42 deletions include/swift/Runtime/Concurrency.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,41 @@ struct AsyncTaskAndContext {
AsyncContext *InitialContext;
};

SWIFT_BEGIN_DECLS

/// Create a task object.
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
AsyncTaskAndContext swift_task_create(
size_t taskCreateFlags,
TaskOptionRecord *options,
const Metadata *futureResultType,
void *closureEntry, HeapObject *closureContext);
AsyncTaskAndContext swift_task_create(size_t taskCreateFlags,
TaskOptionRecord *options,
const Metadata *futureResultType,
void *closureEntry,
HeapObject *closureContext);

SWIFT_END_DECLS

/// Caution: not all future-initializing functions actually throw, so
/// this signature may be incorrect.
using FutureAsyncSignature =
AsyncSignature<void(void*), /*throws*/ true>;

SWIFT_BEGIN_DECLS

/// Create a task object.
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
AsyncTaskAndContext swift_task_create_common(
size_t taskCreateFlags,
TaskOptionRecord *options,
const Metadata *futureResultType,
TaskContinuationFunction *function, void *closureContext,
size_t initialContextSize);
AsyncTaskAndContext
swift_task_create_common(size_t taskCreateFlags, TaskOptionRecord *options,
const Metadata *futureResultType,
TaskContinuationFunction *function,
void *closureContext,
size_t initialContextSize);

SWIFT_END_DECLS

#if SWIFT_CONCURRENCY_TASK_TO_THREAD_MODEL
#define SWIFT_TASK_RUN_INLINE_INITIAL_CONTEXT_BYTES 4096

SWIFT_BEGIN_DECLS

/// Begin an async context in the current sync context and run the indicated
/// closure in it.
///
Expand All @@ -104,8 +115,13 @@ SWIFT_CC(swift)
void swift_task_run_inline(OpaqueValue *result, void *closureAFP,
OpaqueValue *closureContext,
const Metadata *futureResultType);

SWIFT_END_DECLS

#endif

SWIFT_BEGIN_DECLS

/// Allocate memory in a task.
///
/// This must be called synchronously with the task.
Expand Down Expand Up @@ -141,8 +157,7 @@ void swift_task_cancel_group_child_tasks(TaskGroup *group);
/// This has no effect if the task already has at least the given priority.
/// Returns the priority of the task.
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
JobPriority
swift_task_escalate(AsyncTask *task, JobPriority newPriority);
JobPriority swift_task_escalate(AsyncTask *task, JobPriority newPriority);

// TODO: "async let wait" and "async let destroy" would be expressed
// similar to like TaskFutureWait;
Expand All @@ -156,10 +171,9 @@ swift_task_escalate(AsyncTask *task, JobPriority newPriority);
/// -> Success
/// \endcode
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swiftasync)
void swift_task_future_wait(OpaqueValue *,
SWIFT_ASYNC_CONTEXT AsyncContext *, AsyncTask *,
TaskContinuationFunction *,
AsyncContext *);
void
swift_task_future_wait(OpaqueValue *, SWIFT_ASYNC_CONTEXT AsyncContext *,
AsyncTask *, TaskContinuationFunction *, AsyncContext *);

/// Wait for a potentially-throwing future task to complete.
///
Expand All @@ -170,12 +184,12 @@ void swift_task_future_wait(OpaqueValue *,
/// async throws -> Success
/// \endcode
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swiftasync)
void swift_task_future_wait_throwing(
OpaqueValue *,
SWIFT_ASYNC_CONTEXT AsyncContext *,
AsyncTask *,
ThrowingTaskFutureWaitContinuationFunction *,
AsyncContext *);
void
swift_task_future_wait_throwing(OpaqueValue *,
SWIFT_ASYNC_CONTEXT AsyncContext *,
AsyncTask *,
ThrowingTaskFutureWaitContinuationFunction *,
AsyncContext *);

/// Wait for a readyQueue of a Channel to become non empty.
///
Expand All @@ -187,12 +201,13 @@ void swift_task_future_wait_throwing(
/// group: Builtin.RawPointer
/// ) async -> T
/// \endcode
SWIFT_EXPORT_FROM(swift_Concurrency)
SWIFT_CC(swiftasync)
void swift_taskGroup_wait_next_throwing(
OpaqueValue *resultPointer, SWIFT_ASYNC_CONTEXT AsyncContext *callerContext,
TaskGroup *group, ThrowingTaskFutureWaitContinuationFunction *resumeFn,
AsyncContext *callContext);
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swiftasync)
void
swift_taskGroup_wait_next_throwing(OpaqueValue *resultPointer,
SWIFT_ASYNC_CONTEXT AsyncContext *callerContext,
TaskGroup *group,
ThrowingTaskFutureWaitContinuationFunction *resumeFn,
AsyncContext *callContext);

/// Initialize a `TaskGroup` in the passed `group` memory location.
/// The caller is responsible for retaining and managing the group's lifecycle.
Expand Down Expand Up @@ -322,12 +337,16 @@ void swift_asyncLet_begin(AsyncLet *alet,
void *closureEntryPoint, HeapObject *closureContext,
void *resultBuffer);

SWIFT_END_DECLS

/// This matches the ABI of a closure `<T>(Builtin.RawPointer) async -> T`
using AsyncLetWaitSignature =
SWIFT_CC(swiftasync)
void(OpaqueValue *,
SWIFT_ASYNC_CONTEXT AsyncContext *, AsyncTask *, Metadata *);

SWIFT_BEGIN_DECLS

/// DEPRECATED. swift_asyncLet_get is used instead.
/// Wait for a non-throwing async-let to complete.
///
Expand Down Expand Up @@ -608,6 +627,8 @@ void swift_task_localValuePop();
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
void swift_task_localsCopyTo(AsyncTask* target);

SWIFT_END_DECLS

/// This should have the same representation as an enum like this:
/// enum NearestTaskDeadline {
/// case none
Expand All @@ -626,12 +647,13 @@ struct NearestTaskDeadline {
Kind ValueKind;
};

SWIFT_BEGIN_DECLS

/// Returns the nearest deadline that's been registered with this task.
///
/// This must be called synchronously with the task.
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
NearestTaskDeadline
swift_task_getNearestDeadline(AsyncTask *task);
NearestTaskDeadline swift_task_getNearestDeadline(AsyncTask *task);

/// Switch the current task to a new executor if we aren't already
/// running on a compatible executor.
Expand Down Expand Up @@ -680,9 +702,13 @@ void swift_task_enqueue(Job *job, ExecutorRef executor);
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
void swift_task_enqueueGlobal(Job *job);

SWIFT_END_DECLS

/// A count in nanoseconds.
using JobDelay = unsigned long long;

SWIFT_BEGIN_DECLS

SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
void swift_task_enqueueGlobalWithDelay(JobDelay delay, Job *job);

Expand All @@ -694,48 +720,72 @@ void swift_task_enqueueGlobalWithDeadline(long long sec, long long nsec,
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
void swift_task_enqueueMainExecutor(Job *job);

SWIFT_END_DECLS

#if SWIFT_CONCURRENCY_ENABLE_DISPATCH

SWIFT_BEGIN_DECLS

/// Enqueue the given job on the main executor.
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
void swift_task_enqueueOnDispatchQueue(Job *job, HeapObject *queue);

SWIFT_END_DECLS

#endif

/// A hook to take over global enqueuing.
typedef SWIFT_CC(swift) void (*swift_task_enqueueGlobal_original)(Job *job);
SWIFT_EXPORT_FROM(swift_Concurrency)
SWIFT_CC(swift) void (*swift_task_enqueueGlobal_hook)(

SWIFT_BEGIN_DECLS

SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
extern void (*swift_task_enqueueGlobal_hook)(
Job *job, swift_task_enqueueGlobal_original original);

SWIFT_END_DECLS

/// A hook to take over global enqueuing with delay.
typedef SWIFT_CC(swift) void (*swift_task_enqueueGlobalWithDelay_original)(
unsigned long long delay, Job *job);
SWIFT_EXPORT_FROM(swift_Concurrency)
SWIFT_CC(swift) void (*swift_task_enqueueGlobalWithDelay_hook)(

SWIFT_BEGIN_DECLS

SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
extern void (*swift_task_enqueueGlobalWithDelay_hook)(
unsigned long long delay, Job *job,
swift_task_enqueueGlobalWithDelay_original original);

SWIFT_END_DECLS

typedef SWIFT_CC(swift) void (*swift_task_enqueueGlobalWithDeadline_original)(
long long sec,
long long nsec,
long long tsec,
long long tnsec,
int clock, Job *job);
SWIFT_EXPORT_FROM(swift_Concurrency)
SWIFT_CC(swift) void (*swift_task_enqueueGlobalWithDeadline_hook)(

SWIFT_BEGIN_DECLS

SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
extern void (*swift_task_enqueueGlobalWithDeadline_hook)(
long long sec,
long long nsec,
long long tsec,
long long tnsec,
int clock, Job *job,
swift_task_enqueueGlobalWithDeadline_original original);

SWIFT_END_DECLS

/// A hook to take over main executor enqueueing.
typedef SWIFT_CC(swift) void (*swift_task_enqueueMainExecutor_original)(
Job *job);
SWIFT_EXPORT_FROM(swift_Concurrency)
SWIFT_CC(swift) void (*swift_task_enqueueMainExecutor_hook)(

SWIFT_BEGIN_DECLS

SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
extern void (*swift_task_enqueueMainExecutor_hook)(
Job *job, swift_task_enqueueMainExecutor_original original);

/// Initialize the runtime storage for a default actor.
Expand All @@ -756,8 +806,7 @@ void swift_defaultActor_deallocateResilient(HeapObject *actor);

/// Initialize the runtime storage for a distributed remote actor.
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
OpaqueValue*
swift_distributedActor_remote_initialize(const Metadata *actorType);
OpaqueValue* swift_distributedActor_remote_initialize(const Metadata *actorType);

/// Enqueue a job on the default actor implementation.
///
Expand Down Expand Up @@ -817,7 +866,7 @@ void swift_continuation_throwingResumeWithError(AsyncTask *continuation,
/* +1 */ SwiftError *error);

/// SPI helper to log a misuse of a `CheckedContinuation` to the appropriate places in the OS.
extern "C" SWIFT_CC(swift)
SWIFT_CC(swift)
void swift_continuation_logFailedCheck(const char *message);

/// Drain the queue
Expand Down Expand Up @@ -854,15 +903,21 @@ void swift_task_reportUnexpectedExecutor(
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
JobPriority swift_task_getCurrentThreadPriority(void);

SWIFT_END_DECLS

#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR

SWIFT_BEGIN_DECLS

/// Donate this thread to the global executor until either the
/// given condition returns true or we've run out of cooperative
/// tasks to run.
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
void swift_task_donateThreadToGlobalExecutorUntil(bool (*condition)(void*),
void *context);

SWIFT_END_DECLS

#endif

enum swift_clock_id : int {
Expand Down
12 changes: 6 additions & 6 deletions include/swift/Runtime/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,25 +243,25 @@ void _swift_reportToDebugger(uintptr_t flags, const char *message,
RuntimeErrorDetails *details = nullptr);

SWIFT_RUNTIME_STDLIB_SPI
bool _swift_reportFatalErrorsToDebugger;
extern bool _swift_reportFatalErrorsToDebugger;

SWIFT_RUNTIME_STDLIB_SPI
bool _swift_shouldReportFatalErrorsToDebugger();

SWIFT_RUNTIME_STDLIB_SPI
bool _swift_debug_metadataAllocationIterationEnabled;
extern bool _swift_debug_metadataAllocationIterationEnabled;

SWIFT_RUNTIME_STDLIB_SPI
const void * const _swift_debug_allocationPoolPointer;
extern const void * const _swift_debug_allocationPoolPointer;

SWIFT_RUNTIME_STDLIB_SPI
std::atomic<const void *> _swift_debug_metadataAllocationBacktraceList;
extern std::atomic<const void *> _swift_debug_metadataAllocationBacktraceList;

SWIFT_RUNTIME_STDLIB_SPI
const void * const _swift_debug_protocolConformanceStatePointer;
extern const void * const _swift_debug_protocolConformanceStatePointer;

SWIFT_RUNTIME_STDLIB_SPI
const uint64_t _swift_debug_multiPayloadEnumPointerSpareBitsMask;
extern const uint64_t _swift_debug_multiPayloadEnumPointerSpareBitsMask;

// namespace swift
}
Expand Down
Loading