Skip to content

Commit 907ee40

Browse files
committed
Factor out Strideable
1 parent 15a0f25 commit 907ee40

File tree

5 files changed

+4
-116
lines changed

5 files changed

+4
-116
lines changed

stdlib/public/core/BridgeObjectiveC.swift

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -493,54 +493,6 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
493493
}
494494
}
495495

496-
extension AutoreleasingUnsafeMutablePointer /*: Strideable*/ {
497-
/// Returns the distance from this pointer to the given pointer, counted as
498-
/// instances of the pointer's `Pointee` type.
499-
///
500-
/// With pointers `p` and `q`, the result of `p.distance(to: q)` is
501-
/// equivalent to `q - p`.
502-
///
503-
/// Typed pointers are required to be properly aligned for their `Pointee`
504-
/// type. Proper alignment ensures that the result of `distance(to:)`
505-
/// accurately measures the distance between the two pointers, counted in
506-
/// strides of `Pointee`. To find the distance in bytes between two
507-
/// pointers, convert them to `UnsafeRawPointer` instances before calling
508-
/// `distance(to:)`.
509-
///
510-
/// - Parameter end: The pointer to calculate the distance to.
511-
/// - Returns: The distance from this pointer to `end`, in strides of the
512-
/// pointer's `Pointee` type. To access the stride, use
513-
/// `MemoryLayout<Pointee>.stride`.
514-
@inlinable
515-
public func distance(to end: AutoreleasingUnsafeMutablePointer) -> Int {
516-
return
517-
Int(Builtin.sub_Word(Builtin.ptrtoint_Word(end._rawValue),
518-
Builtin.ptrtoint_Word(_rawValue)))
519-
/ MemoryLayout<Pointee>.stride
520-
}
521-
522-
/// Returns a pointer offset from this pointer by the specified number of
523-
/// instances.
524-
///
525-
/// With pointer `p` and distance `n`, the result of `p.advanced(by: n)` is
526-
/// equivalent to `p + n`.
527-
///
528-
/// The resulting pointer must be within the bounds of the same allocation as
529-
/// this pointer.
530-
///
531-
/// - Parameter n: The number of strides of the pointer's `Pointee` type to
532-
/// offset this pointer. To access the stride, use
533-
/// `MemoryLayout<Pointee>.stride`. `n` may be positive, negative, or
534-
/// zero.
535-
/// - Returns: A pointer offset from this pointer by `n` instances of the
536-
/// `Pointee` type.
537-
@inlinable
538-
public func advanced(by n: Int) -> AutoreleasingUnsafeMutablePointer {
539-
return AutoreleasingUnsafeMutablePointer(Builtin.gep_Word(
540-
self._rawValue, n._builtinWordValue, Pointee.self))
541-
}
542-
}
543-
544496
extension UnsafeMutableRawPointer {
545497
/// Creates a new raw pointer from an `AutoreleasingUnsafeMutablePointer`
546498
/// instance.

stdlib/public/core/Pointer.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ extension _Pointer /*: Comparable */ {
137137
}
138138
}
139139

140-
/*
141-
This should be possible but currently segfaulting the compiler:
142140
extension _Pointer /*: Strideable*/ {
143141
/// Returns the distance from this pointer to the given pointer, counted as
144142
/// instances of the pointer's `Pointee` type.
@@ -158,7 +156,7 @@ extension _Pointer /*: Strideable*/ {
158156
/// pointer's `Pointee` type. To access the stride, use
159157
/// `MemoryLayout<Pointee>.stride`.
160158
@inlinable
161-
public func distance(to end: AutoreleasingUnsafeMutablePointer) -> Int {
159+
public func distance(to end: Self) -> Int {
162160
return
163161
Int(Builtin.sub_Word(Builtin.ptrtoint_Word(end._rawValue),
164162
Builtin.ptrtoint_Word(_rawValue)))
@@ -181,12 +179,11 @@ extension _Pointer /*: Strideable*/ {
181179
/// - Returns: A pointer offset from this pointer by `n` instances of the
182180
/// `Pointee` type.
183181
@inlinable
184-
public func advanced(by n: Int) -> AutoreleasingUnsafeMutablePointer {
185-
return AutoreleasingUnsafeMutablePointer(Builtin.gep_Word(
182+
public func advanced(by n: Int) -> Self {
183+
return Self(Builtin.gep_Word(
186184
self._rawValue, n._builtinWordValue, Pointee.self))
187185
}
188186
}
189-
*/
190187

191188
extension _Pointer /*: Hashable */ {
192189
/// Hashes the essential components of this value by feeding them into the

stdlib/public/core/UnsafePointer.swift.gyb

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -745,54 +745,6 @@ public struct ${Self}<Pointee>: _Pointer {
745745
}
746746
}
747747

748-
extension ${Self}: Strideable {
749-
/// Returns the distance from this pointer to the given pointer, counted as
750-
/// instances of the pointer's `Pointee` type.
751-
///
752-
/// With pointers `p` and `q`, the result of `p.distance(to: q)` is
753-
/// equivalent to `q - p`.
754-
///
755-
/// Typed pointers are required to be properly aligned for their `Pointee`
756-
/// type. Proper alignment ensures that the result of `distance(to:)`
757-
/// accurately measures the distance between the two pointers, counted in
758-
/// strides of `Pointee`. To find the distance in bytes between two
759-
/// pointers, convert them to `UnsafeRawPointer` instances before calling
760-
/// `distance(to:)`.
761-
///
762-
/// - Parameter end: The pointer to calculate the distance to.
763-
/// - Returns: The distance from this pointer to `end`, in strides of the
764-
/// pointer's `Pointee` type. To access the stride, use
765-
/// `MemoryLayout<Pointee>.stride`.
766-
@inlinable
767-
public func distance(to end: ${Self}) -> Int {
768-
return
769-
Int(Builtin.sub_Word(Builtin.ptrtoint_Word(end._rawValue),
770-
Builtin.ptrtoint_Word(_rawValue)))
771-
/ MemoryLayout<Pointee>.stride
772-
}
773-
774-
/// Returns a pointer offset from this pointer by the specified number of
775-
/// instances.
776-
///
777-
/// With pointer `p` and distance `n`, the result of `p.advanced(by: n)` is
778-
/// equivalent to `p + n`.
779-
///
780-
/// The resulting pointer must be within the bounds of the same allocation as
781-
/// this pointer.
782-
///
783-
/// - Parameter n: The number of strides of the pointer's `Pointee` type to
784-
/// offset this pointer. To access the stride, use
785-
/// `MemoryLayout<Pointee>.stride`. `n` may be positive, negative, or
786-
/// zero.
787-
/// - Returns: A pointer offset from this pointer by `n` instances of the
788-
/// `Pointee` type.
789-
@inlinable
790-
public func advanced(by n: Int) -> ${Self} {
791-
return ${Self}(Builtin.gep_Word(
792-
self._rawValue, n._builtinWordValue, Pointee.self))
793-
}
794-
}
795-
796748
extension ${Self} {
797749
@inlinable // FIXME(sil-serialize-all)
798750
internal static var _max : ${Self} {

stdlib/public/core/UnsafeRawPointer.swift.gyb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -735,19 +735,6 @@ public struct Unsafe${Mutable}RawPointer: _Pointer {
735735
}
736736

737737
extension ${Self} /*: Strideable*/ {
738-
/// Returns the distance from this pointer to the given pointer.
739-
///
740-
/// With pointers `p` and `q`, the result of `p.distance(to: q)` is
741-
/// equivalent to `q - p`.
742-
///
743-
/// - Parameter x: The pointer to calculate the distance to.
744-
/// - Returns: The distance from this pointer to `x`, in bytes.
745-
@inlinable
746-
public func distance(to x: ${Self}) -> Int {
747-
return Int(Builtin.sub_Word(Builtin.ptrtoint_Word(x._rawValue),
748-
Builtin.ptrtoint_Word(_rawValue)))
749-
}
750-
751738
/// Returns a pointer offset from this pointer by the specified number of
752739
/// bytes.
753740
///

test/IDE/print_stdlib.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
// CHECK-MUTATING-ATTR: mutating func
5050

51-
func foo(x: _Pointer) {} // Checks that this protocol actually exists.
51+
func foo<P: _Pointer>(x: P) {} // Checks that this protocol actually exists.
5252
// CHECK-NOT: _Pointer
5353

5454
// NO-FIXMES-NOT: FIXME

0 commit comments

Comments
 (0)