Skip to content

Commit 5a78a18

Browse files
authored
Refine the doc comments on UnsafeRawPointer.initialize.... (#4560)
Memory that is initialized to a trivial type may be reinitialized without destroying the in-memory values.
2 parents fb32936 + 7f76071 commit 5a78a18

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

stdlib/public/core/UnsafeRawPointer.swift.gyb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ public struct Unsafe${Mutable}RawPointer : Strideable, Hashable, _Pointer {
158158
/// Deallocates uninitialized memory allocated for `bytes` number of bytes
159159
/// with `alignedTo` alignment.
160160
///
161-
/// - Precondition: The memory is not initialized.
161+
/// - Precondition: The memory is uninitialized or initialized to a
162+
/// trivial type.
162163
/// - Postcondition: The memory has been deallocated.
163164
public func deallocate(bytes: Int, alignedTo: Int) {
164165
Builtin.deallocRaw(
@@ -168,7 +169,8 @@ public struct Unsafe${Mutable}RawPointer : Strideable, Hashable, _Pointer {
168169
/// Binds the allocated memory to type `T` and returns an
169170
/// `Unsafe${Mutable}Pointer<T>` to the bound memory at `self`.
170171
///
171-
/// - Precondition: The memory is uninitialized.
172+
/// - Precondition: The memory is uninitialized or initialized to a type
173+
/// that is layout compatible with `T`.
172174
/// - Postcondition: The memory is bound to 'T' starting at `self` continuing
173175
/// through `self` + `count` * `MemoryLayout<T>.stride`
174176
/// - Warning: Binding memory to a type is potentially undefined if the
@@ -203,7 +205,7 @@ public struct Unsafe${Mutable}RawPointer : Strideable, Hashable, _Pointer {
203205
///
204206
/// - Precondition: The memory at
205207
/// `self + index * strideof(T)..<self + (index + count) * strideof(T)`
206-
/// is uninitialized.
208+
/// is uninitialized or initialized to a trivial type.
207209
///
208210
/// - Precondition: The underlying pointer is properly aligned for
209211
/// accessing `T`.
@@ -243,8 +245,9 @@ public struct Unsafe${Mutable}RawPointer : Strideable, Hashable, _Pointer {
243245
/// - Precondition: The memory regions `source..<source + count` and
244246
/// `self..<self + count * MemoryLayout<T>.stride` do not overlap.
245247
/// - Precondition: The memory at
246-
/// `self..<self + count * MemoryLayout<T>.stride` is uninitialized, and
247-
/// the `T` values at `source..<source + count` are initialized.
248+
/// `self..<self + count * MemoryLayout<T>.stride` is uninitialized or
249+
/// initialized to a trivial type, and the `T` values at
250+
/// `source..<source + count` are initialized.
248251
/// - Precondition: The underlying pointer is properly aligned for accessing
249252
/// `T`.
250253
/// - Postcondition: The memory at
@@ -281,7 +284,8 @@ public struct Unsafe${Mutable}RawPointer : Strideable, Hashable, _Pointer {
281284
/// Returns an `UnsafeMutablePointer<T>` this memory.
282285
///
283286
/// - Precondition: The memory at `self..<self + source.count *
284-
/// MemoryLayout<T>.stride` is uninitialized.
287+
/// MemoryLayout<T>.stride` is uninitialized or initialized to a
288+
/// trivial type.
285289
///
286290
/// - Postcondition: The memory at `self..<self + source.count *
287291
/// MemoryLayout<T>.stride` is bound to type `T`.
@@ -310,7 +314,8 @@ public struct Unsafe${Mutable}RawPointer : Strideable, Hashable, _Pointer {
310314
/// - Precondition: `count >= 0`
311315
///
312316
/// - Precondition: The memory at `self..<self + count *
313-
/// MemoryLayout<T>.stride` is uninitialized and the `T` values at
317+
/// MemoryLayout<T>.stride` is uninitialized or initialized to a
318+
/// trivial type and the `T` values at
314319
/// `source..<source + count` are initialized.
315320
///
316321
/// - Postcondition: The memory at `self..<self + count *

0 commit comments

Comments
 (0)