Commit Graph

21665 Commits

Author SHA1 Message Date
Joe Pamer
f55c751958 Add a fixit for optional-typed expressions used in conditional expression positions.
Swift SVN r20639
2014-07-28 19:20:42 +00:00
Joe Pamer
94dac129d4 Remove the BooleanType conformance from optional types (rdar://problem/17110911)
To limit user confusion when using conditional expressions of type Bool?, we've decided to remove the BooleanType (aka "LogicValue") conformance from optional types. (If users would like to use an expression of type Bool? as a conditional, they'll need to check against nil.)

Note: This change effectively regresses the "case is" pattern over types, since it currently demands a BooleanType conformance. I've filed rdar://problem/17791533 to track reinstating it if necessary.

Swift SVN r20637
2014-07-28 19:20:39 +00:00
Dave Abrahams
c76eeec0a5 [stdlib] Drop obsolete @availability
Swift SVN r20634
2014-07-28 18:31:34 +00:00
Dave Abrahams
214e2f03de [stdlib] Drop @availability for renamed protocols
...now that seed 5 has branched.

Fixes <rdar://problem/17672088> #Seed 6: Remove @availability for protocols

Swift SVN r20632
2014-07-28 18:14:27 +00:00
Dave Abrahams
4ece9b1734 [stdlib] Default bitwise assignment operators
|=, &=, and ^= now come along for free with a BitwiseOperationsType
conformance, so we can remove the special-cased operators for
RawOptionSetType.

Also, release notes.

Swift SVN r20630
2014-07-28 16:39:23 +00:00
Doug Gregor
bd75425b0e Remove the notion of non-inheritable conformances entirely <rdar://problem/16880016>.
Swift SVN r20627
2014-07-28 16:29:05 +00:00
Doug Gregor
3cb58e833a Restrict non-final class protocol conformance when Self is part of the requirement signature.
When a non-final class satisfies a method requirement that returns
Self, it must do so with a method that also returns (dynamic)
Self. This ensures conformance will be inheritable, closing off an
awful type-safety hole <rdar://problem/16880016>. Other
non-contravariant uses of Self in the signatures of requirements cause
the protocol to be unusable by non-final classes.

I had to leave a tiny little gaping hole for the ~> operator, whose
removal is covered by <rdar://problem/17828741>. We can possibly put
this on firm footing with clever handling of generic witnesses, but
it's not important right now.



Swift SVN r20626
2014-07-28 16:15:16 +00:00
Dave Abrahams
d90f34a479 [stdlib] RawOptionSetType : BitwiseOperationsType
Add the missing conformance now that Jordan implemented allZeros.

Swift SVN r20625
2014-07-28 15:52:45 +00:00
Dmitri Hrybenko
f75968d9cd stdlib: add a trap() function that traps in debug and release modes
rdar://17792445


Swift SVN r20620
2014-07-28 11:30:42 +00:00
Dmitri Hrybenko
ca07053adc stdlib: rename fatalError() to debugTrap()
Part of rdar://17792445


Swift SVN r20619
2014-07-28 11:14:52 +00:00
Doug Gregor
0b802ce6e9 String: add some unavailable subscript overloads for String with integer (or integer range) indices.
The compiler's QoI for these cases is horrible, and it's a common
pitfall, so be more direct about the fact that this cannot be done.


Swift SVN r20613
2014-07-28 03:50:26 +00:00
Dave Abrahams
31d6f95452 [stdlib] UnsafeBufferPointer: add ".count"
In answering a forum post I noiced that I wanted this and it was
missing.

Also, extensive comments

Also, rename the length: init parameter to count:.  When writing the
comments for the init function it became painfully clear why we use
"count" is better than "length" especially around pointers and memory:
the former is much less easy to mistake for "length in bytes".  Plus
it's consistent with the new ".count" property

Swift SVN r20609
2014-07-28 01:03:09 +00:00
Dmitri Hrybenko
06a9ea552c stdlib/String: fix hasPrefix() and hasSuffix() to perform proper Unicode
comparison

rdar://17498444


Swift SVN r20603
2014-07-27 18:12:02 +00:00
Dmitri Hrybenko
a4c1ef90e7 stdlib/Algorithm: add an overload for startsWith that accepts a
comparison predicate

Swift SVN r20601
2014-07-27 01:00:26 +00:00
Joe Groff
61f64f3323 stdlib: Add a '??' nil-coalescing operator.
Similar to nil-coalescing operators in other languages, this operator takes an optional on the left and a non-optional expression on the right, and if the optional is nil, evaluates the right side, otherwise returning the value from the optional itself. <rdar://problem/15247356>

Swift SVN r20593
2014-07-26 19:48:50 +00:00
Dmitri Hrybenko
729266205d stdlib: mark Float.value as private
Swift SVN r20590
2014-07-26 19:48:03 +00:00
Dmitri Hrybenko
0b76e88fea stdlib: fix memory leak in _stdlib_NSStringNFDHashValue
rdar://17498444


Swift SVN r20589
2014-07-26 18:52:30 +00:00
Dave Abrahams
7fcc484e30 [stdlib] Construct UnicodeScalar from UInt16/UInt8
Fixes <rdar://problem/17819254>

Swift SVN r20588
2014-07-26 05:12:24 +00:00
Dave Abrahams
b81c4b2dca Revert "[stdlib] Concise operators for advance(i, +/-n)"
This reverts r20561 until we've had a chance to discuss it in a design meeting

Swift SVN r20579
2014-07-25 23:52:38 +00:00
Dave Abrahams
96e9bfbe13 [stdlib] Fix Range trap test
We need to detect wrapping end indexes now

Swift SVN r20578
2014-07-25 23:50:33 +00:00
Greg Parker
dc407c6235 [runtime] Improve unrecognized-selector error message for pure-Swift classes.
Swift SVN r20577
2014-07-25 23:42:29 +00:00
Dave Abrahams
92637e786b [stdlib] Integer index operations don't overflow
When an integer type T is used as an Index, there are always
bounds---more restrictive than the full range of T---against which we're
not able to check.  Overflows are not useful indicators of precondition
violations in this context.  Therefore, use masked arithmetic for
RandomAccessIndex conformance.

Performance changes of magnitude >= 5% are below.  Someone might want to
investigate why Fibonacci got 21% faster in -Ounchecked, since nothing
in this change should have removed checks from that build.  (That test
does seem particularly sensitive; see also <rdar://problem/17815767>
Adding three overloads to stdlib slows Fibonacci by 18-19%)

Fixes <rdar://problem/17780469> Integer ranges shouldn't use overflowing adds

====================`PrecommitBench_O`====================
````benchmark`|`baserun0`|`baserun1`|`optrun0`|`optrun1`|``delta`|`speedup`
````Ackermann`|``1428.00`|``1466.00`|`1661.00`|`1657.00`|`229.00`|``-13.8%`
`````ForLoops`|``2021.00`|``1986.00`|`1249.00`|`1255.00`|`737.00`|```59.0%`
`````````Hash`|``1038.00`|```979.00`|``898.00`|``922.00`|``81.00`|````9.0%`
`````````Life`|````63.00`|````63.00`|```60.00`|```61.00`|```3.00`|````5.0%`
```````Memset`|````55.00`|````54.00`|```42.00`|```42.00`|``12.00`|```28.6%`
``MonteCarloE`|``1243.00`|``1265.00`|``885.00`|``880.00`|`363.00`|```41.3%`
`MonteCarloPi`|```994.00`|``1004.00`|``613.00`|``605.00`|`389.00`|```64.3%`
````````NBody`|````45.00`|````45.00`|```42.00`|```43.00`|```3.00`|````7.1%`
````QuickSort`|```105.00`|```103.00`|```83.00`|```83.00`|``20.00`|```24.1%`
````R17315246`|``1080.00`|``1080.00`|``805.00`|``808.00`|`275.00`|```34.2%`
``````SmallPT`|``1008.00`|``1007.00`|``789.00`|``795.00`|`218.00`|```27.6%`
````````Walsh`|```136.00`|```136.00`|``129.00`|``130.00`|```7.00`|````5.4%`
====================`PrecommitBench_Ounchecked`====================
````benchmark`|`baserun0`|`baserun1`|`optrun0`|`optrun1`|``delta`|`speedup`
``Dictionary3`|``1060.00`|``1039.00`|``982.00`|`1029.00`|``57.00`|````5.8%`
````Fibonacci`|```842.00`|```848.00`|``694.00`|``694.00`|`148.00`|```21.3%`
```StringWalk`|```945.00`|```924.00`|``989.00`|``995.00`|``65.00`|```-6.6%`
====================`PrecommitBench_Onone`====================
````benchmark`|`baserun0`|`baserun1`|`optrun0`|`optrun1`|``delta`|`speedup`
`EditDistance`|``2086.00`|``1981.00`|`1492.00`|`1622.00`|`489.00`|```32.8%`
`````````Life`|``1256.00`|``1216.00`|`1110.00`|`1142.00`|`106.00`|````9.5%`
```````MatMul`|``1210.00`|``1245.00`|``705.00`|``705.00`|`505.00`|```71.6%`
````R17315246`|```205.00`|```209.00`|``195.00`|``200.00`|``10.00`|````5.1%`

Swift SVN r20576
2014-07-25 23:37:01 +00:00
Pete Cooper
16f6c73db9 Use unchecked arithmetic for offsets to HeapBuffer values and elements. If these were able to overflow then we'd have already failed in the initializer of the HeapBuffer
Performance numbers are being noisy, but overall there are some good wins.  The losses are the noisy ones unfortunately.

2Sum           ,        1273.00   ,                1292.00   ,        19.00   ,                -1.5%
Ackermann      ,        1423.00   ,                1663.00   ,        240.00  ,                -14.4%
ArrayLiteral   ,        913.00    ,                869.00    ,        44.00   ,                5.1%
Ary            ,        1278.00   ,                1278.00   ,        0.00    ,                0.0%
Ary2           ,        1667.00   ,                1656.00   ,        11.00   ,                0.7%
Ary3           ,        1418.00   ,                1380.00   ,        38.00   ,                2.8%
DeltaBlue      ,        2480.00   ,                2437.00   ,        43.00   ,                1.8%
Dictionary     ,        606.00    ,                594.00    ,        12.00   ,                2.0%
Dictionary2    ,        879.00    ,                862.00    ,        17.00   ,                2.0%
Dictionary3    ,        878.00    ,                871.00    ,        7.00    ,                0.8%
EditDistance   ,        1427.00   ,                1404.00   ,        23.00   ,                1.6%
Fibonacci      ,        1351.00   ,                1335.00   ,        16.00   ,                1.2%
ForLoops       ,        1978.00   ,                1976.00   ,        2.00    ,                0.1%
Forest         ,        1091.00   ,                1076.00   ,        15.00   ,                1.4%
GlobalClass    ,        1714.00   ,                1619.00   ,        95.00   ,                5.9%
Hash           ,        971.00    ,                915.00    ,        56.00   ,                6.1%
HeapSort       ,        1321.00   ,                1261.00   ,        60.00   ,                4.8%
Histogram      ,        1085.00   ,                1079.00   ,        6.00    ,                0.6%
Life           ,        67.00     ,                63.00     ,        4.00    ,                6.3%
LinkedList     ,        1586.00   ,                1535.00   ,        51.00   ,                3.3%
MatMul         ,        239.00    ,                240.00    ,        1.00    ,                -0.4%
Memset         ,        53.00     ,                53.00     ,        0.00    ,                0.0%
MonteCarloE    ,        1243.00   ,                1242.00   ,        1.00    ,                0.1%
MonteCarloPi   ,        993.00    ,                1010.00   ,        17.00   ,                -1.7%
NBody          ,        44.00     ,                43.00     ,        1.00    ,                2.3%
Phonebook      ,        1416.00   ,                1402.00   ,        14.00   ,                1.0%
PrimeNum       ,        347.00    ,                351.00    ,        4.00    ,                -1.1%
Prims          ,        1556.00   ,                1523.00   ,        33.00   ,                2.2%
QuickSort      ,        103.00    ,                101.00    ,        2.00    ,                2.0%
R17315246      ,        1080.00   ,                1076.00   ,        4.00    ,                0.4%
RC4            ,        26.00     ,                25.00     ,        1.00    ,                4.0%
RIPEMD         ,        798.00    ,                767.00    ,        31.00   ,                4.0%
Rectangles     ,        1008.00   ,                972.00    ,        36.00   ,                3.7%
SmallPT        ,        1004.00   ,                1040.00   ,        36.00   ,                -3.5%
StrToInt       ,        795.00    ,                815.00    ,        20.00   ,                -2.5%
StringBuilder  ,        795.00    ,                858.00    ,        63.00   ,                -7.3%
StringWalk     ,        1233.00   ,                1322.00   ,        89.00   ,                -6.7%
Totals         ,        38274.00  ,                38145.00  ,        129.00  ,                0.3%
Walsh          ,        135.00    ,                140.00    ,        5.00    ,                -3.6%

Swift SVN r20569
2014-07-25 22:49:24 +00:00
Greg Parker
e473436383 [runtime] Remove workaround for Swift marker bit in ObjC class data.
arclite and libobjc now preserve this bit.


Swift SVN r20568
2014-07-25 22:49:12 +00:00
Dave Abrahams
71d8e16fbf [stdlib] bitwise assignments for NS_OPTIONS
Fixes <rdar://problem/17797711>

This is rather a kluge because of two other problems.  Having these
fixed would allow a cleaner solution:

<rdar://problem/17815538> synthesize an allZeros static var for
BitwiseOperationsType conformance of imported NS_OPTIONS

<rdar://problem/17815767> Adding three overloads to stdlib slows
Fibonacci by 18-19%

Swift SVN r20563
2014-07-25 22:05:08 +00:00
Dave Abrahams
b2ac0e32dd [stdlib] Concise operators for advance(i, +/-n)
Fixes <rdar://problem/17814560>.

Swift SVN r20561
2014-07-25 20:53:38 +00:00
Dave Abrahams
fedd70715d [stdlib] Add missing mode string to .gyb file
Swift SVN r20560
2014-07-25 20:53:36 +00:00
Dave Abrahams
7d30512409 [stdlib] Improved doc comments
Swift SVN r20557
2014-07-25 20:18:15 +00:00
Dmitri Hrybenko
9b1cf666c2 stdlib: add semantic requirements to the doc comments of Equatable and
Comparable


Swift SVN r20555
2014-07-25 18:43:46 +00:00
Dmitri Hrybenko
ed855afb68 stdlib/String: use the Unicode collation algorithm in String's and Character's conformance to Comparable
rdar://17498444


Swift SVN r20554
2014-07-25 18:32:36 +00:00
Dmitri Hrybenko
c52e9270b8 stdlib: fix grammar in doc comments
Swift SVN r20552
2014-07-25 18:28:01 +00:00
Dmitri Hrybenko
2470d2f439 stdlib: add doc comments for Equatable and Comparable
Swift SVN r20551
2014-07-25 18:21:51 +00:00
Chris Lattner
6d0934d33d Introduce a new 'renamed' modifier on unavailable attributes. This allows Xcode
to emit fixit's when we rename something, e.g.:

t.swift:6:9: error: 'float' has been renamed to Float
var y : float
        ^~~~~
        Float

Adopt this in the stdlib.



Swift SVN r20549
2014-07-25 18:00:37 +00:00
Doug Gregor
681059a089 Make CGFloat conform to Strideable but not RandomAccessIndex.
This brings CGFloat into line with changes recently made to the other
floating-point types. <rdar://problem/17758020>

Swift SVN r20548
2014-07-25 17:17:18 +00:00
Doug Gregor
505674484b Allow construction of CGFloat from the sized Int/UInt types and vice-versa.
Fixes <rdar://problem/17670817> (+ dupes).
Notably, we were also missing a UInt(CGFloat) initializer, which

Swift SVN r20547
2014-07-25 16:56:47 +00:00
Dmitri Hrybenko
089fd8d6ec stdlib/String: rename the function in one more place, follow-up for
r20543

Swift SVN r20544
2014-07-25 14:55:26 +00:00
Dmitri Hrybenko
c44b42c7aa stdlib/String: add a test that shows that equality comparison of strings
is performed according to the deterministic Unicode collation algorithm,
which allows us to use the hash of the NFD form.

rdar://17498444

Swift SVN r20543
2014-07-25 14:31:07 +00:00
Dmitri Hrybenko
eff383932c stdlib/Character: add Hashable conformance
Swift SVN r20539
2014-07-25 10:32:00 +00:00
Dmitri Hrybenko
fbcbd2e118 stdlib/Hashable: add a doc comment about hashValue/equality comparison
consistency requirement

Swift SVN r20538
2014-07-25 10:31:44 +00:00
John McCall
64aa0ea950 When instantiating a generic class, compensate for
unexpected forematter from the superclass.

This requires a pretty substantial shift in the
generic-metadata allocation/initialization dance
because (1) we can't allocate class metadata without
knowing what the superclass is and (2) the offset
from the metadata cache entry to the address point is
no longer determined solely by the metadata pattern.

While I'm making invasive changes to metadata, fix
two race conditions in metadata creation.  The first
is that we need to ensure that only one thread succeeds
at lazily creating a generic-metadata cache.  The second
is that we need to ensure that only one thread actually
attempts to create a particular metadata; any others
should block until the metadata is successfully built.

This commit finishes rdar://17776354.  LLDB will
need to adjust to the runtime-private metadata layout
changes.

Swift SVN r20537
2014-07-25 10:08:51 +00:00
Dmitri Hrybenko
a38b282a7b StdlibUnittest: move checkHashable to unit testing library, it is a
utility that is useful in general

Swift SVN r20536
2014-07-25 10:06:22 +00:00
Dmitri Hrybenko
9302423c3d stdlib/Character: trap when trying to construct a Character from more
than one grapheme cluster

Swift SVN r20535
2014-07-25 10:06:18 +00:00
Dmitri Hrybenko
aa929798d0 stdlib: eliminate an inconsistent overload of == on NSString that would
make == and != inconsistent in non-generic code, and that would not be
used at all in generic code.

Part of rdar://17498444

Swift SVN r20524
2014-07-24 22:38:41 +00:00
Dmitri Hrybenko
27cbb5a9d5 stdlib/String: change == to perform string comparison after NFD
normalization

There is still some obscure bug with != on NSString, probably caused by
an ill-thought overload somewhere.

Part of rdar://17498444

Swift SVN r20518
2014-07-24 21:36:01 +00:00
Dave Abrahams
e00e41af39 [stdlib] Remove String.compare()
This was added for benchmarking purposes, without the realization that
it conflicts with the NSString API we adopt when importing Foundation.
http://oleb.net/blog/2014/07/swift-strings/#comparing-strings describes
the problem.

Fixes <rdar://problem/17800504>

Swift SVN r20517
2014-07-24 21:29:48 +00:00
Dmitri Hrybenko
2324d843ec StdlibUnittest: demangle names in error output
Swift SVN r20515
2014-07-24 21:19:21 +00:00
Pete Cooper
b68de9d4c0 Update strideof in stdlib to call new strideof_nonzero.
This hides the call to max in the compiler and removes the control flow
associated with max.  The resulting -O3 performance is

2Sum           ,  1303.00   ,  1286.00   ,  17.00     ,        1.3%
Ackermann      ,  4077.00   ,  4498.00   ,  421.00    ,        -9.4%
DeltaBlue      ,  19473.00  ,  17265.00  ,  2208.00   ,        12.8%
Dictionary     ,  882.00    ,  817.00    ,  65.00     ,        8.0%
EditDistance   ,  1467.00   ,  1416.00   ,  51.00     ,        3.6%
ForLoops       ,  1998.00   ,  2014.00   ,  16.00     ,        -0.8%
Forest         ,  1125.00   ,  1055.00   ,  70.00     ,        6.6%
GlobalClass    ,  1633.00   ,  1640.00   ,  7.00      ,        -0.4%
Hash           ,  1634.00   ,  945.00    ,  689.00    ,        72.9%
Histogram      ,  1196.00   ,  1054.00   ,  142.00    ,        13.5%
Life           ,  71.00     ,  64.00     ,  7.00      ,        10.9%
LinkedList     ,  1573.00   ,  1573.00   ,  0.00      ,        0.0%
Memset         ,  5987.00   ,  273.00    ,  5714.00   ,        2093.0%
NBody          ,  208.00    ,  44.00     ,  164.00    ,        372.7%
Phonebook      ,  2193.00   ,  1486.00   ,  707.00    ,        47.6%
PrimeNum       ,  1093.00   ,  393.00    ,  700.00    ,        178.1%
Prims          ,  1710.00   ,  1712.00   ,  2.00      ,        -0.1%
QuickSort      ,  121.00    ,  112.00    ,  9.00      ,        8.0%
R17315246      ,  1109.00   ,  1273.00   ,  164.00    ,        -12.9%
RC4            ,  745.00    ,  63.00     ,  682.00    ,        1082.5%
Rectangles     ,  947.00    ,  1015.00   ,  68.00     ,        -6.7%
SmallPT        ,  1071.00   ,  1088.00   ,  17.00     ,        -1.6%
StringBuilder  ,  928.00    ,  799.00    ,  129.00    ,        16.1%
StringWalk     ,  1221.00   ,  1264.00   ,  43.00     ,        -3.4%
Totals         ,  54980.00  ,  43284.00  ,  11696.00  ,        27.0%
Walsh          ,  1215.00   ,  135.00    ,  1080.00   ,        800.0%

Swift SVN r20509
2014-07-24 18:44:42 +00:00
Pete Cooper
3590f4a896 Alignof can never return 0, so don't max against 1
Swift SVN r20507
2014-07-24 18:44:41 +00:00
Dmitri Hrybenko
c2adafc897 Revert "stdlib/String: change == to perform string comparison after NFD"
This breaks consistency between == comparison and hash value.

Swift SVN r20500
2014-07-24 17:28:40 +00:00
Dave Abrahams
4866705260 [stdlib] Fix typo in availability message
Swift SVN r20497
2014-07-24 17:15:15 +00:00