Skip to content

Commit feacbc4

Browse files
gribozavrMax Moiseev
authored and
Max Moiseev
committed
Rename ErrorType to ErrorProtocol
1 parent 99d3f96 commit feacbc4

File tree

123 files changed

+1121
-1118
lines changed

Some content is hidden

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

123 files changed

+1121
-1118
lines changed

docs/ErrorHandling.rst

Lines changed: 9 additions & 9 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
take an argument, which can be any value that conforms to the
260-
``ErrorType`` protocol (described below).
260+
``ErrorProtocol`` 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-
``ErrorType``
315-
-------------
314+
``ErrorProtocol``
315+
-----------------
316316

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

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

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

219219
- In the meanwhile, developers who must handle an Objective-C
@@ -1521,12 +1521,12 @@ allowed in a blocking context.
15211521
Error type
15221522
~~~~~~~~~~
15231523
1524-
The Swift standard library will provide ``ErrorType``, a protocol with
1524+
The Swift standard library will provide ``ErrorProtocol``, a protocol with
15251525
a very small interface (which is not described in this proposal). The
15261526
standard pattern should be to define the conformance of an ``enum`` to
15271527
the type::
15281528
1529-
enum HomeworkError : ErrorType {
1529+
enum HomeworkError : ErrorProtocol {
15301530
case Overworked
15311531
case Impossible
15321532
case EatenByCat(Cat)
@@ -1543,13 +1543,13 @@ techniques for that will work fine in the future.
15431543
Note that this corresponds very cleanly to the ``NSError`` model of an
15441544
error domain, an error code, and optional user data. We expect to
15451545
import system error domains as enums that follow this approach and
1546-
implement ``ErrorType``. ``NSError`` and ``CFError`` themselves will also
1547-
conform to ``ErrorType``.
1546+
implement ``ErrorProtocol``. ``NSError`` and ``CFError`` themselves will also
1547+
conform to ``ErrorProtocol``.
15481548
15491549
The physical representation (still being nailed down) will make it
1550-
efficient to embed an ``NSError`` as an ``ErrorType`` and vice-versa. It
1550+
efficient to embed an ``NSError`` as an ``ErrorProtocol`` and vice-versa. It
15511551
should be possible to turn an arbitrary Swift ``enum`` that conforms to
1552-
``ErrorType`` into an ``NSError`` by using the qualified type name as the
1552+
``ErrorProtocol`` into an ``NSError`` by using the qualified type name as the
15531553
domain key, the enumerator as the error code, and turning the payload
15541554
into user data.
15551555
@@ -1806,9 +1806,9 @@ Let's wade into the details.
18061806
Error types
18071807
~~~~~~~~~~~
18081808
1809-
``NSError`` and ``CFError`` should implement the ``ErrorType`` protocol. It
1809+
``NSError`` and ``CFError`` should implement the ``ErrorProtocol`` protocol. It
18101810
should be possible to turn an arbitrary Swift ``enum`` that conforms to
1811-
``ErrorType`` into an ``NSError`` by using the qualified type name as the
1811+
``ErrorProtocol`` into an ``NSError`` by using the qualified type name as the
18121812
domain key, the enumerator as the error code, and turning the payload
18131813
into user data.
18141814
@@ -2028,7 +2028,7 @@ other words, we should not use table-based unwinding.
20282028
20292029
Error propagation for universal errors should be handled by
20302030
table-based unwinding. ``catch`` handlers can catch both, mapping
2031-
unwind exceptions to ``ErrorType`` values as necessary. With a
2031+
unwind exceptions to ``ErrorProtocol`` values as necessary. With a
20322032
carefully-designed interpretation function aimed to solve the specific
20332033
needs of Swift, we can avoid most of the code-size impact by shifting
20342034
it to the unwind tables, which needn't ever be loaded in the common

docs/Failable Initializers.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 (ErrorType, AnyObject) instead of a single ErrorType. But
122+
returning a pair (ErrorProtocol, AnyObject) instead of a single ErrorProtocol. 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/SIL.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3237,7 +3237,7 @@ container may use one of several representations:
32373237
* `init_existential_metatype`_
32383238
* `open_existential_metatype`_
32393239

3240-
- **Boxed existential containers**: The standard library ``ErrorType`` protocol
3240+
- **Boxed existential containers**: The standard library ``ErrorProtocol`` protocol
32413241
uses a size-optimized reference-counted container, which indirectly stores
32423242
the conforming value. Boxed existential containers can be ``retain``-ed
32433243
and ``release``-d. The following instructions manipulate boxed existential
@@ -3249,21 +3249,21 @@ container may use one of several representations:
32493249

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

32573257
bb(%nserror: $NSError):
3258-
// The slow general way to form an ErrorType, allocating a box and
3258+
// The slow general way to form an ErrorProtocol, allocating a box and
32593259
// storing to its value buffer:
3260-
%error1 = alloc_existential_box $ErrorType, $NSError
3260+
%error1 = alloc_existential_box $ErrorProtocol, $NSError
32613261
strong_retain %nserror: $NSError
32623262
store %nserror to %error1#1 : $NSError
32633263

32643264
// The fast path supported for NSError:
32653265
strong_retain %nserror: $NSError
3266-
%error2 = init_existential_ref %nserror: $NSError, $ErrorType
3266+
%error2 = init_existential_ref %nserror: $NSError, $ErrorProtocol
32673267

32683268
init_existential_addr
32693269
`````````````````````

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: ErrorType) {
43+
init(error: ErrorProtocol) {
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: ErrorType? {
53+
var error: ErrorProtocol? {
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: ErrorType)
79+
case init(error: ErrorProtocol)
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: ErrorType)
150+
case init(error: ErrorProtocol)
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 ErrorType existential values. They have an
80+
indirect enum cases, and for ErrorProtocol 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

include/swift/ABI/MetadataValues.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ enum class SpecialProtocol: uint8_t {
196196
None = 0,
197197
/// The AnyObject protocol.
198198
AnyObject = 1,
199-
/// The ErrorType protocol.
200-
ErrorType = 2,
199+
/// The ErrorProtocol protocol.
200+
ErrorProtocol = 2,
201201
};
202202

203203
/// Identifiers for protocol method dispatch strategies.

include/swift/AST/ASTContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ class ASTContext {
352352
/// specified string.
353353
Identifier getIdentifier(StringRef Str) const;
354354

355-
/// Retrieve the declaration of Swift.ErrorType.
356-
NominalTypeDecl *getExceptionTypeDecl() const;
355+
/// Retrieve the declaration of Swift.ErrorProtocol.
356+
NominalTypeDecl *getErrorProtocolDecl() const;
357357
CanType getExceptionType() const;
358358

359359
/// Retrieve the declaration of Swift.Bool.

include/swift/AST/Builtins.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,13 @@ BUILTIN_SIL_OPERATION(IsUniqueOrPinned_native, "isUniqueOrPinned_native",
344344
BUILTIN(Id, Name, Attrs)
345345
#endif
346346

347-
/// willThrow: ErrorType -> ()
347+
/// willThrow: ErrorProtocol -> ()
348348
BUILTIN_RUNTIME_CALL(WillThrow, "willThrow", "n")
349349

350-
/// unexpectedError: ErrorType -> ()
350+
/// unexpectedError: ErrorProtocol -> ()
351351
BUILTIN_RUNTIME_CALL(UnexpectedError, "unexpectedError", "")
352352

353-
/// errorInMain: ErrorType -> ()
353+
/// errorInMain: ErrorProtocol -> ()
354354
BUILTIN_RUNTIME_CALL(ErrorInMain, "errorInMain", "")
355355

356356
#undef BUILTIN_RUNTIME_CALL

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ ERROR(cannot_convert_to_return_type_nil,sema,none,
243243
"nil is incompatible with return type %0", (Type))
244244

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

250250

251251
ERROR(cannot_convert_raw_initializer_value,sema,none,
@@ -1419,7 +1419,7 @@ ERROR(broken_equatable_requirement,sema_tcd,none,
14191419
ERROR(broken_hashable_requirement,sema_tcd,none,
14201420
"Hashable protocol is broken: unexpected requirement", ())
14211421
ERROR(broken_errortype_requirement,sema_tcd,none,
1422-
"ErrorType protocol is broken: unexpected requirement", ())
1422+
"ErrorProtocol protocol is broken: unexpected requirement", ())
14231423
ERROR(broken_int_hashable_conformance,sema_tcd,none,
14241424
"Int type is broken: does not conform to Hashable", ())
14251425
ERROR(broken_int_integer_literal_convertible_conformance,sema_tcd,none,
@@ -2179,7 +2179,7 @@ WARNING(no_throw_in_do_with_catch,sema,none,
21792179
ERROR(sugar_type_not_found,sema_tct,none,
21802180
"broken standard library: cannot find "
21812181
"%select{Array|Optional|ImplicitlyUnwrappedOptional|Dictionary|"
2182-
"ErrorType}0 type", (unsigned))
2182+
"ErrorProtocol}0 type", (unsigned))
21832183
ERROR(optional_intrinsics_not_found,sema_tct,none,
21842184
"broken standard library: cannot find intrinsic operations on "
21852185
"Optional<T>", ())

include/swift/AST/KnownDecls.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ FUNC_DECL(ForceBridgeFromObjectiveC,
5757
"_forceBridgeFromObjectiveC")
5858
FUNC_DECL(ConditionallyBridgeFromObjectiveC,
5959
"_conditionallyBridgeFromObjectiveC")
60-
FUNC_DECL(BridgeErrorTypeToNSError,
61-
"_bridgeErrorTypeToNSError")
60+
FUNC_DECL(BridgeErrorProtocolToNSError,
61+
"_bridgeErrorProtocolToNSError")
6262

6363
FUNC_DECL(ForceBridgeFromObjectiveCBridgeable,
6464
"_forceBridgeFromObjectiveC_bridgeable")

include/swift/AST/KnownProtocols.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ PROTOCOL(RawRepresentable)
5656
PROTOCOL(Equatable)
5757
PROTOCOL(Hashable)
5858
PROTOCOL(Comparable)
59-
PROTOCOL(ErrorType)
59+
PROTOCOL(ErrorProtocol)
6060
PROTOCOL(OptionSetType)
6161
PROTOCOL_(BridgedNSError)
6262

include/swift/Runtime/Metadata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,8 +1944,8 @@ enum class ExistentialTypeRepresentation {
19441944
Opaque,
19451945
/// The type uses a class existential representation.
19461946
Class,
1947-
/// The type uses the ErrorType boxed existential representation.
1948-
ErrorType,
1947+
/// The type uses the ErrorProtocol boxed existential representation.
1948+
ErrorProtocol,
19491949
};
19501950

19511951
/// The structure of existential type metadata.

include/swift/SIL/BridgedTypes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ BRIDGING_KNOWN_TYPE(Swift, String)
4747
BRIDGING_KNOWN_TYPE(ObjectiveC, ObjCBool)
4848
BRIDGING_KNOWN_TYPE(Darwin, DarwinBoolean)
4949
BRIDGING_KNOWN_TYPE(Swift, Bool)
50-
BRIDGING_KNOWN_TYPE(Swift, ErrorType)
50+
BRIDGING_KNOWN_TYPE(Swift, ErrorProtocol)
5151

5252
BRIDGE_TYPE(Foundation, NSString, Swift, String, true)
5353
BRIDGE_TYPE(ObjectiveC, ObjCBool, Swift, Bool, false)

include/swift/SIL/DynamicCasts.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ void emitIndirectConditionalCastWithScalar(
7878
/// \brief Does the type conform to the _ObjectiveCBridgeable protocol.
7979
bool isObjectiveCBridgeable(ModuleDecl *M, CanType Ty);
8080

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

8585
#endif

include/swift/SIL/TypeLowering.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,6 @@ class TypeConverter {
552552
#define BRIDGING_KNOWN_TYPE(BridgedModule,BridgedType) \
553553
Optional<CanType> BridgedType##Ty;
554554
#include "swift/SIL/BridgedTypes.def"
555-
Optional<CanType> BridgedTypeErrorType;
556555

557556
const TypeLowering &getTypeLoweringForLoweredType(TypeKey key);
558557
const TypeLowering &getTypeLoweringForUncachedLoweredType(TypeKey key);

lib/AST/ASTContext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,16 +551,16 @@ NominalTypeDecl *ASTContext::getStringDecl() const {
551551
}
552552

553553
CanType ASTContext::getExceptionType() const {
554-
if (auto exn = getExceptionTypeDecl()) {
554+
if (auto exn = getErrorProtocolDecl()) {
555555
return exn->getDeclaredType()->getCanonicalType();
556556
} else {
557557
// Use Builtin.NativeObject just as a stand-in.
558558
return TheNativeObjectType;
559559
}
560560
}
561561

562-
NominalTypeDecl *ASTContext::getExceptionTypeDecl() const {
563-
return getProtocol(KnownProtocolKind::ErrorType);
562+
NominalTypeDecl *ASTContext::getErrorProtocolDecl() const {
563+
return getProtocol(KnownProtocolKind::ErrorProtocol);
564564
}
565565

566566
NominalTypeDecl *ASTContext::getArrayDecl() const {

lib/AST/ConformanceLookupTable.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,10 @@ void ConformanceLookupTable::expandImpliedConformances(NominalTypeDecl *nominal,
503503
resolver->resolveInheritanceClause(cast<ExtensionDecl>(dc));
504504
}
505505

506-
// An @objc enum that explicitly conforms to the ErrorType protocol also
507-
// implicitly conforms to _ObjectiveCBridgeableErrorType, via the known
508-
// protocol _BridgedNSError.
509-
if (conformingProtocol->isSpecificProtocol(KnownProtocolKind::ErrorType) &&
506+
// An @objc enum that explicitly conforms to the ErrorProtocol protocol
507+
// also implicitly conforms to _ObjectiveCBridgeableErrorProtocol, via the
508+
// known protocol _BridgedNSError.
509+
if (conformingProtocol->isSpecificProtocol(KnownProtocolKind::ErrorProtocol) &&
510510
isa<EnumDecl>(nominal) && nominal->isObjC() &&
511511
cast<EnumDecl>(nominal)->hasOnlyCasesWithoutAssociatedValues()) {
512512
ASTContext &ctx = nominal->getASTContext();

lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,8 +1889,8 @@ bool NominalTypeDecl::derivesProtocolConformance(ProtocolDecl *protocol) const {
18891889
if (!knownProtocol)
18901890
return false;
18911891

1892-
// All nominal types can derive their ErrorType conformance.
1893-
if (*knownProtocol == KnownProtocolKind::ErrorType)
1892+
// All nominal types can derive their ErrorProtocol conformance.
1893+
if (*knownProtocol == KnownProtocolKind::ErrorProtocol)
18941894
return true;
18951895

18961896
if (auto *enumDecl = dyn_cast<EnumDecl>(this)) {

lib/AST/Verifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2588,7 +2588,7 @@ struct ASTNodeBase {};
25882588
}
25892589

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

25942594
Out << "exception type does not exist in " << where << "\n";

0 commit comments

Comments
 (0)