Skip to content

Commit 57528ef

Browse files
De-gyb Stride.swift (#17956)
1 parent 4949fcd commit 57528ef

File tree

5 files changed

+81
-83
lines changed

5 files changed

+81
-83
lines changed

stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ set(SWIFTLIB_ESSENTIAL
121121
SmallString.swift
122122
Sort.swift
123123
StaticString.swift
124-
Stride.swift.gyb
124+
Stride.swift
125125
StringHashable.swift # ORDER DEPENDENCY: Must precede String.swift
126126
String.swift
127127
StringBridge.swift

stdlib/public/core/MigrationSupport.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,52 @@ extension UnsafeMutablePointer {
869869
}
870870
}
871871

872+
extension Strideable {
873+
@available(swift, deprecated: 3, obsoleted: 4, message: "Please use explicit type conversions or Strideable methods for mixed-type arithmetics.")
874+
public static func + (lhs: Self, rhs: Self.Stride) -> Self {
875+
return lhs.advanced(by: rhs)
876+
}
877+
878+
@available(swift, deprecated: 3, obsoleted: 4, message: "Please use explicit type conversions or Strideable methods for mixed-type arithmetics.")
879+
public static func + (lhs: Self.Stride, rhs: Self) -> Self {
880+
return rhs.advanced(by: lhs)
881+
}
882+
883+
@available(swift, deprecated: 3, obsoleted: 4, message: "Please use explicit type conversions or Strideable methods for mixed-type arithmetics.")
884+
public static func - (lhs: Self, rhs: Self.Stride) -> Self {
885+
return lhs.advanced(by: -rhs)
886+
}
887+
888+
@available(swift, deprecated: 3, obsoleted: 4, message: "Please use explicit type conversions or Strideable methods for mixed-type arithmetics.")
889+
public static func - (lhs: Self, rhs: Self) -> Self.Stride {
890+
return rhs.distance(to: lhs)
891+
}
892+
893+
@available(swift, deprecated: 3, obsoleted: 4, message: "Please use explicit type conversions or Strideable methods for mixed-type arithmetics.")
894+
public static func += (lhs: inout Self, rhs: Self.Stride) {
895+
lhs = lhs.advanced(by: rhs)
896+
}
897+
898+
@available(swift, deprecated: 3, obsoleted: 4, message: "Please use explicit type conversions or Strideable methods for mixed-type arithmetics.")
899+
public static func -= (lhs: inout Self, rhs: Self.Stride) {
900+
lhs = lhs.advanced(by: -rhs)
901+
}
902+
}
903+
904+
extension UnsafeMutableRawPointer {
905+
@available(*, unavailable, renamed: "init(mutating:)")
906+
public init(_ from : UnsafeRawPointer) { Builtin.unreachable() }
907+
908+
@available(*, unavailable, renamed: "init(mutating:)")
909+
public init?(_ from : UnsafeRawPointer?) { Builtin.unreachable() }
910+
911+
@available(*, unavailable, renamed: "init(mutating:)")
912+
public init<T>(_ from : UnsafePointer<T>) { Builtin.unreachable() }
913+
914+
@available(*, unavailable, renamed: "init(mutating:)")
915+
public init?<T>(_ from : UnsafePointer<T>?) { Builtin.unreachable() }
916+
}
917+
872918
extension UnsafeRawPointer : _CustomPlaygroundQuickLookable {
873919
internal var summary: String {
874920
let ptrValue = UInt64(

stdlib/public/core/Pointer.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,39 @@ extension UInt {
292292
}
293293
}
294294

295+
// Pointer arithmetic operators (formerly via Strideable)
296+
extension Strideable where Self : _Pointer {
297+
@_transparent
298+
public static func + (lhs: Self, rhs: Self.Stride) -> Self {
299+
return lhs.advanced(by: rhs)
300+
}
301+
302+
@_transparent
303+
public static func + (lhs: Self.Stride, rhs: Self) -> Self {
304+
return rhs.advanced(by: lhs)
305+
}
306+
307+
@_transparent
308+
public static func - (lhs: Self, rhs: Self.Stride) -> Self {
309+
return lhs.advanced(by: -rhs)
310+
}
311+
312+
@_transparent
313+
public static func - (lhs: Self, rhs: Self) -> Self.Stride {
314+
return rhs.distance(to: lhs)
315+
}
316+
317+
@_transparent
318+
public static func += (lhs: inout Self, rhs: Self.Stride) {
319+
lhs = lhs.advanced(by: rhs)
320+
}
321+
322+
@_transparent
323+
public static func -= (lhs: inout Self, rhs: Self.Stride) {
324+
lhs = lhs.advanced(by: -rhs)
325+
}
326+
}
327+
295328
/// Derive a pointer argument from a convertible pointer type.
296329
@_transparent
297330
public // COMPILER_INTRINSIC

stdlib/public/core/Stride.swift.gyb renamed to stdlib/public/core/Stride.swift

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- Stride.swift.gyb - Components for stride(...) iteration ----------===//
1+
//===--- Stride.swift - Components for stride(...) iteration --------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -163,68 +163,6 @@ extension Strideable {
163163
}
164164
}
165165

166-
//===----------------------------------------------------------------------===//
167-
168-
%{
169-
# Strideable used to provide + and - unconditionally. With the updated
170-
# collection indexing model of Swift 3 this became unnecessary for integer
171-
# types, and was deprecated, as it was a way to write mixed-type arithmetic
172-
# expressions, that are otherwise are not allowed.
173-
}%
174-
% for Base, VersionInfo in [
175-
% ('Strideable where Self : _Pointer', None),
176-
% ('Strideable', 'deprecated: 3, obsoleted: 4'),
177-
% ]:
178-
% Availability = '@available(swift, %s, message: "Please use explicit type conversions or Strideable methods for mixed-type arithmetics.")' % (VersionInfo) if VersionInfo else ''
179-
180-
extension ${Base} {
181-
@inlinable // FIXME(sil-serialize-all)
182-
@_transparent
183-
${Availability}
184-
public static func + (lhs: Self, rhs: Self.Stride) -> Self {
185-
return lhs.advanced(by: rhs)
186-
}
187-
188-
@inlinable // FIXME(sil-serialize-all)
189-
@_transparent
190-
${Availability}
191-
public static func + (lhs: Self.Stride, rhs: Self) -> Self {
192-
return rhs.advanced(by: lhs)
193-
}
194-
195-
@inlinable // FIXME(sil-serialize-all)
196-
@_transparent
197-
${Availability}
198-
public static func - (lhs: Self, rhs: Self.Stride) -> Self {
199-
return lhs.advanced(by: -rhs)
200-
}
201-
202-
@inlinable // FIXME(sil-serialize-all)
203-
@_transparent
204-
${Availability}
205-
public static func - (lhs: Self, rhs: Self) -> Self.Stride {
206-
return rhs.distance(to: lhs)
207-
}
208-
209-
@inlinable // FIXME(sil-serialize-all)
210-
@_transparent
211-
${Availability}
212-
public static func += (lhs: inout Self, rhs: Self.Stride) {
213-
lhs = lhs.advanced(by: rhs)
214-
}
215-
216-
@inlinable // FIXME(sil-serialize-all)
217-
@_transparent
218-
${Availability}
219-
public static func -= (lhs: inout Self, rhs: Self.Stride) {
220-
lhs = lhs.advanced(by: -rhs)
221-
}
222-
}
223-
224-
% end
225-
226-
//===----------------------------------------------------------------------===//
227-
228166
extension Strideable {
229167
@inlinable // protocol-only
230168
public static func _step(
@@ -718,7 +656,3 @@ public func stride<T>(
718656
) -> StrideThrough<T> {
719657
return StrideThrough(_start: start, end: end, stride: stride)
720658
}
721-
722-
// ${'Local Variables'}:
723-
// eval: (read-only-mode 1)
724-
// End:

stdlib/public/core/UnsafeRawPointer.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -967,18 +967,3 @@ extension OpaquePointer {
967967
self._rawValue = unwrapped._rawValue
968968
}
969969
}
970-
971-
972-
extension UnsafeMutableRawPointer {
973-
@available(*, unavailable, renamed: "init(mutating:)")
974-
public init(_ from : UnsafeRawPointer) { Builtin.unreachable() }
975-
976-
@available(*, unavailable, renamed: "init(mutating:)")
977-
public init?(_ from : UnsafeRawPointer?) { Builtin.unreachable(); return nil }
978-
979-
@available(*, unavailable, renamed: "init(mutating:)")
980-
public init<T>(_ from : UnsafePointer<T>) { Builtin.unreachable() }
981-
982-
@available(*, unavailable, renamed: "init(mutating:)")
983-
public init?<T>(_ from : UnsafePointer<T>?) { Builtin.unreachable(); return nil }
984-
}

0 commit comments

Comments
 (0)