@@ -3874,12 +3874,12 @@ arrays or if the element-types do not match.
3874
3874
Enums
3875
3875
~~~~~
3876
3876
3877
- These instructions construct values of enum type. Loadable enum values are
3878
- created with the `enum `_ instruction. Address-only enums require two-step
3879
- initialization. First, if the case requires data, that data is stored into
3880
- the enum at the address projected by `init_enum_data_addr `_. This step is
3881
- skipped for cases without data. Finally, the tag for
3882
- the enum is injected with an `inject_enum_addr `_ instruction::
3877
+ These instructions construct and manipulate values of enum type. Loadable enum
3878
+ values are created with the `enum `_ instruction. Address-only enums require
3879
+ two-step initialization. First, if the case requires data, that data is stored
3880
+ into the enum at the address projected by `init_enum_data_addr `_. This step is
3881
+ skipped for cases without data. Finally, the tag for the enum is injected with
3882
+ an `inject_enum_addr `_ instruction::
3883
3883
3884
3884
enum AddressOnlyEnum {
3885
3885
case HasData(AddressOnlyType)
@@ -3938,6 +3938,21 @@ projecting the enum value with `unchecked_take_enum_data_addr`_::
3938
3938
/* use %b */
3939
3939
}
3940
3940
3941
+ Both `switch_enum `_ and `switch_enum_addr `_ must include a ``default `` case
3942
+ unless the enum can be exhaustively switched in the current function, i.e. when
3943
+ the compiler can be sure that it knows all possible present and future values
3944
+ of the enum in question. This is generally true for enums defined in Swift, but
3945
+ there are two exceptions: *non-frozen enums * declared in libraries compiled
3946
+ with the ``-enable-resilience `` flag, which may grow new cases in the future in
3947
+ an ABI-compatible way; and enums marked with the ``objc `` attribute, for which
3948
+ other bit patterns are permitted for compatibility with C. All enums imported
3949
+ from C are treated as "non-exhaustive" for the same reason, regardless of the
3950
+ presence or value of the ``enum_extensibility `` Clang attribute.
3951
+
3952
+ (See `SE-0192 `__ for more information about non-frozen enums.)
3953
+
3954
+ __ https://github.com/apple/swift-evolution/blob/master/proposals/0192-non-exhaustive-enums.md
3955
+
3941
3956
enum
3942
3957
````
3943
3958
::
@@ -4075,6 +4090,9 @@ but turns the control flow dependency into a data flow dependency.
4075
4090
For address-only enums, `select_enum_addr `_ offers the same functionality for
4076
4091
an indirectly referenced enum value in memory.
4077
4092
4093
+ Like `switch_enum `_, ``select_enum `` must have a ``default `` case unless the
4094
+ enum can be exhaustively switched in the current function.
4095
+
4078
4096
select_enum_addr
4079
4097
````````````````
4080
4098
::
@@ -4097,6 +4115,9 @@ Selects one of the "case" or "default" operands based on the case of the
4097
4115
referenced enum value. This is the address-only counterpart to
4098
4116
`select_enum `_.
4099
4117
4118
+ Like `switch_enum_addr `_, ``select_enum_addr `` must have a ``default `` case
4119
+ unless the enum can be exhaustively switched in the current function.
4120
+
4100
4121
Protocol and Protocol Composition Types
4101
4122
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4102
4123
@@ -5207,13 +5228,13 @@ switch_enum
5207
5228
Conditionally branches to one of several destination basic blocks based on the
5208
5229
discriminator in a loadable ``enum `` value. Unlike ``switch_int ``,
5209
5230
``switch_enum `` requires coverage of the operand type: If the ``enum `` type
5210
- is resilient, the `` default `` branch is required; if the ``enum `` type is
5211
- fragile , the ``default `` branch is required unless a destination is assigned to
5212
- every ``case `` of the ``enum ``. The destination basic block for a `` case `` may
5213
- take an argument of the corresponding ``enum `` ``case ``'s data type (or of the
5214
- address type, if the operand is an address). If the branch is taken, the
5215
- destination's argument will be bound to the associated data inside the
5216
- original enum value. For example::
5231
+ cannot be switched exhaustively in the current function, the ``default `` branch
5232
+ is required; otherwise , the ``default `` branch is required unless a destination
5233
+ is assigned to every ``case `` of the ``enum ``. The destination basic block for
5234
+ a `` case `` may take an argument of the corresponding ``enum `` ``case ``'s data
5235
+ type (or of the address type, if the operand is an address). If the branch is
5236
+ taken, the destination's argument will be bound to the associated data inside
5237
+ the original enum value. For example::
5217
5238
5218
5239
enum Foo {
5219
5240
case Nothing
@@ -5280,11 +5301,12 @@ Conditionally branches to one of several destination basic blocks based on
5280
5301
the discriminator in the enum value referenced by the address operand.
5281
5302
5282
5303
Unlike ``switch_int ``, ``switch_enum `` requires coverage of the operand type:
5283
- If the ``enum `` type is resilient, the `` default `` branch is required; if the
5284
- `` enum `` type is fragile , the ``default `` branch is required unless a
5285
- destination is assigned to every ``case `` of the ``enum ``.
5304
+ If the ``enum `` type cannot be switched exhaustively in the current function,
5305
+ the `` default `` branch is required; otherwise , the ``default `` branch is
5306
+ required unless a destination is assigned to every ``case `` of the ``enum ``.
5286
5307
Unlike ``switch_enum ``, the payload value is not passed to the destination
5287
- basic blocks; it must be projected out separately with `unchecked_take_enum_data_addr `_.
5308
+ basic blocks; it must be projected out separately with
5309
+ `unchecked_take_enum_data_addr `_.
5288
5310
5289
5311
dynamic_method_br
5290
5312
`````````````````
0 commit comments