Commit Graph

124 Commits

Author SHA1 Message Date
Doug Gregor
d42563291e Switch DictionaryLiteralConvertible over to an initializer requirement.
Swift SVN r22033
2014-09-17 19:42:31 +00:00
Dmitri Hrybenko
e6e17ac7d4 stdlib: replace _CocoaArrayType with _SwiftNSArrayRequiredOverridesType
Swift SVN r21972
2014-09-16 12:53:00 +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
cdbd3bae84 stdlib/Dictionary: remove workaround that is no longer needed
Swift SVN r21942
2014-09-15 14:08:56 +00:00
Dmitri Hrybenko
d7acb06c64 stdlib/Dictionary: use 'delayed bridging' to keep pointers, returned
from a bridged NSDictionary, stable

We used to return a fresh pointer value every time an NSDictionary
element is requested, but, unfortunately, our SDK has bugs.

Fixes rdar://18191358 for Dictionary.

Swift SVN r21905
2014-09-12 13:20:30 +00:00
Dmitri Hrybenko
1bac1e6855 stdlib/Dictionary: convert some 'var's to 'let's
Swift SVN r21835
2014-09-10 11:38:44 +00:00
Dave Abrahams
a45cb59747 [stdlib] Eliminate some gratuitous @objc labels
Swift SVN r21511
2014-08-28 02:03:31 +00:00
Dave Abrahams
18dac28aea [stdlib] Eliminate HeapBufferStorageBase
It's just needless complexity

Swift SVN r21508
2014-08-28 01:41:43 +00:00
Dmitri Hrybenko
001c00fb44 stdlib/Dictionary: add a doc comment for _DictionaryBuilder
Swift SVN r21456
2014-08-26 11:33:06 +00:00
Dmitri Hrybenko
3e5154b23a stdlib: fix typo in private API name
Swift SVN r21431
2014-08-23 18:21:36 +00:00
Dave Abrahams
6c07fb4ad1 [stdlib] Revert UnsafePointer casting change
The syntax being reverted added busywork and noise to the common case
where you want to say "I have the right address, but the wrong type,"
without adding any real safety.

Also it eliminated the ability to write UnsafePointer<T>(otherPointer),
without adding ".self" to T.  Overall, it was not a win.

This reverts commits r21324 and r21342

Swift SVN r21424
2014-08-22 21:53:12 +00:00
Dmitri Hrybenko
18bbf0dfef stdlib/Dictionary: implement fast enumartion for NSEnumerator of
bridged Swift.Dictionary; this allows us to autorelease less.

rdar://17944094


Swift SVN r21372
2014-08-21 20:28:28 +00:00
Dmitri Hrybenko
9404f1c055 Dictionary: in fast enumeration, don't autorelease objects that Dictionary has
a strong reference to.

rdar://17944094


Swift SVN r21368
2014-08-21 18:05:06 +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
Dave Abrahams
1fb0f889d7 [stdlib] Make UnsafePointer conversions explicit
Previously, it was possible to write Unsafe[Mutable]Pointer(x) and have
Swift deduce the pointee type based on context.  Since reinterpreting
memory is a fundamentally type-unsafe operation, it's better to be
explicit about conversions from Unsafe[Mutable]Pointer<T> to
Unsafe[Mutable]Pointer<U>.  This change is consistent with the move from
reinterpretCast(x) to unsafeBitCast(x, T.self).

Also, we've encoded the operations of explicitly adding or removing
mutability as properties, so that adding mutability can be separated
from wild reinterpretCast'ing, a much more severe form of unsafety.

Swift SVN r21324
2014-08-20 23:15:56 +00:00
Dmitri Hrybenko
3a04e0809f stdlib: add a function to squeeze a number in a given range from a hash value
This function mixes the bits in the hash value, which improves Dictionary
performance for keys with bad hashes.

PrecommitBenchmark changes with greater than 7% difference:

``````````Dictionary2`,```1456.00`,```1508.00`,```1502.00`,````624.00`,````607.00`,````592.00`,`864.00`,``145.9%
``````````Dictionary3`,```1379.00`,```1439.00`,```1408.00`,````585.00`,````567.00`,````552.00`,`827.00`,``149.8%
````````````Histogram`,````850.00`,````849.00`,````851.00`,```1053.00`,```1049.00`,```1048.00`,`199.00`,``-19.0%
````````````````Prims`,```1999.00`,```2005.00`,```2018.00`,```1734.00`,```1689.00`,```1701.00`,`310.00`,```18.4%
``````````StrSplitter`,```2365.00`,```2334.00`,```2316.00`,```1979.00`,```1997.00`,```2000.00`,`337.00`,```17.0%
```````````````TwoSum`,```1551.00`,```1568.00`,```1556.00`,```1771.00`,```1741.00`,```1716.00`,`165.00`,```-9.6%

Regressions are in benchmarks that use `Int` as dictionary key: we are just
doing more work than previously (hashing an `Int` was an identity function).

rdar://17962402


Swift SVN r21142
2014-08-12 12:02:26 +00:00
Nadav Rotem
4cf6181785 Replace @semantics("readonly") with @effects(readonly).
Swift SVN r21088
2014-08-07 07:22:18 +00:00
Dmitri Hrybenko
56473c34cd stdlib: change out-of-bounds subscripting traps on mirrors to be
_preconditionFailure()s.  Some of these checks are clearly redundant (for
example, the check of array subscript), but since we have no tests for
these traps (and reflection is not fast in general), I prefer to keep this
transformation as straightforward as possible.


Swift SVN r20971
2014-08-03 18:42:53 +00:00
Dmitri Hrybenko
5746e4e9ca stdlib: rename _fatalError to _sanityCheckFailure. Name similarity between
fatalError and _fatalError has caused some damage already, as some
memory-safety checks in Mirrors are _fatalErrors.


Swift SVN r20969
2014-08-03 15:20:37 +00:00
Dave Abrahams
9a13a7148b [stdlib] Consolidate bridging protocols
Squash _[Conditionally]BridgedToObjectiveC into one protocol.  This
change results in simpler bridging code with fewer dynamic protocol
conformance checks, and solves the nasty naming/semantics problem that
resulted from having _ConditionallyBridgedToObjectiveC refining
_BridgedToObjectiveC.

Also, rename things so they're more symmetrical and less confusing.

Swift SVN r20664
2014-07-29 01:30:27 +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
Doug Gregor
5fc8ac7fd1 Require the 'override' keyword for initializers that override designated initializers.
Swift SVN r20490
2014-07-24 15:38:33 +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
297c0a78f4 stdlib: coding style
Swift SVN r20484
2014-07-24 13:07:07 +00:00
Doug Gregor
1cc28d4f80 An initializer requirement can only be satisfied by a required class initializer in a non-final class.
This is part of eliminating the notion of non-inheritable
conformances. Fixes <rdar://problem/17408284>.

Swift SVN r20430
2014-07-23 22:16:38 +00:00
Dave Abrahams
00f9ca5eda [stdlib] Rename [_]elementStorage=>[_]baseAddress
Swift SVN r20342
2014-07-22 22:29:03 +00:00
Dave Abrahams
1438d617cd [stdlib] Rename ConstUnsafePointer=>UnsafePointer
Swift SVN r20318
2014-07-22 17:10:54 +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
Dmitri Hrybenko
2af9bc954a stdlib/Dictionary: underscore-prefix implementation details (even not
marked as public)

Swift SVN r20245
2014-07-21 08:31:32 +00:00
Dave Abrahams
3731a0d1d2 [stdlib] Deal with various zero-division scenarios
Primarily, this means becoming resilient to Builtin.strideof(x) == 0.
Pretty much the only way to get pointers and arrays to make sense is to
treat zero-sized elements as having a stride of 1, so we do that in our
wrapper for Builtin.strideof.  Other points include precondition checks
for radixes in number formatting.

Fixes <rdar://problem/17097768>

Swift SVN r20242
2014-07-21 05:21:22 +00:00
Jordan Rose
8f520414b7 [Accessibility] A private class cannot contain public methods.
There's no meaningful way in which these methods are public, since they
can't be accessed through any value of the type

<rdar://problem/17647878>

Swift SVN r20224
2014-07-20 17:26:24 +00:00
Dmitri Hrybenko
c4138bd192 stdlib/Dictionary: coding style, remove unneeded line breaks
Swift SVN r20080
2014-07-17 09:54:40 +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
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
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
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
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
Dmitri Hrybenko
54efce9aa5 stdlib/Dictionary bridging: optimize NSDictionary to Dictionary conversion
during eager bridging

rdar://17325454


Swift SVN r19808
2014-07-10 13:18:07 +00:00
Dmitri Hrybenko
0e59dcac1f stdlib/Dictionary bridging: don't wrap NSDictionary in Dictionary<K, V> when
either K or V is bridged non-verbatim

rdar://17325454


Swift SVN r19807
2014-07-10 12:02:22 +00:00
Dmitri Hrybenko
909d49495c stdlib/Dictionary: remove debug output that I accidentally committed
Swift SVN r19806
2014-07-10 11:33:35 +00:00
Dmitri Hrybenko
febc98d5a4 stdlib/Dictionary: change internal bridging interfaces so that wrong code (that
does not copy NSDictionary) looks wrong


Swift SVN r19804
2014-07-10 09:45:42 +00:00
Chris Lattner
5b49d59c57 Remove the @ from @final and @lazy, the last major piece of
rdar://17168115.

Also, reinstate the ARM driver change and testcase that I removed
in my last patch.


Swift SVN r19790
2014-07-10 06:23:27 +00:00
Dmitri Hrybenko
f0621d1563 stdlib/Dictionary: eliminate invalid reinterpret casts
rdar://17509909


Swift SVN r19727
2014-07-09 16:03:46 +00:00
Dmitri Hrybenko
0523fea01b stdlib/Dictionary: rewrite iteration over wrapped NSDictionary not to
rely on NSDictionary.allKeys, it leaves the array of keys on the
autorelease pool.  Not very bad, but it is better if we can avoid it.

rdar://17604820

Swift SVN r19724
2014-07-09 14:49:49 +00:00
Chris Lattner
02999cac51 Reinstate the @ on the @objc attribute. This is largely a revert of r19555 with a few tweaks.
Swift SVN r19706
2014-07-08 21:50:34 +00:00
Dmitri Hrybenko
95ac813af3 stdlib/Dictionary: coding style, comments, renamed type generic parameters
Swift SVN r19687
2014-07-08 16:48:11 +00:00
Dmitri Hrybenko
4556f92949 stdlib/Dictionary: comments, coding style, more semantic _sanityChecks
Swift SVN r19684
2014-07-08 14:49:39 +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