Commit Graph

146 Commits

Author SHA1 Message Date
Dmitri Hrybenko
50c99099ec Remove redundant semicolon
Swift SVN r22422
2014-10-01 06:31:25 +00:00
John McCall
1fa4f422ba Use mutable addressors for Array, now that doing so
doesn't prevent us from using a getter for immutable
accesses.

rdar://17270560

Swift SVN r22421
2014-10-01 05:20:43 +00:00
Dave Abrahams
c93f32a4b3 [stdlib] Eliminate needless intermediate class
Swift SVN r22415
2014-09-30 23:43:25 +00:00
Dave Abrahams
156020de19 [stdlib] Rename 'countElements' => 'count'
The name was not only long and unwieldy, but inconsistent with our
conscious decision to avoid the use of "elements" in APIs as mostly
redundant.

Swift SVN r22408
2014-09-30 22:00:26 +00:00
Joe Groff
c04992bf78 stdlib: Remove Array.convertFromHeapArray.
Swift SVN r22297
2014-09-26 04:27:19 +00:00
Joe Groff
9eb4f5b512 SILGen: Use Array._allocateUninitialized to form array literals.
This avoids a pointless copy every time an array literal is written, and will let us retire the horrible "alloc_array" instruction and globs of broken IRGen code. Implements rdar://problem/16386862, and probably fixes a bunch of bugs related to alloc_array brokenness.

Swift SVN r22289
2014-09-25 22:26:20 +00:00
Dmitri Hrybenko
42b9bf3e28 stdlib: use addressors in {ContiguousArray,Slice}.subscript(_: Int)
Swift SVN r22265
2014-09-24 14:38:23 +00:00
Dave Abrahams
a7f3e4222e [stdlib] finish public non-protocol docs
The 58 undocumented public non-operator APIs still present in core are
all on non-exposed (underscored) APIs.

Swift SVN r22263
2014-09-24 12:31:45 +00:00
Dave Abrahams
66d2ba43c6 [stdlib] underscore APIs made visible by r22212
That commit made a protocol public.  The protocol was underscored but
some of its APIs were not, and those became unintentionally publicly
visible.  This commit corrects that problem.  Since Builtin.RawPointer
properties were being renamed from "value" to "_rawValue" for clarity,
COpaquePointer got that treatment too, even though it wasn't strictly
necessary, for consistency.

Swift SVN r22252
2014-09-24 02:50:43 +00:00
Dave Abrahams
dbde275230 [stdlib] Propagate Reflectable docs
230 undocumented public non-operator APIs remain in core

Swift SVN r22236
2014-09-23 23:08:43 +00:00
Dave Abrahams
6bb89ae255 [stdlib] Propagate RangeReplaceableCollectionType docs
240 undocumented public non-operator APIs remain in core

Swift SVN r22235
2014-09-23 22:48:15 +00:00
Dave Abrahams
24fe53ed6c [stdlib] Propagate OutputStream docs
240 undocumented public non-operator APIs remain in core

Note: previous estimates were wrong because my regex was broken.  The
previous commit, for example, had 260 undocumented APIs.

Swift SVN r22234
2014-09-23 22:01:49 +00:00
Dave Abrahams
f5c80b115b [stdlib] Propagate ExtensibleCollectionType docs
184 undocumented public non-operator APIs remain in core

Swift SVN r22231
2014-09-23 21:13:45 +00:00
Dave Abrahams
7c9ebaa19f [stdlib] Propagate LiteralConvertible docs
219 undocumented public APIs remain in core

Swift SVN r22213
2014-09-23 11:12:39 +00:00
Dave Abrahams
f4a7812065 [stdlib] Propagate SequenceType docs to models
235 undocumented public APIs remain in core

Swift SVN r22210
2014-09-23 10:40:37 +00:00
Dave Abrahams
1dd7272fe9 [stdlib] Propagate CollectionType docs to models
266 undocumented public APIs remain in core

Swift SVN r22206
2014-09-23 08:19:23 +00:00
Dave Abrahams
40e9a0f859 [stdlib] Fix memory safety with evil collections
A collection whose count changes between traversals could cause a memory
safety problem, as we would measure the collection in one pass and
assume that it was the same length when actually initializing array
elements.  Fix that by always using the initial measurement, which
corresponds exactly to allocated memory.  If the collection wants to
trap because we've gone past its new bounds, that's fine.  If it
doesn't, at least we haven't done anything unsafe.

Swift SVN r22152
2014-09-20 03:35:23 +00:00
Dmitri Hrybenko
b64f6a48fa stdlib: attach documentation comments to array types
Swift SVN r22072
2014-09-18 14:04:15 +00:00
Dmitri Hrybenko
b095339da7 stdlib/Array: implement delayed bridging
rdar://18191358

Swift SVN r22071
2014-09-18 13:46:39 +00:00
Doug Gregor
3972316d25 Switch ArrayLiteralConvertible over to an initializer requirement.
Swift SVN r22024
2014-09-17 17:46:26 +00:00
Dmitri Hrybenko
e6e17ac7d4 stdlib: replace _CocoaArrayType with _SwiftNSArrayRequiredOverridesType
Swift SVN r21972
2014-09-16 12:53:00 +00:00
Dave Abrahams
213f59e546 [stdlib] doc-comment Arrays.swift.gyb
Swift SVN r21897
2014-09-12 00:35:09 +00:00
Erik Eckstein
962a50160a stdlib: Optimize convertion from array literal for Array
Replaced the general implementation (which works for all array types) to the obvious and trivial implementation for Array.
This speeds up array literal initialization by about 2x.



Swift SVN r21626
2014-09-01 08:21:13 +00:00
Nadav Rotem
9a495b56e5 Inline _arrayReplace into replaceRange.
The buffer argument of _arrayReplace was a protocol and it forced
all of the calls to that member to be virtually dispatched and generic.

This boosts DeltaBlue by 2X.

Swift SVN r21405
2014-08-22 06:56:22 +00:00
Dave Abrahams
1eba71e4e6 [stdlib] Doc comments and parameter naming, NFC
Fixes <rdar://problem/17998481>

Swift SVN r21204
2014-08-14 17:31:54 +00:00
Nadav Rotem
4cf6181785 Replace @semantics("readonly") with @effects(readonly).
Swift SVN r21088
2014-08-07 07:22:18 +00:00
Dave Abrahams
6edfddcc1f [stdlib] Remove obsolete _precondition check
Range now guarantees it won't be inverted.

Swift SVN r20948
2014-08-02 06:01:11 +00:00
Dave Abrahams
50aac71847 [stdlib] Arrays : RangeReplaceableCollectionType
Add the missing APIs and make the conformance complete

Swift SVN r20807
2014-07-31 02:54:27 +00:00
Dave Abrahams
ebcaab1e52 [stdlib/core] add Array init from _CocoaArrayType
Swift SVN r20698
2014-07-29 21:41:09 +00:00
Dave Abrahams
6d1f574089 [stdlib] Separate file for Array bridging/casting
This stuff will require a nice big comment and will go through several
rounds of cleanup; let's get it out of the regular Array flow.

Swift SVN r20642
2014-07-28 20:34:08 +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
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
Dave Abrahams
d00e888d95 [stdlib] Rename reinterpretCast => unsafeBitCast
Also give unsafeBitCast an explicit type parameter.  So

  let x: T = reinterpretCast(y)

becomes

  let x = unsafeBitCast(y, T.self)

Swift SVN r20487
2014-07-24 13:17:36 +00:00
Dave Abrahams
8f5180cf71 [stdlib] Add entry point for array literals
Array literal construction currently goes through an expensive dance;
Adding _allocateUninitialized will allow SILGen to do something much
smarter.

Swift SVN r20448
2014-07-23 23:46:02 +00:00
Andrew Trick
f36ff584cf Add array.init semantics.
This way, array optimization can see initialization as a copy of the
whole array value into a local variable, regardless of whether it's
from a factory method or Array initializer.

I'm making an assumption that when we return an Array by value, we
can't have an alias of the array buffer without retaining it.

Swift SVN r20444
2014-07-23 23:25:17 +00:00
Pete Cooper
e0add45e63 Add isInBounds to stdlib and use this for bounds checking on array subscript.
Ultimately this gets to HeapBuffer which checks the index is in range by separately checking whether the storage is nil, then the index is less than the count

Swift SVN r20363
2014-07-23 02:53:45 +00:00
Dave Abrahams
478c41fa3c [stdlib] Drop withUnsafe[Mutable]PointerToElements
Now that arrays have withUnsafe[Mutable]BufferPointer, and the buffer
pointers have a baseAddress property, this API is obsolete.

Swift SVN r20347
2014-07-22 23:04:45 +00:00
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