@@ -120,6 +120,9 @@ public struct Unsafe${Mutable}RawBufferPointer {
120
120
}
121
121
}
122
122
123
+ @available ( * , unavailable)
124
+ extension Unsafe ${ Mutable} RawBufferPointer: Sendable { }
125
+
123
126
% if not mutable:
124
127
extension UnsafeRawBufferPointer {
125
128
/// An iterator over the bytes viewed by a raw buffer pointer.
@@ -136,6 +139,9 @@ extension UnsafeRawBufferPointer {
136
139
}
137
140
}
138
141
142
+ @available ( * , unavailable)
143
+ extension UnsafeRawBufferPointer . Iterator : Sendable { }
144
+
139
145
extension UnsafeRawBufferPointer . Iterator : IteratorProtocol , Sequence {
140
146
/// Advances to the next byte and returns it, or `nil` if no next byte
141
147
/// exists.
@@ -400,6 +406,9 @@ extension Unsafe${Mutable}RawBufferPointer {
400
406
return baseAddress!. load ( fromByteOffset: offset, as: T . self)
401
407
}
402
408
409
+ // FIXME(NCG): Add a consuming analogue of `load`, like `move(fromByteOffset:as:_:)`
410
+ // FIXME(NCG): Add a borrow analogue of `load`, like `withBorrow(fromByteOffset:as:_:)`
411
+
403
412
/// Returns a new instance of the given type, constructed from the raw memory
404
413
/// at the specified offset.
405
414
///
@@ -431,7 +440,6 @@ extension Unsafe${Mutable}RawBufferPointer {
431
440
/// - Returns: A new instance of type `T`, copied from the buffer pointer's
432
441
/// memory.
433
442
#if $BitwiseCopyable
434
- @inlinable
435
443
@_alwaysEmitIntoClient
436
444
public func loadUnaligned< T : _BitwiseCopyable > (
437
445
fromByteOffset offset: Int = 0 ,
@@ -443,7 +451,7 @@ extension Unsafe${Mutable}RawBufferPointer {
443
451
return baseAddress!. loadUnaligned ( fromByteOffset: offset, as: T . self)
444
452
}
445
453
#endif
446
- @ inlinable
454
+
447
455
@_alwaysEmitIntoClient
448
456
public func loadUnaligned< T> (
449
457
fromByteOffset offset: Int = 0 ,
@@ -508,7 +516,7 @@ extension Unsafe${Mutable}RawBufferPointer {
508
516
// This unavailable implementation uses the expected mangled name
509
517
// of `storeBytes<T>(of:toByteOffset:as:)`, and provides an entry point for
510
518
// any binary linked against the stdlib binary for Swift 5.6 and older.
511
- @available ( * , unavailable )
519
+ @_spi ( SwiftStdlibLegacyABI ) @ available ( swift , obsoleted : 2 )
512
520
@_silgen_name ( " $sSw10storeBytes2of12toByteOffset2asyx_SixmtlF " )
513
521
@usableFromInline func _legacy_se0349_storeBytes< T> (
514
522
of value: T , toByteOffset offset: Int = 0 , as type: T . Type
@@ -620,7 +628,8 @@ extension Unsafe${Mutable}RawBufferPointer {
620
628
/// - Parameter buffer: The typed buffer to convert to a raw buffer. The
621
629
/// buffer's type `T` must be a trivial type.
622
630
@inlinable
623
- public init < T> ( _ buffer: UnsafeMutableBufferPointer < T > ) {
631
+ @_preInverseGenerics
632
+ public init < T: ~ Copyable> ( _ buffer: UnsafeMutableBufferPointer < T > ) {
624
633
self . init ( start: buffer. baseAddress,
625
634
count: buffer. count * MemoryLayout< T> . stride)
626
635
}
@@ -631,7 +640,8 @@ extension Unsafe${Mutable}RawBufferPointer {
631
640
/// - Parameter buffer: The typed buffer to convert to a raw buffer. The
632
641
/// buffer's type `T` must be a trivial type.
633
642
@inlinable
634
- public init < T> ( _ buffer: UnsafeBufferPointer < T > ) {
643
+ @_preInverseGenerics
644
+ public init < T: ~ Copyable> ( _ buffer: UnsafeBufferPointer < T > ) {
635
645
self . init ( start: buffer. baseAddress,
636
646
count: buffer. count * MemoryLayout< T> . stride)
637
647
}
@@ -934,7 +944,7 @@ extension Unsafe${Mutable}RawBufferPointer {
934
944
@discardableResult
935
945
@inlinable
936
946
@_alwaysEmitIntoClient
937
- public func moveInitializeMemory< T> (
947
+ public func moveInitializeMemory< T: ~ Copyable > (
938
948
as type: T . Type ,
939
949
fromContentsOf source: UnsafeMutableBufferPointer < T >
940
950
) -> UnsafeMutableBufferPointer < T > {
@@ -985,7 +995,6 @@ extension Unsafe${Mutable}RawBufferPointer {
985
995
/// The returned buffer references memory starting at the same
986
996
/// base address as this buffer, and its count is equal to `source.count`.
987
997
@discardableResult
988
- @inlinable
989
998
@_alwaysEmitIntoClient
990
999
public func moveInitializeMemory< T> (
991
1000
as type: T . Type ,
@@ -997,8 +1006,8 @@ extension Unsafe${Mutable}RawBufferPointer {
997
1006
998
1007
% end # mutable
999
1008
1000
- /// Binds this buffer’s memory to the specified type and returns a typed buffer
1001
- /// of the bound memory.
1009
+ /// Binds this buffer’s memory to the specified type and returns a typed
1010
+ /// buffer of the bound memory.
1002
1011
///
1003
1012
/// Use the `bindMemory(to:)` method to bind the memory referenced
1004
1013
/// by this buffer to the type `T`. The memory must be uninitialized or
@@ -1015,9 +1024,11 @@ extension Unsafe${Mutable}RawBufferPointer {
1015
1024
/// region is bound to `T`, but has not been modified in any other way.
1016
1025
/// The typed buffer references `self.count / MemoryLayout<T>.stride`
1017
1026
/// instances of `T`.
1027
+ @inlinable
1018
1028
@_transparent
1029
+ @_preInverseGenerics
1019
1030
@discardableResult
1020
- public func bindMemory< T> (
1031
+ public func bindMemory< T: ~ Copyable > (
1021
1032
to type: T . Type
1022
1033
) -> Unsafe ${ Mutable} BufferPointer< T> {
1023
1034
guard let base = _position else {
@@ -1076,7 +1087,7 @@ extension Unsafe${Mutable}RawBufferPointer {
1076
1087
/// - Returns: The return value, if any, of the `body` closure parameter.
1077
1088
@inlinable
1078
1089
@_alwaysEmitIntoClient
1079
- public func withMemoryRebound< T, Result, E: Error > (
1090
+ public func withMemoryRebound< T: ~ Copyable , Result: ~ Copyable , E: Error > (
1080
1091
to type: T . Type ,
1081
1092
_ body: ( _ buffer: Unsafe ${ Mutable} BufferPointer< T > ) throws ( E ) -> Result
1082
1093
) throws ( E) -> Result {
@@ -1114,7 +1125,7 @@ extension Unsafe${Mutable}RawBufferPointer {
1114
1125
/// - Returns: A typed pointer to the same memory as this raw pointer.
1115
1126
@inlinable
1116
1127
@_alwaysEmitIntoClient
1117
- public func assumingMemoryBound< T> (
1128
+ public func assumingMemoryBound< T: ~ Copyable > (
1118
1129
to: T . Type
1119
1130
) -> Unsafe ${ Mutable} BufferPointer< T > {
1120
1131
guard let s = _position else {
@@ -1130,7 +1141,7 @@ extension Unsafe${Mutable}RawBufferPointer {
1130
1141
% if Mutable:
1131
1142
@inlinable
1132
1143
@_alwaysEmitIntoClient
1133
- public func withContiguousMutableStorageIfAvailable< R> (
1144
+ public func withContiguousMutableStorageIfAvailable< R: ~ Copyable > (
1134
1145
_ body: ( inout UnsafeMutableBufferPointer < Element > ) throws -> R
1135
1146
) rethrows -> R ? {
1136
1147
#if $TypedThrows
@@ -1152,7 +1163,7 @@ extension Unsafe${Mutable}RawBufferPointer {
1152
1163
% end
1153
1164
@inlinable
1154
1165
@_alwaysEmitIntoClient
1155
- public func withContiguousStorageIfAvailable< R> (
1166
+ public func withContiguousStorageIfAvailable< R: ~ Copyable > (
1156
1167
_ body: ( UnsafeBufferPointer < Element > ) throws -> R
1157
1168
) rethrows -> R ? {
1158
1169
#if $TypedThrows
@@ -1216,7 +1227,6 @@ extension ${Self} {
1216
1227
/// function. The buffer pointer argument is valid only for the duration
1217
1228
/// of the closure's execution.
1218
1229
/// - Returns: The return value, if any, of the `body` closure.
1219
- @inlinable
1220
1230
@_alwaysEmitIntoClient
1221
1231
public func withUnsafeMutableBytes< T, E: Error , Result> (
1222
1232
of value: inout T ,
@@ -1281,7 +1291,6 @@ public func _withUnprotectedUnsafeMutableBytes<T, E: Error, Result>(
1281
1291
/// If you want to mutate a value by writing through a pointer, use
1282
1292
/// `withUnsafeMutableBytes(of:_:)` instead.
1283
1293
/// - Returns: The return value, if any, of the `body` closure.
1284
- @inlinable
1285
1294
@_alwaysEmitIntoClient
1286
1295
public func withUnsafeBytes< T, E: Error , Result> (
1287
1296
of value: inout T ,
@@ -1341,7 +1350,6 @@ public func _withUnprotectedUnsafeBytes<T, E: Error, Result>(
1341
1350
/// If you want to mutate a value by writing through a pointer, use
1342
1351
/// `withUnsafeMutableBytes(of:_:)` instead.
1343
1352
/// - Returns: The return value, if any, of the `body` closure.
1344
- @inlinable
1345
1353
@_alwaysEmitIntoClient
1346
1354
public func withUnsafeBytes< T, E: Error , Result> (
1347
1355
of value: T ,
@@ -1383,14 +1391,6 @@ public func _withUnprotectedUnsafeBytes<T, E: Error, Result>(
1383
1391
return try body ( buffer)
1384
1392
}
1385
1393
1386
- @available ( * , unavailable)
1387
- extension UnsafeRawBufferPointer : Sendable { }
1388
- @available ( * , unavailable)
1389
- extension UnsafeRawBufferPointer . Iterator : Sendable { }
1390
- @available ( * , unavailable)
1391
- extension UnsafeMutableRawBufferPointer : Sendable { }
1392
-
1393
-
1394
1394
// ${'Local Variables'}:
1395
1395
// eval: (read-only-mode 1)
1396
1396
// End:
0 commit comments