Skip to content

Commit 19d2953

Browse files
authored
Merge pull request #11232 from moiseev/integers-revised-4
[swift-4.0-branch] Implement SE-0104 changes
2 parents e067279 + ccd4c98 commit 19d2953

29 files changed

+316
-439
lines changed

stdlib/private/StdlibUnicodeUnittest/Collation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,13 @@ public struct StringComparisonTest {
338338

339339
public func sortKey(forCollationElements ces: [UInt64]) -> ([UInt16], [UInt16], [UInt16]) {
340340
func L1(_ ce: UInt64) -> UInt16 {
341-
return UInt16(extendingOrTruncating: ce &>> 32)
341+
return UInt16(truncatingIfNeeded: ce &>> 32)
342342
}
343343
func L2(_ ce: UInt64) -> UInt16 {
344-
return UInt16(extendingOrTruncating: ce &>> 16)
344+
return UInt16(truncatingIfNeeded: ce &>> 16)
345345
}
346346
func L3(_ ce: UInt64) -> UInt16 {
347-
return UInt16(extendingOrTruncating: ce)
347+
return UInt16(truncatingIfNeeded: ce)
348348
}
349349

350350
var result1: [UInt16] = []

stdlib/public/core/ASCII.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension Unicode.ASCII : Unicode.Encoding {
4141
_ source: Unicode.Scalar
4242
) -> EncodedScalar? {
4343
guard source.value < (1&<<7) else { return nil }
44-
return EncodedScalar(UInt8(extendingOrTruncating: source.value))
44+
return EncodedScalar(UInt8(truncatingIfNeeded: source.value))
4545
}
4646

4747
@inline(__always)
@@ -80,7 +80,7 @@ extension Unicode.ASCII.Parser : Unicode.Parser {
8080
where I.Element == Encoding.CodeUnit {
8181
let n = input.next()
8282
if _fastPath(n != nil), let x = n {
83-
guard _fastPath(Int8(extendingOrTruncating: x) >= 0)
83+
guard _fastPath(Int8(truncatingIfNeeded: x) >= 0)
8484
else { return .error(length: 1) }
8585
return .valid(Unicode.ASCII.EncodedScalar(x))
8686
}

stdlib/public/core/ArrayBody.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal struct _ArrayBody {
3232
_storage = _SwiftArrayBodyStorage(
3333
count: count,
3434
_capacityAndFlags:
35-
(UInt(extendingOrTruncating: capacity) &<< 1) |
35+
(UInt(truncatingIfNeeded: capacity) &<< 1) |
3636
(elementTypeIsBridgedVerbatim ? 1 : 0))
3737
}
3838

stdlib/public/core/Builtin.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ func _canBeClass<T>(_: T.Type) -> Int8 {
9090
/// - Value conversion from one integer type to another. Use the destination
9191
/// type's initializer or the `numericCast(_:)` function.
9292
/// - Bitwise conversion from one integer type to another. Use the destination
93-
/// type's `init(extendingOrTruncating:)` or `init(bitPattern:)`
94-
/// initializer.
93+
/// type's `init(truncatingIfNeeded:)` or `init(bitPattern:)` initializer.
9594
/// - Conversion from a pointer to an integer value with the bit pattern of the
9695
/// pointer's address in memory, or vice versa. Use the `init(bitPattern:)`
9796
/// initializer for the destination type.

stdlib/public/core/Character.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public struct Character :
130130
shift += 16
131131
}
132132
}
133-
guard _fastPath(Int64(extendingOrTruncating: bits) >= 0) else {
133+
guard _fastPath(Int64(truncatingIfNeeded: bits) >= 0) else {
134134
break FastPath
135135
}
136136
_representation = .smallUTF16(Builtin.trunc_Int64_Int63(bits._value))
@@ -224,7 +224,7 @@ public struct Character :
224224

225225
if _fastPath(s._core.count <= 4) {
226226
let b = _UIntBuffer<UInt64, Unicode.UTF16.CodeUnit>(s._core)
227-
if _fastPath(Int64(extendingOrTruncating: b._storage) >= 0) {
227+
if _fastPath(Int64(truncatingIfNeeded: b._storage) >= 0) {
228228
_representation = .smallUTF16(
229229
Builtin.trunc_Int64_Int63(b._storage._value))
230230
return

stdlib/public/core/CharacterUnicodeScalars.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ extension Character.UnicodeScalarView : Collection {
101101
case .valid(let s):
102102
return Index(
103103
_encodedOffset: startOfNextScalar, _scalar: s,
104-
_stride: UInt8(extendingOrTruncating: s.count))
104+
_stride: UInt8(truncatingIfNeeded: s.count))
105105
case .error:
106106
return Index(
107107
_encodedOffset: startOfNextScalar,
@@ -138,7 +138,7 @@ extension Character.UnicodeScalarView : BidirectionalCollection {
138138
case .valid(let s):
139139
return Index(
140140
_encodedOffset: i._encodedOffset - s.count, _scalar: s,
141-
_stride: UInt8(extendingOrTruncating: s.count))
141+
_stride: UInt8(truncatingIfNeeded: s.count))
142142
case .error:
143143
return Index(
144144
_encodedOffset: i._encodedOffset - 1,

stdlib/public/core/FloatingPointTypes.swift.gyb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,11 +754,11 @@ extension ${Self} : Hashable {
754754
%if bits <= word_bits:
755755
return Int(bitPattern: UInt(bitPattern))
756756
%elif bits == 64: # Double -> 32-bit Int
757-
return Int(extendingOrTruncating: bitPattern &>> 32) ^
758-
Int(extendingOrTruncating: bitPattern)
757+
return Int(truncatingIfNeeded: bitPattern &>> 32) ^
758+
Int(truncatingIfNeeded: bitPattern)
759759
%elif word_bits == 32: # Float80 -> 32-bit Int
760-
return Int(extendingOrTruncating: significandBitPattern &>> 32) ^
761-
Int(extendingOrTruncating: significandBitPattern) ^
760+
return Int(truncatingIfNeeded: significandBitPattern &>> 32) ^
761+
Int(truncatingIfNeeded: significandBitPattern) ^
762762
Int(_representation.signAndExponent)
763763
%else: # Float80 -> 64-bit Int
764764
return Int(bitPattern: UInt(significandBitPattern)) ^

stdlib/public/core/IntegerParsing.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ internal func _asciiDigit<CodeUnit : UnsignedInteger, Result : BinaryInteger>(
1818
let lower = _ascii16("a")..._ascii16("z")
1919
let upper = _ascii16("A")..._ascii16("Z")
2020

21-
let u = UInt16(extendingOrTruncating: u_)
21+
let u = UInt16(truncatingIfNeeded: u_)
2222
let d: UInt16
2323
if _fastPath(digit ~= u) { d = u &- digit.lowerBound }
2424
else if _fastPath(upper ~= u) { d = u &- upper.lowerBound &+ 10 }
2525
else if _fastPath(lower ~= u) { d = u &- lower.lowerBound &+ 10 }
2626
else { return nil }
2727
guard _fastPath(d < radix) else { return nil }
28-
return Result(extendingOrTruncating: d)
28+
return Result(truncatingIfNeeded: d)
2929
}
3030

3131
@inline(__always)
@@ -40,7 +40,7 @@ where Rest.Element : UnsignedInteger {
4040
if !positive {
4141
let (result0, overflow0)
4242
= (0 as Result).subtractingReportingOverflow(result)
43-
guard _fastPath(overflow0 == .none) else { return nil }
43+
guard _fastPath(!overflow0) else { return nil }
4444
result = result0
4545
}
4646

@@ -51,7 +51,7 @@ where Rest.Element : UnsignedInteger {
5151
let (result2, overflow2) = positive
5252
? result1.addingReportingOverflow(d)
5353
: result1.subtractingReportingOverflow(d)
54-
guard _fastPath(overflow1 == .none && overflow2 == .none)
54+
guard _fastPath(!overflow1 && !overflow2)
5555
else { return nil }
5656
result = result2
5757
}

0 commit comments

Comments
 (0)