Commit Graph

675 Commits

Author SHA1 Message Date
Dave Abrahams
ec8b29cdf1 [stdlib] Fix the public interface of partition
It should not take the predicate as inout!

Swift SVN r20193
2014-07-19 00:35:45 +00:00
Joe Groff
c556d92ccd SILGen: Implement codegen for lvalue ForceValueExprs.
Add a set of _preconditionOptionalHasValue intrinsics that merely test that an optional has a case. Emit an lvalue ForceValueExpr as a physical lvalue, first asserting the precondition then projecting out the Some payload.

Swift SVN r20188
2014-07-18 22:49:49 +00:00
Dave Abrahams
71913ae085 [stdlib] Rename @semantics for array bounds checks
There are two kinds of bounds check: valid for subscripting, and valid
as an index.  Rename the semantics accordingly.

Swift SVN r20181
2014-07-18 20:54:26 +00:00
Enrico Granata
e4cfd3ae0a Reflect ranges in the half-open format - it's not always consistent with what the user typed, but at least it resembles language syntax, and is more consistent with what LLDB already does too. Last chunk of work for rdar://16117421
Swift SVN r20168
2014-07-18 18:26:17 +00:00
Dave Abrahams
3a90aaf8a3 [stdlib] Ensure full bounds checking for Array
Swift SVN r20132
2014-07-18 02:40:24 +00:00
Dave Abrahams
4d704c3574 Revert "[stdlib] Array resilient slicing"
We've decided resilience is wrong for Swift given current constraints;
see rdar://problem/11940897 for more detail.

This reverts commit r20052

Swift SVN r20127
2014-07-18 00:21:22 +00:00
Dave Abrahams
a84f46ca26 [stdlib] Add prefix/suffix functions on Sliceable
Also, improve comments in Collection.swift

Swift SVN r20125
2014-07-18 00:11:44 +00:00
Dave Abrahams
4e54fafb35 [stdlib] Fix symmetry of bounded advance()
It wasn't properly handling the cases where the bound was in the
opposite direction from the amount, when advancing random access
indices.

Swift SVN r20123
2014-07-18 00:11:43 +00:00
Dmitri Hrybenko
c4138bd192 stdlib/Dictionary: coding style, remove unneeded line breaks
Swift SVN r20080
2014-07-17 09:54:40 +00:00
Dmitri Hrybenko
4c4f83fb52 stdlib: underscore-prefix requirements of _BridgedToObjectiveCType and
_ConditionallyBridgedToObjectiveCType protocols

rdar://17283639


Swift SVN r20079
2014-07-17 09:42:19 +00:00
Dave Abrahams
e2d9f6f6a5 [stdlib] Fix clamp parameter name
Thanks, Jordan!

Swift SVN r20053
2014-07-16 22:33:01 +00:00
Dave Abrahams
304f27218b [stdlib] Array resilient slicing
Partially addresses <rdar://problem/11940897> #Seed 4: Slicing should
limit to valid slices

Swift SVN r20052
2014-07-16 22:27:09 +00:00
Dave Abrahams
3d61398376 [stdlib] Add clamp method to Interval
Swift SVN r20051
2014-07-16 22:16:26 +00:00
Dave Abrahams
c4f798e246 [stdlib] Make our BidirectionalIndexTypes Comparable
This will allow more error checking, resilient slicing, and occasionally
other useful capabilities.

Step 1 of <rdar://problem/11940897>

Swift SVN r20036
2014-07-16 20:43:42 +00:00
Dmitri Hrybenko
d125ac1e24 stdlib/runtime: stdlib casts to existentials: correctly project the buffer as
required

rdar://17628745


Swift SVN r20024
2014-07-16 15:17:46 +00:00
Mark Lacey
41643d0ef3 Revert "Remove @transparent from a few functions in the stdlib."
This reverts commit r19996.

I'll either fix <rdar://problem/17687851>, or work around it in a
different way.

Swift SVN r20020
2014-07-16 08:09:56 +00:00
Mark Lacey
36b035b93b Remove @transparent from a few functions in the stdlib.
Marking these generic functions as transparent results in our not
emitting diagnostics for unreachable code if these functions are the
only code in a block and inlining generic code is enabled (due to
<rdar://problem/17687851>).

I don't believe other diagnostics benefit in any way from having these
marked as @transparent, and removing @transparent actually improved
Ackerman at -O3 by 15%.

Swift SVN r19996
2014-07-16 01:22:59 +00:00
Enrico Granata
b730ab0da7 Add a Mirror for Interval types
Swift SVN r19983
2014-07-15 20:31:30 +00:00
Chris Lattner
3ad9c58c18 Disallow (with a nice fixit) the infix modifier on func decls, it is just validated
and ignored anyway.  It is still required on operator decls though.


Swift SVN r19978
2014-07-15 16:52:04 +00:00
Dave Abrahams
b5f682b4d3 [stdlib] @availability for renamed protocols
Swift SVN r19964
2014-07-14 23:09:09 +00:00
Chris Lattner
e0b0205cd7 Remove the @assignment attribute entirely. It doesn't do anything except
enforce its own little constraints.  The type checker isn't using it for
anything, and it is just clutter.

This resolves <rdar://problem/16656024> Remove @assignment from operator implementations



Swift SVN r19960
2014-07-14 22:44:25 +00:00
Doug Gregor
71cd9245ba Rename swift_stdlib_core -> swiftCore and swift_runtime -> swiftRuntime.
We can't use underscores in plists, so just makes the names consistent
<rdar://problem/17652418>.

Swift SVN r19954
2014-07-14 22:19:03 +00:00
Dave Abrahams
166ebb2996 [stdlib] Add Range pattern matching
But it doesn't work yet, pending rdar://17668465

Swift SVN r19946
2014-07-14 21:02:30 +00:00
Dave Abrahams
fa991ca164 [stdlib] deep debugDescription for Interval/Range
debugDescription on a type that represents its subparts should use
toDebugString() for their representations.

Swift SVN r19937
2014-07-14 17:53:25 +00:00
Chris Lattner
f0911fd4ed Update the .gyb file.
Swift SVN r19934
2014-07-14 17:13:36 +00:00
Chris Lattner
57cd2506ff Change "operator infix" to "infix operator" for consistency with the rest of the declaration
modifiers and with the func implementations of the operators.  This resolves the rest of:
<rdar://problem/17527000> change operator declarations from "operator prefix" to "prefix operator" & make operator a keyword




Swift SVN r19931
2014-07-14 16:39:10 +00:00
Chris Lattner
8991456ff2 Switch infix/postfix/prefix to be declaration modifiers instead of attributes,
eliminating the @'s from them when used on func's.  This is progress towards
<rdar://problem/17527000> change operator declarations from "operator prefix" to "prefix operator" & make operator a keyword

This also consolidates rejection of custom operator definitions into one
place and makes it consistent, and adds postfix "?" to the list of rejected
operators.

This also changes the demangler to demangle weak/inout/postfix and related things
without the @.



Swift SVN r19929
2014-07-14 15:51:49 +00:00
Chris Lattner
d3ee7520fe remove the old .. operator.
Swift SVN r19926
2014-07-14 14:29:47 +00:00
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