Skip to content

Validity of aggregate types (structs, enums, tuples, arrays, ...) #69

Open
@RalfJung

Description

@RalfJung

Discussing what the validity invariants of aggregate types are (and assembling a full list of aggregate types).

Safe compound types include enums, structs, tuples, arrays, slices, closures, generators, SIMD vectors.

The obvious invariant is

  • If applicable: The discriminant matches a possible variant (for enums). This applies to repr(C) enums as well! See #[repr(C)] C-like enums and out of range values rust-memory-model#41 for some discussion of that specific case.
  • All fields (of the active variant, for enums) are valid at their respective type.
  • All bytes not covered by any field ("padding") may have arbitrary content (including uninitialized).

Is there any exception? Currently at least, generators are an exception: Their fields may be uninitialized, leading to special cases in both layout computation code and Miri.

(I put these all together because my expectation is that there's not much to say here. We can split this up into several topics if that seems necessary.)

Metadata

Metadata

Assignees

Labels

A-validityTopic: Related to validity invariantsS-writeup-assignedStatus: Ready for a writeup and someone is assigned to it

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions