From 5bc13a0eb24d8771feda0bf4124f3dd3e50ec344 Mon Sep 17 00:00:00 2001 From: Connor Horman Date: Fri, 22 Nov 2024 13:30:59 -0500 Subject: [PATCH] Elaborate on how union constructors produce union values --- src/types/union.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/types/union.md b/src/types/union.md index 08d78dfd8..dbc71ad22 100644 --- a/src/types/union.md +++ b/src/types/union.md @@ -25,10 +25,16 @@ The memory layout of a `union` is undefined by default (in particular, fields do fix a layout. r[type.union.value] -A value of a union type consists of a sequence of bytes, corresponding to each [value byte][type.struct.value.value-bytes]. The value bytes of a union are represented exactly. Each [padding byte][type.struct.value.padding] is set to uninit. +A value of a union type consists of a sequence of bytes, corresponding to each [value byte][type.struct.value.value-bytes]. The value bytes of a union are represented exactly. Each [padding byte][type.struct.value.padding] is set to uninit when encoded. > [!NOTE] -> When a union value is constructed or a field is read/written to, the value of that field is encoded or decoded appropriately. +> A given value byte is guaranteed allowed to be uninit if it is padding in any field, recursively expanding union fields. Whether a byte of a union is allowed to be uninit in any other case is not yet decided. + +r[type.union.constructor] +The constructor of a union type encodes the initialized field value into the corresponding bytes of the union, and sets all bytes that are not used by the field to uninit. + +r[type.union.field-access] +When a field is written to by a field access expression, the value written is encoded into the corresponding bytes of the union. When a field is read, the value of that field is decoded from the corresponding bytes. [`Copy`]: ../special-types-and-traits.md#copy [item]: ../items/unions.md