Skip to content

Commit 9349cd3

Browse files
committed
Refactor definition of struct values/representation
1 parent 2cbdb58 commit 9349cd3

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/types/struct.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ A _unit-like struct_ type is like a struct type, except that it has no fields.
2929
The one value constructed by the associated [struct expression] is the only
3030
value that inhabits such a type.
3131

32-
## Struct and aggregate values
32+
## Struct
3333

3434
r[type.struct.value]
3535

36+
r[type.struct.value.intro]
37+
A value of a struct type consists of a list of values for each field.
38+
3639
r[type.struct.value.value-bytes]
3740
A byte `b` in the representation of an aggregate is a value byte if there exists a field of that aggregate such that:
3841
* The field has some type `T`,
@@ -45,15 +48,15 @@ A byte `b` in the representation of an aggregate is a value byte if there exists
4548
r[type.struct.value.padding]
4649
Every byte in an aggregate which is not a value byte is a padding byte.
4750

48-
r[type.struct.value.struct]
49-
A value of a struct type consists of the values of each of its fields.
50-
The representation of such a struct contains the representation of the value of each field at its corresponding offset.
51+
> [!NOTE]
52+
> Enum types can also have padding bytes.
5153
52-
r[type.struct.value.padding-uninit]
53-
When a value of an aggregate is encoded, each padding byte is left as uninit
54+
r[type.struct.value.encode-decode]
55+
When a value of a struct type is encoded, each field of the struct is encoded at its corresponding offset and each byte that is not within a field of the struct is set to uninit.
56+
When a value of a struct type is decoded, each field of the struct is decoded from its corresponding offset.
5457

5558
> [!NOTE]
56-
> It is valid for padding bytes to hold a value other than uninit when decoded, and these bytes are ignored when decoding an aggregate.
59+
> It is valid for padding bytes to hold a value other than uninit when decoded, and these bytes are ignored when decoding an struct value.
5760
5861
[^structtype]: `struct` types are analogous to `struct` types in C, the
5962
*record* types of the ML family, or the *struct* types of the Lisp family.

src/types/tuple.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Tuple fields can be accessed by either a [tuple index expression] or [pattern ma
5252
r[type.tuple.repr]
5353
The values and representation of a tuple type are the same as a [struct type][type.struct.value] with the same fields and layout.
5454

55+
5556
[^1]: Structural types are always equivalent if their internal types are equivalent.
5657
For a nominal version of tuples, see [tuple structs].
5758

0 commit comments

Comments
 (0)