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