Skip to content

Commit

Permalink
[SE-0112] Rename ErrorProtocol to Error.
Browse files Browse the repository at this point in the history
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
  • Loading branch information
DougGregor committed Jul 12, 2016
1 parent fcd5d07 commit 823c24b
Show file tree
Hide file tree
Showing 257 changed files with 1,416 additions and 1,412 deletions.
2 changes: 1 addition & 1 deletion apinotes/Foundation.apinotes
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Classes:
SwiftName: NSDateInterval
SwiftBridge: DateInterval
- Name: NSError
SwiftBridge: Swift.ErrorProtocol
SwiftBridge: Swift.Error
Methods:
- Selector: 'setUserInfoValueProviderForDomain:provider:'
SwiftName: setUserInfoValueProvider(forDomain:provider:)
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/ErrorHandling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import TestsUtils

enum PizzaError : ErrorProtocol {
enum PizzaError : Error {
case Pepperoni, Olives, Anchovy
}

Expand Down
16 changes: 8 additions & 8 deletions docs/ErrorHandling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ Throwing an error

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

::

Expand Down Expand Up @@ -311,15 +311,15 @@ be marked ``throws``).

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

``ErrorProtocol``
``Error``
-----------------

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

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

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

Expand Down
20 changes: 10 additions & 10 deletions docs/ErrorHandlingRationale.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ implementing it in the future:
a major compatibility break.

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

- In the meanwhile, developers who must handle an Objective-C
Expand Down Expand Up @@ -1523,12 +1523,12 @@ allowed in a blocking context.
Error type
~~~~~~~~~~
The Swift standard library will provide ``ErrorProtocol``, a protocol with
The Swift standard library will provide ``Error``, a protocol with
a very small interface (which is not described in this proposal). The
standard pattern should be to define the conformance of an ``enum`` to
the type::
enum HomeworkError : ErrorProtocol {
enum HomeworkError : Error {
case Overworked
case Impossible
case EatenByCat(Cat)
Expand All @@ -1545,13 +1545,13 @@ techniques for that will work fine in the future.
Note that this corresponds very cleanly to the ``NSError`` model of an
error domain, an error code, and optional user data. We expect to
import system error domains as enums that follow this approach and
implement ``ErrorProtocol``. ``NSError`` and ``CFError`` themselves will also
conform to ``ErrorProtocol``.
implement ``Error``. ``NSError`` and ``CFError`` themselves will also
conform to ``Error``.
The physical representation (still being nailed down) will make it
efficient to embed an ``NSError`` as an ``ErrorProtocol`` and vice-versa. It
efficient to embed an ``NSError`` as an ``Error`` and vice-versa. It
should be possible to turn an arbitrary Swift ``enum`` that conforms to
``ErrorProtocol`` into an ``NSError`` by using the qualified type name as the
``Error`` into an ``NSError`` by using the qualified type name as the
domain key, the enumerator as the error code, and turning the payload
into user data.
Expand Down Expand Up @@ -1808,9 +1808,9 @@ Let's wade into the details.
Error types
~~~~~~~~~~~
``NSError`` and ``CFError`` should implement the ``ErrorProtocol`` protocol. It
``NSError`` and ``CFError`` should implement the ``Error`` protocol. It
should be possible to turn an arbitrary Swift ``enum`` that conforms to
``ErrorProtocol`` into an ``NSError`` by using the qualified type name as the
``Error`` into an ``NSError`` by using the qualified type name as the
domain key, the enumerator as the error code, and turning the payload
into user data.
Expand Down Expand Up @@ -2030,7 +2030,7 @@ other words, we should not use table-based unwinding.
Error propagation for universal errors should be handled by
table-based unwinding. ``catch`` handlers can catch both, mapping
unwind exceptions to ``ErrorProtocol`` values as necessary. With a
unwind exceptions to ``Error`` values as necessary. With a
carefully-designed interpretation function aimed to solve the specific
needs of Swift, we can avoid most of the code-size impact by shifting
it to the unwind tables, which needn't ever be loaded in the common
Expand Down
2 changes: 1 addition & 1 deletion docs/FailableInitializers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ self value looks like it should have been consumed but it wasn't.

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

Expand Down
6 changes: 3 additions & 3 deletions docs/GenericsManifesto.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ Generic parameters could be given the ability to provide default arguments, whic
```
public final class Promise<Value, Reason=Error> { ... }
func getRandomPromise() -> Promise<Int, ErrorProtocol> { ... }
func getRandomPromise() -> Promise<Int, Error> { ... }
var p1: Promise<Int> = ...
var p2: Promise<Int, Error> = p1 // okay: p1 and p2 have the same type Promise<Int, Error>
var p3: Promise = getRandomPromise() // p3 has type Promise<Int, ErrorProtocol> due to type inference
var p3: Promise = getRandomPromise() // p3 has type Promise<Int, Error> due to type inference
```

### Generalized `class` constraints
Expand Down Expand Up @@ -737,4 +737,4 @@ if let storedInE1 = e1 openas T { // T is a the type of storedInE1, a copy o
if storedInE1 == storedInE2 { ... } // okay: storedInT1 and storedInE2 are both of type T, which we know is Equatable
}
}
```
```
2 changes: 1 addition & 1 deletion docs/Lexicon.rst
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,4 @@ source code, tests, and commit messages. See also the `LLVM lexicon`_.
A compilation mode where all files in a module are compiled in a single
process. In this mode there is no `primary file`; all files are parsed,
type-checked, and optimized together at the SIL level. LLVM optimization
and object file generation may happen all together or in separate threads.
and object file generation may happen all together or in separate threads.
12 changes: 6 additions & 6 deletions docs/SIL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3415,7 +3415,7 @@ container may use one of several representations:
* `init_existential_metatype`_
* `open_existential_metatype`_

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

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

bb(%nserror: $NSError):
// The slow general way to form an ErrorProtocol, allocating a box and
// The slow general way to form an Error, allocating a box and
// storing to its value buffer:
%error1 = alloc_existential_box $ErrorProtocol, $NSError
%addr = project_existential_box $NSError in %error1 : $ErrorProtocol
%error1 = alloc_existential_box $Error, $NSError
%addr = project_existential_box $NSError in %error1 : $Error
strong_retain %nserror: $NSError
store %nserror to %addr : $NSError

// The fast path supported for NSError:
strong_retain %nserror: $NSError
%error2 = init_existential_ref %nserror: $NSError, $ErrorProtocol
%error2 = init_existential_ref %nserror: $NSError, $Error

init_existential_addr
`````````````````````
Expand Down
8 changes: 4 additions & 4 deletions docs/proposals/EnumStyle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ amounts of language sugar it's given, vends initializers corresponding to
init(success: Wrapped) {
self = .Success(success)
}
init(error: ErrorProtocol) {
init(error: Error) {
self = .Error(error)
}

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

enum Result<Wrapped> {
case init(success: Wrapped)
case init(error: ErrorProtocol)
case init(error: Error)
}

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

enum Result<Wrapped> {
case init(success: Wrapped)
case init(error: ErrorProtocol)
case init(error: Error)
}

enum List<Element> {
Expand Down
2 changes: 1 addition & 1 deletion docs/proposals/RemoteMirrors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Boxes
~~~~~

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

Expand Down
4 changes: 2 additions & 2 deletions include/swift/ABI/MetadataValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ enum class SpecialProtocol: uint8_t {
None = 0,
/// The AnyObject protocol.
AnyObject = 1,
/// The ErrorProtocol protocol.
ErrorProtocol = 2,
/// The Error protocol.
Error = 2,
};

/// Identifiers for protocol method dispatch strategies.
Expand Down
4 changes: 2 additions & 2 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ class ASTContext {
/// specified string.
Identifier getIdentifier(StringRef Str) const;

/// Retrieve the declaration of Swift.ErrorProtocol.
NominalTypeDecl *getErrorProtocolDecl() const;
/// Retrieve the declaration of Swift.Error.
NominalTypeDecl *getErrorDecl() const;
CanType getExceptionType() const;

/// Retrieve the declaration of Swift.Bool.
Expand Down
6 changes: 3 additions & 3 deletions include/swift/AST/Builtins.def
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,13 @@ BUILTIN_SIL_OPERATION(IsUniqueOrPinned_native, "isUniqueOrPinned_native",
BUILTIN(Id, Name, Attrs)
#endif

/// willThrow: ErrorProtocol -> ()
/// willThrow: Error -> ()
BUILTIN_RUNTIME_CALL(WillThrow, "willThrow", "n")

/// unexpectedError: ErrorProtocol -> ()
/// unexpectedError: Error -> ()
BUILTIN_RUNTIME_CALL(UnexpectedError, "unexpectedError", "")

/// errorInMain: ErrorProtocol -> ()
/// errorInMain: Error -> ()
BUILTIN_RUNTIME_CALL(ErrorInMain, "errorInMain", "")

/// IsOptionalType : T.Type -> Bool
Expand Down
8 changes: 4 additions & 4 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ ERROR(cannot_convert_to_return_type_nil,none,
"nil is incompatible with return type %0", (Type))

ERROR(cannot_convert_thrown_type,none,
"thrown expression type %0 does not conform to 'ErrorProtocol'", (Type))
"thrown expression type %0 does not conform to 'Error'", (Type))
ERROR(cannot_throw_nil,none,
"cannot infer concrete ErrorProtocol for thrown 'nil' value", ())
"cannot infer concrete Error for thrown 'nil' value", ())


ERROR(cannot_convert_raw_initializer_value,none,
Expand Down Expand Up @@ -1659,7 +1659,7 @@ ERROR(broken_equatable_requirement,none,
ERROR(broken_hashable_requirement,none,
"Hashable protocol is broken: unexpected requirement", ())
ERROR(broken_errortype_requirement,none,
"ErrorProtocol protocol is broken: unexpected requirement", ())
"Error protocol is broken: unexpected requirement", ())
ERROR(broken_int_hashable_conformance,none,
"Int type is broken: does not conform to Hashable", ())
ERROR(broken_int_integer_literal_convertible_conformance,none,
Expand Down Expand Up @@ -2501,7 +2501,7 @@ ERROR(recursive_enum_not_indirect,none,
ERROR(sugar_type_not_found,none,
"broken standard library: cannot find "
"%select{Array|Optional|ImplicitlyUnwrappedOptional|Dictionary|"
"ErrorProtocol}0 type", (unsigned))
"Error}0 type", (unsigned))
ERROR(optional_intrinsics_not_found,none,
"broken standard library: cannot find intrinsic operations on "
"Optional<T>", ())
Expand Down
4 changes: 2 additions & 2 deletions include/swift/AST/KnownDecls.def
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ FUNC_DECL(ForceBridgeFromObjectiveC,
"_forceBridgeFromObjectiveC")
FUNC_DECL(ConditionallyBridgeFromObjectiveC,
"_conditionallyBridgeFromObjectiveC")
FUNC_DECL(BridgeErrorProtocolToNSError,
"_bridgeErrorProtocolToNSError")
FUNC_DECL(BridgeErrorToNSError,
"_bridgeErrorToNSError")

FUNC_DECL(ForceBridgeFromObjectiveCBridgeable,
"_forceBridgeFromObjectiveC_bridgeable")
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/KnownProtocols.def
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ PROTOCOL(RawRepresentable)
PROTOCOL(Equatable)
PROTOCOL(Hashable)
PROTOCOL(Comparable)
PROTOCOL(ErrorProtocol)
PROTOCOL(Error)
PROTOCOL_(ErrorCodeProtocol)
PROTOCOL(OptionSet)
PROTOCOL_(BridgedNSError)
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ enum class ForeignRepresentableKind : uint8_t {
/// This type is representable in the foreign language via bridging.
Bridged,
/// This type is representable in the foreign language via bridging
/// of ErrorProtocol.
/// of Error.
BridgedError,
/// This type is representable in the foreign language via static
/// bridging code, only (which is not available at runtime).
Expand Down
4 changes: 2 additions & 2 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,8 @@ class alignas(1 << TypeAlignInBits) TypeBase {
bool isEmptyExistentialComposition();

/// Whether this is an existential composition containing
/// ErrorProtocol.
bool isExistentialWithErrorProtocol();
/// Error.
bool isExistentialWithError();

void dump() const LLVM_ATTRIBUTE_USED;
void dump(raw_ostream &os, unsigned indent = 0) const;
Expand Down
4 changes: 2 additions & 2 deletions include/swift/Reflection/ReflectionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class ReflectionContext
}

case MetadataKind::ErrorObject:
// ErrorProtocol boxed existential on non-Objective-C runtime target
// Error boxed existential on non-Objective-C runtime target
return nullptr;

default:
Expand Down Expand Up @@ -301,7 +301,7 @@ class ReflectionContext
return false;

// Now we need to skip over the instance metadata pointer and instance's
// conformance pointer for Swift.ErrorProtocol.
// conformance pointer for Swift.Error.
StoredPointer InstanceAddress = InstanceMetadataAddressAddress +
2 * sizeof(StoredPointer);

Expand Down
4 changes: 2 additions & 2 deletions include/swift/Reflection/TypeRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ class ProtocolTypeRef final : public TypeRef {
return MangledName == "Ps9AnyObject_";
}

bool isErrorProtocol() const {
return MangledName == "Ps13ErrorProtocol_";
bool isError() const {
return MangledName == "Ps5Error_";
}

const std::string &getMangledName() const {
Expand Down
4 changes: 2 additions & 2 deletions include/swift/Runtime/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -2345,8 +2345,8 @@ enum class ExistentialTypeRepresentation {
Opaque,
/// The type uses a class existential representation.
Class,
/// The type uses the ErrorProtocol boxed existential representation.
ErrorProtocol,
/// The type uses the Error boxed existential representation.
Error,
};

/// The structure of existential type metadata.
Expand Down
Loading

0 comments on commit 823c24b

Please sign in to comment.