Skip to content

Commit ee700e2

Browse files
authored
Ensure Locked+Platform.swift is not stripped when statically linking. (#1035)
All symbols in Locked+Platform.swift are referenced _indirectly_ by the Swift compiler due to `LockedWith` being generic, which can cause symbols from that file (including protocol conformance metadata) to be stripped at link time as if it were unused. This change (hopefully) works around that issue. Works around rdar://147250336. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent eef2340 commit ee700e2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Sources/Testing/Support/Locked+Platform.swift

+11
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,14 @@ typealias DefaultLock = Never
9494
#warning("Platform-specific implementation missing: locking unavailable")
9595
typealias DefaultLock = Never
9696
#endif
97+
98+
#if SWT_NO_DYNAMIC_LINKING
99+
/// A function which, when called by another file, ensures that the file in
100+
/// which ``DefaultLock`` is declared is linked.
101+
///
102+
/// When static linking is used, the linker may opt to strip some or all of the
103+
/// symbols (including protocol conformance metadata) declared in this file.
104+
/// ``LockedWith`` calls this function in ``LockedWith/init(rawValue:)`` to work
105+
/// around that issue.
106+
func linkLockImplementations() {}
107+
#endif

Sources/Testing/Support/Locked.swift

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ struct LockedWith<L, T>: RawRepresentable where L: Lockable {
6666
private nonisolated(unsafe) var _storage: ManagedBuffer<T, L>
6767

6868
init(rawValue: T) {
69+
#if SWT_NO_DYNAMIC_LINKING
70+
linkLockImplementations()
71+
#endif
72+
6973
_storage = _Storage.create(minimumCapacity: 1, makingHeaderWith: { _ in rawValue })
7074
_storage.withUnsafeMutablePointerToElements { lock in
7175
L.initializeLock(at: lock)

0 commit comments

Comments
 (0)