@@ -7037,18 +7037,25 @@ unchecked_take_enum_data_addr
7037
7037
// #U.DataCase must be a case of enum $U with data
7038
7038
// %1 will be of address type $*T for the data type of case U.DataCase
7039
7039
7040
- Invalidates an enum value, and takes the address of the payload for the given
7041
- enum ``case `` in-place in memory. The referenced enum value is no longer valid,
7042
- but the payload value referenced by the result address is valid and must be
7043
- destroyed. It is undefined behavior if the referenced enum does not contain a
7044
- value of the given ``case ``. The result shares memory with the original enum
7045
- value; the enum memory cannot be reinitialized as an enum until the payload has
7046
- also been invalidated.
7047
-
7048
- (1.0 only)
7049
-
7050
- For the first payloaded case of an enum, ``unchecked_take_enum_data_addr ``
7051
- is guaranteed to have no side effects; the enum value will not be invalidated.
7040
+ Takes the address of the payload for the given enum ``case `` in-place in
7041
+ memory. It is undefined behavior if the referenced enum does not contain a
7042
+ value of the given ``case ``.
7043
+
7044
+ The result shares memory with the original enum value. If an enum declaration
7045
+ is unconditionally loadable (meaning it's loadable regardless of any generic
7046
+ parameters), and it has more than one case with an associated value, then it
7047
+ may embed the enum tag within the payload area. If this is the case, then
7048
+ `unchecked_take_enum_data_addr ` will clear the tag from the payload,
7049
+ invalidating the referenced enum value, but leaving the
7050
+ payload value referenced by the result address valid. In these cases,
7051
+ the enum memory cannot be reinitialized as an enum until the payload has also
7052
+ been invalidated.
7053
+
7054
+ If an enum has no more than one payload case, or if the declaration is ever
7055
+ address-only, then `unchecked_take_enum_data_addr ` is guaranteed to be
7056
+ nondestructive, and the payload address can be accessed without invalidating
7057
+ the enum in these cases. The payload can be invalidated to invalidate the
7058
+ enum (assuming the enum does not have a `deinit ` at the type level).
7052
7059
7053
7060
select_enum
7054
7061
```````````
0 commit comments