Skip to content

Commit 9b389a3

Browse files
committed
Fix tests and toolchain build
1 parent e992688 commit 9b389a3

File tree

4 files changed

+66
-122
lines changed

4 files changed

+66
-122
lines changed

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,30 +2218,31 @@ function(add_swift_target_library name)
22182218
endif()
22192219

22202220
# Append SDK specific sources to the full list of sources
2221+
set(sources ${SWIFTLIB_SOURCES})
22212222
if(sdk STREQUAL "OSX")
2222-
list(APPEND SWIFTLIB_SOURCES ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_MACOS})
2223+
list(APPEND sources ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_MACOS})
22232224
elseif(sdk STREQUAL "IOS" OR sdk STREQUAL "IOS_SIMULATOR")
2224-
list(APPEND SWIFTLIB_SOURCES ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_IOS})
2225+
list(APPEND sources ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_IOS})
22252226
elseif(sdk STREQUAL "TVOS" OR sdk STREQUAL "TVOS_SIMULATOR")
2226-
list(APPEND SWIFTLIB_SOURCES ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_TVOS})
2227+
list(APPEND sources ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_TVOS})
22272228
elseif(sdk STREQUAL "WATCHOS" OR sdk STREQUAL "WATCHOS_SIMULATOR")
2228-
list(APPEND SWIFTLIB_SOURCES ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_WATCHOS})
2229+
list(APPEND sources ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_WATCHOS})
22292230
elseif(sdk STREQUAL "FREESTANDING")
2230-
list(APPEND SWIFTLIB_SOURCES ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_FREESTANDING})
2231+
list(APPEND sources ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_FREESTANDING})
22312232
elseif(sdk STREQUAL "FREEBSD")
2232-
list(APPEND SWIFTLIB_SOURCES ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_FREEBSD})
2233+
list(APPEND sources ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_FREEBSD})
22332234
elseif(sdk STREQUAL "OPENBSD")
2234-
list(APPEND SWIFTLIB_SOURCES ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_OPENBSD})
2235+
list(APPEND sources ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_OPENBSD})
22352236
elseif(sdk STREQUAL "LINUX" OR sdk STREQUAL "ANDROID")
2236-
list(APPEND SWIFTLIB_SOURCES ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_LINUX})
2237+
list(APPEND sources ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_LINUX})
22372238
elseif(sdk STREQUAL "CYGWIN")
2238-
list(APPEND SWIFTLIB_SOURCES ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_CYGWIN})
2239+
list(APPEND sources ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_CYGWIN})
22392240
elseif(sdk STREQUAL "HAIKU")
2240-
list(APPEND SWIFTLIB_SOURCES ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_HAIKU})
2241+
list(APPEND sources ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_HAIKU})
22412242
elseif(sdk STREQUAL "WASI")
2242-
list(APPEND SWIFTLIB_SOURCES ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_WASI})
2243+
list(APPEND sources ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_WASI})
22432244
elseif(sdk STREQUAL "WINDOWS")
2244-
list(APPEND SWIFTLIB_SOURCES ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_WINDOWS})
2245+
list(APPEND sources ${SWIFTLIB_SWIFT_SOURCES_DEPENDS_WINDOWS})
22452246
endif()
22462247

22472248
# We unconditionally removed "-z,defs" from CMAKE_SHARED_LINKER_FLAGS in
@@ -2448,7 +2449,7 @@ function(add_swift_target_library name)
24482449
${SWIFTLIB_NO_LINK_NAME_keyword}
24492450
${SWIFTLIB_OBJECT_LIBRARY_keyword}
24502451
${SWIFTLIB_INSTALL_WITH_SHARED_keyword}
2451-
${SWIFTLIB_SOURCES}
2452+
${sources}
24522453
MODULE_TARGETS ${module_variant_names}
24532454
SDK ${sdk}
24542455
ARCHITECTURE ${arch}

stdlib/public/SwiftShims/swift/shims/SynchronizationShims.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@
2424
#define SWIFT_FUTEX_WAITERS FUTEX_WAITERS
2525

2626
static inline __swift_uint32_t _swift_stdlib_gettid() {
27-
static __thread tid = syscall(SYS_gettid);
27+
static __thread tid = 0;
28+
29+
if (tid == 0) {
30+
tid = syscall(SYS_gettid);
31+
}
32+
2833
return tid;
2934
}
3035

stdlib/public/Synchronization/Mutex/Mutex.swift

Lines changed: 16 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -52,48 +52,41 @@ public struct Mutex<Value: ~Copyable>: ~Copyable {
5252
}
5353
}
5454

55+
@available(SwiftStdlib 6.0, *)
56+
extension Mutex: @unchecked Sendable where Value: ~Copyable {}
57+
5558
@available(SwiftStdlib 6.0, *)
5659
extension Mutex where Value: ~Copyable {
57-
/// Attempts to acquire the lock and then calls the given closure if
58-
/// successful.
59-
///
60-
/// If the calling thread was successful in acquiring the lock, the
61-
/// closure will be executed and then immediately after it will
62-
/// release ownership of the lock. If we were unable to acquire the
63-
/// lock, this will return `nil`.
60+
/// Calls the given closure after acquring the lock and then releases
61+
/// ownership.
6462
///
6563
/// This method is equivalent to the following sequence of code:
6664
///
67-
/// guard mutex.tryLock() else {
68-
/// return nil
69-
/// }
65+
/// mutex.lock()
7066
/// defer {
7167
/// mutex.unlock()
7268
/// }
7369
/// return try body(&value)
7470
///
75-
/// - Warning: Recursive calls to `tryWithLock` within the
71+
/// - Warning: Recursive calls to `withLock` within the
7672
/// closure parameter has behavior that is platform dependent.
7773
/// Some platforms may choose to panic the process, deadlock,
7874
/// or leave this behavior unspecified.
7975
///
8076
/// - Parameter body: A closure with a parameter of `Value`
8177
/// that has exclusive access to the value being stored within
8278
/// this mutex. This closure is considered the critical section
83-
/// as it will only be executed if the calling thread acquires
84-
/// the lock.
79+
/// as it will only be executed once the calling thread has
80+
/// acquired the lock.
8581
///
86-
/// - Returns: The return value, if any, of the `body` closure parameter
87-
/// or nil if the lock couldn't be acquired.
82+
/// - Returns: The return value, if any, of the `body` closure parameter.
8883
@available(SwiftStdlib 6.0, *)
8984
@_alwaysEmitIntoClient
9085
@_transparent
91-
public borrowing func tryWithLock<Result: ~Copyable & Sendable, E: Error>(
86+
public borrowing func withLock<Result: ~Copyable & Sendable, E: Error>(
9287
_ body: @Sendable (inout Value) throws(E) -> Result
93-
) throws(E) -> Result? {
94-
guard handle.tryLock() else {
95-
return nil
96-
}
88+
) throws(E) -> Result {
89+
handle.lock()
9790

9891
defer {
9992
handle.unlock()
@@ -120,10 +113,7 @@ extension Mutex where Value: ~Copyable {
120113
/// }
121114
/// return try body(&value)
122115
///
123-
/// - Note: This version of `tryWithLock` is unchecked because it does
124-
/// not enforce any sendability guarantees.
125-
///
126-
/// - Warning: Recursive calls to `tryWithLockUnchecked` within the
116+
/// - Warning: Recursive calls to `withLockIfAvailable` within the
127117
/// closure parameter has behavior that is platform dependent.
128118
/// Some platforms may choose to panic the process, deadlock,
129119
/// or leave this behavior unspecified.
@@ -139,8 +129,8 @@ extension Mutex where Value: ~Copyable {
139129
@available(SwiftStdlib 6.0, *)
140130
@_alwaysEmitIntoClient
141131
@_transparent
142-
public borrowing func tryWithLockUnchecked<Result: ~Copyable, E: Error>(
143-
_ body: (inout Value) throws(E) -> Result
132+
public borrowing func withLockIfAvailable<Result: ~Copyable & Sendable, E: Error>(
133+
_ body: @Sendable (inout Value) throws(E) -> Result
144134
) throws(E) -> Result? {
145135
guard handle.tryLock() else {
146136
return nil
@@ -152,85 +142,6 @@ extension Mutex where Value: ~Copyable {
152142

153143
return try body(&value.address.pointee)
154144
}
155-
156-
/// Calls the given closure after acquring the lock and then releases
157-
/// ownership.
158-
///
159-
/// This method is equivalent to the following sequence of code:
160-
///
161-
/// mutex.lock()
162-
/// defer {
163-
/// mutex.unlock()
164-
/// }
165-
/// return try body(&value)
166-
///
167-
/// - Warning: Recursive calls to `withLock` within the
168-
/// closure parameter has behavior that is platform dependent.
169-
/// Some platforms may choose to panic the process, deadlock,
170-
/// or leave this behavior unspecified.
171-
///
172-
/// - Parameter body: A closure with a parameter of `Value`
173-
/// that has exclusive access to the value being stored within
174-
/// this mutex. This closure is considered the critical section
175-
/// as it will only be executed once the calling thread has
176-
/// acquired the lock.
177-
///
178-
/// - Returns: The return value, if any, of the `body` closure parameter.
179-
@available(SwiftStdlib 6.0, *)
180-
@_alwaysEmitIntoClient
181-
@_transparent
182-
public borrowing func withLock<Result: ~Copyable & Sendable, E: Error>(
183-
_ body: @Sendable (inout Value) throws(E) -> Result
184-
) throws(E) -> Result {
185-
handle.lock()
186-
187-
defer {
188-
handle.unlock()
189-
}
190-
191-
return try body(&value.address.pointee)
192-
}
193-
194-
/// Calls the given closure after acquring the lock and then releases
195-
/// ownership.
196-
///
197-
/// This method is equivalent to the following sequence of code:
198-
///
199-
/// mutex.lock()
200-
/// defer {
201-
/// mutex.unlock()
202-
/// }
203-
/// return try body(&value)
204-
///
205-
/// - Warning: Recursive calls to `withLockUnchecked` within the
206-
/// closure parameter has behavior that is platform dependent.
207-
/// Some platforms may choose to panic the process, deadlock,
208-
/// or leave this behavior unspecified.
209-
///
210-
/// - Note: This version of `withLock` is unchecked because it does
211-
/// not enforce any sendability guarantees.
212-
///
213-
/// - Parameter body: A closure with a parameter of `Value`
214-
/// that has exclusive access to the value being stored within
215-
/// this mutex. This closure is considered the critical section
216-
/// as it will only be executed once the calling thread has
217-
/// acquired the lock.
218-
///
219-
/// - Returns: The return value, if any, of the `body` closure parameter.
220-
@available(SwiftStdlib 6.0, *)
221-
@_alwaysEmitIntoClient
222-
@_transparent
223-
public borrowing func withLockUnchecked<Result: ~Copyable, E: Error>(
224-
_ body: (inout Value) throws(E) -> Result
225-
) throws(E) -> Result {
226-
handle.lock()
227-
228-
defer {
229-
handle.unlock()
230-
}
231-
232-
return try body(&value.address.pointee)
233-
}
234145
}
235146

236147
@available(SwiftStdlib 6.0, *)
@@ -256,6 +167,3 @@ extension Mutex where Value == Void {
256167
handle.unlock()
257168
}
258169
}
259-
260-
@available(SwiftStdlib 6.0, *)
261-
extension Mutex: @unchecked Sendable where Value: Sendable {}

test/abi/macOS/arm64/synchronization.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,3 +655,33 @@ Added: _$ss7UInt128V15Synchronization19AtomicRepresentableACMc
655655

656656
// protocol witness table for Swift.UInt128 : Synchronization.AtomicRepresentable in Synchronization
657657
Added: _$ss7UInt128V15Synchronization19AtomicRepresentableACWP
658+
659+
// Synchronization._MutexHandle.value.read : Synchronization._Cell<__C.os_unfair_lock_s>
660+
Added: _$s15Synchronization12_MutexHandleV5valueAA5_CellVySo16os_unfair_lock_sVGvr
661+
662+
// type metadata accessor for Synchronization._MutexHandle
663+
Added: _$s15Synchronization12_MutexHandleVMa
664+
665+
// nominal type descriptor for Synchronization._MutexHandle
666+
Added: _$s15Synchronization12_MutexHandleVMn
667+
668+
// type metadata for Synchronization._MutexHandle
669+
Added: _$s15Synchronization12_MutexHandleVN
670+
671+
// (extension in Synchronization):Synchronization.Mutex< where A: ~Swift.Copyable>.value.read : Synchronization._Cell<A>
672+
Added: _$s15Synchronization5MutexVAARi_zrlE5valueAA5_CellVyxGvr
673+
674+
// (extension in Synchronization):Synchronization.Mutex< where A: ~Swift.Copyable>.handle.read : Synchronization._MutexHandle
675+
Added: _$s15Synchronization5MutexVAARi_zrlE6handleAA01_B6HandleVvr
676+
677+
// type metadata accessor for Synchronization.Mutex
678+
Added: _$s15Synchronization5MutexVMa
679+
680+
// nominal type descriptor for Synchronization.Mutex
681+
Added: _$s15Synchronization5MutexVMn
682+
683+
// type metadata accessor for Synchronization._Cell
684+
Added: _$s15Synchronization5_CellVMa
685+
686+
// nominal type descriptor for Synchronization._Cell
687+
Added: _$s15Synchronization5_CellVMn

0 commit comments

Comments
 (0)