Commit Graph

1397 Commits

Author SHA1 Message Date
Dave Abrahams
cced061ee9 [stdlib] Printable conformance for Range
Swift SVN r19906
2014-07-13 21:21:32 +00:00
Dave Abrahams
9ecbdc2135 [stdlib] punctuation fix in comment
Swift SVN r19905
2014-07-13 21:21:30 +00:00
Dave Abrahams
be37cd904b [stdlib] Trap invalid Ranges of Comparable Indexes
When the Index type of a Range is Comparable, we can reject invalid
ranges at their formation.

It might be worth injecting some checkability concept into ForwardIndex
so that even in generic contexts where Comparability is unknown, we can
do this same check in the Range constructor.

Also, remove pattern matching support for Ranges of RandomAccessIndex,
as that is covered by Interval.

Fixes <rdar://problem/16254937> (#Seed 4: Ranges with negative strides
are broken) to the extent possible (it's still possible to form an
invalid Range of indices that are not Comparable)

Fixes <rdar://problem/17164391> (Swift: Using ranges in for in for
counting down, causes the loop to go inifinely)

Fixes <rdar://problem/17580871> (Swift: Closed range with negative
endpoint excludes that endpoint)

Swift SVN r19903
2014-07-13 19:58:21 +00:00
Dave Abrahams
d85a7f5d0c [stdlib] Pointer types are not BooleanType's
Fixes <rdar://problem/17597917>.  Someone still needs to do this for the
Optional types.

Swift SVN r19901
2014-07-13 19:21:54 +00:00
Dave Abrahams
cb050eee52 [stdlib] Add Interval support
This allows 0.0..<10.3 and 0.1...4.4 to work properly in pattern
matching.

Fixes <rdar://problem/12016900> (#Seed 4: add a "contains" method to the
range types) by making "contains" available on Interval

Addresses <rdar://problem/16254937> (#Seed 4: Ranges with negative
strides are broken) by making the formation of an invalid Interval a
runtime error.

Fixes <rdar://problem/16304317> (Range<T> has limited awesomeness: it is
restricted to types that conform to ForwardIndex)

Fixes <rdar://problem/16736924> (#Seed 4: Enable range inclusion pattern
matching for all types that conform to Equatable and Comparable)

Addresses <rdar://problem/16846325> (#Seed 4: Introduce index range) by
distinguishing Range (which operates on indices) from Interval

Fixes <rdar://problem/17051263> (Pattern-matching a Double range with an
infinite endpoint triggers an assertion failure)

Fixes <rdar://problem/17051271> (#Seed 4: Pattern-matching Double ranges
excludes fractional values)

Addresses <rdar://problem/17171420> (Separate types for closed and
half-open ranges)

Swift SVN r19900
2014-07-13 18:49:36 +00:00
Dmitri Hrybenko
b53ed944b0 stdlib: replace masking arithmetic with less complex code
Swift SVN r19899
2014-07-13 15:42:51 +00:00
Dmitri Hrybenko
45f9706c22 stdlib/Dictionary: remove 'public' from more Dictionary implementation details
Swift SVN r19898
2014-07-13 12:21:20 +00:00
Dmitri Hrybenko
08d6650828 stdlib/Dictionary: move implementation of Dictionary.bridgeToObjectiveC() from
Foundation overlay to core stdlib, and remove 'public' from some Dictionary
implementation details


Swift SVN r19897
2014-07-13 11:51:23 +00:00
Doug Gregor
a5c079af59 Replace the class_protocol attribute with a "class" requirement.
This only tackles the protocol case (<rdar://problem/17510790>); it
does not yet generalize to an arbitrary "class" requirement on either
existentials or generics.

Swift SVN r19896
2014-07-13 06:57:48 +00:00
Dave Abrahams
0412b0cfc1 [stdlib] BooleanType is just for Bools
For now, it still applies to Optionals and Pointers, but this commit
removes it from everything else.

Swift SVN r19888
2014-07-13 01:19:39 +00:00
Dave Abrahams
bf55e6b4ed [stdlib] s/FloatingPointNumberType/FloatingPointType/
Swift SVN r19887
2014-07-13 01:00:51 +00:00
Dave Abrahams
cbcf9aba21 s/LogicValueType/BooleanType/
We're moving toward using that protocol for straight-up Bool types

Swift SVN r19884
2014-07-12 18:58:18 +00:00
Dave Abrahams
6d1095f44e Protocol names end in "Type," "ible," or "able"
Mechanically add "Type" to the end of any protocol names that don't end
in "Type," "ible," or "able."  Also, drop "Type" from the end of any
associated type names, except for those of the *LiteralConvertible
protocols.

There are obvious improvements to make in some of these names, which can
be handled with separate commits.

Fixes <rdar://problem/17165920> Protocols `Integer` etc should get
uglier names.

Swift SVN r19883
2014-07-12 17:29:57 +00:00
Dmitri Hrybenko
355316a49b stdlib/Dictionary: when bridging from Objective-C, recognize bridged
native Dictionary storage and adopt it if KeyType and ValueType match
exactly

This was the last missing piece to allow Dictionary to round-trip
thorough objc entrypoints of Swift methods in O(1).

Fixes rdar://17556319, partially fixes rdar://17010353

Swift SVN r19873
2014-07-12 01:17:13 +00:00
Nadav Rotem
bb3ad55201 Document the use of the non overflowing arithmetic when multiplying sizeof() by 8.
Swift SVN r19856
2014-07-11 18:35:23 +00:00
Dmitri Hrybenko
9cbf6df734 stdlib/Dictionary: add _DictionaryBuilder, which is faster than adding elements
one by one.

Use _DictionaryBuilder in Foundation overlay instead of poking Dictionary's
internals directly.


Swift SVN r19855
2014-07-11 17:35:32 +00:00
Dmitri Hrybenko
bc682c8e3e stdlib: coding style: don't hide 'public' at the end of the line where it is
hard to notice it


Swift SVN r19854
2014-07-11 17:26:25 +00:00
Dmitri Hrybenko
ee06efdd2c stdlib/Dictionary: when bridging Dictionary of non-verbatim-bridged
types to NSDictionary, perform bridging operation in O(1), and defer
bridging of the contents until the NSDictionary is accessed

There is no cache for bridged keys and values; the Swift NSDictionary
will return values with different pointer values when a given key is
repeatedly accessed.

Part of rdar://17556319

Does not fix the O(N) performance of objc thunks, because Dictionary is
not recognizing its own native storage when bridging from Objective-C.
This tracked by rdar://17010353

Swift SVN r19853
2014-07-11 17:24:06 +00:00
Andrew Trick
8882999b63 Add Array semantic model.
This unblocks work on bounds and mutable check hoisting. Pete is also
tuning -O3 Array performance, which should be done on top of this
patch.

Overall, this significantly improves performance, but there is one
issue that causes regressions on Hash and QuickSort at -O3 only. This
patch does not cause the performance issue. It is already a serious
problem that needs to be fixed. This patch just adds a level of benign
function calls that further exposes the existing performance problem.
We are independently working on fixing this: <rdar://problem/17634697>
Array access forces retain/release of storage object for each inlined
call.

-O3
| benchmark    | baserun0 | baserun1 | baserun2 |  optrun0 |  optrun1 |  optrun2 |   delta | speedup |
| Dictionary   |  1072.00 |  1087.00 |  1099.00 |  1060.00 |  1132.00 |  1172.00 |   12.00 |    1.1% |
| EditDistance |  1602.00 |  1612.00 |  1611.00 |  1646.00 |  1652.00 |  1678.00 |   44.00 |   -2.7% |
| ForLoops     |  1511.00 |  1506.00 |  1519.00 |  1519.00 |  1521.00 |  1614.00 |   13.00 |   -0.9% |
| Forest       |  1245.00 |  1233.00 |  1252.00 |  1233.00 |  1248.00 |  1245.00 |    0.00 |    0.0% |
| GlobalClass  |  3624.00 |  3571.00 |  3569.00 |  3533.00 |  3540.00 |  3548.00 |   36.00 |    1.0% |
| Hash         |  1855.00 |  1760.00 |  1796.00 |  2085.00 |  2160.00 |  2075.00 |  315.00 |  -15.2% |
| Histogram    |  1695.00 |  1714.00 |  1763.00 |  1802.00 |  1865.00 |  1987.00 |  107.00 |   -5.9% |
| LinkedList   |  1584.00 |  1594.00 |  1587.00 |  1576.00 |  1598.00 |  1652.00 |    8.00 |    0.5% |
| NBody        |   700.00 |   698.00 |   691.00 |   480.00 |   479.00 |   484.00 |  212.00 |   44.3% |
| Phonebook    |  1886.00 |  1814.00 |  1849.00 |  1823.00 |  1801.00 |  1836.00 |   13.00 |    0.7% |
| QuickSort    |   248.00 |   245.00 |   237.00 |   265.00 |   287.00 |   291.00 |   28.00 |  -10.6% |
| R17315246    |   541.00 |   545.00 |   549.00 |   551.00 |   561.00 |   578.00 |   10.00 |   -1.8% |
| RC4          |  1664.00 |  1781.00 |  1776.00 |   953.00 |   961.00 |   974.00 |  711.00 |   74.6% |
| Rectangles   |   739.00 |   725.00 |   734.00 |   724.00 |   719.00 |   729.00 |    6.00 |    0.8% |
| SmallPT      |  1421.00 |  1429.00 |  1406.00 |   574.00 |   589.00 |   599.00 |  832.00 |  144.9% |
| StringWalk   |   651.00 |   647.00 |   653.00 |   645.00 |   633.00 |   673.00 |   14.00 |    2.2% |
| Total        | 26525.00 | 26445.00 | 26593.00 | 24908.00 | 25227.00 | 25793.00 | 1537.00 |    6.2% |
-Ofast
| benchmark    | baserun0 | baserun1 | baserun2 |  optrun0 |  optrun1 |  optrun2 |  delta | speedup |
| Dictionary   |  1103.00 |  1051.00 |  1047.00 |  1051.00 |  1033.00 |  1036.00 |  14.00 |    1.4% |
| EditDistance |  1554.00 |  1493.00 |  1512.00 |  1524.00 |  1511.00 |  1524.00 |  18.00 |   -1.2% |
| ForLoops     |  1644.00 |  1610.00 |  1612.00 |  1638.00 |  1628.00 |  1630.00 |  18.00 |   -1.1% |
| Forest       |  1118.00 |  1066.00 |  1105.00 |  1062.00 |  1079.00 |  1076.00 |   4.00 |    0.4% |
| GlobalClass  |  2226.00 |  2204.00 |  2194.00 |  2248.00 |  2227.00 |  2234.00 |  33.00 |   -1.5% |
| Hash         |  1006.00 |   967.00 |   975.00 |   998.00 |   996.00 |  1011.00 |  29.00 |   -2.9% |
| Histogram    |  1324.00 |  1173.00 |  1225.00 |  1197.00 |  1183.00 |  1217.00 |  10.00 |   -0.8% |
| LinkedList   |  1558.00 |  1552.00 |  1558.00 |  1560.00 |  1571.00 |  1558.00 |   6.00 |   -0.4% |
| NBody        |   910.00 |   906.00 |   903.00 |   796.00 |   790.00 |   789.00 | 114.00 |   14.4% |
| Phonebook    |  1659.00 |  1649.00 |  1638.00 |  1846.00 |  1713.00 |  1613.00 |  25.00 |    1.5% |
| QuickSort    |   699.00 |   700.00 |   689.00 |   686.00 |   679.00 |   679.00 |  10.00 |    1.5% |
| R17315246    |     0.00 |     0.00 |     0.00 |     0.00 |     0.00 |     0.00 |   0.00 |       * |
| RC4          |  1281.00 |  1227.00 |  1234.00 |  1056.00 |  1051.00 |  1066.00 | 176.00 |   16.7% |
| Rectangles   |   726.00 |   772.00 |   738.00 |   737.00 |   727.00 |   721.00 |   5.00 |    0.7% |
| SmallPT      |   978.00 |   963.00 |   971.00 |   629.00 |   623.00 |   631.00 | 340.00 |   54.6% |
| StringWalk   |   456.00 |   462.00 |   450.00 |   467.00 |   461.00 |   445.00 |   5.00 |    1.1% |
| Total        | 22315.00 | 21688.00 | 21716.00 | 21589.00 | 21342.00 | 21294.00 | 394.00 |    1.9% |

Swift SVN r19849
2014-07-11 16:44:16 +00:00
Nadav Rotem
f4a470979b Use unsafe arithmetic for basic sizeof and alignof calculations.
Swift SVN r19838
2014-07-11 00:03:57 +00:00
Nadav Rotem
98ab6d8286 Perform unsafe arithmetic on sizeof() calculations. This calculation is unlikely to overflow. I did not see a noticable performance change to the string benchmarks.
Swift SVN r19836
2014-07-10 23:43:15 +00:00
Enrico Granata
2cd27ad3d2 Tweaks to get PlaygroundLogger to build and work in a world of accessibility-enforced rules
1) Add an ObjCObject disposition that tells us this Mirror is reflecting upon an ObjC-imported type
2) Change the default summary of _ClassMirror and _StructMirror to be the mangled typename, with no children count



Swift SVN r19817
2014-07-10 18:54:25 +00:00
Dmitri Hrybenko
86f58123f9 stdlib/Array: hide some Array implementation details:
ArrayBuffer
ArrayBufferType
ContiguousArrayBuffer
ContiguousArrayStorage
IndirectArrayBuffer
SliceBuffer

Unfortunately, can not remove 'public' from them since they are used by
Foundation overlay in bridging code.


Swift SVN r19810
2014-07-10 14:30:54 +00:00
Dmitri Hrybenko
8ea2b6b887 stdlib/Array: remove some dead code that supported 'Array' being named
'NewArray'


Swift SVN r19809
2014-07-10 13:33:12 +00:00
Dmitri Hrybenko
54efce9aa5 stdlib/Dictionary bridging: optimize NSDictionary to Dictionary conversion
during eager bridging

rdar://17325454


Swift SVN r19808
2014-07-10 13:18:07 +00:00
Dmitri Hrybenko
0e59dcac1f stdlib/Dictionary bridging: don't wrap NSDictionary in Dictionary<K, V> when
either K or V is bridged non-verbatim

rdar://17325454


Swift SVN r19807
2014-07-10 12:02:22 +00:00
Dmitri Hrybenko
909d49495c stdlib/Dictionary: remove debug output that I accidentally committed
Swift SVN r19806
2014-07-10 11:33:35 +00:00
Dmitri Hrybenko
febc98d5a4 stdlib/Dictionary: change internal bridging interfaces so that wrong code (that
does not copy NSDictionary) looks wrong


Swift SVN r19804
2014-07-10 09:45:42 +00:00
Dave Abrahams
cf6842efdb [stdlib] Drop the "by" method on Range<T>
That functionality is now covered by the stride() functions for
Range<T:RandomAccessIndex>, and probably shouldn't be used for ranges of
lesser Index protocols anyway.

Swift SVN r19803
2014-07-10 09:29:03 +00:00
Dave Abrahams
0cbd541a16 [stdlib] Floating point types are Strideable...
...but not RandomAccessIndex'en

Swift SVN r19802
2014-07-10 09:19:28 +00:00
Dave Abrahams
4c31d819ec [stdlib] Striding over closed ranges
Swift SVN r19801
2014-07-10 09:10:02 +00:00
Dave Abrahams
34374354cd [stdlib] Striding over half-open ranges
Swift SVN r19800
2014-07-10 08:44:31 +00:00
Dave Abrahams
c36beddfb4 [stdlib] Every FloatingPointNumber is Strideable
Swift SVN r19795
2014-07-10 06:56:36 +00:00
Dave Abrahams
bec9a26380 [stdlib] Strideable refines Comparable
We can stop handling Comparable explicitly as part of RandomAccessIndex,
because RandomAccessIndex is Strideable

Swift SVN r19794
2014-07-10 06:56:36 +00:00
Chris Lattner
5b49d59c57 Remove the @ from @final and @lazy, the last major piece of
rdar://17168115.

Also, reinstate the ARM driver change and testcase that I removed
in my last patch.


Swift SVN r19790
2014-07-10 06:23:27 +00:00
Dave Abrahams
9e89dba36f [stdlib] make FloatingPoint.swift.gyb parse as swift
Swift SVN r19786
2014-07-10 05:43:28 +00:00
Dave Abrahams
eb1a5cfac4 [stdlib] Add Strideable protocol
And make RandomAccessIndex refine it.

* had to XFAIL
  test/Prototypes/TextFormatting.swift (<rdar://problem/17619178>)

* Had to compromise on the name of Strideable's associated
  type (<rdar://problem/17619038>)

Swift SVN r19785
2014-07-10 05:39:13 +00:00
Dave Abrahams
3e3f4a6e52 Revert "infix + and - for RandomAccessIndex"
This commit was premature; we're having trouble with protocols that needs to be
resolved first.

This reverts r19778

Swift SVN r19780
2014-07-10 04:47:12 +00:00
Dave Abrahams
64c6d32a99 [stdlib] infix + and - for RandomAccessIndex
A step towards implementing generalized striding

Swift SVN r19778
2014-07-10 04:16:53 +00:00
Greg Parker
bde0d301fc Fix fmod() covers. Add CGFloat to the math.h tests.
<rdar://problem/17275152> Can't call C fmodf() from stdlib


Swift SVN r19777
2014-07-10 03:54:27 +00:00
Dave Abrahams
b56c3a84d3 [stdlib] Drop Sliceable conformance for Range<T>
Sliceable is a totally non-critical protocol and Range slicing wasn't
even being tested.  Along with r19771, fixes <rdar://problem/16363898>

Swift SVN r19775
2014-07-10 02:08:46 +00:00
Dave Abrahams
b84a3377f0 [stdlib] Drop ReverseRange
Swift SVN r19773
2014-07-10 01:20:58 +00:00
Dave Abrahams
e261dda22b [stdlib] Give reverse() the eager/lazy treatments
Swift SVN r19772
2014-07-10 01:20:57 +00:00
Dave Abrahams
58f94698c3 [stdlib] Disallow indexing integer ranges with Int
This horrible hack prevents the user from indexing Range<I>, for all
integer types I, outside of a generic context.  This seems to be the
best we can do to prevent confusion given the current language.

Addresses <rdar://problem/16363898>

Unfortunately, I can't make this work for slicing ranges yet.

Swift SVN r19771
2014-07-10 01:20:57 +00:00
Dave Abrahams
9918145209 [stdlib] Drop RandomAccessRange
It won't be needed in the new Range plan after all

Swift SVN r19770
2014-07-10 01:20:56 +00:00
Doug Gregor
2f3f6acf21 Make "true" and "false" Boolean literal constants for the BooleanLiteralConvertible protocol.
Introduce the new BooleanLiteralConvertible protocol for Boolean
literals. Take "true" and "false" as real keywords (which is most of the
reason for the testsuite churn). Make Bool BooleanLiteralConvertible
and the default Boolean literal type, and ObjCBool
BooleanLiteralConvertible. Fixes <rdar://problem/17405310> and the
recent regression that made ObjCBool not work with true/false.


Swift SVN r19728
2014-07-09 16:57:35 +00:00
Dmitri Hrybenko
f0621d1563 stdlib/Dictionary: eliminate invalid reinterpret casts
rdar://17509909


Swift SVN r19727
2014-07-09 16:03:46 +00:00
Dmitri Hrybenko
19f3875079 stdlib/Array: remove === and !== for array types
Swift SVN r19725
2014-07-09 15:06:32 +00:00
Dmitri Hrybenko
0523fea01b stdlib/Dictionary: rewrite iteration over wrapped NSDictionary not to
rely on NSDictionary.allKeys, it leaves the array of keys on the
autorelease pool.  Not very bad, but it is better if we can avoid it.

rdar://17604820

Swift SVN r19724
2014-07-09 14:49:49 +00:00
Chris Lattner
02999cac51 Reinstate the @ on the @objc attribute. This is largely a revert of r19555 with a few tweaks.
Swift SVN r19706
2014-07-08 21:50:34 +00:00