Commit Graph

812 Commits

Author SHA1 Message Date
Doug Gregor
fcd5d07c20 [Grand renaming] Rename MachError constants to lowerCamelCase. 2016-07-12 10:53:52 -07:00
Doug Gregor
c78aa11278 [Foundation] Drop 'NS' from NSCocoaError. 2016-07-12 10:53:52 -07:00
Doug Gregor
419586b063 [SE-0112] Rename attemptRecovery(optionIndex:andThen:) to attemptRecovery(optionIndex:resultHandler:). 2016-07-12 10:53:52 -07:00
Doug Gregor
b86b8126a7 [SE-0112] Import an Objective-C error enum as a struct wrapping NSError.
A given Objective-C error enum, which is effectively an NS_ENUM that
specifies its corresponding error domain, will now be mapped to an
ErrorProtocol-conforming struct that wraps an NSError, much like
NSCocoaError does. The actual enum is mapped to a nested "Code"
enum. For example, CoreLocation's CLError becomes:

  struct CLError : ErrorProtocol {
    let _nsError: NSError
    // ...
   @objc enum Code : Int {
     case ...
   }
  }

This implements bullet (2) in the proposed solution of SE-0112, so
that Cocoa error types are mapped into structures that maintain the
underlying NSError to allow more information to be extracted from it.
2016-07-12 10:53:52 -07:00
Doug Gregor
b1777b194c [SE-0112] Teach MachError to store the underlying NSError.
The error code is now specified by MachErrorCode.
2016-07-12 10:53:52 -07:00
Doug Gregor
d3f077e46d [SE-0112] Teach POSIXError to store the underlying NSError.
The error code is now specified by POSIXErrorCode.
2016-07-12 10:53:52 -07:00
Doug Gregor
9b6e39e312 [SE-0112] Generalize _BridgedStoredNSError for all integer types.
This will get clearer when SE-0104 gets implemented and we can use the
Integer protocol.
2016-07-12 10:53:52 -07:00
Doug Gregor
9522d997ab [SE-0112] Make NSCustomError.errorDomain static.
The error domain is meant to identify the type; it cannot meaningfully vary.
2016-07-12 10:53:52 -07:00
Doug Gregor
5cd06305f9 [SE-0112] Make NSURLError embed its NSError.
This ensures that we don't lose information about the NSError when it
is bridged to NSError. Use this to expose information for common keys
in the NSURLError domain (NSURLErrorFailingURLErrorKey,
NSURLErrorFailingURLStringErrorKey,
NSURLErrorFailingURLPeerTrustErrorKey).

This is effectively part of bullet (4) in the proposed solution of
SE-0112, applied to NSURLError. There are a handful of other domains
that need this treatment as well.
2016-07-12 10:53:52 -07:00
Doug Gregor
4fd78234c4 [SE-0112] Retain the underlying NSError in NSCocoaError.
NSCocoaError was capturing only the code of a Cocoa error, making it
basically useless. Instead, capture the entire NSError, the code of
which is tracked by an nested, RawRepresentable type Code. Provide
typed accessors for the common keys in the Cocoa error domain, e.g.,
NSFilePathErrorKey, NSStringEncodingErrorKey, NSUnderlyingErrorKey,
and NSURLErrorKey, to make this type easier to use.

This is specifically an implementation of part (4) of the proposed
solution to SE-0112, which makes NSCocoaError more usable. It also
adds localizedDescription to ErrorProtocol.

However, it also introduces the infrastructure needed for importing
error enumeration types more smoothly, e.g., ErrorCodeProtocol
(underscored for now), the ~= operator for matching error codes, and
so on. In essence, NSCocoaError is the pattern that the importer will
follow.
2016-07-12 10:53:52 -07:00
Doug Gregor
0bcf4e6d05 [SE-0112] Sink RawRepresentable down into _BridgedNSError.
This is part of loosening _BridgedNSError up a bit, so it can work
with error types that directly embed an NSError instance.
2016-07-12 10:53:52 -07:00
Doug Gregor
a428452c3c [SE-0112] Implement ErrorProtocol.localizedDescription.
Provides a localized description for an error, using Cocoa's
error-handling logic. The first part of item (4) in SE-0112's proposed
solution.
2016-07-12 10:53:52 -07:00
Doug Gregor
b0f9317765 [SE-0112] Add error protocols LocalizedError, RecoverableError, CustomNSError
An error type can conform to one or more of these new protocols to
customize its behavior and representation. From an implementation
standpoint, the protocol conformances are used to fill in the
user-info dictionary in NSError to interoperate with the Cocoa
error-handling system.

There are a few outstanding problems with this implementation,
although it is fully functional:
  * Population of the userInfo dictionary is currently eager; we
  should use user info providers on platforms where they are
  available.
  * At present, the Swift dynamic casting machinery is unable to unbox a
  _SwiftNativeNSError when trying to cast from it to (e.g.) an
  existential, which makes it impossible to retrieve the
  RecoverableError from the NSError. Instead, just capture the original
  error---hey, they're supposed to be value types anyway!---and use that
  to implement the entry points for the informal
  NSErrorRecoveryAttempting protocol.

This is part (1) of the proposal solution.
2016-07-12 10:53:52 -07:00
Tony Parker
f9c1dd4386 Adopt the new indexing model for better perf in IndexSet
Concurrently with the development of struct IndexSet, the stdlib team
was busy reworking the way that all indexes in collections worked
(https://github.com/apple/swift-evolution/blob/master/proposals/0065-collections-move-indices.md).
Both efforts landed at basically the same time. We did the minimum
possible to adopt the new indexing model when IndexSet landed. This
change more correctly adopts the new model.

In summary, the new model has the Collection change the value of the
Index, instead of the Index changing the value on its own. Previously,
the Index had methods like successor(), but now the Collection has
methods like index(after:). This means that the index no longer has to
store a reference to the collection in many cases, which means that CoW
semantics can kick in far more often as the index is a dead simple model
object that just stores a bunch of integers. So basically, this change
moves all the logic for moving indexes from Index into IndexSet.

<rdar://problem/26269319> More fully adopt new indexing model for better performance in IndexSet
2016-07-08 14:15:49 -07:00
Tony Parker
b4e10dabad Fix a typo (thanks @KentaKudo) 2016-07-08 11:26:24 -07:00
Tony Parker
c2c1b8468a Add overloads for range types to IndexSet
The Swift 3 refactoring of the range type has led to its split into 4
different types. The IndexSet API should accept any of these as long as
they contain the element type (Int, which is inherently Countable). This
allows callers to use both the ... and ..< syntax, for example.

This commit also adds additional unit tests for some of the IndexSet
API, and turns a few methods with optional/default args into properties
or a method family, since otherwise callers would end up with an
ambigious method call as the range argument would have been defaulted to
nil.

<rdar://problem/26532614> Add overloads for range types to IndexSet
2016-07-08 10:17:03 -07:00
Dmitri Gribenko
ce94bd9cca Merge pull request #3268 from natecook1000/nc-scalarindex-nocore
[stdlib] Remove _StringCore from UnicodeScalarIndex
2016-07-07 17:41:36 -07:00
practicalswift
1c04dd113f Merge pull request #3384 from practicalswift/typo-fixes-20160707
[gardening] Fix recently introduced typos.
2016-07-07 19:22:38 +02:00
Tony Parker
443bb590f5 Add a workaround for MeasurementFormatter so it can use Measurement
Due to current language limitations (26607639), MeasurementFormatter's
stringFromMeasurement: is esentially useless when imported into Swift.
This workaround allows it to work as expected.

<rdar://problem/27173952> Workaround: MeasurementFormatter.string(from:
Measurement<Unit>) doesn't recognize subclasses of Unit
2016-07-07 09:57:54 -07:00
practicalswift
9a8bbe0014 [gardening] Fix recently introduced typos. 2016-07-07 13:14:25 +02:00
Tony Parker
b5db69ff24 Add a fix-it for bytes/mutableBytes, to help migrate from NSData to
struct Data.

<rdar://problem/26246299> Missing fixit for Data.bytes
2016-07-06 16:45:46 -07:00
Tony Parker
29baf4818d Add RangeReplaceableCollection conformance to struct Data.
This also addresses a TODO in the code, now that we can access the base
of a slice.
2016-07-06 16:05:25 -07:00
Mishal Shah
65a44b581a Update Foundation URL to use new name urlForResource -> url 2016-07-06 13:44:54 -07:00
Mishal Shah
23b646eed2 Update master to build with Xcode 8 beta 2, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs 2016-07-06 10:48:45 -07:00
Philippe Hausler
24ff368d4f [Foundation] Swift3 API naming feedback
Addresses the following issues:

rdar://problem/25992816 -[NSUserDefaults registerDefaults] is being imported as NSUserDefaults.register(), which is confusing
rdar://problem/26291437 UserDefaults has 'setURL(forKey:)' instead of 'set(_:forKey:)'
rdar://problem/26375229 FileManager overlay has old naming
rdar://problem/26090891 NSBundle methods that are overridden in the apinotes incorrectly handle the first argument pattern
rdar://problem/26271340 struct URL initializer for fileURLWithFileSystemRepresentation is incorrectly named'
rdar://problem/26443640 XMLDTDNode.Kind conflicts with XMLNode.Kind and should be renamed to XMLDTDNode.DTDKind
rdar://problem/26500390 registerUndoWithTarget in overlay not updated for new API names
rdar://problem/26653451 NSCoder encodeDataObject is misleading
rdar://problem/26653653 NSCoder decodeObjectOfClass is redundant
rdar://problem/26653694 NSCoder.decodeTopLevelObjectForKey does not follow naming guidelines
rdar://problem/26656299 SocketNativeHandle should be a hoisted type to SocketPort
https://bugs.swift.org/browse/SR-1903
2016-07-05 11:19:12 -07:00
Philippe Hausler
0db73cb80c Revert "[Foundation] Workaround for importer NS_REFINED_FOR_SWIFT failure in development environments"
This reverts commit 1bfd433d3e.
2016-07-05 11:19:12 -07:00
Nate Cook
2d75c12c2d [stdlib] Remove _StringCore reference from UnicodeScalarIndex
This removes the `_core` property from UnicodeScalarView.Index
and moves any remaining index-moving logic from the index to
the view in UnicodeScalarView and CharacterView.
2016-07-02 23:16:22 -05:00
Chris Lattner
45f2cfaaa0 Implement SE-0099, but where the migration diagnostics are left as warnings
for now.  I'll upgrade them to errors in a week or two to give downstream
projects a chance to update.
2016-07-02 15:44:57 -07:00
practicalswift
e78e7e4c3c [gardening] Fix recently introduced typos. 2016-06-23 16:42:48 +02:00
Philippe Hausler
c1ab18e3e7 [gardening] add .self to recent changes for struct Data 2016-06-22 13:11:11 -07:00
Tony Parker
7c0910a2ec Address review feedback 2016-06-22 09:55:59 -07:00
swift-ci
bd2091fd85 Merge pull request #3098 from austinzheng/az-gardening 2016-06-21 11:03:27 -07:00
Tony Parker
11e85d73a4 Add a new set of initializers to Data to aid efficiency and clarity when wrapping NSData.
addresses:
rdar://problem/26385078 Data() really needs a init(length:) and replaceBytes(in:withBytes:)
rdar://problem/26508250 Add more specific init method to Data to indicate keeping a ref type
2016-06-21 10:42:31 -07:00
Philippe Hausler
1bfd433d3e [Foundation] Workaround for importer NS_REFINED_FOR_SWIFT failure in development environments
This is just a work-around for the underlying importer failure tracked by <rdar://problem/26921178>
2016-06-21 10:28:18 -07:00
Austin Zheng
6d385b80ed [gardening] Adding .self suffixes to suppress warnings 2016-06-20 21:46:13 -07:00
Philippe Hausler
2a3787ed08 [Foundation] Fetching userInfo from notifications can cause leaks
<rdar://problem/26882026>
2016-06-20 15:51:28 -07:00
Tony Parker
9da8decff8 Merge pull request #3031 from discorev/patch-1
Correct Foundation Data initialiser to use Base64DecodingOptions
2016-06-20 15:37:30 -07:00
Philippe Hausler
07f0049e75 [Foundation] Override mutable copying for CharacterSet
Some mutation cases will cause the underlying copy on write cases to crash with a  _SwiftNSCharacterSet doesn't respond to -mutableCopyWithZone: failure.
Fixes Bugs:
https://bugs.swift.org/browse/SR-1782
<rdar://problem/26608216>
2016-06-20 08:02:08 -07:00
swift-ci
d68c6dcd6b Merge pull request #3069 from practicalswift/typo-fixes-20160619 2016-06-19 16:02:06 -07:00
practicalswift
4ae4e37b14 [gardening] Fix some spacing inconsistencies. 2016-06-19 21:38:59 +02:00
practicalswift
8d03ea1347 [gardening] Fix some recently introduced typos. 2016-06-19 21:28:36 +02:00
Dmitri Gribenko
5dd3ce9195 Merge pull request #3020 from modocache/sr-1738-add-swift-library-shared-static-args
[SR-1738] add_swift_library takes SHARED/STATIC arg
2016-06-18 15:38:57 -07:00
Brian Gesiak
328de9e280 [SR-1738] add_swift_library takes SHARED/STATIC arg
As a first step to allowing the build script to build *only*
static library versions of the stdlib, change `add_swift_library`
such that callers must pass in `SHARED`, `STATIC`, or `OBJECT_LIBRARY`.

Ideally, only these flags would be used to determine whether to
build shared, static, or object libraries, but that is not currently
the case -- `add_swift_library` also checks whether the library
`IS_STDLIB` before performing certain additional actions. This will be
cleaned up in a future commit.
2016-06-16 13:15:58 -04:00
Ollie Hayman
bf92f0c983 Corrected initialiser to use Base64DecodingOptions
Initialising with a base64 encoded string was using Base64EncodingOptions rather than Base64DecodingOptions - this means strings with unknown characters cannot be decoded properly as the .ignoreUnknownCharacters option is unavailable
2016-06-15 23:00:03 +01:00
practicalswift
b43a26f3ff [gardening] Remove invisible ^P 2016-06-15 22:54:11 +02:00
practicalswift
64b3c6c880 [gardening] Remove invisible ^H 2016-06-15 22:54:11 +02:00
practicalswift
223d8d63f7 [gardening] Use "\"" instead of "“" or "”". 2016-06-15 22:54:11 +02:00
practicalswift
dcab7e726f [gardening] Use "*" instead of "•" 2016-06-15 22:44:23 +02:00
practicalswift
cc47c70019 [gardening] Use "'" instead of "’". 2016-06-15 22:43:25 +02:00
Mishal Shah
87b7bcfd3e Update master to build with Xcode 8 beta 1, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-06-14 14:53:55 -07:00