Skip to content

Commit edd389a

Browse files
authored
Merge pull request #3459 from apple/nserror-bridging
Implement SE-0112: Improved NSError bridging
2 parents e9688dc + d53a2f6 commit edd389a

File tree

280 files changed

+4976
-2385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

280 files changed

+4976
-2385
lines changed

apinotes/Foundation.apinotes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Classes:
8989
SwiftName: NSDateInterval
9090
SwiftBridge: DateInterval
9191
- Name: NSError
92-
SwiftName: NSError
92+
SwiftBridge: Swift.Error
9393
Methods:
9494
- Selector: 'setUserInfoValueProviderForDomain:provider:'
9595
SwiftName: setUserInfoValueProvider(forDomain:provider:)

benchmark/single-source/ErrorHandling.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import TestsUtils
1414

15-
enum PizzaError : ErrorProtocol {
15+
enum PizzaError : Error {
1616
case Pepperoni, Olives, Anchovy
1717
}
1818

docs/ErrorHandling.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ Throwing an error
257257

258258
The ``throw`` statement begins the propagation of an error. It always
259259
takes an argument, which can be any value that conforms to the
260-
``ErrorProtocol`` protocol (described below).
260+
``Error`` protocol (described below).
261261

262262
::
263263

@@ -311,15 +311,15 @@ be marked ``throws``).
311311

312312
We expect to refine the ``catch`` syntax with usage experience.
313313

314-
``ErrorProtocol``
314+
``Error``
315315
-----------------
316316

317-
The Swift standard library will provide ``ErrorProtocol``, a protocol with
317+
The Swift standard library will provide ``Error``, a protocol with
318318
a very small interface (which is not described in this proposal). The
319319
standard pattern should be to define the conformance of an ``enum`` to
320320
the type::
321321

322-
enum HomeworkError : ErrorProtocol {
322+
enum HomeworkError : Error {
323323
case Overworked
324324
case Impossible
325325
case EatenByCat(Cat)
@@ -332,13 +332,13 @@ within that namespace, and optional values to attach to each option.
332332
Note that this corresponds very cleanly to the ``NSError`` model of an
333333
error domain, an error code, and optional user data. We expect to
334334
import system error domains as enums that follow this approach and
335-
implement ``ErrorProtocol``. ``NSError`` and ``CFError`` themselves will also
336-
conform to ``ErrorProtocol``.
335+
implement ``Error``. ``NSError`` and ``CFError`` themselves will also
336+
conform to ``Error``.
337337

338338
The physical representation (still being nailed down) will make it
339-
efficient to embed an ``NSError`` as an ``ErrorProtocol`` and vice-versa. It
339+
efficient to embed an ``NSError`` as an ``Error`` and vice-versa. It
340340
should be possible to turn an arbitrary Swift ``enum`` that conforms to
341-
``ErrorProtocol`` into an ``NSError`` by using the qualified type name as the
341+
``Error`` into an ``NSError`` by using the qualified type name as the
342342
domain key, the enumerator as the error code, and turning the payload
343343
into user data.
344344

docs/ErrorHandlingRationale.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ implementing it in the future:
215215
a major compatibility break.
216216

217217
- With some admitted awkwardness, external exceptions can be reflected
218-
into an ``ErrorProtocol`` - like model automatically by the catch
218+
into an ``Error`` - like model automatically by the catch
219219
mechanism.
220220

221221
- In the meanwhile, developers who must handle an Objective-C
@@ -1523,12 +1523,12 @@ allowed in a blocking context.
15231523
Error type
15241524
~~~~~~~~~~
15251525
1526-
The Swift standard library will provide ``ErrorProtocol``, a protocol with
1526+
The Swift standard library will provide ``Error``, a protocol with
15271527
a very small interface (which is not described in this proposal). The
15281528
standard pattern should be to define the conformance of an ``enum`` to
15291529
the type::
15301530
1531-
enum HomeworkError : ErrorProtocol {
1531+
enum HomeworkError : Error {
15321532
case Overworked
15331533
case Impossible
15341534
case EatenByCat(Cat)
@@ -1545,13 +1545,13 @@ techniques for that will work fine in the future.
15451545
Note that this corresponds very cleanly to the ``NSError`` model of an
15461546
error domain, an error code, and optional user data. We expect to
15471547
import system error domains as enums that follow this approach and
1548-
implement ``ErrorProtocol``. ``NSError`` and ``CFError`` themselves will also
1549-
conform to ``ErrorProtocol``.
1548+
implement ``Error``. ``NSError`` and ``CFError`` themselves will also
1549+
conform to ``Error``.
15501550
15511551
The physical representation (still being nailed down) will make it
1552-
efficient to embed an ``NSError`` as an ``ErrorProtocol`` and vice-versa. It
1552+
efficient to embed an ``NSError`` as an ``Error`` and vice-versa. It
15531553
should be possible to turn an arbitrary Swift ``enum`` that conforms to
1554-
``ErrorProtocol`` into an ``NSError`` by using the qualified type name as the
1554+
``Error`` into an ``NSError`` by using the qualified type name as the
15551555
domain key, the enumerator as the error code, and turning the payload
15561556
into user data.
15571557
@@ -1808,9 +1808,9 @@ Let's wade into the details.
18081808
Error types
18091809
~~~~~~~~~~~
18101810
1811-
``NSError`` and ``CFError`` should implement the ``ErrorProtocol`` protocol. It
1811+
``NSError`` and ``CFError`` should implement the ``Error`` protocol. It
18121812
should be possible to turn an arbitrary Swift ``enum`` that conforms to
1813-
``ErrorProtocol`` into an ``NSError`` by using the qualified type name as the
1813+
``Error`` into an ``NSError`` by using the qualified type name as the
18141814
domain key, the enumerator as the error code, and turning the payload
18151815
into user data.
18161816
@@ -2030,7 +2030,7 @@ other words, we should not use table-based unwinding.
20302030
20312031
Error propagation for universal errors should be handled by
20322032
table-based unwinding. ``catch`` handlers can catch both, mapping
2033-
unwind exceptions to ``ErrorProtocol`` values as necessary. With a
2033+
unwind exceptions to ``Error`` values as necessary. With a
20342034
carefully-designed interpretation function aimed to solve the specific
20352035
needs of Swift, we can avoid most of the code-size impact by shifting
20362036
it to the unwind tables, which needn't ever be loaded in the common

docs/FailableInitializers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ self value looks like it should have been consumed but it wasn't.
119119

120120
It is also difficult to encode this tri-state return for throwing initializers.
121121
One can imagine changing the try_apply and throw SIL instructions to support
122-
returning a pair (ErrorProtocol, AnyObject) instead of a single ErrorProtocol. But
122+
returning a pair (Error, AnyObject) instead of a single Error. But
123123
this would ripple changes throughout various SIL analyses, and require IRGen
124124
to encode the pair return value in an efficient way.
125125

docs/GenericsManifesto.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ Generic parameters could be given the ability to provide default arguments, whic
205205
```
206206
public final class Promise<Value, Reason=Error> { ... }
207207
208-
func getRandomPromise() -> Promise<Int, ErrorProtocol> { ... }
208+
func getRandomPromise() -> Promise<Int, Error> { ... }
209209
210210
var p1: Promise<Int> = ...
211211
var p2: Promise<Int, Error> = p1 // okay: p1 and p2 have the same type Promise<Int, Error>
212-
var p3: Promise = getRandomPromise() // p3 has type Promise<Int, ErrorProtocol> due to type inference
212+
var p3: Promise = getRandomPromise() // p3 has type Promise<Int, Error> due to type inference
213213
```
214214

215215
### Generalized `class` constraints
@@ -737,4 +737,4 @@ if let storedInE1 = e1 openas T { // T is a the type of storedInE1, a copy o
737737
if storedInE1 == storedInE2 { ... } // okay: storedInT1 and storedInE2 are both of type T, which we know is Equatable
738738
}
739739
}
740-
```
740+
```

docs/Lexicon.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,4 @@ source code, tests, and commit messages. See also the `LLVM lexicon`_.
266266
A compilation mode where all files in a module are compiled in a single
267267
process. In this mode there is no `primary file`; all files are parsed,
268268
type-checked, and optimized together at the SIL level. LLVM optimization
269-
and object file generation may happen all together or in separate threads.
269+
and object file generation may happen all together or in separate threads.

docs/SIL.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3415,7 +3415,7 @@ container may use one of several representations:
34153415
* `init_existential_metatype`_
34163416
* `open_existential_metatype`_
34173417

3418-
- **Boxed existential containers**: The standard library ``ErrorProtocol`` protocol
3418+
- **Boxed existential containers**: The standard library ``Error`` protocol
34193419
uses a size-optimized reference-counted container, which indirectly stores
34203420
the conforming value. Boxed existential containers can be ``retain``-ed
34213421
and ``release``-d. The following instructions manipulate boxed existential
@@ -3428,22 +3428,22 @@ container may use one of several representations:
34283428

34293429
Some existential types may additionally support specialized representations
34303430
when they contain certain known concrete types. For example, when Objective-C
3431-
interop is available, the ``ErrorProtocol`` protocol existential supports
3431+
interop is available, the ``Error`` protocol existential supports
34323432
a class existential container representation for ``NSError`` objects, so it
34333433
can be initialized from one using ``init_existential_ref`` instead of the
34343434
more expensive ``alloc_existential_box``::
34353435

34363436
bb(%nserror: $NSError):
3437-
// The slow general way to form an ErrorProtocol, allocating a box and
3437+
// The slow general way to form an Error, allocating a box and
34383438
// storing to its value buffer:
3439-
%error1 = alloc_existential_box $ErrorProtocol, $NSError
3440-
%addr = project_existential_box $NSError in %error1 : $ErrorProtocol
3439+
%error1 = alloc_existential_box $Error, $NSError
3440+
%addr = project_existential_box $NSError in %error1 : $Error
34413441
strong_retain %nserror: $NSError
34423442
store %nserror to %addr : $NSError
34433443

34443444
// The fast path supported for NSError:
34453445
strong_retain %nserror: $NSError
3446-
%error2 = init_existential_ref %nserror: $NSError, $ErrorProtocol
3446+
%error2 = init_existential_ref %nserror: $NSError, $Error
34473447

34483448
init_existential_addr
34493449
`````````````````````

docs/proposals/EnumStyle.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ amounts of language sugar it's given, vends initializers corresponding to
4040
init(success: Wrapped) {
4141
self = .Success(success)
4242
}
43-
init(error: ErrorProtocol) {
43+
init(error: Error) {
4444
self = .Error(error)
4545
}
4646

@@ -50,7 +50,7 @@ amounts of language sugar it's given, vends initializers corresponding to
5050
case .Error: return nil
5151
}
5252
}
53-
var error: ErrorProtocol? {
53+
var error: Error? {
5454
switch self {
5555
case .Success: return nil
5656
case .Error(let error): return error
@@ -76,7 +76,7 @@ I'd like to start discussion by proposing the following:
7676

7777
enum Result<Wrapped> {
7878
case init(success: Wrapped)
79-
case init(error: ErrorProtocol)
79+
case init(error: Error)
8080
}
8181

8282
Constructing a value of the case can then be done with the usual initializer
@@ -147,7 +147,7 @@ other kinds of initializer::
147147

148148
enum Result<Wrapped> {
149149
case init(success: Wrapped)
150-
case init(error: ErrorProtocol)
150+
case init(error: Error)
151151
}
152152

153153
enum List<Element> {

docs/proposals/RemoteMirrors.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Boxes
7777
~~~~~
7878

7979
These are used for heap-allocating mutable values captured in closures, for
80-
indirect enum cases, and for ErrorProtocol existential values. They have an
80+
indirect enum cases, and for Error existential values. They have an
8181
identifying isa pointer and reference count, but the isa pointer is shared by
8282
all boxes and thus does not describe the heap layout of the box.
8383

0 commit comments

Comments
 (0)