Skip to content

Commit

Permalink
Rename ErrorType to ErrorProtocol
Browse files Browse the repository at this point in the history
  • Loading branch information
gribozavr authored and Max Moiseev committed Dec 10, 2015
1 parent 99d3f96 commit feacbc4
Show file tree
Hide file tree
Showing 123 changed files with 1,121 additions and 1,118 deletions.
18 changes: 9 additions & 9 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
take an argument, which can be any value that conforms to the
``ErrorType`` protocol (described below).
``ErrorProtocol`` protocol (described below).

::

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

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

``ErrorType``
-------------
``ErrorProtocol``
-----------------

The Swift standard library will provide ``ErrorType``, a protocol with
The Swift standard library will provide ``ErrorProtocol``, 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 : ErrorType {
enum HomeworkError : ErrorProtocol {
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 ``ErrorType``. ``NSError`` and ``CFError`` themselves will also
conform to ``ErrorType``.
implement ``ErrorProtocol``. ``NSError`` and ``CFError`` themselves will also
conform to ``ErrorProtocol``.

The physical representation (still being nailed down) will make it
efficient to embed an ``NSError`` as an ``ErrorType`` and vice-versa. It
efficient to embed an ``NSError`` as an ``ErrorProtocol`` and vice-versa. It
should be possible to turn an arbitrary Swift ``enum`` that conforms to
``ErrorType`` into an ``NSError`` by using the qualified type name as the
``ErrorProtocol`` 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 @@ -213,7 +213,7 @@ implementing it in the future:
a major compatibility break.

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

- In the meanwhile, developers who must handle an Objective-C
Expand Down Expand Up @@ -1521,12 +1521,12 @@ allowed in a blocking context.
Error type
~~~~~~~~~~
The Swift standard library will provide ``ErrorType``, a protocol with
The Swift standard library will provide ``ErrorProtocol``, 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 : ErrorType {
enum HomeworkError : ErrorProtocol {
case Overworked
case Impossible
case EatenByCat(Cat)
Expand All @@ -1543,13 +1543,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 ``ErrorType``. ``NSError`` and ``CFError`` themselves will also
conform to ``ErrorType``.
implement ``ErrorProtocol``. ``NSError`` and ``CFError`` themselves will also
conform to ``ErrorProtocol``.
The physical representation (still being nailed down) will make it
efficient to embed an ``NSError`` as an ``ErrorType`` and vice-versa. It
efficient to embed an ``NSError`` as an ``ErrorProtocol`` and vice-versa. It
should be possible to turn an arbitrary Swift ``enum`` that conforms to
``ErrorType`` into an ``NSError`` by using the qualified type name as the
``ErrorProtocol`` 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 @@ -1806,9 +1806,9 @@ Let's wade into the details.
Error types
~~~~~~~~~~~
``NSError`` and ``CFError`` should implement the ``ErrorType`` protocol. It
``NSError`` and ``CFError`` should implement the ``ErrorProtocol`` protocol. It
should be possible to turn an arbitrary Swift ``enum`` that conforms to
``ErrorType`` into an ``NSError`` by using the qualified type name as the
``ErrorProtocol`` 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 @@ -2028,7 +2028,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 ``ErrorType`` values as necessary. With a
unwind exceptions to ``ErrorProtocol`` 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/Failable Initializers.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 (ErrorType, AnyObject) instead of a single ErrorType. But
returning a pair (ErrorProtocol, AnyObject) instead of a single ErrorProtocol. But
this would ripple changes throughout various SIL analyses, and require IRGen
to encode the pair return value in an efficient way.

Expand Down
10 changes: 5 additions & 5 deletions docs/SIL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3237,7 +3237,7 @@ container may use one of several representations:
* `init_existential_metatype`_
* `open_existential_metatype`_

- **Boxed existential containers**: The standard library ``ErrorType`` protocol
- **Boxed existential containers**: The standard library ``ErrorProtocol`` 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 @@ -3249,21 +3249,21 @@ 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 ``ErrorType`` protocol existential supports
interop is available, the ``ErrorProtocol`` 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 ErrorType, allocating a box and
// The slow general way to form an ErrorProtocol, allocating a box and
// storing to its value buffer:
%error1 = alloc_existential_box $ErrorType, $NSError
%error1 = alloc_existential_box $ErrorProtocol, $NSError
strong_retain %nserror: $NSError
store %nserror to %error1#1 : $NSError

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

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: ErrorType) {
init(error: ErrorProtocol) {
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: ErrorType? {
var error: ErrorProtocol? {
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: ErrorType)
case init(error: ErrorProtocol)
}

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: ErrorType)
case init(error: ErrorProtocol)
}

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 ErrorType existential values. They have an
indirect enum cases, and for ErrorProtocol 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 @@ -196,8 +196,8 @@ enum class SpecialProtocol: uint8_t {
None = 0,
/// The AnyObject protocol.
AnyObject = 1,
/// The ErrorType protocol.
ErrorType = 2,
/// The ErrorProtocol protocol.
ErrorProtocol = 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 @@ -352,8 +352,8 @@ class ASTContext {
/// specified string.
Identifier getIdentifier(StringRef Str) const;

/// Retrieve the declaration of Swift.ErrorType.
NominalTypeDecl *getExceptionTypeDecl() const;
/// Retrieve the declaration of Swift.ErrorProtocol.
NominalTypeDecl *getErrorProtocolDecl() 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 @@ -344,13 +344,13 @@ BUILTIN_SIL_OPERATION(IsUniqueOrPinned_native, "isUniqueOrPinned_native",
BUILTIN(Id, Name, Attrs)
#endif

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

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

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

#undef BUILTIN_RUNTIME_CALL
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 @@ -243,9 +243,9 @@ ERROR(cannot_convert_to_return_type_nil,sema,none,
"nil is incompatible with return type %0", (Type))

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


ERROR(cannot_convert_raw_initializer_value,sema,none,
Expand Down Expand Up @@ -1419,7 +1419,7 @@ ERROR(broken_equatable_requirement,sema_tcd,none,
ERROR(broken_hashable_requirement,sema_tcd,none,
"Hashable protocol is broken: unexpected requirement", ())
ERROR(broken_errortype_requirement,sema_tcd,none,
"ErrorType protocol is broken: unexpected requirement", ())
"ErrorProtocol protocol is broken: unexpected requirement", ())
ERROR(broken_int_hashable_conformance,sema_tcd,none,
"Int type is broken: does not conform to Hashable", ())
ERROR(broken_int_integer_literal_convertible_conformance,sema_tcd,none,
Expand Down Expand Up @@ -2179,7 +2179,7 @@ WARNING(no_throw_in_do_with_catch,sema,none,
ERROR(sugar_type_not_found,sema_tct,none,
"broken standard library: cannot find "
"%select{Array|Optional|ImplicitlyUnwrappedOptional|Dictionary|"
"ErrorType}0 type", (unsigned))
"ErrorProtocol}0 type", (unsigned))
ERROR(optional_intrinsics_not_found,sema_tct,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(BridgeErrorTypeToNSError,
"_bridgeErrorTypeToNSError")
FUNC_DECL(BridgeErrorProtocolToNSError,
"_bridgeErrorProtocolToNSError")

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(ErrorType)
PROTOCOL(ErrorProtocol)
PROTOCOL(OptionSetType)
PROTOCOL_(BridgedNSError)

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 @@ -1944,8 +1944,8 @@ enum class ExistentialTypeRepresentation {
Opaque,
/// The type uses a class existential representation.
Class,
/// The type uses the ErrorType boxed existential representation.
ErrorType,
/// The type uses the ErrorProtocol boxed existential representation.
ErrorProtocol,
};

/// The structure of existential type metadata.
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SIL/BridgedTypes.def
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ BRIDGING_KNOWN_TYPE(Swift, String)
BRIDGING_KNOWN_TYPE(ObjectiveC, ObjCBool)
BRIDGING_KNOWN_TYPE(Darwin, DarwinBoolean)
BRIDGING_KNOWN_TYPE(Swift, Bool)
BRIDGING_KNOWN_TYPE(Swift, ErrorType)
BRIDGING_KNOWN_TYPE(Swift, ErrorProtocol)

BRIDGE_TYPE(Foundation, NSString, Swift, String, true)
BRIDGE_TYPE(ObjectiveC, ObjCBool, Swift, Bool, false)
Expand Down
4 changes: 2 additions & 2 deletions include/swift/SIL/DynamicCasts.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ void emitIndirectConditionalCastWithScalar(
/// \brief Does the type conform to the _ObjectiveCBridgeable protocol.
bool isObjectiveCBridgeable(ModuleDecl *M, CanType Ty);

/// \brief Does the type conform to the _Error protocol.
bool isErrorType(ModuleDecl *M, CanType Ty);
/// \brief Does the type conform to ErrorProtocol.
bool isErrorProtocol(ModuleDecl *M, CanType Ty);
} // end namespace swift

#endif
Expand Down
1 change: 0 additions & 1 deletion include/swift/SIL/TypeLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ class TypeConverter {
#define BRIDGING_KNOWN_TYPE(BridgedModule,BridgedType) \
Optional<CanType> BridgedType##Ty;
#include "swift/SIL/BridgedTypes.def"
Optional<CanType> BridgedTypeErrorType;

const TypeLowering &getTypeLoweringForLoweredType(TypeKey key);
const TypeLowering &getTypeLoweringForUncachedLoweredType(TypeKey key);
Expand Down
6 changes: 3 additions & 3 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,16 +551,16 @@ NominalTypeDecl *ASTContext::getStringDecl() const {
}

CanType ASTContext::getExceptionType() const {
if (auto exn = getExceptionTypeDecl()) {
if (auto exn = getErrorProtocolDecl()) {
return exn->getDeclaredType()->getCanonicalType();
} else {
// Use Builtin.NativeObject just as a stand-in.
return TheNativeObjectType;
}
}

NominalTypeDecl *ASTContext::getExceptionTypeDecl() const {
return getProtocol(KnownProtocolKind::ErrorType);
NominalTypeDecl *ASTContext::getErrorProtocolDecl() const {
return getProtocol(KnownProtocolKind::ErrorProtocol);
}

NominalTypeDecl *ASTContext::getArrayDecl() const {
Expand Down
8 changes: 4 additions & 4 deletions lib/AST/ConformanceLookupTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,10 @@ void ConformanceLookupTable::expandImpliedConformances(NominalTypeDecl *nominal,
resolver->resolveInheritanceClause(cast<ExtensionDecl>(dc));
}

// An @objc enum that explicitly conforms to the ErrorType protocol also
// implicitly conforms to _ObjectiveCBridgeableErrorType, via the known
// protocol _BridgedNSError.
if (conformingProtocol->isSpecificProtocol(KnownProtocolKind::ErrorType) &&
// An @objc enum that explicitly conforms to the ErrorProtocol protocol
// also implicitly conforms to _ObjectiveCBridgeableErrorProtocol, via the
// known protocol _BridgedNSError.
if (conformingProtocol->isSpecificProtocol(KnownProtocolKind::ErrorProtocol) &&
isa<EnumDecl>(nominal) && nominal->isObjC() &&
cast<EnumDecl>(nominal)->hasOnlyCasesWithoutAssociatedValues()) {
ASTContext &ctx = nominal->getASTContext();
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1889,8 +1889,8 @@ bool NominalTypeDecl::derivesProtocolConformance(ProtocolDecl *protocol) const {
if (!knownProtocol)
return false;

// All nominal types can derive their ErrorType conformance.
if (*knownProtocol == KnownProtocolKind::ErrorType)
// All nominal types can derive their ErrorProtocol conformance.
if (*knownProtocol == KnownProtocolKind::ErrorProtocol)
return true;

if (auto *enumDecl = dyn_cast<EnumDecl>(this)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2588,7 +2588,7 @@ struct ASTNodeBase {};
}

Type checkExceptionTypeExists(const char *where) {
auto exn = Ctx.getExceptionTypeDecl();
auto exn = Ctx.getErrorProtocolDecl();
if (exn) return exn->getDeclaredType();

Out << "exception type does not exist in " << where << "\n";
Expand Down
Loading

0 comments on commit feacbc4

Please sign in to comment.