@@ -819,8 +819,8 @@ def overflowOperationComment(operator):
819
819
/// - Parameter rhs: The value to add to this value.
820
820
/// - Returns: A tuple containing the result of the addition along with a
821
821
/// flag indicating whether overflow occurred. If the `overflow` component
822
- /// is `.none `, the `partialValue` component contains the entire sum. If
823
- /// the `overflow` component is `.overflow `, an overflow occurred and the
822
+ /// is `false `, the `partialValue` component contains the entire sum. If
823
+ /// the `overflow` component is `true `, an overflow occurred and the
824
824
/// `partialValue` component contains the truncated sum of this value and
825
825
/// `rhs`.
826
826
""" ,
@@ -831,8 +831,8 @@ def overflowOperationComment(operator):
831
831
/// - Parameter rhs: The value to subtract from this value.
832
832
/// - Returns: A tuple containing the result of the subtraction along with a
833
833
/// flag indicating whether overflow occurred. If the `overflow` component
834
- /// is `.none `, the `partialValue` component contains the entire
835
- /// difference. If the `overflow` component is `.overflow `, an overflow
834
+ /// is `false `, the `partialValue` component contains the entire
835
+ /// difference. If the `overflow` component is `true `, an overflow
836
836
/// occurred and the `partialValue` component contains the truncated
837
837
/// result of `rhs` subtracted from this value.
838
838
""" ,
@@ -843,8 +843,8 @@ def overflowOperationComment(operator):
843
843
/// - Parameter rhs: The value to multiply by this value.
844
844
/// - Returns: A tuple containing the result of the multiplication along with
845
845
/// a flag indicating whether overflow occurred. If the `overflow`
846
- /// component is `.none `, the `partialValue` component contains the entire
847
- /// product. If the `overflow` component is `.overflow `, an overflow
846
+ /// component is `false `, the `partialValue` component contains the entire
847
+ /// product. If the `overflow` component is `true `, an overflow
848
848
/// occurred and the `partialValue` component contains the truncated
849
849
/// product of this value and `rhs`.
850
850
""" ,
@@ -853,13 +853,13 @@ def overflowOperationComment(operator):
853
853
/// a flag indicating whether overflow occurred in the operation.
854
854
///
855
855
/// Dividing by zero is not an error when using this method. For a value `x`,
856
- /// the result of `x.dividedReportingOverflow(by: 0)` is `(x, .overflow )`.
856
+ /// the result of `x.dividedReportingOverflow(by: 0)` is `(x, true )`.
857
857
///
858
858
/// - Parameter rhs: The value to divide this value by.
859
859
/// - Returns: A tuple containing the result of the division along with a
860
860
/// flag indicating whether overflow occurred. If the `overflow` component
861
- /// is `.none `, the `partialValue` component contains the entire quotient.
862
- /// If the `overflow` component is `.overflow `, an overflow occurred and
861
+ /// is `false `, the `partialValue` component contains the entire quotient.
862
+ /// If the `overflow` component is `true `, an overflow occurred and
863
863
/// the `partialValue` component contains the truncated quotient.
864
864
""" ,
865
865
'% ': """ \
@@ -868,13 +868,13 @@ def overflowOperationComment(operator):
868
868
/// a flag indicating whether overflow occurred in the operation.
869
869
///
870
870
/// Dividing by zero is not an error when using this method. For a value `x`,
871
- /// the result of `x.dividedReportingOverflow(by: 0)` is `(x, .overflow )`.
871
+ /// the result of `x.dividedReportingOverflow(by: 0)` is `(x, true )`.
872
872
///
873
873
/// - Parameter rhs: The value to divide this value by.
874
874
/// - Returns: A tuple containing the result of the division along with a
875
875
/// flag indicating whether overflow occurred. If the `overflow` component
876
- /// is `.none `, the `partialValue` component contains the entire quotient.
877
- /// If the `overflow` component is `.overflow `, an overflow occurred and
876
+ /// is `false `, the `partialValue` component contains the entire quotient.
877
+ /// If the `overflow` component is `true `, an overflow occurred and
878
878
/// the `partialValue` component contains the truncated quotient.
879
879
""" ,
880
880
}
@@ -1844,28 +1844,6 @@ extension BinaryInteger {
1844
1844
//===--- FixedWidthInteger ------------------------------------------------===//
1845
1845
//===----------------------------------------------------------------------===//
1846
1846
1847
- /// An indicator of whether an arithmetic operation overflowed.
1848
- ///
1849
- /// Some arithmetic operations on fixed-width integers return an
1850
- /// `ArithmeticOverflow` instance to indicate whether an overflow has
1851
- /// occurred. For example, adding `UInt8.max` to itself results in a value that
1852
- /// can't be represented by an `UInt8` instance without overflowing.
1853
- ///
1854
- /// let x = UInt8.max
1855
- /// // x == 255
1856
- /// let (y, overflow) = x.addingReportingOverflow(x)
1857
- /// // y == 254
1858
- /// // overflow == ArithmeticOverflow.overflow
1859
- @_fixed_layout
1860
- public enum ArithmeticOverflow {
1861
- @_transparent
1862
- public init ( _ overflow: Bool ) { self = overflow ? . overflow : . none }
1863
- /// An indication that no overflow occurred in the operation.
1864
- case none
1865
- /// An indication that an overflow did occur in the operation.
1866
- case overflow
1867
- }
1868
-
1869
1847
/// An integer type that uses a fixed size for every instance.
1870
1848
///
1871
1849
/// The `FixedWidthInteger` protocol adds binary bitwise operations, bit
@@ -1909,7 +1887,7 @@ public enum ArithmeticOverflow {
1909
1887
///
1910
1888
/// func squared<T: FixedWidthInteger>(_ x: T) -> T? {
1911
1889
/// let (result, overflow) = x.multipliedReportingOverflow(by: x)
1912
- /// guard overflow == .none else {
1890
+ /// if overflow {
1913
1891
/// return nil
1914
1892
/// }
1915
1893
/// return result
@@ -1960,7 +1938,7 @@ public protocol FixedWidthInteger : BinaryInteger, _BitwiseOperations {
1960
1938
${ overflowOperationComment ( x. operator) }
1961
1939
func ${ x. name} ReportingOverflow(
1962
1940
${ x. firstArg} rhs: Self
1963
- ) -> ( partialValue: Self, overflow: ArithmeticOverflow )
1941
+ ) -> ( partialValue: Self, overflow: Bool )
1964
1942
% end
1965
1943
1966
1944
/// Returns a tuple containing the high and low parts of the result of
@@ -2251,7 +2229,7 @@ ${assignmentOperatorComment(x.operator, True)}
2251
2229
@_transparent
2252
2230
public static func ${ x. operator} = ( _ lhs: inout Self, _ rhs: Self) {
2253
2231
let ( result, overflow) = lhs . ${ x. name} ReportingOverflow( ${ callLabel} rhs)
2254
- _precondition ( overflow == . none , " Overflow in ${x.operator}= " )
2232
+ _precondition ( ! overflow, " Overflow in ${x.operator}= " )
2255
2233
lhs = result
2256
2234
}
2257
2235
#endif
@@ -2262,7 +2240,7 @@ ${unsafeOperationComment(x.operator)}
2262
2240
public func unsafe${ capitalize ( x. name) } ( ${ x. firstArg} other: Self) - > Self {
2263
2241
let ( result, overflow) = self . ${ x. name} ReportingOverflow( ${ callLabel} other)
2264
2242
2265
- if ( overflow != . none ) {
2243
+ if overflow {
2266
2244
if ( _isDebugAssertConfiguration ( ) ) {
2267
2245
_preconditionFailure ( " overflow in unsafe${capitalize(x.name)} " )
2268
2246
}
@@ -2646,7 +2624,7 @@ public struct ${Self}
2646
2624
@_transparent
2647
2625
public func ${ x. name} ReportingOverflow(
2648
2626
${ x. firstArg} other: ${ Self}
2649
- ) - > ( partialValue: ${ Self} , overflow: ArithmeticOverflow ) {
2627
+ ) - > ( partialValue: ${ Self} , overflow: Bool ) {
2650
2628
2651
2629
% if x. kind == '/ ':
2652
2630
// No LLVM primitives for checking overflow of division
@@ -2655,7 +2633,7 @@ public struct ${Self}
2655
2633
other == ( 0 as ${ Self} )
2656
2634
${ '|| self == % s. min && other == ( - 1 as % s) ' % ( Self, Self) if signed else ''}
2657
2635
) {
2658
- return ( partialValue: self , overflow: . overflow )
2636
+ return ( partialValue: self , overflow: true )
2659
2637
}
2660
2638
2661
2639
let ( newStorage, overflow) = (
@@ -2671,7 +2649,7 @@ public struct ${Self}
2671
2649
2672
2650
return (
2673
2651
partialValue: ${ Self} ( newStorage) ,
2674
- overflow: ArithmeticOverflow ( Bool ( overflow) ) )
2652
+ overflow: Bool ( overflow) )
2675
2653
}
2676
2654
% end
2677
2655
@@ -3218,7 +3196,7 @@ extension FixedWidthInteger {
3218
3196
) - > ( Self, overflow: Bool) {
3219
3197
let ( partialValue, overflow) =
3220
3198
lhs . ${ newPrefix} ReportingOverflow( ${ argLabel} rhs)
3221
- return ( partialValue, overflow == . overflow)
3199
+ return ( partialValue, overflow: overflow)
3222
3200
}
3223
3201
3224
3202
% end
0 commit comments