Commit Graph

812 Commits

Author SHA1 Message Date
Maxim Moiseev
16b7de05a3 Merge pull request #10376 from moiseev/foundation-string-extensions
[WIP][overlay] Port Foundation String extensions to StringProtocol
2017-07-13 14:50:47 -07:00
Jordan Rose
1e38b4b624 Merge pull request #10893 from jrose-apple/are-you-having-issues
[stdlib] Surface NSKeyedArchiver issues in Xcode.
2017-07-13 12:53:01 -07:00
Jordan Rose
fd3b585de0 [stdlib] Surface NSKeyedArchiver issues in Xcode.
By calling through to swift_reportToDebugger, Xcode can pick up the
NSKeyedArchiver/Unarchiver issues with Swift classes and display them
in the Issues Navigator. This increases the probability that they'll
be seen and acted upon.

This is not a fully-general interface yet, please do not start hooking
random things up to it. Especially if you're working on something that
doesn't ship with Xcode itself. :-)

rdar://problem/32900735
2017-07-13 11:19:03 -07:00
Dave Abrahams
69eb4d6fe2 Merge pull request #10785 from xwu/silence-warnings
[gardening] Silence compiler warnings [NFC]
2017-07-11 23:13:30 -07:00
Xiaodi Wu
075948c099 Explicitly discard result of NSDecimal operations 2017-07-10 17:11:42 -05:00
Itai Ferber
acadd6ca32 Merge pull request #10819 from itaiferber/encoders-eliminate-overlapping-exclusive-accesses
Remove overlapping exclusive accesses in encoders
2017-07-07 16:08:17 -07:00
Max Moiseev
1a0436e9c7 [overlay] Use RangeExpression whenever possible instead of Range 2017-07-07 15:34:56 -07:00
Max Moiseev
77edc65003 [overlay] Potentially better bridging to NSString in StringProtocol extensions 2017-07-07 15:34:56 -07:00
Max Moiseev
72479aca50 [overlay] Move static unavailable members back to String 2017-07-07 15:34:56 -07:00
Max Moiseev
5f1c3f7021 [overlay] Generalize Foundation StringProtocol extensions 2017-07-07 15:34:56 -07:00
Max Moiseev
fc0cf33bdc [overlay] Mark Foundation String slicing methods as deprecated 2017-07-07 15:34:56 -07:00
Max Moiseev
fe1ebdfc73 [overlay] Port Foundation extensions from String to StringProtocol 2017-07-07 15:34:08 -07:00
Xiaodi Wu
2c29408430 Merge branch 'master' into silence-warnings 2017-07-07 17:33:55 -05:00
Max Moiseev
f45c1888b6 [overlay] Move unavailable declarations to StringProtocol 2017-07-07 15:29:47 -07:00
Max Moiseev
b2b0dc42d4 [overlay] Extracting static string extensions 2017-07-07 15:29:46 -07:00
Dave Abrahams
076b2e115f Merge pull request #10814 from apple/index-interchange
Index interchange
2017-07-07 15:01:17 -07:00
Itai Ferber
18b523289d Remove overlapping exclusive accesses in encoders
{JSON,Plist}{Encoder,Decoder} had overlapping accesses which were supposed to be mutually exclusive in their `with(pushedKey:)` methods.

Removes those methods and the overlapping accesses.
2017-07-07 13:43:21 -07:00
Itai Ferber
b8dc826d41 Merge pull request #10766 from itaiferber/jsonencoder-conditional-conformance-workarounds
JSONEncoder conditional conformance workarounds
2017-07-07 13:20:54 -07:00
Dave Abrahams
9159239995 Un-revert "[stdlib] String index interchange, etc." (#10812)
I failed to merge the upstream changes to swift-corelibs-foundation at the same
time as I merged that #9806, and it broke on linux. Going to get it right this
time.
2017-07-07 12:13:25 -07:00
Xi Ge
d9fb110674 Revert "[stdlib] String index interchange, etc." (#10812)
rdar://33186295
2017-07-07 12:03:16 -07:00
Itai Ferber
9f7506f002 Allow application of JSON strategies in all cases
One of the limitations of not having conditional conformance at the
moment is that the implementation of `init(from:)` and `encode(to:)` on
types which require it is that failure to cast dependent types to
`Encodable` or `Decodable` is a runtime failure. There is no way to
statically guarantee that the wrapped type is `Encodable` or
`Decodable`.

As such, in those implementations, at best we can directly call
`(element as! Encodable).encode(to: encoder)`, or similar. However, this
encodes the element directly into an encoder, without giving the encoder
a chance to intercept the type. This is problematic for `JSONEncoder`
because it cannot apply a strategy if it doesn't get to intercept the
type.

This gives a temporary workaround for JSON strategies because of
internal Foundation knowledge.
2017-07-07 09:38:07 -07:00
Dave Abrahams
2e0bb2f533 [stdlib] String index interchange, part II (UTF16) 2017-07-07 06:15:23 -07:00
Dave Abrahams
e523c80339 [stdlib] Index interchange, part I 2017-07-07 00:59:04 -07:00
Philippe Hausler
56f509f059 [Foundation] Merge sequence initializer fast paths into one initializer 2017-07-06 19:24:17 -07:00
Philippe Hausler
a842c6d43d [Foundation] Update Data sequence initializer to use initialize(from:) and add _copyContents 2017-07-06 09:45:53 -07:00
Philippe Hausler
aeb61e361b [Foundation] Add fast paths for Data initialization for common sequences 2017-07-06 09:45:53 -07:00
Xiaodi Wu
590ce5314d Restore indentation (partially) 2017-07-06 00:15:17 -05:00
Xiaodi Wu
3528479730 Silence compiler warnings 2017-07-05 23:56:44 -05:00
Itai Ferber
e1007a2e3b Make coding paths non-optional
For the benefit of unkeyed containers, coding paths currently contain optional `CodingKey`s — unkeyed containers are allowed to report a `nil` key in a path. However, this is unhelpful for debugging purposes, or inspecting the coding path for context, since any unkeyed container simply reports `nil`, whether it’s at index 1 or 1000.

Now all containers are required to report a non-optional CodingKey for their segment of the coding path, and coding paths are now exposed as `[CodingKey]`.
2017-06-30 12:43:40 -07:00
Itai Ferber
aa91b7273d Merge pull request #10667 from itaiferber/codable-encode-decode-nil-changes
Optionality updates to Codable API
2017-06-29 13:15:25 -07:00
Itai Ferber
b40c0bd3db Merge pull request #10685 from itaiferber/codingerror-bridging-and-conveniences
EncodingError/DecodingError bridging fixes and conveniences
2017-06-29 10:05:35 -07:00
Itai Ferber
cf0ebc195d Expose underlying serialization errors
If JSONSerialization or PropertyListSerialization throw errors during encoding or decoding, the error should be exposed as an EncodingError or DecodingError
2017-06-28 15:10:19 -07:00
Itai Ferber
92fccf964b Fix coding error bridging to NSError
CustomNSError briding only works when the CustomNSError conformance is in the same module as the original error declaration. We need to sink these down into the standard library.
2017-06-28 14:33:15 -07:00
Itai Ferber
850b21f50d JSONEncoder data encoding strategy tweaks
* Add deferredToData strategy on encode and decode
* Rename base64{Encode,Decode} to base64 (missed this in previous fixes)
* Add unit test to confirm behavior
2017-06-28 14:17:23 -07:00
Itai Ferber
baca811820 Ensure values are decodable from nil
* Eliminate null checks from unboxing in the general case (so types
  can at least attempt to decode from nil)
* Add unit tests to confirm this behavior
2017-06-28 11:23:22 -07:00
Itai Ferber
692a893e16 Allow superDecoder to wrap null values
* Update {JSON,PropertyList}Decoder to allow superDecoder()s to wrap
  null value so current implementations of collections can decode
  contained objects from nil
2017-06-28 10:10:21 -07:00
Itai Ferber
bf1d2a745e Accessibility cleanup in {JSON,Plist}Encoder
To make it slightly easier to tell at a glance if a method is
implemented as part of API (public/open), shared implementation detail
(fileprivate), or implementation detail meaningful only to a given type
(private).
2017-06-28 10:10:21 -07:00
Itai Ferber
0a0e6b7397 Update PlistEncoder with proposed nil changes
* Add encodeNil/decodeNil variants on keyed and unkeyed containers
* Give implementations of decode() variants instead of decodeIfPresent()
2017-06-28 10:10:21 -07:00
Itai Ferber
f20d4425e5 Update JSONEncoder with proposed nil changes
* Add encodeNil/decodeNil variants on keyed and unkeyed containers
* Give implementations of decode() variants instead of decodeIfPresent()
2017-06-28 10:10:21 -07:00
Ian Partridge
ad2311d9e2 PropertyListEncoder: Typo in documentation of encode<Value>(Value) 2017-06-27 10:24:25 +01:00
Ian Partridge
399caebf11 JSONEncoder: Typo in documentation of encode<T>(T) 2017-06-27 10:18:08 +01:00
Philippe Hausler
e5504cdf15 [Foundation] slices of slices that use range expressions incorrectly calculated relative indexing 2017-06-26 16:35:40 -07:00
Itai Ferber
da27019800 Merge pull request #10539 from itaiferber/foundation-json-decimal
Encode Decimal as a numeric value in JSON
2017-06-23 15:41:51 -07:00
Itai Ferber
07d396b712 Encode Decimal as a numeric value in JSON
Allow JSONEncoder/JSONDecoder to intercept Decimal values so they get
a numeric representation in JSON (instead of their default keyed
implementation).
2017-06-23 13:02:13 -07:00
Itai Ferber
72d62af309 Merge pull request #10520 from itaiferber/foundation-shared-encoders
Allow Codable classes to share an Encoder with superclass
2017-06-23 12:48:09 -07:00
Itai Ferber
25fc3ed34f Merge pull request #10515 from itaiferber/nskeyedarchiver-data-overloads
Change NSKeyedUnarchiver method instead of adding overloads
2017-06-22 15:54:49 -07:00
Itai Ferber
184efb085c Allow classes to share an Encoder with superclass
On encode, we previously treated every container request as a push;
instead, we should allow the same container type to be requested
multiple times so a class can pass its Encoder directly to its
superclass if it needs to.
2017-06-22 15:45:02 -07:00
Itai Ferber
a5df6fa484 Change modified method instead of adding overloads
The unarchiveTopLevelObjectWithData which returns Any? (instead of
AnyObject?) was added in Swift 4 and has only shipped in the betas so
far. Instead of adding new overloads which take different types, we
should just fix this one and call it a day.
2017-06-22 14:23:21 -07:00
Philippe Hausler
d31ffc7d5e [Foundation] Validate indexes and ranges passed into Data so that bounding conditions are respected 2017-06-22 11:25:57 -07:00
Itai Ferber
004a98b76f Merge pull request #10474 from itaiferber/nskeyedarchiver-data-overloads
NSKeyedUnarchiver methods should take Data (instead of just NSData)
2017-06-22 10:44:54 -07:00