Skip to content

Commit 38001ae

Browse files
committed
[stdlib] Apply @Azoy’s remaining review notes (thanks!)
1 parent 2a1f155 commit 38001ae

File tree

8 files changed

+66
-52
lines changed

8 files changed

+66
-52
lines changed

stdlib/public/Synchronization/AtomicPointers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2023 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2023 - 2024 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information

stdlib/public/core/Optional.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ extension Optional where Wrapped: ~Copyable {
769769
/// type as the `Wrapped` type of `optional`.
770770
@_transparent
771771
@_alwaysEmitIntoClient
772+
// FIXME: This needs to support typed throws.
772773
public func ?? <T: ~Copyable>(
773774
optional: consuming T?,
774775
defaultValue: @autoclosure () throws -> T
@@ -839,6 +840,7 @@ internal func ?? <T>(
839840
/// `optional` have the same type.
840841
@_transparent
841842
@_alwaysEmitIntoClient
843+
// FIXME: This needs to support typed throws.
842844
public func ?? <T: ~Copyable>(
843845
optional: consuming T?,
844846
defaultValue: @autoclosure () throws -> T?

stdlib/public/core/Result.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public enum Result<Success: ~Copyable, Failure: Error> {
2121
case failure(Failure)
2222
}
2323

24-
extension Result: Copyable where Success: Copyable {}
24+
extension Result: Copyable /* where Success: Copyable */ {}
2525

2626
extension Result: Sendable where Success: Sendable & ~Copyable {}
2727

stdlib/public/core/TemporaryAllocation.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ internal func _isStackAllocationSafe(byteCount: Int, alignment: Int) -> Bool {
124124
/// This function encapsulates the various calls to builtins required by
125125
/// `withUnsafeTemporaryAllocation()`.
126126
@_alwaysEmitIntoClient @_transparent
127-
internal func _withUnsafeTemporaryAllocation<T: ~Copyable, R/*FIXME(NCG): ~Copyable*/>(
127+
// FIXME(NCG): R needs to be ~Copyable too, but that leads to lifetime failures (rdar://124571365).
128+
internal func _withUnsafeTemporaryAllocation<T: ~Copyable, R>(
128129
of type: T.Type,
129130
capacity: Int,
130131
alignment: Int,
@@ -168,7 +169,8 @@ internal func _withUnsafeTemporaryAllocation<T: ~Copyable, R/*FIXME(NCG): ~Copya
168169

169170
@_alwaysEmitIntoClient @_transparent
170171
internal func _withUnprotectedUnsafeTemporaryAllocation<
171-
T: ~Copyable, R/*FIXME(NCG): ~Copyable*/
172+
// FIXME(NCG): R needs to be ~Copyable too, but that leads to lifetime failures (rdar://124571365).
173+
T: ~Copyable, R
172174
>(
173175
of type: T.Type,
174176
capacity: Int,
@@ -265,7 +267,8 @@ internal func _fallBackToHeapAllocation<R: ~Copyable>(
265267
/// the buffer) must not escape. It will be deallocated when `body` returns and
266268
/// cannot be used afterward.
267269
@_alwaysEmitIntoClient @_transparent
268-
public func withUnsafeTemporaryAllocation<R/*FIXME(NCG): ~Copyable*/>(
270+
// FIXME(NCG): R needs to be ~Copyable, but that leads to lifetime failures (rdar://124571365).
271+
public func withUnsafeTemporaryAllocation<R>(
269272
byteCount: Int,
270273
alignment: Int,
271274
_ body: (UnsafeMutableRawBufferPointer) throws -> R
@@ -289,7 +292,8 @@ public func withUnsafeTemporaryAllocation<R/*FIXME(NCG): ~Copyable*/>(
289292
/// This function is similar to `withUnsafeTemporaryAllocation`, except that it
290293
/// doesn't trigger stack protection for the stack allocated memory.
291294
@_alwaysEmitIntoClient @_transparent
292-
public func _withUnprotectedUnsafeTemporaryAllocation<R/*FIXME(NCG): ~Copyable*/>(
295+
// FIXME(NCG): R needs to be ~Copyable, but that leads to lifetime failures (rdar://124571365).
296+
public func _withUnprotectedUnsafeTemporaryAllocation<R>(
293297
byteCount: Int,
294298
alignment: Int,
295299
_ body: (UnsafeMutableRawBufferPointer) throws -> R
@@ -339,7 +343,8 @@ public func _withUnprotectedUnsafeTemporaryAllocation<R/*FIXME(NCG): ~Copyable*/
339343
/// the buffer) must not escape. It will be deallocated when `body` returns and
340344
/// cannot be used afterward.
341345
@_alwaysEmitIntoClient @_transparent
342-
public func withUnsafeTemporaryAllocation<T: ~Copyable, R/*FIXME(NCG): ~Copyable*/>(
346+
// FIXME(NCG): R needs to be ~Copyable too, but that leads to lifetime failures (rdar://124571365).
347+
public func withUnsafeTemporaryAllocation<T: ~Copyable, R>(
343348
of type: T.Type,
344349
capacity: Int,
345350
_ body: (UnsafeMutableBufferPointer<T>) throws -> R
@@ -364,7 +369,8 @@ public func withUnsafeTemporaryAllocation<T: ~Copyable, R/*FIXME(NCG): ~Copyable
364369
/// This function is similar to `withUnsafeTemporaryAllocation`, except that it
365370
/// doesn't trigger stack protection for the stack allocated memory.
366371
@_alwaysEmitIntoClient @_transparent
367-
public func _withUnprotectedUnsafeTemporaryAllocation<T: ~Copyable, R/*FIXME(NCG): ~Copyable*/>(
372+
// FIXME(NCG): R needs to be ~Copyable too, but that leads to lifetime failures (rdar://124571365).
373+
public func _withUnprotectedUnsafeTemporaryAllocation<T: ~Copyable, R>(
368374
of type: T.Type,
369375
capacity: Int,
370376
_ body: (UnsafeMutableBufferPointer<T>) throws -> R

stdlib/public/core/UnsafeBufferPointer.swift.gyb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public struct Unsafe${Mutable}BufferPointer<Element: ~Copyable>: Copyable {
110110
}
111111

112112
@available(*, unavailable)
113-
extension Unsafe${Mutable}BufferPointer: Sendable {}
113+
extension Unsafe${Mutable}BufferPointer: Sendable where Element: ~Copyable {}
114114

115115
extension Unsafe${Mutable}BufferPointer where Element: ~Copyable {
116116
/// A pointer to the first element of the buffer.
@@ -521,7 +521,6 @@ extension Unsafe${Mutable}BufferPointer {
521521
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
522522
@usableFromInline
523523
internal subscript(_unchecked i: Int) -> Element {
524-
@_transparent
525524
get {
526525
_internalInvariant(i >= 0)
527526
_internalInvariant(i < endIndex)
@@ -1262,8 +1261,6 @@ extension Unsafe${Mutable}BufferPointer where Element: ~Copyable {
12621261
/// - buffer: The buffer temporarily bound to `T`.
12631262
/// - Returns: The return value, if any, of the `body` closure parameter.
12641263
@_alwaysEmitIntoClient
1265-
// FIXME(NCG): Get rid of this once the new mangling rules are working.
1266-
@_silgen_name("_swift_stdlib_tempSymbol_Unsafe${Mutable}BufferPointer_withMemoryRebound")
12671264
public func withMemoryRebound<T: ~Copyable, Result: ~Copyable>(
12681265
to type: T.Type,
12691266
_ body: (_ buffer: ${Self}<T>) throws -> Result

stdlib/public/core/UnsafePointer.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ extension UnsafePointer: _Pointer where Pointee: ~Copyable {
229229

230230
@_preInverseGenerics
231231
extension UnsafePointer: Equatable where Pointee: ~Copyable {}
232+
232233
@_preInverseGenerics
233234
extension UnsafePointer: Hashable where Pointee: ~Copyable {
234235
// Note: This explicit `hashValue` applies @_preInverseGenerics to emulate the
@@ -240,13 +241,16 @@ extension UnsafePointer: Hashable where Pointee: ~Copyable {
240241
}
241242
@_preInverseGenerics
242243
extension UnsafePointer: Comparable where Pointee: ~Copyable {}
244+
243245
@_preInverseGenerics
244246
extension UnsafePointer: Strideable where Pointee: ~Copyable {}
247+
245248
#if !$Embedded
246249
@_preInverseGenerics
247250
extension UnsafePointer: CustomDebugStringConvertible
248251
where Pointee: ~Copyable {}
249252
#endif
253+
250254
#if SWIFT_ENABLE_REFLECTION
251255
@_preInverseGenerics
252256
extension UnsafePointer: CustomReflectable where Pointee: ~Copyable {}
@@ -674,6 +678,7 @@ extension UnsafeMutablePointer: _Pointer where Pointee: ~Copyable {
674678

675679
@_preInverseGenerics
676680
extension UnsafeMutablePointer: Equatable where Pointee: ~Copyable {}
681+
677682
@_preInverseGenerics
678683
extension UnsafeMutablePointer: Hashable where Pointee: ~Copyable {
679684
// Note: This explicit `hashValue` applies @_preInverseGenerics to emulate the
@@ -683,15 +688,19 @@ extension UnsafeMutablePointer: Hashable where Pointee: ~Copyable {
683688
_hashValue(for: self)
684689
}
685690
}
691+
686692
@_preInverseGenerics
687693
extension UnsafeMutablePointer: Comparable where Pointee: ~Copyable {}
694+
688695
@_preInverseGenerics
689696
extension UnsafeMutablePointer: Strideable where Pointee: ~Copyable {}
697+
690698
#if !$Embedded
691699
@_preInverseGenerics
692700
extension UnsafeMutablePointer: CustomDebugStringConvertible
693701
where Pointee: ~Copyable {}
694702
#endif
703+
695704
#if SWIFT_ENABLE_REFLECTION
696705
@_preInverseGenerics
697706
extension UnsafeMutablePointer: CustomReflectable where Pointee: ~Copyable {}

test/abi/macOS/arm64/synchronization.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,18 @@ Added: _$sSO15Synchronization27AtomicOptionalRepresentableAAMc
449449
// protocol witness table for Swift.ObjectIdentifier : Synchronization.AtomicOptionalRepresentable in Synchronization
450450
Added: _$sSO15Synchronization27AtomicOptionalRepresentableAAWP
451451

452+
// protocol conformance descriptor for < where A: ~Swift.Copyable> Swift.UnsafePointer<A> : Synchronization.AtomicRepresentable in Synchronization
453+
Added: _$sSPyxG15Synchronization19AtomicRepresentableABRiczrlMc
454+
455+
// protocol witness table for < where A: ~Swift.Copyable> Swift.UnsafePointer<A> : Synchronization.AtomicRepresentable in Synchronization
456+
Added: _$sSPyxG15Synchronization19AtomicRepresentableABRiczrlWP
457+
458+
// protocol conformance descriptor for < where A: ~Swift.Copyable> Swift.UnsafePointer<A> : Synchronization.AtomicOptionalRepresentable in Synchronization
459+
Added: _$sSPyxG15Synchronization27AtomicOptionalRepresentableABRiczrlMc
460+
461+
// protocol witness table for < where A: ~Swift.Copyable> Swift.UnsafePointer<A> : Synchronization.AtomicOptionalRepresentable in Synchronization
462+
Added: _$sSPyxG15Synchronization27AtomicOptionalRepresentableABRiczrlWP
463+
452464
// protocol conformance descriptor for Swift.UnsafeBufferPointer<A> : Synchronization.AtomicRepresentable in Synchronization
453465
Added: _$sSRyxG15Synchronization19AtomicRepresentableABMc
454466

@@ -497,6 +509,18 @@ Added: _$sSi15Synchronization19AtomicRepresentableAAMc
497509
// protocol witness table for Swift.Int : Synchronization.AtomicRepresentable in Synchronization
498510
Added: _$sSi15Synchronization19AtomicRepresentableAAWP
499511

512+
// protocol conformance descriptor for < where A: ~Swift.Copyable> Swift.UnsafeMutablePointer<A> : Synchronization.AtomicRepresentable in Synchronization
513+
Added: _$sSpyxG15Synchronization19AtomicRepresentableABRiczrlMc
514+
515+
// protocol witness table for < where A: ~Swift.Copyable> Swift.UnsafeMutablePointer<A> : Synchronization.AtomicRepresentable in Synchronization
516+
Added: _$sSpyxG15Synchronization19AtomicRepresentableABRiczrlWP
517+
518+
// protocol conformance descriptor for < where A: ~Swift.Copyable> Swift.UnsafeMutablePointer<A> : Synchronization.AtomicOptionalRepresentable in Synchronization
519+
Added: _$sSpyxG15Synchronization27AtomicOptionalRepresentableABRiczrlMc
520+
521+
// protocol witness table for < where A: ~Swift.Copyable> Swift.UnsafeMutablePointer<A> : Synchronization.AtomicOptionalRepresentable in Synchronization
522+
Added: _$sSpyxG15Synchronization27AtomicOptionalRepresentableABRiczrlWP
523+
500524
// protocol conformance descriptor for Swift.UnsafeMutableBufferPointer<A> : Synchronization.AtomicRepresentable in Synchronization
501525
Added: _$sSryxG15Synchronization19AtomicRepresentableABMc
502526

@@ -620,27 +644,3 @@ Added: _$ss9UnmanagedVyxG15Synchronization27AtomicOptionalRepresentableADWP
620644
// protocol conformance descriptor for <A where A: Synchronization.AtomicOptionalRepresentable> A? : Synchronization.AtomicRepresentable in Synchronization
621645
Added: _$sxSg15Synchronization19AtomicRepresentableA2B0b8OptionalC0RzlMc
622646

623-
// protocol conformance descriptor for < where A: ~Swift.Copyable> Swift.UnsafePointer<A> : Synchronization.AtomicRepresentable in Synchronization
624-
Added: _$sSPyxG15Synchronization19AtomicRepresentableABRiczrlMc
625-
626-
// protocol witness table for < where A: ~Swift.Copyable> Swift.UnsafePointer<A> : Synchronization.AtomicRepresentable in Synchronization
627-
Added: _$sSPyxG15Synchronization19AtomicRepresentableABRiczrlWP
628-
629-
// protocol conformance descriptor for < where A: ~Swift.Copyable> Swift.UnsafePointer<A> : Synchronization.AtomicOptionalRepresentable in Synchronization
630-
Added: _$sSPyxG15Synchronization27AtomicOptionalRepresentableABRiczrlMc
631-
632-
// protocol witness table for < where A: ~Swift.Copyable> Swift.UnsafePointer<A> : Synchronization.AtomicOptionalRepresentable in Synchronization
633-
Added: _$sSPyxG15Synchronization27AtomicOptionalRepresentableABRiczrlWP
634-
635-
// protocol conformance descriptor for < where A: ~Swift.Copyable> Swift.UnsafeMutablePointer<A> : Synchronization.AtomicRepresentable in Synchronization
636-
Added: _$sSpyxG15Synchronization19AtomicRepresentableABRiczrlMc
637-
638-
// protocol witness table for < where A: ~Swift.Copyable> Swift.UnsafeMutablePointer<A> : Synchronization.AtomicRepresentable in Synchronization
639-
Added: _$sSpyxG15Synchronization19AtomicRepresentableABRiczrlWP
640-
641-
// protocol conformance descriptor for < where A: ~Swift.Copyable> Swift.UnsafeMutablePointer<A> : Synchronization.AtomicOptionalRepresentable in Synchronization
642-
Added: _$sSpyxG15Synchronization27AtomicOptionalRepresentableABRiczrlMc
643-
644-
// protocol witness table for < where A: ~Swift.Copyable> Swift.UnsafeMutablePointer<A> : Synchronization.AtomicOptionalRepresentable in Synchronization
645-
Added: _$sSpyxG15Synchronization27AtomicOptionalRepresentableABRiczrlWP
646-

test/abi/macOS/x86_64/synchronization.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -449,17 +449,17 @@ Added: _$sSO15Synchronization27AtomicOptionalRepresentableAAMc
449449
// protocol witness table for Swift.ObjectIdentifier : Synchronization.AtomicOptionalRepresentable in Synchronization
450450
Added: _$sSO15Synchronization27AtomicOptionalRepresentableAAWP
451451

452-
// protocol conformance descriptor for Swift.UnsafePointer<A> : Synchronization.AtomicRepresentable in Synchronization
453-
Added: _$sSPyxG15Synchronization19AtomicRepresentableABMc
452+
// protocol conformance descriptor for < where A: ~Swift.Copyable> Swift.UnsafePointer<A> : Synchronization.AtomicRepresentable in Synchronization
453+
Added: _$sSPyxG15Synchronization19AtomicRepresentableABRiczrlMc
454454

455-
// protocol witness table for Swift.UnsafePointer<A> : Synchronization.AtomicRepresentable in Synchronization
456-
Added: _$sSPyxG15Synchronization19AtomicRepresentableABWP
455+
// protocol witness table for < where A: ~Swift.Copyable> Swift.UnsafePointer<A> : Synchronization.AtomicRepresentable in Synchronization
456+
Added: _$sSPyxG15Synchronization19AtomicRepresentableABRiczrlWP
457457

458-
// protocol conformance descriptor for Swift.UnsafePointer<A> : Synchronization.AtomicOptionalRepresentable in Synchronization
459-
Added: _$sSPyxG15Synchronization27AtomicOptionalRepresentableABMc
458+
// protocol conformance descriptor for < where A: ~Swift.Copyable> Swift.UnsafePointer<A> : Synchronization.AtomicOptionalRepresentable in Synchronization
459+
Added: _$sSPyxG15Synchronization27AtomicOptionalRepresentableABRiczrlMc
460460

461-
// protocol witness table for Swift.UnsafePointer<A> : Synchronization.AtomicOptionalRepresentable in Synchronization
462-
Added: _$sSPyxG15Synchronization27AtomicOptionalRepresentableABWP
461+
// protocol witness table for < where A: ~Swift.Copyable> Swift.UnsafePointer<A> : Synchronization.AtomicOptionalRepresentable in Synchronization
462+
Added: _$sSPyxG15Synchronization27AtomicOptionalRepresentableABRiczrlWP
463463

464464
// protocol conformance descriptor for Swift.UnsafeBufferPointer<A> : Synchronization.AtomicRepresentable in Synchronization
465465
Added: _$sSRyxG15Synchronization19AtomicRepresentableABMc
@@ -509,17 +509,17 @@ Added: _$sSi15Synchronization19AtomicRepresentableAAMc
509509
// protocol witness table for Swift.Int : Synchronization.AtomicRepresentable in Synchronization
510510
Added: _$sSi15Synchronization19AtomicRepresentableAAWP
511511

512-
// protocol conformance descriptor for Swift.UnsafeMutablePointer<A> : Synchronization.AtomicRepresentable in Synchronization
513-
Added: _$sSpyxG15Synchronization19AtomicRepresentableABMc
512+
// protocol conformance descriptor for < where A: ~Swift.Copyable> Swift.UnsafeMutablePointer<A> : Synchronization.AtomicRepresentable in Synchronization
513+
Added: _$sSpyxG15Synchronization19AtomicRepresentableABRiczrlMc
514514

515-
// protocol witness table for Swift.UnsafeMutablePointer<A> : Synchronization.AtomicRepresentable in Synchronization
516-
Added: _$sSpyxG15Synchronization19AtomicRepresentableABWP
515+
// protocol witness table for < where A: ~Swift.Copyable> Swift.UnsafeMutablePointer<A> : Synchronization.AtomicRepresentable in Synchronization
516+
Added: _$sSpyxG15Synchronization19AtomicRepresentableABRiczrlWP
517517

518-
// protocol conformance descriptor for Swift.UnsafeMutablePointer<A> : Synchronization.AtomicOptionalRepresentable in Synchronization
519-
Added: _$sSpyxG15Synchronization27AtomicOptionalRepresentableABMc
518+
// protocol conformance descriptor for < where A: ~Swift.Copyable> Swift.UnsafeMutablePointer<A> : Synchronization.AtomicOptionalRepresentable in Synchronization
519+
Added: _$sSpyxG15Synchronization27AtomicOptionalRepresentableABRiczrlMc
520520

521-
// protocol witness table for Swift.UnsafeMutablePointer<A> : Synchronization.AtomicOptionalRepresentable in Synchronization
522-
Added: _$sSpyxG15Synchronization27AtomicOptionalRepresentableABWP
521+
// protocol witness table for < where A: ~Swift.Copyable> Swift.UnsafeMutablePointer<A> : Synchronization.AtomicOptionalRepresentable in Synchronization
522+
Added: _$sSpyxG15Synchronization27AtomicOptionalRepresentableABRiczrlWP
523523

524524
// protocol conformance descriptor for Swift.UnsafeMutableBufferPointer<A> : Synchronization.AtomicRepresentable in Synchronization
525525
Added: _$sSryxG15Synchronization19AtomicRepresentableABMc

0 commit comments

Comments
 (0)