Commit Graph

56 Commits

Author SHA1 Message Date
Doug Gregor
bea1d3d9b3 Use dictionary type sugar in the standard library.
Swift SVN r19264
2014-06-26 22:26:58 +00:00
Joe Groff
8eec49e50c stdlib: Introduce a staging typealias for the itemsPtr of fast enumeration states.
We (correctly) import this as AutoreleasingUnsafePointer instead of UnsafePointer in the new regime, but need to stage out the old regime fully before switching over.

Swift SVN r19200
2014-06-26 00:21:20 +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
Ted Kremenek
58558fcca3 Rename 'succ' and 'pred' to 'successor' and 'predecessor' respectively.
This is motivated by <rdar://problem/17051606>.

This ends up renaming variables as well, which seems right for
consistency since we use "predicate" as variable name.

Swift SVN r19135
2014-06-24 19:27:19 +00:00
Enrico Granata
2ab2e6c07b Change the very cryptic "don't ask" to something more informative
Fixes <rdar://problem/16922703>



Swift SVN r19123
2014-06-24 01:50:02 +00:00
Doug Gregor
22dc55058e Make bridgeFromObjectiveC return non-optional.
Now that we use bridgeFromObjectiveCConditional to perform conditional
bridging, make bridgeFromObjectiveC handle forced bridging. For the
latter, deferred checking is acceptable.

Almost all of <rdar://problem/17319154>.


Swift SVN r19046
2014-06-20 13:15:41 +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
Chris Lattner
62cad3dce8 add a "..<" operator, which is an alias for ".." and switch the stdlib to use it.
Until I have a chance to update the testsuite, we'll accept both.



Swift SVN r18998
2014-06-19 05:42:29 +00:00
Doug Gregor
ff8fe8b150 Add forced downcasting entry points for dictionary, _dictionaryDownCast and _dictionaryBridgeFromObjectiveC.
Swift SVN r18953
2014-06-17 10:10:57 +00:00
Doug Gregor
2ccbcccc0a Rename Dictionary downcast entry points to include "Conditional".
s/_dictionaryCheckedDownCast/_dictionaryDownCastConditional/g
s/_dictionaryBridgeFromObjectiveC/_dictionaryBridgeFromObjectiveCConditional/g


Swift SVN r18931
2014-06-16 15:35:18 +00:00
Doug Gregor
7acecc5457 Add a library entry point for Dictionary downcasting for bridged keys & values.
This is an inefficient, copying implementation of
_dictionaryBridgeToObjectiveC to aid progress on wiring up dictionary
downcasting <rdar://problem/16847470>. Making this implementation
efficient is tracked by <rdar://problem/16852016>.



Swift SVN r18897
2014-06-14 16:55:53 +00:00
Doug Gregor
2d4148796b Add a library entry point for Dictionary upcasting for object keys & values.
This is an inefficient, copying implementation of
_dictionaryCheckedDownCast to aid progress on wiring up dictionary
downcasting <rdar://problem/16847470>.  Making this implementation
efficient is tracked by <rdar://problem/16852016>.


Swift SVN r18896
2014-06-14 16:25:08 +00:00
Doug Gregor
47fbf0d166 Extend dictionary upcast support for handle mixed bridging/upcasting.
This allows dictionary upcasting where the key is bridged and the
value is not, or vice-versa. Finishes <rdar://problem/17289296>.


Swift SVN r18895
2014-06-14 15:48:12 +00:00
Doug Gregor
47748ba9aa Add stub implementations of the dictionary upcast entry points.
This introduces _dictionaryUpCast and _dictionaryBridgeToObjectiveC,
which will be used for upcasting for non-bridged and bridged key/value
types, respectively. _dictionaryUpCast is a horrible copying O(n)
implementation where we should be able to provide an O(1)
implementation, and _dictionaryBridgeToObjectiveC is similarly
awful. Hence, this is not for <rdar://problem/16852016>, but is merely
a stub to let us make progress on upcasting in the frontend
(<rdar://problem/17289296>).

Swift SVN r18867
2014-06-13 16:32:49 +00:00
Doug Gregor
5ca3882b06 Rename array upcast/bridge expressions to "collection".
This is staging for dictionary bridging upcasts.


Swift SVN r18840
2014-06-12 21:41:55 +00:00
Joe Groff
ac903bf943 IRGen: Make our use of spare bits in heap objects tagged-pointer-safe.
Don't use spare bits on platforms that use ObjC tagged pointers when an enum payload involves a class-constrained existential, archetype, or ObjC-defined class type. If a payload is of a Swift-defined class type, we can still assume it's a real pointer and use its spare bits. Add an @unsafe_no_objc_tagged_pointer attribute that can be applied to protocols to denote that existentials bounded by that protocol can use spare bits; this is necessary to preserve the layout of bridged Array and Dictionary types, which should not be bound to tagged pointer types in practice (fingers crossed). Fixes <rdar://problem/16270219>.

Swift SVN r18781
2014-06-10 17:07:47 +00:00
Manman Ren
aec78d0693 [stdlib] revert r18764.
Swift SVN r18765
2014-06-10 00:13:41 +00:00
Manman Ren
cc90c81239 [stdlib] add two-operand version of max and use max2 in stdlib when appropriate.
This helps array append's performance by ~ 2x. The generic max with a variadic
argument creates a temporary array then iterates over the array.

rdar://17140639 rdar://17073827


Swift SVN r18764
2014-06-09 23:56:40 +00:00
Dmitri Hrybenko
bd0c7f4651 stdlib/Dictionary: rename variables to match the new semantics. No public API
changes.


Swift SVN r18588
2014-05-23 09:09:51 +00:00
Dmitri Hrybenko
47bae74a59 stdlib/Dictionary: fix a bug in deletion
If we were deleting a key in the middle of a collision chain, and the tail of
the collision chain had keys whose ideal bucket was located before the hole
that we just created, we would mistakenly not relocate those keys.

rdar://16984824


Swift SVN r18562
2014-05-22 10:47:22 +00:00
John McCall
5ddee671b6 Provide a hacky hook for specifying a class's instance size
and alignment for the purposes of deallocation.

If a class contains a method named __getInstanceSizeAndAlignMask,
and it takes no arguments and returns a pair of words, call
that method directly in order to get the size and alignment
mask instead of trusting the class's formal size and alignment.

This is not a replacement for a proper language solution for
custom allocation, but it'll suffice to fix some immediate
problems with HeapBufferStorage.

If we decide we like this approach, we should really raise
the deallocating destructor up to SIL.

rdar://16979846

Swift SVN r18485
2014-05-21 07:22:39 +00:00
Joe Pamer
1d34a88477 Revert "Fix two problems with implicit conversions: - rdar://problem/16776273, wherein conversions between nil and .None were permitted due to an implicit conversion between nil and COpaquePointer. - rdar://problem/16877526, where we needed to add new equality overloads to handle conversions between nil and .None given the supression of user conversions. (Thanks to Ted for the overloads and test.)"
This reverts commit r18473.

Swift SVN r18477
2014-05-21 00:28:46 +00:00
Joe Pamer
f469d8f1f6 Fix two problems with implicit conversions:
- rdar://problem/16776273, wherein conversions between nil and .None were permitted
due to an implicit conversion between nil and COpaquePointer.
- rdar://problem/16877526, where we needed to add new equality overloads to handle
conversions between nil and .None given the supression of user conversions.
(Thanks to Ted for the overloads and test.)

Swift SVN r18473
2014-05-20 23:53:34 +00:00
Dmitri Hrybenko
bbf7b0af98 stdlib/Dictionary: add 'removeAll:' API
rdar://16953595

Swift SVN r18453
2014-05-20 14:52:01 +00:00
Dmitri Hrybenko
2bc1088de3 stdlib/Dictionary: finish removing the assumption that keys and values are
bridged back from Objective-C verbatim

The internal API assertingGet(KeyType) is dead code now, so no tests.


Swift SVN r18421
2014-05-19 14:56:32 +00:00
Dmitri Hrybenko
af11f8f8b7 stdlib/Dictionary: continue removing the assumption that keys and values are
bridged back from Objective-C verbatim

Fixes == operator.


Swift SVN r18420
2014-05-19 14:48:53 +00:00
Dmitri Hrybenko
0d20e71f51 stdlib/Dictionary: continue removing the assumption that keys and values are
bridged back from Objective-C verbatim

Fixes generate: API and DictionaryGenerator.


Swift SVN r18415
2014-05-19 11:48:44 +00:00
Dmitri Hrybenko
6d3026266f stdlib/Dictionary: continue removing the assumption that keys and values are
bridged back from Objective-C verbatim

Fixes removeValueForKey: API.


Swift SVN r18413
2014-05-19 11:33:25 +00:00
Dmitri Hrybenko
2aabfeaaca stdlib/Dictionary: remove comment that is no longer true
Swift SVN r18412
2014-05-19 11:21:07 +00:00
Dmitri Hrybenko
72354e8a47 stdlib/Dictionary: continue removing the assumption that keys and values are
bridged back from Objective-C verbatim

Fixes removeAtIndex: API.


Swift SVN r18411
2014-05-19 11:20:34 +00:00
Dmitri Hrybenko
c4492b4544 stdlib/Dictionary: continue removing the assumption that keys and values are
bridged back from Objective-C verbatim

Fixes subscript(KeyType) API.


Swift SVN r18409
2014-05-19 10:36:11 +00:00
Dmitri Hrybenko
785aabd53e stdlib/Dictionary: start removing the assumption that keys and values are
bridged back from Objective-C verbatim

Fixes subscript(Index) API.


Swift SVN r18408
2014-05-19 10:03:59 +00:00
Dave Abrahams
215da18af9 [stdlib] Publicize Map, add lazy map()
As declared, Dictionary's keys and values were private.  Instead of
hiding Map away as _Map, give it a "nice" verbose name and expose it
through a "nice" lowercase global function called map(), which we
overload so it works on both Collections and Sequences, returning a
Collection when that's what it started on.

We'll follow this pattern for filter, which was requested on Array.  The
implementation is easy once you have a lazy view!

Swift SVN r18340
2014-05-18 19:00:42 +00:00
Dmitri Hrybenko
948ddb3a39 Revert "Make 'maybeGet' and 'assertingGet' private API."
These are private APIs already because they are inside private types.


Swift SVN r18322
2014-05-18 14:01:24 +00:00
Ted Kremenek
a8c2b61cdb Always make 'allKeys' a property (coincides with Foundation).
Swift SVN r18305
2014-05-18 04:20:07 +00:00
Ted Kremenek
ef2d73fb16 Make 'maybeGet' and 'assertingGet' private API.
Swift SVN r18303
2014-05-18 04:07:20 +00:00
Ted Kremenek
16dea15a24 Hide CocoaArray ('_' to mark as private API).
Swift SVN r18302
2014-05-18 04:03:32 +00:00
Ted Kremenek
eab7f90a81 Per design discussion today, rename UnsafePointer ".pointee" to ".memory".
Swift SVN r18269
2014-05-17 20:35:16 +00:00
Dmitri Hrybenko
0d5b40a0e8 stdlib/Dictionary: s/removeObjectForKey/removeValueForKey/ per API review
emails


Swift SVN r18268
2014-05-17 20:15:40 +00:00
Dmitri Hrybenko
6a2192f76f stdlib/Dictionary: add doc comments for new APIs
Swift SVN r18267
2014-05-17 20:11:40 +00:00
Dmitri Hrybenko
d213355030 stdlib/Dictionary: address internal API review
Add 'removeObjectForKey:'


Swift SVN r18265
2014-05-17 19:47:48 +00:00
Dmitri Hrybenko
fbb9ed3729 stdlib/Dictionary: address internal API review
Add 'removeAtIndex:'


Swift SVN r18222
2014-05-16 22:42:09 +00:00
Arnold Schwaighofer
da6d9152b6 Differentiate between user assertion and preconditions and the like
assert() and fatalError()
These functions are meant to be used in user code. They are enabled in debug
mode and disabled in release or fast mode.

_precondition() and _preconditionFailure()
These functions are meant to be used in library code to check preconditions at
the api boundry. They are enabled in debug mode (with a verbose message) and
release mode (trap). In fast mode they are disabled.

_debugPrecondition() and _debugPreconditionFailure()
These functions are meant to be used in library code to check preconditions that
are not neccesarily comprehensive for safety (UnsafePointer can be null or an
invalid pointer but we can't check both). They are enabled only in debug mode.

_sanityCheck() and _fatalError()
These are meant to be used for internal consistency checks. They are only
enabled when the library is build with -DSWIFT_STDLIB_INTERNAL_CHECKS=ON.

I modified the code in the standard library to the best of my judgement.

rdar://16477198

Swift SVN r18212
2014-05-16 20:49:54 +00:00
Dmitri Hrybenko
92335b2f91 tdlib/Dictionary: address internal API review
Removed 'find:'
Added 'indexForKey:'


Swift SVN r18197
2014-05-16 16:03:56 +00:00
Dmitri Hrybenko
2c1715fe78 stdlib/Dictionary: address internal API review: preallocate storage when
creating a Dictionary from a dictionary literal

Also fixes rdar://16876745, because once the code moved to using lower-level
interfaces, it became trivial to detect duplicate keys without a performance
hit.


Swift SVN r18193
2014-05-16 14:41:03 +00:00
Dmitri Hrybenko
b054a086e8 stdlib/Dictionary: add some comments
Swift SVN r18192
2014-05-16 12:45:23 +00:00
Dmitri Hrybenko
70c062814a stdlib/Dictionary: address internal API review
Removed 'itemsAsArray'


Swift SVN r18190
2014-05-16 11:53:14 +00:00
Dmitri Hrybenko
9abf7a9fa3 stdlib/Dictionary: address internal API review requests
Removed 'add:value:'
Added 'updateValue:forKey:'


Swift SVN r18188
2014-05-16 11:37:25 +00:00
Dmitri Hrybenko
828acd2738 stdlib: hide _NSSwiftArray, _NSSwiftDictionary, _NSSwiftEnumerator
Swift SVN r18187
2014-05-16 08:29:17 +00:00