Skip to content

Commit ab3a15c

Browse files
committed
[SE-0091 / Foundation overlay] Move operators into types.
Foundation provides a number of specific operators defined in the global scope. Push all of these into their corresponding types. This cleanup helps verify that the SE-0091 implementation is generally functional.
1 parent 80f0852 commit ab3a15c

21 files changed

+404
-405
lines changed

stdlib/public/SDK/Foundation/AffineTransform.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,13 @@ extension AffineTransform : ReferenceConvertible, Hashable, CustomStringConverti
254254
public var debugDescription: String {
255255
return description
256256
}
257-
}
258257

259-
public func ==(lhs: AffineTransform, rhs: AffineTransform) -> Bool {
260-
return lhs.m11 == rhs.m11 && lhs.m12 == rhs.m12 &&
261-
lhs.m21 == rhs.m21 && lhs.m22 == rhs.m22 &&
262-
lhs.tX == rhs.tX && lhs.tY == rhs.tY
258+
public static func ==(lhs: AffineTransform, rhs: AffineTransform) -> Bool {
259+
return lhs.m11 == rhs.m11 && lhs.m12 == rhs.m12 &&
260+
lhs.m21 == rhs.m21 && lhs.m22 == rhs.m22 &&
261+
lhs.tX == rhs.tX && lhs.tY == rhs.tY
262+
}
263+
263264
}
264265

265266
extension AffineTransform : _ObjectiveCBridgeable {

stdlib/public/SDK/Foundation/Calendar.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,19 +1065,20 @@ public struct Calendar : CustomStringConvertible, CustomDebugStringConvertible,
10651065
return identifierMap[identifier]!
10661066
}
10671067
}
1068-
}
10691068

1070-
public func ==(lhs: Calendar, rhs: Calendar) -> Bool {
1071-
if lhs._autoupdating || rhs._autoupdating {
1072-
return lhs._autoupdating == rhs._autoupdating
1073-
} else {
1074-
// NSCalendar's isEqual is broken (27019864) so we must implement this ourselves
1075-
return lhs.identifier == rhs.identifier &&
1076-
lhs.locale == rhs.locale &&
1077-
lhs.timeZone == rhs.timeZone &&
1078-
lhs.firstWeekday == rhs.firstWeekday &&
1079-
lhs.minimumDaysInFirstWeek == rhs.minimumDaysInFirstWeek
1069+
public static func ==(lhs: Calendar, rhs: Calendar) -> Bool {
1070+
if lhs._autoupdating || rhs._autoupdating {
1071+
return lhs._autoupdating == rhs._autoupdating
1072+
} else {
1073+
// NSCalendar's isEqual is broken (27019864) so we must implement this ourselves
1074+
return lhs.identifier == rhs.identifier &&
1075+
lhs.locale == rhs.locale &&
1076+
lhs.timeZone == rhs.timeZone &&
1077+
lhs.firstWeekday == rhs.firstWeekday &&
1078+
lhs.minimumDaysInFirstWeek == rhs.minimumDaysInFirstWeek
1079+
}
10801080
}
1081+
10811082
}
10821083

10831084
extension Calendar : _ObjectiveCBridgeable {

stdlib/public/SDK/Foundation/CharacterSet.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,11 @@ public struct CharacterSet : ReferenceConvertible, Equatable, Hashable, SetAlgeb
424424
public func isSuperset(of other: CharacterSet) -> Bool {
425425
return _mapUnmanaged { $0.isSuperset(of: other) }
426426
}
427-
}
428427

429-
/// Returns true if the two `CharacterSet`s are equal.
430-
public func ==(lhs : CharacterSet, rhs: CharacterSet) -> Bool {
431-
return lhs._wrapped.isEqual(rhs as NSCharacterSet)
428+
/// Returns true if the two `CharacterSet`s are equal.
429+
public static func ==(lhs : CharacterSet, rhs: CharacterSet) -> Bool {
430+
return lhs._wrapped.isEqual(rhs as NSCharacterSet)
431+
}
432432
}
433433

434434

stdlib/public/SDK/Foundation/Data.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,11 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H
644644

645645
@available(*, unavailable, message: "use withUnsafeMutableBytes instead")
646646
public var mutableBytes: UnsafeMutablePointer<Void> { fatalError() }
647-
}
648647

649-
/// Returns `true` if the two `Data` arguments are equal.
650-
public func ==(d1 : Data, d2 : Data) -> Bool {
651-
return d1._wrapped.isEqual(to: d2)
648+
/// Returns `true` if the two `Data` arguments are equal.
649+
public static func ==(d1 : Data, d2 : Data) -> Bool {
650+
return d1._wrapped.isEqual(to: d2)
651+
}
652652
}
653653

654654
/// Provides bridging functionality for struct Data to class NSData and vice-versa.

stdlib/public/SDK/Foundation/Date.swift

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -186,45 +186,46 @@ public struct Date : ReferenceConvertible, Comparable, Equatable, CustomStringCo
186186
}
187187

188188
public var debugDescription: String { return description }
189-
}
190189

191-
/// Returns true if the two `Date` values represent the same point in time.
192-
public func ==(lhs: Date, rhs: Date) -> Bool {
193-
return lhs.timeIntervalSinceReferenceDate == rhs.timeIntervalSinceReferenceDate
194-
}
190+
/// Returns true if the two `Date` values represent the same point in time.
191+
public static func ==(lhs: Date, rhs: Date) -> Bool {
192+
return lhs.timeIntervalSinceReferenceDate == rhs.timeIntervalSinceReferenceDate
193+
}
195194

196-
/// Returns true if the left hand `Date` is earlier in time than the right hand `Date`.
197-
public func <(lhs: Date, rhs: Date) -> Bool {
198-
return lhs.timeIntervalSinceReferenceDate < rhs.timeIntervalSinceReferenceDate
199-
}
195+
/// Returns true if the left hand `Date` is earlier in time than the right hand `Date`.
196+
public static func <(lhs: Date, rhs: Date) -> Bool {
197+
return lhs.timeIntervalSinceReferenceDate < rhs.timeIntervalSinceReferenceDate
198+
}
200199

201-
/// Returns true if the left hand `Date` is later in time than the right hand `Date`.
202-
public func >(lhs: Date, rhs: Date) -> Bool {
203-
return lhs.timeIntervalSinceReferenceDate > rhs.timeIntervalSinceReferenceDate
204-
}
200+
/// Returns true if the left hand `Date` is later in time than the right hand `Date`.
201+
public static func >(lhs: Date, rhs: Date) -> Bool {
202+
return lhs.timeIntervalSinceReferenceDate > rhs.timeIntervalSinceReferenceDate
203+
}
205204

206-
/// Returns a `Date` with a specified amount of time added to it.
207-
public func +(lhs: Date, rhs: TimeInterval) -> Date {
208-
return Date(timeIntervalSinceReferenceDate: lhs.timeIntervalSinceReferenceDate + rhs)
209-
}
205+
/// Returns a `Date` with a specified amount of time added to it.
206+
public static func +(lhs: Date, rhs: TimeInterval) -> Date {
207+
return Date(timeIntervalSinceReferenceDate: lhs.timeIntervalSinceReferenceDate + rhs)
208+
}
210209

211-
/// Returns a `Date` with a specified amount of time subtracted from it.
212-
public func -(lhs: Date, rhs: TimeInterval) -> Date {
213-
return Date(timeIntervalSinceReferenceDate: lhs.timeIntervalSinceReferenceDate - rhs)
214-
}
210+
/// Returns a `Date` with a specified amount of time subtracted from it.
211+
public static func -(lhs: Date, rhs: TimeInterval) -> Date {
212+
return Date(timeIntervalSinceReferenceDate: lhs.timeIntervalSinceReferenceDate - rhs)
213+
}
215214

216-
/// Add a `TimeInterval` to a `Date`.
217-
///
218-
/// - warning: This only adjusts an absolute value. If you wish to add calendrical concepts like hours, days, months then you must use a `Calendar`. That will take into account complexities like daylight saving time, months with different numbers of days, and more.
219-
public func +=(lhs: inout Date, rhs: TimeInterval) {
220-
lhs = lhs + rhs
221-
}
215+
/// Add a `TimeInterval` to a `Date`.
216+
///
217+
/// - warning: This only adjusts an absolute value. If you wish to add calendrical concepts like hours, days, months then you must use a `Calendar`. That will take into account complexities like daylight saving time, months with different numbers of days, and more.
218+
public static func +=(lhs: inout Date, rhs: TimeInterval) {
219+
lhs = lhs + rhs
220+
}
221+
222+
/// Subtract a `TimeInterval` from a `Date`.
223+
///
224+
/// - warning: This only adjusts an absolute value. If you wish to add calendrical concepts like hours, days, months then you must use a `Calendar`. That will take into account complexities like daylight saving time, months with different numbers of days, and more.
225+
public static func -=(lhs: inout Date, rhs: TimeInterval) {
226+
lhs = lhs - rhs
227+
}
222228

223-
/// Subtract a `TimeInterval` from a `Date`.
224-
///
225-
/// - warning: This only adjusts an absolute value. If you wish to add calendrical concepts like hours, days, months then you must use a `Calendar`. That will take into account complexities like daylight saving time, months with different numbers of days, and more.
226-
public func -=(lhs: inout Date, rhs: TimeInterval) {
227-
lhs = lhs - rhs
228229
}
229230

230231
extension Date : _ObjectiveCBridgeable {

stdlib/public/SDK/Foundation/DateComponents.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,14 @@ public struct DateComponents : ReferenceConvertible, Hashable, Equatable, _Mutab
281281
_handle = _MutableHandle(reference: reference)
282282
}
283283

284-
}
284+
public static func ==(lhs : DateComponents, rhs: DateComponents) -> Bool {
285+
// Don't copy references here; no one should be storing anything
286+
return lhs._handle._uncopiedReference().isEqual(rhs._handle._uncopiedReference())
287+
}
285288

286-
public func ==(lhs : DateComponents, rhs: DateComponents) -> Bool {
287-
// Don't copy references here; no one should be storing anything
288-
return lhs._handle._uncopiedReference().isEqual(rhs._handle._uncopiedReference())
289289
}
290290

291+
291292
// MARK: - Bridging
292293

293294
extension DateComponents : _ObjectiveCBridgeable {

stdlib/public/SDK/Foundation/DateInterval.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,17 @@ public struct DateInterval : ReferenceConvertible, Comparable, Hashable {
168168
public var debugDescription: String {
169169
return description
170170
}
171-
}
172171

173-
@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
174-
public func ==(lhs: DateInterval, rhs: DateInterval) -> Bool {
175-
return lhs.start == rhs.start && lhs.duration == rhs.duration
176-
}
172+
@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
173+
public static func ==(lhs: DateInterval, rhs: DateInterval) -> Bool {
174+
return lhs.start == rhs.start && lhs.duration == rhs.duration
175+
}
176+
177+
@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
178+
public static func <(lhs: DateInterval, rhs: DateInterval) -> Bool {
179+
return lhs.compare(rhs) == .orderedAscending
180+
}
177181

178-
@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
179-
public func <(lhs: DateInterval, rhs: DateInterval) -> Bool {
180-
return lhs.compare(rhs) == .orderedAscending
181182
}
182183

183184
@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)

stdlib/public/SDK/Foundation/Decimal.swift

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -123,38 +123,39 @@ extension Decimal {
123123
public var nextDown: Decimal {
124124
return self - Decimal(_exponent: _exponent, _length: 1, _isNegative: 0, _isCompact: 1, _reserved: 0, _mantissa: (0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000))
125125
}
126-
}
127126

128-
public func +(lhs: Decimal, rhs: Decimal) -> Decimal {
129-
var res = Decimal()
130-
var leftOp = lhs
131-
var rightOp = rhs
132-
NSDecimalAdd(&res, &leftOp, &rightOp, .plain)
133-
return res
134-
}
127+
public static func +(lhs: Decimal, rhs: Decimal) -> Decimal {
128+
var res = Decimal()
129+
var leftOp = lhs
130+
var rightOp = rhs
131+
NSDecimalAdd(&res, &leftOp, &rightOp, .plain)
132+
return res
133+
}
135134

136-
public func -(lhs: Decimal, rhs: Decimal) -> Decimal {
137-
var res = Decimal()
138-
var leftOp = lhs
139-
var rightOp = rhs
140-
NSDecimalSubtract(&res, &leftOp, &rightOp, .plain)
141-
return res
142-
}
135+
public static func -(lhs: Decimal, rhs: Decimal) -> Decimal {
136+
var res = Decimal()
137+
var leftOp = lhs
138+
var rightOp = rhs
139+
NSDecimalSubtract(&res, &leftOp, &rightOp, .plain)
140+
return res
141+
}
143142

144-
public func /(lhs: Decimal, rhs: Decimal) -> Decimal {
145-
var res = Decimal()
146-
var leftOp = lhs
147-
var rightOp = rhs
148-
NSDecimalDivide(&res, &leftOp, &rightOp, .plain)
149-
return res
150-
}
143+
public static func /(lhs: Decimal, rhs: Decimal) -> Decimal {
144+
var res = Decimal()
145+
var leftOp = lhs
146+
var rightOp = rhs
147+
NSDecimalDivide(&res, &leftOp, &rightOp, .plain)
148+
return res
149+
}
150+
151+
public static func *(lhs: Decimal, rhs: Decimal) -> Decimal {
152+
var res = Decimal()
153+
var leftOp = lhs
154+
var rightOp = rhs
155+
NSDecimalMultiply(&res, &leftOp, &rightOp, .plain)
156+
return res
157+
}
151158

152-
public func *(lhs: Decimal, rhs: Decimal) -> Decimal {
153-
var res = Decimal()
154-
var leftOp = lhs
155-
var rightOp = rhs
156-
NSDecimalMultiply(&res, &leftOp, &rightOp, .plain)
157-
return res
158159
}
159160

160161
public func pow(_ x: Decimal, _ y: Int) -> Decimal {
@@ -218,18 +219,18 @@ extension Decimal : Hashable, Comparable {
218219
public var hashValue: Int {
219220
return Int(bitPattern: __CFHashDouble(doubleValue))
220221
}
221-
}
222222

223-
public func ==(lhs: Decimal, rhs: Decimal) -> Bool {
224-
var lhsVal = lhs
225-
var rhsVal = rhs
226-
return NSDecimalCompare(&lhsVal, &rhsVal) == .orderedSame
227-
}
223+
public static func ==(lhs: Decimal, rhs: Decimal) -> Bool {
224+
var lhsVal = lhs
225+
var rhsVal = rhs
226+
return NSDecimalCompare(&lhsVal, &rhsVal) == .orderedSame
227+
}
228228

229-
public func <(lhs: Decimal, rhs: Decimal) -> Bool {
230-
var lhsVal = lhs
231-
var rhsVal = rhs
232-
return NSDecimalCompare(&lhsVal, &rhsVal) == .orderedAscending
229+
public static func <(lhs: Decimal, rhs: Decimal) -> Bool {
230+
var lhsVal = lhs
231+
var rhsVal = rhs
232+
return NSDecimalCompare(&lhsVal, &rhsVal) == .orderedAscending
233+
}
233234
}
234235

235236
extension Decimal : ExpressibleByFloatLiteral {

stdlib/public/SDK/Foundation/IndexPath.swift

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -177,36 +177,35 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
177177
}
178178
}
179179

180-
}
181-
182-
public func ==(lhs: IndexPath, rhs: IndexPath) -> Bool {
183-
return lhs._indexes == rhs._indexes
184-
}
180+
public static func ==(lhs: IndexPath, rhs: IndexPath) -> Bool {
181+
return lhs._indexes == rhs._indexes
182+
}
185183

186-
public func +(lhs: IndexPath, rhs: IndexPath) -> IndexPath {
187-
return lhs.appending(rhs)
188-
}
184+
public static func +(lhs: IndexPath, rhs: IndexPath) -> IndexPath {
185+
return lhs.appending(rhs)
186+
}
189187

190-
public func +=(lhs: inout IndexPath, rhs: IndexPath) {
191-
lhs.append(rhs)
192-
}
188+
public static func +=(lhs: inout IndexPath, rhs: IndexPath) {
189+
lhs.append(rhs)
190+
}
193191

194-
public func <(lhs: IndexPath, rhs: IndexPath) -> Bool {
195-
return lhs.compare(rhs) == ComparisonResult.orderedAscending
196-
}
192+
public static func <(lhs: IndexPath, rhs: IndexPath) -> Bool {
193+
return lhs.compare(rhs) == ComparisonResult.orderedAscending
194+
}
197195

198-
public func <=(lhs: IndexPath, rhs: IndexPath) -> Bool {
199-
let order = lhs.compare(rhs)
200-
return order == ComparisonResult.orderedAscending || order == ComparisonResult.orderedSame
201-
}
196+
public static func <=(lhs: IndexPath, rhs: IndexPath) -> Bool {
197+
let order = lhs.compare(rhs)
198+
return order == ComparisonResult.orderedAscending || order == ComparisonResult.orderedSame
199+
}
202200

203-
public func >(lhs: IndexPath, rhs: IndexPath) -> Bool {
204-
return lhs.compare(rhs) == ComparisonResult.orderedDescending
205-
}
201+
public static func >(lhs: IndexPath, rhs: IndexPath) -> Bool {
202+
return lhs.compare(rhs) == ComparisonResult.orderedDescending
203+
}
206204

207-
public func >=(lhs: IndexPath, rhs: IndexPath) -> Bool {
208-
let order = lhs.compare(rhs)
209-
return order == ComparisonResult.orderedDescending || order == ComparisonResult.orderedSame
205+
public static func >=(lhs: IndexPath, rhs: IndexPath) -> Bool {
206+
let order = lhs.compare(rhs)
207+
return order == ComparisonResult.orderedDescending || order == ComparisonResult.orderedSame
208+
}
210209
}
211210

212211
extension IndexPath : _ObjectiveCBridgeable {

0 commit comments

Comments
 (0)