Skip to content

Commit ec7a926

Browse files
committed
Fix asyncMainDrainQueue noreturn warning
The async main drain queue function is noreturn, but was emitting a warning due to the override compatibility returning the result of the overridden function in the wrapper override function. To work around this, I've added the `OVERRIDE_TASK_NORETURN` macro, which provides an override point for noreturn functions in the concurrency library that doesn't return the result from the wrapped function, avoiding the warning. In the event that the function is not set, the macro is set to the normal `OVERRIDE` with the return type set to `void`.
1 parent 16baee3 commit ec7a926

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

stdlib/public/CompatibilityOverride/CompatibilityOverride.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ static OverrideSection *getOverrideSectionPtr() {
8989
return nullptr; \
9090
return Section->name; \
9191
}
92+
93+
#define OVERRIDE_NORETURN(name, attrs, ccAttrs, namespace, typedArgs, namedArgs) \
94+
Override_ ## name swift::getOverride_ ## name() { \
95+
auto *Section = getOverrideSectionPtr(); \
96+
if (Section == nullptr) \
97+
nullptr; \
98+
Section->name; \
99+
}
100+
92101
#include COMPATIBILITY_OVERRIDE_INCLUDE_PATH
93102

94103
#endif // #ifdef SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT

stdlib/public/CompatibilityOverride/CompatibilityOverrideConcurrency.def

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777
# define OVERRIDE_TASK_GROUP OVERRIDE
7878
# define OVERRIDE_TASK_LOCAL OVERRIDE
7979
# define OVERRIDE_TASK_STATUS OVERRIDE
80+
#ifndef OVERRIDE_TASK_NORETURN
81+
# define OVERRIDE_TASK_NORETURN(name, attrs, ccAttrs, namespace, typedArgs, \
82+
namedArgs) \
83+
OVERRIDE(name, void, attrs, ccAttrs, namespace, typedArgs, namedArgs)
84+
#endif
8085
#else
8186
# ifndef OVERRIDE_ACTOR
8287
# define OVERRIDE_ACTOR(...)
@@ -96,6 +101,9 @@
96101
# ifndef OVERRIDE_TASK_STATUS
97102
# define OVERRIDE_TASK_STATUS(...)
98103
# endif
104+
# ifndef OVERRIDE_TASK_NORETURN
105+
# define OVERRIDE_TASK_NORETURN(...)
106+
# endif
99107
#endif
100108

101109
OVERRIDE_ACTOR(task_enqueue, void,
@@ -181,7 +189,7 @@ OVERRIDE_TASK(task_createNullaryContinuationJob, NullaryContinuationJob *,
181189
(size_t priority,
182190
AsyncTask *continuation), (priority, continuation))
183191

184-
OVERRIDE_TASK(task_asyncMainDrainQueue, void,
192+
OVERRIDE_TASK_NORETURN(task_asyncMainDrainQueue,
185193
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift), swift::,
186194
, )
187195

@@ -380,3 +388,4 @@ OVERRIDE_TASK_STATUS(task_escalate, JobPriority,
380388
#undef OVERRIDE_TASK_GROUP
381389
#undef OVERRIDE_TASK_LOCAL
382390
#undef OVERRIDE_TASK_STATUS
391+
#undef OVERRIDE_TASK_NORETURN

stdlib/public/Concurrency/Task.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,4 +1590,33 @@ static void swift_task_asyncMainDrainQueueImpl() {
15901590
}
15911591

15921592
#define OVERRIDE_TASK COMPATIBILITY_OVERRIDE
1593+
1594+
#ifdef SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT
1595+
/// The original COMPATIBILITY_OVERRIDE defined in CompatibilityOverride.h
1596+
/// returns the result of the impl function and override function. This results
1597+
/// in a warning emitted for noreturn functions. Overriding the override macro
1598+
/// to not return.
1599+
#define OVERRIDE_TASK_NORETURN(name, attrs, ccAttrs, namespace, typedArgs, \
1600+
namedArgs) \
1601+
attrs ccAttrs void namespace swift_##name COMPATIBILITY_PAREN(typedArgs) { \
1602+
static Override_##name Override; \
1603+
static swift_once_t Predicate; \
1604+
swift_once( \
1605+
&Predicate, [](void *) { Override = getOverride_##name(); }, nullptr); \
1606+
if (Override != nullptr) \
1607+
Override(COMPATIBILITY_UNPAREN_WITH_COMMA(namedArgs) \
1608+
swift_##name##Impl); \
1609+
swift_##name##Impl COMPATIBILITY_PAREN(namedArgs); \
1610+
}
1611+
1612+
#else // ifndef SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT
1613+
// Call directly through to the original implementation when we don't support
1614+
// overrides.
1615+
#define OVERRIDE_TASK_NORETURN(name, attrs, ccAttrs, namespace, typedArgs, \
1616+
namedArgs) \
1617+
attrs ccAttrs void namespace swift_##name COMPATIBILITY_PAREN(typedArgs) { \
1618+
swift_##name##Impl COMPATIBILITY_PAREN(namedArgs); \
1619+
}
1620+
#endif // #else SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT
1621+
15931622
#include COMPATIBILITY_OVERRIDE_INCLUDE_PATH

unittests/runtime/CompatibilityOverrideConcurrency.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ ExecutorRef getEmptyValue() {
4444
Ran = true; \
4545
return getEmptyValue<ret>(); \
4646
}
47+
#define OVERRIDE_TASK_NORETURN(name, attrs, ccAttrs, namespace, typedArgs, \
48+
namedArgs) \
49+
static ccAttrs void name##Override(COMPATIBILITY_UNPAREN_WITH_COMMA( \
50+
typedArgs) Original_##name originalImpl) { \
51+
if (!EnableOverride) \
52+
originalImpl COMPATIBILITY_PAREN(namedArgs); \
53+
Ran = true; \
54+
}
55+
4756
#include "../../stdlib/public/CompatibilityOverride/CompatibilityOverrideConcurrency.def"
4857

4958
struct OverrideSection {

0 commit comments

Comments
 (0)