Commit Graph

109 Commits

Author SHA1 Message Date
Dave Abrahams
00f9ca5eda [stdlib] Rename [_]elementStorage=>[_]baseAddress
Swift SVN r20342
2014-07-22 22:29:03 +00:00
Dave Abrahams
e3f8d0e630 [stdlib] rename UnsafeArray => UnsafeBufferPointer
Also,

  UnsafeMutableArray => UnsafeMutableBufferPointer
  withUnsafeMutableStorage => withUnsafeMutableBufferPointer

Swift SVN r20340
2014-07-22 22:20:37 +00:00
Dave Abrahams
e570866bf6 [stdlib] On-demand unique contiguous Array storage
Lift the precondition that contiguous storage already exist on the use
of Array.withUnsafe[Mutable]PointerToElements.  Automatically guarantee
that storage is unique when using the mutable variants of these methods.

Also, fix some---essentially---inout aliasing violations in
test/stdlib/Unicode.swift that were revealed by the new careful
implementation of these methods.

Swift SVN r20339
2014-07-22 21:34:57 +00:00
Dave Abrahams
dfe2ba4d8d [stdlib] const-correct withUnsafePointer APIs
Fixes <rdar://problem/17364737>

Swift SVN r20329
2014-07-22 20:39:59 +00:00
Dave Abrahams
1a6c80a93d [stdlib] .first and .last are var:T?, not func->T
The global first() and last() algorithms return T?, nil when empty

All .first() and .last() methods became T? vars that are nil when the
Collection is empty

Swift SVN r20326
2014-07-22 19:30:42 +00:00
Dave Abrahams
21669b3aee [stdlib] Add "Mutable" to [Autoreleasing]UnsafePointer
UnsafePointer becomes UnsafeMutablePointer
AutoreleasingUnsafePointer becomes AutoreleasingUnsafeMutablePointer

Swift SVN r20316
2014-07-22 16:56:23 +00:00
Dave Abrahams
2c3ab47cf2 [stdlib] O(1) Array<non-verbatim> round-tripping
Arrays of non-verbatim-bridged types (such as Int, and today's String)
are converted to Objective-C lazily, with the objects created due to
element conversion being autoreleased when necessary.

Fixes <rdar://problem/17360154>

Note: test/SIL/Parser/array_roundtrip.swift was XFAIL'd;
see <rdar://problem/17758203>

Swift SVN r20293
2014-07-22 04:42:47 +00:00
Dave Abrahams
079b5e57ef [stdlib] += no longer appends array elements
+= only extends arrays with another sequence of the same element type.

Fixes <rdar://problem/17151420> The use of the overloaded += operator in
Swift is inconsistent and confusing with Arrays.

Note that this commits generated 3 new radars against the type checker:

  <rdar://problem/17751308>
  <rdar://problem/17750582>
  <rdar://problem/17751359>

Swift SVN r20274
2014-07-21 20:07:13 +00:00
Dave Abrahams
c9e55b48c4 [stdlib] Add first() and last() to Array types
Also, tests for the isEmpty property

<rdar://problem/16953693> part 2 of 3

Swift SVN r20238
2014-07-21 03:27:17 +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
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
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
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
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
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
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
19f3875079 stdlib/Array: remove === and !== for array types
Swift SVN r19725
2014-07-09 15:06:32 +00:00
Nadav Rotem
a227fcab6c Mark the Array and Dictionary builders with the readonly marker to allow removal of dead code.
Swift SVN r19678
2014-07-08 04:18:46 +00:00
Jordan Rose
da29f099f0 Update stdlib for accessibility modifiers becoming context-sensitive keywords.
Swift SVN r19672
2014-07-08 02:17:46 +00:00
Dmitri Hrybenko
b20abdfcbe stdlib: fix grammar in Array comments (they used to say 'a Array')
rdar://17075487


Swift SVN r19612
2014-07-07 15:31:11 +00:00
Dmitri Hrybenko
62c772ad6a stdlib: hide Objective-C bridging implementation details
Swift SVN r19595
2014-07-07 09:46:07 +00:00
Dave Abrahams
8db106ea17 [stdlib] Optimize Array member sort
Have it use withUnsafeMutableStorage just like the overloaded free
algorithm does.

Swift SVN r19533
2014-07-03 21:45:50 +00:00
Dave Abrahams
1f68ff48cc [stdlib] Detect/fix potential memory-safety issue
When a user violates the inout rules by "re-entering" an array that is
currently undergoing mutation, it must not admit a memory-safety
violation.  To ensure that it doesn't, temporarily make the buffer being
operated on inaccessible through the original array.

Swift SVN r19532
2014-07-03 21:44:49 +00:00
Dmitri Hrybenko
f7e926e5b0 stdlib/Arrays: refer to the parameter correctly.
Swift SVN r19460
2014-07-02 14:32:50 +00:00
Dmitri Hrybenko
db4fbb4f33 stdlib/Array: use monospaced text in a comment
Swift SVN r19459
2014-07-02 14:15:38 +00:00
Manman Ren
2b2330bf5b [attribute] rename @noinline to @inline(never).
Add support for parsing inline(never), it can be easily expanded to
handle inline(always).

rdar://17527111


Swift SVN r19447
2014-07-02 01:27:05 +00:00
Jordan Rose
f746b8c6dd [Accessibility] Public variables cannot have private types.
This does not yet handle variables with inferred types, since those don't
have TypePatterns.

There is some nasty propagation of @public into the stdlib because of this
one, mainly because Foundation needs access to some of the implementation
details of Array and Dictionary. We may want to try to improve this later
(or just build Foundation with -disable-access-control if it comes to that).

Swift SVN r19432
2014-07-01 22:30:53 +00:00
Jordan Rose
748efed913 [Accessibility] Protocol witnesses must be as accessible as the protocol.
...unless the type has less accessibility than the protocol, in which case
they must be as accessible as the type.

This restriction applies even with access control checking disabled, but
shouldn't affect any decls not already marked with access control modifiers.

Swift SVN r19382
2014-06-30 23:38:35 +00:00
Dave Abrahams
8e7d45f2c0 [stdlib] Normalize .gyb files
- Follow LLVM conventions for emacs mode specification

- Use local variables suffix to make the output read-only (at least on
  Emacs)

- But drop the admonitions not to edit the generated files;
  line-directive mostly takes care of that problem now.

Swift SVN r19381
2014-06-30 23:24:17 +00:00
Nadav Rotem
715565e4ea Rename a member function
Swift SVN r19364
2014-06-30 20:16:26 +00:00
Dave Abrahams
52c01c9ee4 [stdlib] Give filter() the lazy() treatment
Swift SVN r19359
2014-06-30 19:32:34 +00:00
Jordan Rose
5e59d30c6f Update stdlib for memberwise access control.
As before, there may be more things marked @public than we actually want
public. Judicious use of the frontend option -disable-access-control may
help reduce the public surface area of the stdlib.

Swift SVN r19353
2014-06-30 18:50:50 +00:00
Dave Abrahams
6b0d2f92f0 [stdlib] Give reverse() the lazy() treatment
This one shows the unfortunate consequence that we need
Lazy[Forward|Bidirectional|RandomAccess]Collection.  There's gonna be a
whole lotta gyb'bing going on...

Swift SVN r19316
2014-06-28 01:35:34 +00:00
Dave Abrahams
a7f6b97222 [stdlib] Introduce lazy() and use it for mapping
Swift SVN r19312
2014-06-28 00:35:43 +00:00
Joe Groff
cb48fbd24b Enable pointer conversions.
Swift SVN r19274
2014-06-26 23:26:31 +00:00
Dave Abrahams
c1539b3e5d [stdlib] Put the "unsafe" in withUnsafeMutableStorage
This API exposes unmediated access to memory, and most users will never
see the UnsafeArray argument that's passed to the closure, so best to be
explicit.

Swift SVN r19243
2014-06-26 18:22:54 +00:00
Dave Abrahams
1fb11d623b [stdlib] Remove _buffer requirement from ArrayType
Until we get an optimizer pass to remove get/set pairs, passing a
property that is a protocol requirement as inout from generic code is
always going to cause an extra retain, causing many unintended Array
copies.

Because this dropped reference counts to 1 in some cases, it exercised
previously-untested code paths and uncovered bugs, particularly in the
handling of subrange replacement on Slice<T>.

There are still differences in speed for short arrays of CGPoint that bear
investigation, but at least as things scale up, the ratio of time goes
to 1.

Fixes <rdar://problem/17040913> append and += on an array have
completely different performance

Swift SVN r19228
2014-06-26 08:54:07 +00:00
Dave Abrahams
321d608935 [stdlib] 80-column / endline layout fix
Swift SVN r19227
2014-06-26 08:53:50 +00:00
Dave Abrahams
d1aa6fe2b8 [stdlib] Rename Array internals for clarity
Because _demandUniqueMutableBuffer returns nil if the buffer already
exists, rename to _createUniqueMutableBuffer.

Because _requestUniqueMutableBuffer may return native backing storage
for a slice whose bounds don't exactly match the backing storage, rename
to _requestUniqueMutableBackingBuffer

Swift SVN r19214
2014-06-26 01:49:54 +00:00
Dave Abrahams
f146b40401 [stdlib] 80-column fix
Swift SVN r19213
2014-06-26 01:49:53 +00:00
Doug Gregor
37df5c430c Update standard library to use [T] array syntax.
Swift SVN r19190
2014-06-25 23:39:20 +00:00
Manman Ren
544cd15eb9 [stdlib] add noinline on makeUnique.
Swift SVN r19174
2014-06-25 18:39:49 +00:00
Nadav Rotem
a3d2883887 Refactor the makeUnique parts of array subscript outside of the closure. We inline this closure with the new pass order.
Swift SVN r19164
2014-06-25 17:13:50 +00:00
Joe Groff
87dd6ed419 stdlib: Add #ifs to help stage in pointer conversions.
Hide the bridged C*Pointer types if the stdlib is built with -DENABLE_POINTER_CONVERSIONS as a temporary transition aid.

Swift SVN r19159
2014-06-25 16:37:25 +00:00
Jordan Rose
cca27d02a0 Tag everything in the standard library with accessibility attributes.
Keep calm: remember that the standard library has many more public exports
than the average target, and that this contains ALL of them at once.
I also deliberately tried to tag nearly every top-level decl, even if that
was just to explicitly mark things @internal, to make sure I didn't miss
something.

This does export more than we might want to, mostly for protocol conformance
reasons, along with our simple-but-limiting typealias rule. I tried to also
mark things private where possible, but it's really going to be up to the
standard library owners to get this right. This is also only validated
against top-level access control; I haven't fully tested against member-level
access control yet, and none of our semantic restrictions are in place.

Along the way I also noticed bits of stdlib cruft; to keep this patch
understandable, I didn't change any of them.

Swift SVN r19145
2014-06-24 21:32:18 +00:00
Doug Gregor
fd62de4373 Use bridgeFromObjectiveCConditional where we want conditional bridging.
More of <rdar://problem/17319154>.


Swift SVN r19038
2014-06-20 07:41:50 +00:00
Michael Gottesman
8de060ff3f Revert "[stdlib] mask unused bits in uniqueness checks"
Revert "[stdlib] Use an enum for ArrayBuffer storage"

This reverts commit r18996.
This reverts commit r18954.

The optimizer is not ready yet to handle this change especially given
the time until Beta 3. After speaking with DaveA, we agreed to revert
this and take such large changes onto private branches until we are sure
that the optimizer is ready to handle them rather than risking
performance regressions due to hitting the "optimization cliff".

Swift SVN r19026
2014-06-20 01:41:04 +00:00
Dmitri Hrybenko
c4fd1c4092 stdlib: explain the trick used to achieve @noinline without @noinline
Swift SVN r19018
2014-06-19 23:53:09 +00:00