Commit Graph

83 Commits

Author SHA1 Message Date
Dave Abrahams
f07b42ee9a [stdlib] replace an assign with a swap
Theoretically, this should cut down retain/release traffic

Swift SVN r22957
2014-10-27 04:45:46 +00:00
Dave Abrahams
60e79b7560 [stdlib] Replace an unsafeBitCast
Swift SVN r22956
2014-10-27 04:45:45 +00:00
Dave Abrahams
f8f82a9061 [stdlib] ContiguousArrayBuffer: tiny logic cleanup
Swift SVN r22951
2014-10-26 21:37:40 +00:00
Dave Abrahams
6786969209 [stdlib] Introduce _SwiftDeferredNSArray
This is mostly just a renaming of _SwiftNativeNSArray, except that we
want to add another NSArray subclass for verbatim-bridged elements, so
we want a common base class.  _SwiftNativeNSArray is the name of that
new base class, to parallel the other _SwiftNativeNSXXX classes.

Swift SVN r22913
2014-10-24 15:48:48 +00:00
Dave Abrahams
418aa75eb2 [stdlib] Rename _NSSwiftXXX => _SwiftNativeNSXXX
...to better reflect the purpose of these classes

Swift SVN r22911
2014-10-24 15:48:46 +00:00
Dave Abrahams
4a1d2e67ec [stdlib] ContiguousArrayBuffer: truthful types
The buffer stored in a _ContiguousArrayBuffer<T> is not always
_ContiguousArrayStorage<T>.  It might in fact be the special empty
buffer class.

Swift SVN r22835
2014-10-20 05:13:21 +00:00
Dave Abrahams
b9bdbb87b6 Revert "[stdlib] ContiguousArrayBuffer: truthful types"
This reverts commit r22824, which I suspect of causing the
closure_multivalue failure at

Swift SVN r22834
2014-10-20 03:20:46 +00:00
Dave Abrahams
f765ffdc45 [stdlib] ContiguousArrayBuffer: truthful types
The buffer stored in a _ContiguousArrayBuffer<T> is not always
_ContiguousArrayStorage<T>.  It might in fact be the special empty
buffer class.

Swift SVN r22823
2014-10-18 04:49:00 +00:00
Dave Abrahams
69194280a7 [stdlib] Nix an unused protocol and rename another
Swift SVN r22791
2014-10-16 03:46:34 +00:00
Dave Abrahams
4bdb9462c7 [stdlib] ArrayBufferType: identity is base address
Buffer identity is only used by tests.  The switch to an identity
representation that accounts for the buffer length was actually
incorrect for the way many tests used it.

Swift SVN r22771
2014-10-15 20:27:57 +00:00
Dave Abrahams
ab69e26656 [stdlib] Actually run the ArrayCore test
Fixes rdar://problem/18646425

Running the test uncovered avoidable inefficiencies in Array copying, so
dispatch of _copyToNativeArrayBuffer was revamped.  It's reasonable to
expect some speedups from this.

Also, the internal Array API requestNativeBuffer was highly error prone
when the source was a Slice, because it could return an array buffer
that represented more than the entire slice.  That capability was
probably used for optimization once, but is no longer, and the error
prone API probably caused bugs, so it was reformed.

Swift SVN r22746
2014-10-15 03:24:47 +00:00
Dave Abrahams
2d850421bc [stdlib] Internalize HeapBuffer[Storage], OnHeap
They were never really useful to users, because their APIs were
insufficiently public.  They have been replaced with a single class,
ManagedBuffer<Value,Element>, which is really designed for user
consumption.

Swift SVN r22636
2014-10-09 21:45:44 +00:00
Dave Abrahams
1f38b125f4 [stdlib] Fix typos in sanity check strings
Swift SVN r22627
2014-10-09 18:25:24 +00:00
Dave Abrahams
add753905b [stdlib] Use a lifetime-managed "with" construct
...instead of an internal API that releases an UnsafeBufferPointer into the wild.

Swift SVN r22561
2014-10-07 01:08:35 +00:00
Dave Abrahams
41fe3896d8 [stdlib] Synchronization-free empty array buffer
Now that <rdar://problem/18540783> is fixed, we can stop allocating the
empty array buffer dynamically and go back to using the one that is
statically laid out in GlobalObjects.cpp, thereby avoiding the
atomic instructions required to make it threadsafe.

Swift SVN r22545
2014-10-06 18:40:06 +00:00
Dave Abrahams
eac8ca27f9 [stdlib] Use a universal empty array buffer
NFC, and no significant performance change expected.  This is part one
of a move to eliminate nil checks from the array implementation.

Swift SVN r22526
2014-10-05 17:55:11 +00:00
Dave Abrahams
b740ad0df9 Revert "[stdlib] Use a universal empty array buffer"
This reverts commit r22495, because it wroke havoc with SIL and the perf
test suite somehow.

Swift SVN r22499
2014-10-03 18:52:11 +00:00
Dave Abrahams
f2f068c3dc [stdlib] Use a universal empty array buffer
NFC, and no significant performance change expected.  This is part one
of a move to eliminate nil checks from the array implementation.

Swift SVN r22495
2014-10-03 16:01:50 +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
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
b095339da7 stdlib/Array: implement delayed bridging
rdar://18191358

Swift SVN r22071
2014-09-18 13:46:39 +00:00
Dmitri Hrybenko
0e7e60b50b Remove stale comment
Swift SVN r22069
2014-09-18 11:42:41 +00:00
Dmitri Hrybenko
e6e17ac7d4 stdlib: replace _CocoaArrayType with _SwiftNSArrayRequiredOverridesType
Swift SVN r21972
2014-09-16 12:53:00 +00:00
Dmitri Hrybenko
9b62c620a7 stdlib: remove implied default 'internal' access modifier
Swift SVN r21970
2014-09-16 11:14:38 +00:00
Dmitri Hrybenko
4cf865de73 stdlib: factor all _NSXXXBase classes to a single place
Swift SVN r21969
2014-09-16 11:13:06 +00:00
Dmitri Hrybenko
50d497c05f stdlib/Array: fix an issue in fast enumeration
Array did not initialize fast enumeration state if it was empty.
Surprisingly, this did not break code that is generated by Clang
currently.  (But as far as I understand fast enumeration, it may abort
the program because mutation pointer is null.)

Swift SVN r21940
2014-09-15 13:49:56 +00:00
Dmitri Hrybenko
4a1dfdb6ad stdlib/Array: remove default parameters in bridging routines, and
reorder function declarations

Swift SVN r21938
2014-09-15 07:08:09 +00:00
Dmitri Hrybenko
001db58bb1 stdlib: remove trailing whitespace and fix coding style
Swift SVN r21906
2014-09-12 13:23:21 +00:00
Dave Abrahams
09793716cb [stdlib] try to measure sequences before array-izing
When creating an array from a SequenceType not statically known to be a
CollectionType, don't neglect to pre-allocate based on its
underestimated count.

Swift SVN r21829
2014-09-10 03:21:14 +00:00
Andrew Trick
125846a213 Consider capacity >= mincapacity the _fastPath in requestUniqueMutableBackingBuffer.
This should allow us to better optimize repeated push/pop benchmarks.

I didn't notice a performance change at the time I did this. I'm just
putting it in as a hopefully obvious drive-by fix.

Swift SVN r21429
2014-08-23 01:31:07 +00:00
Arnold Schwaighofer
16e41ada77 Make Builtin.canBeClass return a tri-state
Replace the true/maybe state that Builtin.canBeClass was returning by a
tri-state (yes, no, maybe) allowing the optimizer to use the definite no
answer.  This removes the need of the sizeof check that we had in
isClassOrObjCExistential. It also removes the need to CSE this function since
in most cases we will be able to instantiate canBeClass to yes or no (vs maybe)
at compile time.

benchmark``````````````,``baserun0``,``optrun2``,``delta,``speedup
ClassArrayGetter```````,``988.00````,``337.00```,``644.00``,````````191.7%
DeltaBlue``````````````,``2429.00```,``1927.00``,``460.00``,````````23.9%
Dictionary`````````````,``1374.00```,``1231.00``,``129.00``,````````10.9%
Havlak`````````````````,``1079.00```,``911.00```,``124.00``,````````13.7%
Rectangles`````````````,``924.00````,``541.00```,``379.00``,````````70.1%

radar://16823238

Swift SVN r21331
2014-08-21 00:55:40 +00:00
Arnold Schwaighofer
dc001d3ece stdlib: Don't check overflow on UnsafePointers they are unsafe
This also reverts the commit "stdlib: Don't check for overflow in subscript accesses to
ContigousArrayBuffer" as removing the overflow check on all unsafe pointers has
the same effect.

Swift SVN r21220
2014-08-14 23:16:20 +00:00
Arnold Schwaighofer
70caa2e83e stdlib: Don't check for overflow in subscript accesses to ContigousArrayBuffer
We overflow checked the mulitplication in "a + sizeof(T) * i". This is not
necessary for ContingousArrayBuffer because this overflow check has happened
when we compute the size of the array during allocation of a native swift array
or a NSArray.

benchmark``````````````,``baserun0``,``optrun2``,``delta,``speedup
Memset`````````````````,``1184.00```,``487.00```,``698.00``,````````143.9%
QuickSort``````````````,``1299.00```,``1458.00``,``178.00``,````````-12.2%
SelectionSort``````````,``1027.00```,``814.00```,``213.00``,````````26.2%
StdlibSort`````````````,``1718.00```,``1587.00``,``127.00``,````````8.0%
Walsh``````````````````,``1160.00```,``1076.00``,``86.00```,````````8.1%
XorLoop````````````````,``1248.00```,``884.00```,``369.00``,````````42.0%

The  regression in quicksort is noise - i looked at the LLVM IR and the only
thing different in the graph is that we have removed the mulitplication with
overflow check (that is - we should be running faster). Same thing looking at
the assembly.

XorLoop and Memset speed up because we are now able to vectorize those loops.

Swift SVN r21218
2014-08-14 21:49:34 +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
Doug Gregor
a6a3e48d1e Work around inability to deserialize local typealiases <rdar://problem/17795074>.
Swift SVN r20491
2014-07-24 15:53:38 +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
Dmitri Hrybenko
b46f1fae25 stdlib: remove 'public' from two functions on underscored types
Swift SVN r20401
2014-07-23 15:28:01 +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
dfe2ba4d8d [stdlib] const-correct withUnsafePointer APIs
Fixes <rdar://problem/17364737>

Swift SVN r20329
2014-07-22 20:39:59 +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
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
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