Skip to content

[swift-4.0-branch] Implement SE-0104 changes #11232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stdlib/private/StdlibUnicodeUnittest/Collation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,13 @@ public struct StringComparisonTest {

public func sortKey(forCollationElements ces: [UInt64]) -> ([UInt16], [UInt16], [UInt16]) {
func L1(_ ce: UInt64) -> UInt16 {
return UInt16(extendingOrTruncating: ce &>> 32)
return UInt16(truncatingIfNeeded: ce &>> 32)
}
func L2(_ ce: UInt64) -> UInt16 {
return UInt16(extendingOrTruncating: ce &>> 16)
return UInt16(truncatingIfNeeded: ce &>> 16)
}
func L3(_ ce: UInt64) -> UInt16 {
return UInt16(extendingOrTruncating: ce)
return UInt16(truncatingIfNeeded: ce)
}

var result1: [UInt16] = []
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/ASCII.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extension Unicode.ASCII : Unicode.Encoding {
_ source: Unicode.Scalar
) -> EncodedScalar? {
guard source.value < (1&<<7) else { return nil }
return EncodedScalar(UInt8(extendingOrTruncating: source.value))
return EncodedScalar(UInt8(truncatingIfNeeded: source.value))
}

@inline(__always)
Expand Down Expand Up @@ -80,7 +80,7 @@ extension Unicode.ASCII.Parser : Unicode.Parser {
where I.Element == Encoding.CodeUnit {
let n = input.next()
if _fastPath(n != nil), let x = n {
guard _fastPath(Int8(extendingOrTruncating: x) >= 0)
guard _fastPath(Int8(truncatingIfNeeded: x) >= 0)
else { return .error(length: 1) }
return .valid(Unicode.ASCII.EncodedScalar(x))
}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/ArrayBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal struct _ArrayBody {
_storage = _SwiftArrayBodyStorage(
count: count,
_capacityAndFlags:
(UInt(extendingOrTruncating: capacity) &<< 1) |
(UInt(truncatingIfNeeded: capacity) &<< 1) |
(elementTypeIsBridgedVerbatim ? 1 : 0))
}

Expand Down
3 changes: 1 addition & 2 deletions stdlib/public/core/Builtin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ func _canBeClass<T>(_: T.Type) -> Int8 {
/// - Value conversion from one integer type to another. Use the destination
/// type's initializer or the `numericCast(_:)` function.
/// - Bitwise conversion from one integer type to another. Use the destination
/// type's `init(extendingOrTruncating:)` or `init(bitPattern:)`
/// initializer.
/// type's `init(truncatingIfNeeded:)` or `init(bitPattern:)` initializer.
/// - Conversion from a pointer to an integer value with the bit pattern of the
/// pointer's address in memory, or vice versa. Use the `init(bitPattern:)`
/// initializer for the destination type.
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/Character.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public struct Character :
shift += 16
}
}
guard _fastPath(Int64(extendingOrTruncating: bits) >= 0) else {
guard _fastPath(Int64(truncatingIfNeeded: bits) >= 0) else {
break FastPath
}
_representation = .smallUTF16(Builtin.trunc_Int64_Int63(bits._value))
Expand Down Expand Up @@ -224,7 +224,7 @@ public struct Character :

if _fastPath(s._core.count <= 4) {
let b = _UIntBuffer<UInt64, Unicode.UTF16.CodeUnit>(s._core)
if _fastPath(Int64(extendingOrTruncating: b._storage) >= 0) {
if _fastPath(Int64(truncatingIfNeeded: b._storage) >= 0) {
_representation = .smallUTF16(
Builtin.trunc_Int64_Int63(b._storage._value))
return
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/CharacterUnicodeScalars.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ extension Character.UnicodeScalarView : Collection {
case .valid(let s):
return Index(
_encodedOffset: startOfNextScalar, _scalar: s,
_stride: UInt8(extendingOrTruncating: s.count))
_stride: UInt8(truncatingIfNeeded: s.count))
case .error:
return Index(
_encodedOffset: startOfNextScalar,
Expand Down Expand Up @@ -138,7 +138,7 @@ extension Character.UnicodeScalarView : BidirectionalCollection {
case .valid(let s):
return Index(
_encodedOffset: i._encodedOffset - s.count, _scalar: s,
_stride: UInt8(extendingOrTruncating: s.count))
_stride: UInt8(truncatingIfNeeded: s.count))
case .error:
return Index(
_encodedOffset: i._encodedOffset - 1,
Expand Down
8 changes: 4 additions & 4 deletions stdlib/public/core/FloatingPointTypes.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -754,11 +754,11 @@ extension ${Self} : Hashable {
%if bits <= word_bits:
return Int(bitPattern: UInt(bitPattern))
%elif bits == 64: # Double -> 32-bit Int
return Int(extendingOrTruncating: bitPattern &>> 32) ^
Int(extendingOrTruncating: bitPattern)
return Int(truncatingIfNeeded: bitPattern &>> 32) ^
Int(truncatingIfNeeded: bitPattern)
%elif word_bits == 32: # Float80 -> 32-bit Int
return Int(extendingOrTruncating: significandBitPattern &>> 32) ^
Int(extendingOrTruncating: significandBitPattern) ^
return Int(truncatingIfNeeded: significandBitPattern &>> 32) ^
Int(truncatingIfNeeded: significandBitPattern) ^
Int(_representation.signAndExponent)
%else: # Float80 -> 64-bit Int
return Int(bitPattern: UInt(significandBitPattern)) ^
Expand Down
8 changes: 4 additions & 4 deletions stdlib/public/core/IntegerParsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ internal func _asciiDigit<CodeUnit : UnsignedInteger, Result : BinaryInteger>(
let lower = _ascii16("a")..._ascii16("z")
let upper = _ascii16("A")..._ascii16("Z")

let u = UInt16(extendingOrTruncating: u_)
let u = UInt16(truncatingIfNeeded: u_)
let d: UInt16
if _fastPath(digit ~= u) { d = u &- digit.lowerBound }
else if _fastPath(upper ~= u) { d = u &- upper.lowerBound &+ 10 }
else if _fastPath(lower ~= u) { d = u &- lower.lowerBound &+ 10 }
else { return nil }
guard _fastPath(d < radix) else { return nil }
return Result(extendingOrTruncating: d)
return Result(truncatingIfNeeded: d)
}

@inline(__always)
Expand All @@ -40,7 +40,7 @@ where Rest.Element : UnsignedInteger {
if !positive {
let (result0, overflow0)
= (0 as Result).subtractingReportingOverflow(result)
guard _fastPath(overflow0 == .none) else { return nil }
guard _fastPath(!overflow0) else { return nil }
result = result0
}

Expand All @@ -51,7 +51,7 @@ where Rest.Element : UnsignedInteger {
let (result2, overflow2) = positive
? result1.addingReportingOverflow(d)
: result1.subtractingReportingOverflow(d)
guard _fastPath(overflow1 == .none && overflow2 == .none)
guard _fastPath(!overflow1 && !overflow2)
else { return nil }
result = result2
}
Expand Down
Loading