Skip to content

New integer protocols #3796

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 262 commits into from
Apr 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
262 commits
Select commit Hold shift + click to select a range
ac7201d
no IntMax in IntegerParsing
Jul 27, 2016
1dd6c2d
Addressing some of the FIXMEs
Jul 27, 2016
0195fb1
adding a proper arguemnt label to 'unsafe' methods
Jul 28, 2016
4cc7c00
replacing Int32()._value with let zero: Int32 = 0
Jul 28, 2016
2df96d0
removing commented out default implementation
Jul 28, 2016
655bfe2
FIXMEs to change FixedWidthInteger to BinaryInteger in generic code
Jul 28, 2016
8341f6c
removing explicit typecasts
Jul 28, 2016
1f07b84
FIXME for the unsafe functions
Jul 28, 2016
148282d
a better fixme message on == (Int, Int). removing < (Int, Int)
Jul 28, 2016
d42743f
removing IntegerArithmetic.swift
Jul 28, 2016
3517b62
implementing popcount
Jul 28, 2016
bf1467c
removing unnecessary fatalError calls
Jul 28, 2016
522ad4e
a bunch of unavailable declarations
Jul 28, 2016
1cb48c4
fixing the benchmarks
Jul 28, 2016
969bbfb
Turning operators into static funcs
Jul 29, 2016
f01bc2d
Simplifying too complex expressions in benchmarks with type casts
Jul 29, 2016
2540b6d
getting rid of toIntMax in StdlibCollectionUnittest
Jul 29, 2016
f06a9a1
Merge 'origin/master' into new-integer-protocols
Jul 30, 2016
59adfe9
[stdlib] Correct renamed protocol @available decls
Jul 30, 2016
0d1477a
[emacs support] properly parse some test failures
Jul 30, 2016
ccf555c
[stdlib] Improve unavailable diagnostics
Jul 30, 2016
d4030a9
[stdlib] Fix constraint tests for new integers
Jul 30, 2016
60160cf
[stdlib] New integers simplify generic code!
Jul 30, 2016
4af655e
Provisionally adjust DebugInfo test
Jul 30, 2016
d6dec00
[Integer protocols] Make .negate() the customization point (#4413)
natecook1000 Aug 19, 2016
ea8e0f0
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Sep 21, 2016
06dfb51
[integers] making stdlib compile after merging master
Sep 21, 2016
f6a7343
[integers] adding labels to the quotientAndRemainder return tuple
Sep 21, 2016
84f3ccd
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Sep 22, 2016
6803cda
Merge branch 'master' into new-integer-protocols
Sep 26, 2016
09c3e80
turning the memcpy and memmove alignment arguments into compile time …
Sep 26, 2016
61ba07f
Merge branch 'master' into new-integer-protocols
Sep 27, 2016
3a43d8c
Adding a (bad) implementation of init(_ source: FloatingPoint) to fix…
Sep 27, 2016
e0b8532
introducing concrete initializers from all floating point types
Sep 29, 2016
17b3e38
Merge branch 'master' into new-integer-protocols
Sep 30, 2016
68a307e
[stdlib] Revise documentation for integer types & protocols (#5083)
natecook1000 Oct 5, 2016
530e97e
Merge branch 'new-integer-protocols' of github.com:apple/swift into n…
Oct 5, 2016
08cf1de
[WIP] fixing some of the integer related test failures
Oct 5, 2016
99837a4
Merge branch 'master' into new-integer-protocols
Oct 5, 2016
5cc2c8c
Operators as static funcs for Arithmetic (see SE-0091)
Oct 10, 2016
9428c82
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Oct 10, 2016
9cba734
Moving unavailable operators out of concrete types
Oct 11, 2016
4902db2
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Oct 11, 2016
c91dce7
Adding specific versions of arithmetics operators for CGFloat to spee…
Oct 11, 2016
9a0f3ba
Revert "Adding specific versions of arithmetics operators for CGFloat…
Oct 12, 2016
2190819
Breaking up complex expression to improve compilation time
Oct 12, 2016
079ead9
Cleaning up the gyb
Oct 12, 2016
fe3c737
Removing FIXMEs
Oct 17, 2016
8d1155c
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Oct 17, 2016
b2fecd2
Merge branch 'master' into new-integer-protocols
Oct 18, 2016
543fd10
Comparable operators to static funcs
Oct 19, 2016
a9af3d6
Choosing the right overloads for comparison operators
Oct 19, 2016
e3a2e5b
Minor fixes and improvements
Oct 19, 2016
196ea95
Avoiding the force unwrap in UnsafePointer.count
Oct 19, 2016
47ba2e9
Turning more operators into static funcs
Oct 20, 2016
3dcdd1a
Get rid of _DisallowMixedSignArithmetic
Oct 20, 2016
8912dc0
Merge branch 'master' into new-integer-protocols
Oct 20, 2016
01ec747
Adding back accidentally deleted UnsignedInteger protocol
Oct 20, 2016
8e109de
Using Strideable APIs instead of + and -
Oct 20, 2016
62044de
Different Strideable conformances for Swift 3 and Swift 4
Oct 20, 2016
c63086d
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Oct 21, 2016
d1cc46d
Fixing Dispatch tests
Oct 24, 2016
d285158
Operators from free functions to static methods
Oct 24, 2016
bf7f17e
Obsoleted concrete type overloads for integer arithemtic operators
Oct 24, 2016
6935316
Merge branch 'master' into new-integer-protocols
Oct 24, 2016
ce5d7e8
Adding a few missing operators
Oct 26, 2016
7fa5aa5
Commenting out the arithmetic operators on concrete types
Oct 27, 2016
c5a36a3
Adding a temporary workaround for a missing optimizer feature
Oct 28, 2016
c9119fc
Commenting out some checks pending optimizer work
Oct 28, 2016
3d4f000
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Oct 28, 2016
76e0a99
Merge branch 'master' into new-integer-protocols
Oct 31, 2016
205389a
Marking workarounds for <rdar://problem/29029561>
Oct 31, 2016
d1a1570
Addressing compiler warning for unsigned integers
Oct 31, 2016
51a3e22
Marking init(truncatingBitPattern:) as obsoleted in Swift 4
Oct 31, 2016
fd42e03
Marking IntMax and UIntMax as obsoleted
Oct 31, 2016
2a576b9
numericCast is wort keeping
Oct 31, 2016
9cd1d27
Turning SignedArithmetic.negated() into a static prefix func -
Oct 31, 2016
e51af7e
Merge branch 'master' into new-integer-protocols
Nov 1, 2016
79f1ff3
Removing workarounds for <rdar://problem/29029561>
Nov 1, 2016
11132bd
SeeAlso updated for the negate() function
Nov 1, 2016
8fdb6f0
Uncommenting arithmetic operators in the FloatingPoint protocol
Nov 1, 2016
35dbab7
Proper availability attribute for toIntMax() method
Nov 1, 2016
874930b
Implementing doubleWidthDivide
Nov 1, 2016
8789e62
Speeding up Strideable conformance for integers
Nov 2, 2016
f832c0c
Changing preconditions in integer inits for better performance
Nov 2, 2016
e03f3d3
Adding a fixme to possibly remove minimumSignedRepresentationBitWidth
Nov 2, 2016
252106f
Revert "Speeding up Strideable conformance for integers"
Nov 2, 2016
31c2aac
Specialized implementation of Strideable conformance for Int
Nov 2, 2016
06d191c
[SILOptimizer] add support for always false comparisons to ArrayBound…
Nov 2, 2016
92813be
Merge branch 'master' into new-integer-protocols
Nov 12, 2016
f34808b
using masking shifts
Nov 14, 2016
9d742bb
Merge branch 'master' into new-integer-protocols
Nov 14, 2016
8fea72d
Using more masking shifts
Nov 14, 2016
60751f6
Hiding the shift operators of type (Self, Int) -> Self
Nov 14, 2016
ffc8a37
Strideable for _Pointer is not necessary in Swift 4
Nov 16, 2016
6104f86
Simplifying masking shift implementation on concrete integers
Nov 16, 2016
ffeeaca
Using faster initializer for integers where appropriate
Nov 16, 2016
953d919
Merge branch 'master' into new-integer-protocols
Nov 16, 2016
4f39608
Speeding up the RC4 benchmark by using right initializers for ints
Nov 16, 2016
645210e
Revert "Speeding up the RC4 benchmark by using right initializers for…
Nov 17, 2016
716a378
Merge branch 'master' into new-integer-protocols
Nov 17, 2016
3faa9aa
optimizing preconditions
Nov 18, 2016
9798190
Merge branch 'master' into new-integer-protocols
Nov 18, 2016
deead1f
Faster comparisons with integer literals
Nov 19, 2016
28b0da2
Avoiding recursive calls to init(extendingOrTruncating:) and speeding…
Nov 19, 2016
c0d624f
Minor improvements
Nov 19, 2016
164232d
adding type hints in signum implementation
Nov 28, 2016
70b2343
Merge branch 'master' into new-integer-protocols
Nov 28, 2016
3aba0f7
Removing unary + for floating point types and changing the unary - to…
Nov 28, 2016
2b50c6f
Fixing the benchmark crash
Nov 29, 2016
d2d814e
Changing == and < on UnsafeRawPointer to static funcs
Nov 30, 2016
3b4c804
Fixing the benchmarks now that the + is not defined for Strideable
Nov 30, 2016
3059b3c
Merge branch 'master' into new-integer-protocols
Nov 30, 2016
7afd9bb
Making StdlibUnittest compile in absense of + on Strideable
Dec 2, 2016
fa8adad
Not using arithmetic operators on strideables in test
Dec 2, 2016
baf392e
Deprecating the BitwiseOperations protocol in favor of FixedWidthInteger
Dec 3, 2016
d8e35f2
Adding trailingZeros property to BinaryInteger protocol
Dec 6, 2016
356c15c
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Dec 6, 2016
b9c910a
Deprecation message to FixedWidthInteger.allZeros
Dec 6, 2016
ae89d38
Consistent implementation of mutating vs non-mutating operators on Fi…
Dec 6, 2016
edc08ac
Adding prefix ~ protocol requirement to FixedWidthInteger
Dec 6, 2016
01ba85d
Type hints for operators
Dec 6, 2016
485e7c0
More type hints and inlining to speed up integer convertions
Dec 8, 2016
9b2f885
Merge branch 'master' into new-integer-protocols
Dec 8, 2016
4831aac
Speeding up conversion between integer types
Dec 8, 2016
72fe1e4
Speeding up .description for built-in integers
Dec 8, 2016
5fb929c
Merge branch 'master' into new-integer-protocols
Dec 9, 2016
74253ea
Speeding up the heterogeneous == and < by using more opimizable checks
Dec 12, 2016
c655d8a
Cleaning up the smart shifts
Dec 12, 2016
b42c514
Commenting an overload that leads to compiler error
Dec 13, 2016
0b271e8
Removing overloads of == on concrete types in favor of a generic one …
Dec 13, 2016
bfbab79
Merge branch 'master' into new-integer-protocols
Dec 13, 2016
7a8a840
Fixing a typo
Dec 14, 2016
26111e8
Speeding up the generic smart shift
Dec 14, 2016
701740a
Revert "Speeding up the generic smart shift"
Dec 14, 2016
265060d
Adding integer unit tests from the original prototype
Dec 15, 2016
9a8cdbc
Merge branch 'master' into new-integer-protocols
Dec 15, 2016
94564eb
Adding some doubleWidthMultiply and bouldWidthDivide tests
Dec 15, 2016
61b923f
Using init(extendingOrTruncating:) instead of a deprecated init(trunc…
Dec 15, 2016
d7e92a5
Using masking shifts
Dec 15, 2016
9518082
Removing dead and commented code
Dec 15, 2016
d318ec5
Type hints in comparisons
Dec 16, 2016
ea8f220
Overflow checks in division/modulo operators + tests
Dec 16, 2016
3b7dd4a
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Dec 16, 2016
3276aa5
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Dec 19, 2016
059f7a5
doubleWidth operations on Int64 need special implementation for 32bit…
Dec 19, 2016
4c1cc0f
Moving bitwise operations and shifts to BinaryInteger protocol
Dec 19, 2016
4675e12
Implementing non-mutating shifts using mutating ones (for consistency)
Dec 19, 2016
51128d3
Adding smart shift default implementations to BinaryInteger via an ex…
Dec 20, 2016
138d9df
Getting rid of no longer needed minimumSignedRepresentationBitWidth
Dec 20, 2016
d9013a4
Adding endianness related inits and properties to FixedWidthInteger
Dec 20, 2016
36ad3b4
Introducing abs<T : SignedArithmetic & Comparable>
Jan 5, 2017
156b171
Adding DoubleWidth<>
Jan 5, 2017
e91536b
Correcting doubleWidthDivide precondition
Jan 6, 2017
9968995
Adding init(bitPattern: FLOATING_POINT) to Int32 and Int64
Jan 6, 2017
d356e14
Using trailingZeros and leadingZeros provided by integers in floating…
Jan 6, 2017
27889c6
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Jan 6, 2017
6a06b66
Fixing some and XFAILing other failing tests
Jan 7, 2017
d71c73b
Fixing stdlib tests
Jan 7, 2017
e1de9fc
More test fixes
Jan 9, 2017
7ecd605
Disabling some SILGen tests, that started to fail due to new integers
Jan 10, 2017
aecccc7
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Jan 10, 2017
a872ada
Fixing and XFAILing tests
Jan 10, 2017
ed50ac9
Fixing couple more tests
Jan 11, 2017
fa7368a
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Jan 11, 2017
e1a8e28
Making non-masking shift helper function public (compiler requires it…
Jan 11, 2017
d5e56d6
Removing explicit implementation of arithmetic operators from Decimal…
Jan 12, 2017
a167238
Fixing more tests
Jan 12, 2017
de5b03d
Getting rid of Arithmetic.init() in favor of 0
Jan 14, 2017
a8d7fc5
Annotating init() as transparent
Jan 19, 2017
d82ddea
Using chain() instead of a 2-level list comprehension in gyb
Jan 19, 2017
e600da4
Moving arithmetic operators back onto concrete types level temporarily
Jan 19, 2017
d128ed4
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Jan 19, 2017
871d1a2
Removing arithemtic operator default implementations from BinaryInteg…
Jan 19, 2017
1265f07
Implementing arithmetic operators on NSDecimal, CGFloat, and concrete…
Jan 23, 2017
1814e4f
Fixing tests
Jan 23, 2017
b5ab726
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Jan 23, 2017
3522f3c
Fixing tests with artihmetic operators back on concrete types
Jan 23, 2017
d382ac9
Using >= instead of > to catch overshifts correctly
Jan 24, 2017
6d380d9
Correcting the logic in the reasoning for the heterogeneous compariso…
Jan 24, 2017
7f00cf4
Add BigInt prototype for testing generic integers (#7005)
natecook1000 Jan 24, 2017
90ef268
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Jan 26, 2017
5601f5f
Adding back a transparrent attribute in an initializer
Jan 28, 2017
06a45cb
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Jan 28, 2017
b5d25cc
Fixing the tests (again)
Jan 28, 2017
0e78631
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Jan 31, 2017
125efc1
Moving / down to the BinaryInteger protocol
Jan 31, 2017
c342166
Renaming leadingZeros to leadingZeroBits. Same for trailingZeros
Jan 31, 2017
494acaa
Fixing the trailingZeroBits test
Jan 31, 2017
3ab1060
[stdlib] Doc comment revisions for (un)signed integers (#7541)
natecook1000 Feb 16, 2017
835b880
Merge branch 'master' into new-integer-protocols
Mar 8, 2017
f4c7e04
Merge remote-tracking branch 'origin/new-integer-protocols' into new-…
Mar 8, 2017
187aa92
Fixing heterogeneous <, failable init from other ints, and init from …
Mar 11, 2017
8ffbc81
Fixing some validation tests
Mar 11, 2017
7d73b2e
Arithmetic => Numeric
Mar 13, 2017
ff81681
Properly naming bit count properties
Mar 13, 2017
48b5899
WithOverflow => ReportingOverflow
Mar 13, 2017
233fb21
multipliedFullWidth(by:) and dividingFullWidth(_:)
Mar 13, 2017
daf088d
Default implementation of instance bitWidth for FixedWidthInteger
Mar 13, 2017
4f0c7a5
Fixing some more validation tests
Mar 13, 2017
b9fb3ba
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Mar 22, 2017
be1ffd0
Removing the test artifacts
Mar 22, 2017
8a8e27f
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Mar 22, 2017
6f6c2ae
Fixing the rest of the tests
Mar 22, 2017
09af9ae
Fixing tests for Linux
Mar 23, 2017
2c9be47
Merge branch 'master' into new-integer-protocols
Mar 23, 2017
ec8e286
Merge branch 'master' into new-integer-protocols
Mar 24, 2017
2f5fd8e
Improving benchmarks
Mar 27, 2017
969b481
Merge branch 'master' into new-integer-protocols
Mar 28, 2017
cd98994
Improving the performance of String.UTF8View
Mar 30, 2017
b0c4548
Adding an explicit type context for ==
Mar 30, 2017
3cbcd71
Merge branch 'master' into new-integer-protocols
Mar 31, 2017
47e10e5
Fixing a few SIL tests
Mar 31, 2017
594b0f4
Merge branch 'master' into new-integer-protocols
Mar 31, 2017
10f0c9e
Merge branch 'master' into new-integer-protocols
Apr 3, 2017
42095bf
Merge branch 'master' into new-integer-protocols
Apr 4, 2017
a1682a8
Speeding up the build by breaking complex expressions into smaller pi…
Apr 4, 2017
9feb799
Adding an explicit type context
Apr 5, 2017
52882c4
Merge branch 'master' into new-integer-protocols
Apr 5, 2017
5242168
Reverting becnhmarks code to master
Apr 5, 2017
4b20175
Replacing @_transparent with @inline(__always)
Apr 5, 2017
dffad4d
Fixing the returnlocation test
Apr 6, 2017
8fe28b4
Merge branch 'master' into new-integer-protocols
Apr 6, 2017
ed90d8c
Adding a few Swift 3 compatibilty APIs
Apr 6, 2017
5b613b3
Adding deprecated mixed-type arithmetic operators for Strideable & Si…
Apr 6, 2017
9bf43d6
Arithmetic operators for Strideable where Stride : ExpressibleByInteg…
Apr 7, 2017
dfc8c65
Adding overloads for << and >> with the literal on the left-hand side
Apr 7, 2017
0226655
Merge branch 'master' into new-integer-protocols
Apr 7, 2017
31e1b1f
Splitting a complex expression in the benchmarks
Apr 8, 2017
cb82daa
Speculatively replacing a couple more transparent's with inline-alway…
Apr 10, 2017
d30a2f9
Adding non-masking shifts on concrete types
Apr 10, 2017
a3a3351
Merge branch 'master' into new-integer-protocols
Apr 10, 2017
def49e8
Adding SignedInteger.&+ and &- for source compatibility
Apr 11, 2017
3d7ddc5
More typealiases for Swift 3 protocols
Apr 12, 2017
fe4553e
Merge branch 'master' into new-integer-protocols
Apr 12, 2017
0478c06
Removing obsolete rename tests
Apr 12, 2017
bc7918b
Commenting out deprecated +/- on Strideable
Apr 13, 2017
f106bd9
Running new integer tests in Swift 4 mode only
Apr 13, 2017
54e5f5d
Handling the differences in << and >> for Swift 3 vs Swift 4
Apr 13, 2017
8de33b4
Overloads for +/- on Strideable for Swift 3 compatibility mode
Apr 14, 2017
fbc9809
Splitting the MixedTypeArithmeticsDiagnostics test into two (Swift 3 …
Apr 14, 2017
2e67c13
Fixing some tests
Apr 14, 2017
7b98267
Fixing the unicode tests by removing the potential optimization
Apr 15, 2017
4018472
Listing expected source stability exceptions
Apr 15, 2017
9b53efd
Merge branch 'master' into new-integer-protocols
Apr 17, 2017
e35b3c9
Fixing the complex expression test
Apr 17, 2017
192c112
Adding arithmetic methods to FloatingPoint for Swift 3 mode
Apr 17, 2017
71b2c1f
Adding Swift 3 alias for _SignedInteger
Apr 17, 2017
b7f715f
Fixing the iOS test failures
Apr 17, 2017
8ca814c
Merge remote-tracking branch 'origin/master' into new-integer-protocols
Apr 17, 2017
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
17 changes: 9 additions & 8 deletions benchmark/single-source/ByteSwap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import TestsUtils

// a naive O(n) implementation of byteswap.
func byteswap_n(_ a: UInt64) -> UInt64 {
return ((a & 0x00000000000000FF) << 56) |
((a & 0x000000000000FF00) << 40) |
((a & 0x0000000000FF0000) << 24) |
((a & 0x00000000FF000000) << 8) |
((a & 0x000000FF00000000) >> 8) |
((a & 0x0000FF0000000000) >> 24) |
((a & 0x00FF000000000000) >> 40) |
((a & 0xFF00000000000000) >> 56)
var result = ((a & 0x00000000000000FF) << 56)
result |= ((a & 0x000000000000FF00) << 40)
result |= ((a & 0x0000000000FF0000) << 24)
result |= ((a & 0x00000000FF000000) << 8)
result |= ((a & 0x000000FF00000000) >> 8)
result |= ((a & 0x0000FF0000000000) >> 24)
result |= ((a & 0x00FF000000000000) >> 40)
result |= ((a & 0xFF00000000000000) >> 56)
return result
}

// a O(logn) implementation of byteswap.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ internal func _checkIncrementalAdvance<Instances, BaseCollection>(
-baseCollection.distance(from: limit, to: i)

var offset: BaseCollection.IndexDistance = 0
for _ in 0...(d * sign).toIntMax() {
for _ in 0...Int64(d * sign) {
let j = baseCollection.index(i, offsetBy: offset)
let k = baseCollection.index(i, offsetBy: offset + sign, limitedBy: limit) ?? limit
let jAtLimit = offset == d
Expand Down Expand Up @@ -447,8 +447,7 @@ public func checkOneLevelOf${Traversal}Collection<
let expectedArray = Array(expected)

// Check `count`.
expectEqual(
expectedArray.count.toIntMax(), collection.count.toIntMax(), ${trace})
expectEqual(Int64(expectedArray.count), Int64(collection.count), ${trace})

//===------------------------------------------------------------------===//
// Check Iteration behavior.
Expand Down
12 changes: 8 additions & 4 deletions stdlib/private/StdlibCollectionUnittest/CheckSequenceType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -790,10 +790,14 @@ public let mapTests = [
[], [],
{ _ -> Int32 in expectUnreachable(); return 0xffff }),

MapTest([ 101 ], [ 1 ], { (x: Int) -> Int32 in Int32(x + 100) }),
MapTest([ 101, 102 ], [ 1, 2 ], { (x: Int) -> Int32 in Int32(x + 100) }),
MapTest([ 101, 102, 103 ], [ 1, 2, 3 ], { (x: Int) -> Int32 in Int32(x + 100) }),
MapTest(Array(101..<200), Array(1..<100), { (x: Int) -> Int32 in Int32(x + 100) }),
MapTest([ 101 ], [ 1 ],
{ (x: Int) -> Int32 in Int32(x + 100) }),
MapTest([ 101, 102 ], [ 1, 2 ],
{ (x: Int) -> Int32 in Int32(x + 100) }),
MapTest([ 101, 102, 103 ], [ 1, 2, 3 ],
{ (x: Int) -> Int32 in Int32(x + 100) }),
MapTest(Array(101..<200), Array(1..<100),
{ (x: Int) -> Int32 in Int32(x + 100) }),
]

public let minMaxTests = [
Expand Down
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(truncatingBitPattern: ce >> 32)
return UInt16(extendingOrTruncating: ce &>> 32)
}
func L2(_ ce: UInt64) -> UInt16 {
return UInt16(truncatingBitPattern: ce >> 16)
return UInt16(extendingOrTruncating: ce &>> 16)
}
func L3(_ ce: UInt64) -> UInt16 {
return UInt16(truncatingBitPattern: ce)
return UInt16(extendingOrTruncating: ce)
}

var result1: [UInt16] = []
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -2447,7 +2447,7 @@ public func expectEqualsUnordered<
public func expectEqualsUnordered<T : Strideable>(
_ expected: CountableRange<T>, _ actual: [T], ${TRACE}
) {
if numericCast(expected.count) != actual.count {
if expected.count != actual.count {
expectationFailure("expected elements: \"\(expected)\"\n"
+ "actual: \"\(actual)\" (of type \(String(reflecting: type(of: actual))))",
trace: ${trace})
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/SwiftPrivate/ShardedAtomicCounter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public struct _stdlib_ShardedAtomicCounter {

public mutating func randomInt() -> Int {
var result = 0
for _ in 0..<Int._sizeInBits {
for _ in 0..<Int.bitWidth {
result = (result << 1) | (_state & 1)
_state = (_state >> 1) ^ (-(_state & 1) & Int(bitPattern: 0xD0000001))
}
Expand Down
11 changes: 7 additions & 4 deletions stdlib/private/SwiftPrivate/SwiftPrivate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
import SwiftShims

/// Convert the given numeric value to a hexadecimal string.
public func asHex<T : Integer>(_ x: T) -> String {
return "0x" + String(x.toIntMax(), radix: 16)
// FIXME(integers): support a more general BinaryInteger protocol
public func asHex<T : FixedWidthInteger>(_ x: T) -> String {
return "0x" + String(x, radix: 16)
}

/// Convert the given sequence of numeric values to a string representing
/// their hexadecimal values.
public func asHex<S: Sequence>(_ x: S) -> String
where S.Iterator.Element : Integer {
// FIXME(integers): support a more general BinaryInteger protocol
public func asHex<S : Sequence>(_ x: S) -> String
where
S.Iterator.Element : FixedWidthInteger {
return "[ " + x.lazy.map { asHex($0) }.joined(separator: ", ") + " ]"
}

Expand Down
5 changes: 3 additions & 2 deletions stdlib/public/Platform/tgmath.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

// Generic functions implementable directly on FloatingPoint.
@_transparent
public func fabs<T: FloatingPoint>(_ x: T) -> T {
return abs(x)
public func fabs<T: FloatingPoint>(_ x: T) -> T
where T.Magnitude == T {
return x.magnitude
}

@_transparent
Expand Down
95 changes: 46 additions & 49 deletions stdlib/public/SDK/CoreGraphics/CGFloat.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ public struct CGFloat {
public var native: NativeType
}

extension CGFloat : SignedNumeric {
// FIXME(integers): implement properly
public init?<T : BinaryInteger>(exactly source: T) {
fatalError()
}

@_transparent
public var magnitude: CGFloat {
return CGFloat(Swift.abs(native))
}

}

extension CGFloat : BinaryFloatingPoint {

public typealias RawSignificand = UInt
Expand Down Expand Up @@ -196,34 +209,28 @@ extension CGFloat : BinaryFloatingPoint {
return CGFloat(native.nextUp)
}

@_transparent
public var magnitude: CGFloat {
return CGFloat(Swift.abs(native))
}

@_transparent
public mutating func negate() {
native.negate()
}

@_transparent
public mutating func add(_ other: CGFloat) {
native.add(other.native)
public static func +=(_ lhs: inout CGFloat, _ rhs: CGFloat) {
lhs.native += rhs.native
}

@_transparent
public mutating func subtract(_ other: CGFloat) {
native.subtract(other.native)
public static func -=(_ lhs: inout CGFloat, _ rhs: CGFloat) {
lhs.native -= rhs.native
}

@_transparent
public mutating func multiply(by other: CGFloat) {
native.multiply(by: other.native)
public static func *=(_ lhs: inout CGFloat, _ rhs: CGFloat) {
lhs.native *= rhs.native
}

@_transparent
public mutating func divide(by other: CGFloat) {
native.divide(by: other.native)
public static func /=(_ lhs: inout CGFloat, _ rhs: CGFloat) {
lhs.native /= rhs.native
}

@_transparent
Expand Down Expand Up @@ -418,44 +425,34 @@ extension Float {
// tweaking the overload resolution rules, or by removing the other
// definitions in the standard lib, or both.

@_transparent
public func +(lhs: CGFloat, rhs: CGFloat) -> CGFloat {
return lhs.adding(rhs)
}

@_transparent
public func -(lhs: CGFloat, rhs: CGFloat) -> CGFloat {
return lhs.subtracting(rhs)
}

@_transparent
public func *(lhs: CGFloat, rhs: CGFloat) -> CGFloat {
return lhs.multiplied(by: rhs)
}

@_transparent
public func /(lhs: CGFloat, rhs: CGFloat) -> CGFloat {
return lhs.divided(by: rhs)
}

@_transparent
public func +=(lhs: inout CGFloat, rhs: CGFloat) {
lhs.add(rhs)
}
extension CGFloat {
@_transparent
public static func +(lhs: CGFloat, rhs: CGFloat) -> CGFloat {
var lhs = lhs
lhs += rhs
return lhs
}

@_transparent
public func -=(lhs: inout CGFloat, rhs: CGFloat) {
lhs.subtract(rhs)
}
@_transparent
public static func -(lhs: CGFloat, rhs: CGFloat) -> CGFloat {
var lhs = lhs
lhs -= rhs
return lhs
}

@_transparent
public func *=(lhs: inout CGFloat, rhs: CGFloat) {
lhs.multiply(by: rhs)
}
@_transparent
public static func *(lhs: CGFloat, rhs: CGFloat) -> CGFloat {
var lhs = lhs
lhs *= rhs
return lhs
}

@_transparent
public func /=(lhs: inout CGFloat, rhs: CGFloat) {
lhs.divide(by: rhs)
@_transparent
public static func /(lhs: CGFloat, rhs: CGFloat) -> CGFloat {
var lhs = lhs
lhs /= rhs
return lhs
}
}

//===----------------------------------------------------------------------===//
Expand Down
39 changes: 22 additions & 17 deletions stdlib/public/SDK/Dispatch/Time.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ public struct DispatchTime : Comparable {
}
}

public func <(a: DispatchTime, b: DispatchTime) -> Bool {
return a.rawValue < b.rawValue
}

public func ==(a: DispatchTime, b: DispatchTime) -> Bool {
return a.rawValue == b.rawValue
extension DispatchTime {
public static func < (a: DispatchTime, b: DispatchTime) -> Bool {
return a.rawValue < b.rawValue
}

public static func ==(a: DispatchTime, b: DispatchTime) -> Bool {
return a.rawValue == b.rawValue
}
}

public struct DispatchWallTime : Comparable {
Expand All @@ -96,17 +98,20 @@ public struct DispatchWallTime : Comparable {
}
}

public func <(a: DispatchWallTime, b: DispatchWallTime) -> Bool {
if b.rawValue == ~0 {
return a.rawValue != ~0
} else if a.rawValue == ~0 {
return false
}
return -Int64(bitPattern: a.rawValue) < -Int64(bitPattern: b.rawValue)
}

public func ==(a: DispatchWallTime, b: DispatchWallTime) -> Bool {
return a.rawValue == b.rawValue
extension DispatchWallTime {
public static func <(a: DispatchWallTime, b: DispatchWallTime) -> Bool {
let negativeOne: dispatch_time_t = ~0
if b.rawValue == negativeOne {
return a.rawValue != negativeOne
} else if a.rawValue == negativeOne {
return false
}
return -Int64(bitPattern: a.rawValue) < -Int64(bitPattern: b.rawValue)
}

public static func ==(a: DispatchWallTime, b: DispatchWallTime) -> Bool {
return a.rawValue == b.rawValue
}
}

public enum DispatchTimeInterval {
Expand Down
8 changes: 7 additions & 1 deletion stdlib/public/SDK/Foundation/AffineTransform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,13 @@ public struct AffineTransform : ReferenceConvertible, Hashable, CustomStringConv
}

public var hashValue : Int {
return Int(m11 + m12 + m21 + m22 + tX + tY)
// FIXME(integers): the expression was broken into pieces to speed up
// compilation.
// Used to be just: return Int(m11 + m12 + m21 + m22 + tX + tY)
let a: CGFloat = m11 + m12
let b: CGFloat = m21 + m22
let c: CGFloat = tX + tY
return Int(a + b + c)
}

public var description: String {
Expand Down
Loading