Skip to content

Commit cf48095

Browse files
committed
Runtime: split out extern "C" marker from SWIFT_RUNTIME_EXPORT
Although the runtime exported symbols must be exported with "C" linkage and decoration, we split out the externalisation in the C++ mode. This is required to ensure that we are able to attribute the functions without following the more stringent rules that clang now enforces which place the attributes following the identifier to which they appertain, resulting in the attributes interleaving within the signature. The resulting spelling is more difficult to process for humans as well as more difficult to identify as function declarations making code perusal a challenge, particularly for the uninitiated.
1 parent a478034 commit cf48095

40 files changed

+732
-293
lines changed

include/swift/Runtime/Casting.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
namespace swift {
2323

24+
SWIFT_BEGIN_DECLS
25+
2426
/// Perform a checked dynamic cast of a value to a target type.
2527
///
2628
/// \param dest A buffer into which to write the destination value.
@@ -244,6 +246,8 @@ SWIFT_RUNTIME_EXPORT
244246
const WitnessTable *swift_conformsToProtocol(const Metadata *type,
245247
const ProtocolDescriptor *protocol);
246248

249+
SWIFT_END_DECLS
250+
247251
} // end namespace swift
248252

249253
#endif // SWIFT_RUNTIME_CASTING_H

include/swift/Runtime/Concurrency.h

Lines changed: 97 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,41 @@ struct AsyncTaskAndContext {
7070
AsyncContext *InitialContext;
7171
};
7272

73+
SWIFT_BEGIN_DECLS
74+
7375
/// Create a task object.
7476
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
75-
AsyncTaskAndContext swift_task_create(
76-
size_t taskCreateFlags,
77-
TaskOptionRecord *options,
78-
const Metadata *futureResultType,
79-
void *closureEntry, HeapObject *closureContext);
77+
AsyncTaskAndContext swift_task_create(size_t taskCreateFlags,
78+
TaskOptionRecord *options,
79+
const Metadata *futureResultType,
80+
void *closureEntry,
81+
HeapObject *closureContext);
82+
83+
SWIFT_END_DECLS
8084

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

90+
SWIFT_BEGIN_DECLS
91+
8692
/// Create a task object.
8793
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
88-
AsyncTaskAndContext swift_task_create_common(
89-
size_t taskCreateFlags,
90-
TaskOptionRecord *options,
91-
const Metadata *futureResultType,
92-
TaskContinuationFunction *function, void *closureContext,
93-
size_t initialContextSize);
94+
AsyncTaskAndContext
95+
swift_task_create_common(size_t taskCreateFlags, TaskOptionRecord *options,
96+
const Metadata *futureResultType,
97+
TaskContinuationFunction *function,
98+
void *closureContext,
99+
size_t initialContextSize);
100+
101+
SWIFT_END_DECLS
94102

95103
#if SWIFT_CONCURRENCY_TASK_TO_THREAD_MODEL
96104
#define SWIFT_TASK_RUN_INLINE_INITIAL_CONTEXT_BYTES 4096
105+
106+
SWIFT_BEGIN_DECLS
107+
97108
/// Begin an async context in the current sync context and run the indicated
98109
/// closure in it.
99110
///
@@ -104,8 +115,13 @@ SWIFT_CC(swift)
104115
void swift_task_run_inline(OpaqueValue *result, void *closureAFP,
105116
OpaqueValue *closureContext,
106117
const Metadata *futureResultType);
118+
119+
SWIFT_END_DECLS
120+
107121
#endif
108122

123+
SWIFT_BEGIN_DECLS
124+
109125
/// Allocate memory in a task.
110126
///
111127
/// This must be called synchronously with the task.
@@ -141,8 +157,7 @@ void swift_task_cancel_group_child_tasks(TaskGroup *group);
141157
/// This has no effect if the task already has at least the given priority.
142158
/// Returns the priority of the task.
143159
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
144-
JobPriority
145-
swift_task_escalate(AsyncTask *task, JobPriority newPriority);
160+
JobPriority swift_task_escalate(AsyncTask *task, JobPriority newPriority);
146161

147162
// TODO: "async let wait" and "async let destroy" would be expressed
148163
// similar to like TaskFutureWait;
@@ -156,10 +171,9 @@ swift_task_escalate(AsyncTask *task, JobPriority newPriority);
156171
/// -> Success
157172
/// \endcode
158173
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swiftasync)
159-
void swift_task_future_wait(OpaqueValue *,
160-
SWIFT_ASYNC_CONTEXT AsyncContext *, AsyncTask *,
161-
TaskContinuationFunction *,
162-
AsyncContext *);
174+
void
175+
swift_task_future_wait(OpaqueValue *, SWIFT_ASYNC_CONTEXT AsyncContext *,
176+
AsyncTask *, TaskContinuationFunction *, AsyncContext *);
163177

164178
/// Wait for a potentially-throwing future task to complete.
165179
///
@@ -170,12 +184,12 @@ void swift_task_future_wait(OpaqueValue *,
170184
/// async throws -> Success
171185
/// \endcode
172186
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swiftasync)
173-
void swift_task_future_wait_throwing(
174-
OpaqueValue *,
175-
SWIFT_ASYNC_CONTEXT AsyncContext *,
176-
AsyncTask *,
177-
ThrowingTaskFutureWaitContinuationFunction *,
178-
AsyncContext *);
187+
void
188+
swift_task_future_wait_throwing(OpaqueValue *,
189+
SWIFT_ASYNC_CONTEXT AsyncContext *,
190+
AsyncTask *,
191+
ThrowingTaskFutureWaitContinuationFunction *,
192+
AsyncContext *);
179193

180194
/// Wait for a readyQueue of a Channel to become non empty.
181195
///
@@ -187,12 +201,13 @@ void swift_task_future_wait_throwing(
187201
/// group: Builtin.RawPointer
188202
/// ) async -> T
189203
/// \endcode
190-
SWIFT_EXPORT_FROM(swift_Concurrency)
191-
SWIFT_CC(swiftasync)
192-
void swift_taskGroup_wait_next_throwing(
193-
OpaqueValue *resultPointer, SWIFT_ASYNC_CONTEXT AsyncContext *callerContext,
194-
TaskGroup *group, ThrowingTaskFutureWaitContinuationFunction *resumeFn,
195-
AsyncContext *callContext);
204+
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swiftasync)
205+
void
206+
swift_taskGroup_wait_next_throwing(OpaqueValue *resultPointer,
207+
SWIFT_ASYNC_CONTEXT AsyncContext *callerContext,
208+
TaskGroup *group,
209+
ThrowingTaskFutureWaitContinuationFunction *resumeFn,
210+
AsyncContext *callContext);
196211

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

340+
SWIFT_END_DECLS
341+
325342
/// This matches the ABI of a closure `<T>(Builtin.RawPointer) async -> T`
326343
using AsyncLetWaitSignature =
327344
SWIFT_CC(swiftasync)
328345
void(OpaqueValue *,
329346
SWIFT_ASYNC_CONTEXT AsyncContext *, AsyncTask *, Metadata *);
330347

348+
SWIFT_BEGIN_DECLS
349+
331350
/// DEPRECATED. swift_asyncLet_get is used instead.
332351
/// Wait for a non-throwing async-let to complete.
333352
///
@@ -608,6 +627,8 @@ void swift_task_localValuePop();
608627
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
609628
void swift_task_localsCopyTo(AsyncTask* target);
610629

630+
SWIFT_END_DECLS
631+
611632
/// This should have the same representation as an enum like this:
612633
/// enum NearestTaskDeadline {
613634
/// case none
@@ -626,12 +647,13 @@ struct NearestTaskDeadline {
626647
Kind ValueKind;
627648
};
628649

650+
SWIFT_BEGIN_DECLS
651+
629652
/// Returns the nearest deadline that's been registered with this task.
630653
///
631654
/// This must be called synchronously with the task.
632655
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
633-
NearestTaskDeadline
634-
swift_task_getNearestDeadline(AsyncTask *task);
656+
NearestTaskDeadline swift_task_getNearestDeadline(AsyncTask *task);
635657

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

705+
SWIFT_END_DECLS
706+
683707
/// A count in nanoseconds.
684708
using JobDelay = unsigned long long;
685709

710+
SWIFT_BEGIN_DECLS
711+
686712
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
687713
void swift_task_enqueueGlobalWithDelay(JobDelay delay, Job *job);
688714

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

723+
SWIFT_END_DECLS
724+
697725
#if SWIFT_CONCURRENCY_ENABLE_DISPATCH
698726

727+
SWIFT_BEGIN_DECLS
728+
699729
/// Enqueue the given job on the main executor.
700730
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
701731
void swift_task_enqueueOnDispatchQueue(Job *job, HeapObject *queue);
702732

733+
SWIFT_END_DECLS
734+
703735
#endif
704736

705737
/// A hook to take over global enqueuing.
706738
typedef SWIFT_CC(swift) void (*swift_task_enqueueGlobal_original)(Job *job);
707-
SWIFT_EXPORT_FROM(swift_Concurrency)
708-
SWIFT_CC(swift) void (*swift_task_enqueueGlobal_hook)(
739+
740+
SWIFT_BEGIN_DECLS
741+
742+
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
743+
extern void (*swift_task_enqueueGlobal_hook)(
709744
Job *job, swift_task_enqueueGlobal_original original);
710745

746+
SWIFT_END_DECLS
747+
711748
/// A hook to take over global enqueuing with delay.
712749
typedef SWIFT_CC(swift) void (*swift_task_enqueueGlobalWithDelay_original)(
713750
unsigned long long delay, Job *job);
714-
SWIFT_EXPORT_FROM(swift_Concurrency)
715-
SWIFT_CC(swift) void (*swift_task_enqueueGlobalWithDelay_hook)(
751+
752+
SWIFT_BEGIN_DECLS
753+
754+
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
755+
extern void (*swift_task_enqueueGlobalWithDelay_hook)(
716756
unsigned long long delay, Job *job,
717757
swift_task_enqueueGlobalWithDelay_original original);
718758

759+
SWIFT_END_DECLS
760+
719761
typedef SWIFT_CC(swift) void (*swift_task_enqueueGlobalWithDeadline_original)(
720762
long long sec,
721763
long long nsec,
722764
long long tsec,
723765
long long tnsec,
724766
int clock, Job *job);
725-
SWIFT_EXPORT_FROM(swift_Concurrency)
726-
SWIFT_CC(swift) void (*swift_task_enqueueGlobalWithDeadline_hook)(
767+
768+
SWIFT_BEGIN_DECLS
769+
770+
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
771+
extern void (*swift_task_enqueueGlobalWithDeadline_hook)(
727772
long long sec,
728773
long long nsec,
729774
long long tsec,
730775
long long tnsec,
731776
int clock, Job *job,
732777
swift_task_enqueueGlobalWithDeadline_original original);
733778

779+
SWIFT_END_DECLS
780+
734781
/// A hook to take over main executor enqueueing.
735782
typedef SWIFT_CC(swift) void (*swift_task_enqueueMainExecutor_original)(
736783
Job *job);
737-
SWIFT_EXPORT_FROM(swift_Concurrency)
738-
SWIFT_CC(swift) void (*swift_task_enqueueMainExecutor_hook)(
784+
785+
SWIFT_BEGIN_DECLS
786+
787+
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
788+
extern void (*swift_task_enqueueMainExecutor_hook)(
739789
Job *job, swift_task_enqueueMainExecutor_original original);
740790

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

757807
/// Initialize the runtime storage for a distributed remote actor.
758808
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
759-
OpaqueValue*
760-
swift_distributedActor_remote_initialize(const Metadata *actorType);
809+
OpaqueValue* swift_distributedActor_remote_initialize(const Metadata *actorType);
761810

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

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

823872
/// Drain the queue
@@ -854,15 +903,21 @@ void swift_task_reportUnexpectedExecutor(
854903
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
855904
JobPriority swift_task_getCurrentThreadPriority(void);
856905

906+
SWIFT_END_DECLS
907+
857908
#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
858909

910+
SWIFT_BEGIN_DECLS
911+
859912
/// Donate this thread to the global executor until either the
860913
/// given condition returns true or we've run out of cooperative
861914
/// tasks to run.
862915
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
863916
void swift_task_donateThreadToGlobalExecutorUntil(bool (*condition)(void*),
864917
void *context);
865918

919+
SWIFT_END_DECLS
920+
866921
#endif
867922

868923
enum swift_clock_id : int {

include/swift/Runtime/Debug.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,25 +243,25 @@ void _swift_reportToDebugger(uintptr_t flags, const char *message,
243243
RuntimeErrorDetails *details = nullptr);
244244

245245
SWIFT_RUNTIME_STDLIB_SPI
246-
bool _swift_reportFatalErrorsToDebugger;
246+
extern bool _swift_reportFatalErrorsToDebugger;
247247

248248
SWIFT_RUNTIME_STDLIB_SPI
249249
bool _swift_shouldReportFatalErrorsToDebugger();
250250

251251
SWIFT_RUNTIME_STDLIB_SPI
252-
bool _swift_debug_metadataAllocationIterationEnabled;
252+
extern bool _swift_debug_metadataAllocationIterationEnabled;
253253

254254
SWIFT_RUNTIME_STDLIB_SPI
255-
const void * const _swift_debug_allocationPoolPointer;
255+
extern const void * const _swift_debug_allocationPoolPointer;
256256

257257
SWIFT_RUNTIME_STDLIB_SPI
258-
std::atomic<const void *> _swift_debug_metadataAllocationBacktraceList;
258+
extern std::atomic<const void *> _swift_debug_metadataAllocationBacktraceList;
259259

260260
SWIFT_RUNTIME_STDLIB_SPI
261-
const void * const _swift_debug_protocolConformanceStatePointer;
261+
extern const void * const _swift_debug_protocolConformanceStatePointer;
262262

263263
SWIFT_RUNTIME_STDLIB_SPI
264-
const uint64_t _swift_debug_multiPayloadEnumPointerSpareBitsMask;
264+
extern const uint64_t _swift_debug_multiPayloadEnumPointerSpareBitsMask;
265265

266266
// namespace swift
267267
}

0 commit comments

Comments
 (0)