Skip to content

Commit df8486d

Browse files
authored
Merge pull request #5994 from Gankro/doc-ptr
Fixups for UnsafePointer documentation
2 parents e54ec3d + ff82c1e commit df8486d

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

stdlib/public/core/UnsafePointer.swift.gyb

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -432,21 +432,29 @@ public struct ${Self}<Pointee>
432432
}
433433

434434
/// Returns the next consecutive position.
435+
///
436+
/// - Precondition: The result is within the bounds of the same allocation.
435437
public func successor() -> ${Self} {
436438
return self + 1
437439
}
438440

439441
/// Returns the previous consecutive position.
442+
///
443+
/// - Precondition: The result is within the bounds of the same allocation.
440444
public func predecessor() -> ${Self} {
441445
return self - 1
442446
}
443447

444448
/// Returns `end - self`.
445-
public func distance(to x: ${Self}) -> Int {
446-
return x - self
449+
///
450+
/// - Precondition: The result is within the bounds of the same allocation.
451+
public func distance(to end: ${Self}) -> Int {
452+
return end - self
447453
}
448454

449455
/// Returns `self + n`.
456+
///
457+
/// - Precondition: The result is within the bounds of the same allocation.
450458
public func advanced(by n: Int) -> ${Self} {
451459
return self + n
452460
}
@@ -478,39 +486,43 @@ extension ${Self} : CustomPlaygroundQuickLookable {
478486
}
479487
}
480488

481-
/// - Note: Strideable's implementation is potentially less efficient and cannot
482-
/// handle misaligned pointers.
489+
// - Note: Strideable's implementation is potentially less efficient and cannot
490+
// handle misaligned pointers.
483491
@_transparent
484492
public func == <Pointee>(
485493
lhs: ${Self}<Pointee>, rhs: ${Self}<Pointee>
486494
) -> Bool {
487495
return Bool(Builtin.cmp_eq_RawPointer(lhs._rawValue, rhs._rawValue))
488496
}
489497

490-
/// - Note: Strideable's implementation is potentially less efficient and cannot
491-
/// handle misaligned pointers.
492-
///
493-
/// - Note: This is an unsigned comparison unlike Strideable's implementation.
498+
// - Note: Strideable's implementation is potentially less efficient and cannot
499+
// handle misaligned pointers.
500+
//
501+
// - Note: This is an unsigned comparison unlike Strideable's implementation.
494502
@_transparent
495503
public func < <Pointee>(lhs: ${Self}<Pointee>, rhs: ${Self}<Pointee>) -> Bool {
496504
return Bool(Builtin.cmp_ult_RawPointer(lhs._rawValue, rhs._rawValue))
497505
}
498506

499-
/// - Note: The following family of operator overloads are redundant
500-
/// with Strideable. However, optimizer improvements are needed
501-
/// before they can be removed without affecting performance.
507+
// - Note: The following family of operator overloads are redundant
508+
// with Strideable. However, optimizer improvements are needed
509+
// before they can be removed without affecting performance.
510+
511+
/// - Precondition: The result is within bounds of the same allocation.
502512
@_transparent
503513
public func + <Pointee>(lhs: ${Self}<Pointee>, rhs: Int) -> ${Self}<Pointee> {
504514
return ${Self}(Builtin.gep_Word(
505515
lhs._rawValue, rhs._builtinWordValue, Pointee.self))
506516
}
507517

518+
/// - Precondition: The result is within the bounds of the same allocation.
508519
@_transparent
509520
public func + <Pointee>(lhs: Int,
510521
rhs: ${Self}<Pointee>) -> ${Self}<Pointee> {
511522
return rhs + lhs
512523
}
513524

525+
/// - Precondition: The result is within the bounds of the same allocation.
514526
@_transparent
515527
public func - <Pointee>(lhs: ${Self}<Pointee>, rhs: Int) -> ${Self}<Pointee> {
516528
return lhs + -rhs
@@ -524,11 +536,13 @@ public func - <Pointee>(lhs: ${Self}<Pointee>, rhs: ${Self}<Pointee>) -> Int {
524536
/ MemoryLayout<Pointee>.stride
525537
}
526538

539+
/// - Precondition: The result is within the bounds of the same allocation.
527540
@_transparent
528541
public func += <Pointee>(lhs: inout ${Self}<Pointee>, rhs: Int) {
529542
lhs = lhs + rhs
530543
}
531544

545+
/// - Precondition: The result is within the bounds of the same allocation.
532546
@_transparent
533547
public func -= <Pointee>(lhs: inout ${Self}<Pointee>, rhs: Int) {
534548
lhs = lhs - rhs

0 commit comments

Comments
 (0)