Skip to content

Commit f04bf4e

Browse files
authored
Merge pull request #39554 from DougGregor/concurrency-static-link-5.5-08092021
Rename duplicated swift::fatalError in swiftRuntime and swift_Concurrency
2 parents 6fc6a3f + a0ed930 commit f04bf4e

File tree

16 files changed

+141
-18
lines changed

16 files changed

+141
-18
lines changed

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
4747
CheckedContinuation.swift
4848
GlobalExecutor.cpp
4949
Errors.swift
50+
Error.cpp
5051
Executor.swift
5152
AsyncCompactMapSequence.swift
5253
AsyncDropFirstSequence.swift

stdlib/public/Concurrency/Error.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===--- Error.cpp - Error handling support code --------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "Error.h"
14+
15+
// swift::fatalError is not exported from libswiftCore and not shared, so define another
16+
// internal function instead.
17+
SWIFT_NORETURN void swift::swift_Concurrency_fatalError(uint32_t flags, const char *format, ...) {
18+
abort();
19+
}

stdlib/public/Concurrency/Error.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===--- Error.h - Swift Concurrency error helpers --------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// Error handling support.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SWIFT_CONCURRENCY_ERRORS_H
18+
#define SWIFT_CONCURRENCY_ERRORS_H
19+
20+
#include "../SwiftShims/Visibility.h"
21+
#include <cstdint>
22+
#include <stdlib.h>
23+
24+
namespace swift {
25+
26+
SWIFT_NORETURN void swift_Concurrency_fatalError(uint32_t flags, const char *format, ...);
27+
28+
} // namespace swift
29+
30+
#endif

stdlib/public/Concurrency/GlobalExecutor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "swift/Runtime/Concurrency.h"
5858
#include "swift/Runtime/EnvironmentVariables.h"
5959
#include "TaskPrivate.h"
60+
#include "Error.h"
6061

6162
#include <dispatch/dispatch.h>
6263

@@ -267,7 +268,7 @@ static std::atomic<dispatch_queue_t> globalQueueCache[globalQueueCacheCount];
267268
static dispatch_queue_t getGlobalQueue(JobPriority priority) {
268269
size_t numericPriority = static_cast<size_t>(priority);
269270
if (numericPriority >= globalQueueCacheCount)
270-
fatalError(0, "invalid job priority %#zx");
271+
swift_Concurrency_fatalError(0, "invalid job priority %#zx");
271272

272273
auto *ptr = &globalQueueCache[numericPriority];
273274
auto queue = ptr->load(std::memory_order_relaxed);

stdlib/public/Concurrency/Mutex.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "Error.h"
14+
15+
#define SWIFT_FATAL_ERROR swift_Concurrency_fatalError
16+
1317
// Include the runtime's mutex support code.
1418
// FIXME: figure out some reasonable way to share this stuff
1519

1620
#include "../runtime/MutexPThread.cpp"
1721
#include "../runtime/MutexWin32.cpp"
18-
19-
SWIFT_NORETURN void swift::fatalError(uint32_t flags, const char *format, ...) {
20-
abort();
21-
}

stdlib/public/Concurrency/Task.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "TaskPrivate.h"
2727
#include "AsyncCall.h"
2828
#include "Debug.h"
29+
#include "Error.h"
2930

3031
#include <dispatch/dispatch.h>
3132

@@ -786,7 +787,7 @@ static void swift_task_future_waitImpl(
786787
}
787788

788789
case FutureFragment::Status::Error:
789-
fatalError(0, "future reported an error, but wait cannot throw");
790+
swift_Concurrency_fatalError(0, "future reported an error, but wait cannot throw");
790791
}
791792
}
792793

stdlib/public/Concurrency/TaskAlloc.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "swift/Runtime/Concurrency.h"
2121
#include "swift/ABI/Task.h"
2222
#include "TaskPrivate.h"
23-
2423
#include <stdlib.h>
2524

2625
using namespace swift;

stdlib/public/Concurrency/TaskPrivate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#include "swift/Runtime/Exclusivity.h"
2626
#include "swift/Runtime/HeapObject.h"
2727

28+
#include "Error.h"
29+
30+
#define SWIFT_FATAL_ERROR swift_Concurrency_fatalError
2831
#include "../runtime/StackAllocator.h"
2932

3033
#if HAVE_PTHREAD_H

stdlib/public/runtime/MutexPThread.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
#endif
2121

2222
#if defined(_POSIX_THREADS) && !defined(SWIFT_STDLIB_SINGLE_THREADED_RUNTIME)
23+
24+
// Notes: swift::fatalError is not shared between libswiftCore and libswift_Concurrency
25+
// and libswift_Concurrency uses swift_Concurrency_fatalError instead.
26+
#ifndef SWIFT_FATAL_ERROR
27+
#define SWIFT_FATAL_ERROR swift::fatalError
28+
#endif
29+
2330
#include "swift/Runtime/Mutex.h"
2431

2532
#include "swift/Runtime/Debug.h"
@@ -32,8 +39,8 @@ using namespace swift;
3239
do { \
3340
int errorcode = PThreadFunction; \
3441
if (errorcode != 0) { \
35-
fatalError(/* flags = */ 0, "'%s' failed with error '%s'(%d)\n", \
36-
#PThreadFunction, errorName(errorcode), errorcode); \
42+
SWIFT_FATAL_ERROR(/* flags = */ 0, "'%s' failed with error '%s'(%d)\n", \
43+
#PThreadFunction, errorName(errorcode), errorcode); \
3744
} \
3845
} while (false)
3946

@@ -44,8 +51,8 @@ using namespace swift;
4451
return true; \
4552
if (returnFalseOnEBUSY && errorcode == EBUSY) \
4653
return false; \
47-
fatalError(/* flags = */ 0, "'%s' failed with error '%s'(%d)\n", \
48-
#PThreadFunction, errorName(errorcode), errorcode); \
54+
SWIFT_FATAL_ERROR(/* flags = */ 0, "'%s' failed with error '%s'(%d)\n", \
55+
#PThreadFunction, errorName(errorcode), errorcode); \
4956
} while (false)
5057

5158
static const char *errorName(int errorcode) {

stdlib/public/runtime/MutexWin32.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
//===----------------------------------------------------------------------===//
1717

1818
#if defined(_WIN32)
19+
20+
// Notes: swift::fatalError is not shared between libswiftCore and libswift_Concurrency
21+
// and libswift_Concurrency uses swift_Concurrency_fatalError instead.
22+
#ifndef SWIFT_FATAL_ERROR
23+
#define SWIFT_FATAL_ERROR swift::fatalError
24+
#endif
25+
1926
#include "swift/Runtime/Mutex.h"
2027
#include "swift/Runtime/Debug.h"
2128

@@ -26,9 +33,9 @@ void ConditionPlatformHelper::wait(CONDITION_VARIABLE &condition,
2633
BOOL result = SleepConditionVariableSRW(&condition, &mutex, INFINITE, 0);
2734
if (!result) {
2835
DWORD errorcode = GetLastError();
29-
fatalError(/* flags = */ 0,
30-
"'SleepConditionVariableSRW()' failed with error code %d\n",
31-
errorcode);
36+
SWIFT_FATAL_ERROR(/* flags = */ 0,
37+
"'SleepConditionVariableSRW()' failed with error code %d\n",
38+
errorcode);
3239
}
3340
}
3441
#endif

0 commit comments

Comments
 (0)