Skip to content

Missed enum layout optimization with a NonZeroU64 + more space in an enum #101567

Description

@RalfJung

The Provenance type defined here is 24 bytes in size:

use std::num::NonZeroU64;

pub enum Provenance {
    Concrete {
        alloc_id: NonZeroU64,
        sb: NonZeroU64,
    },
    Wildcard,
    None,
}

However, it should be possible to encode Provenance in 16 bytes: e.g. (0usize, 0suize) could encode None and (0usize, 1usize) could encode Wildcard.

In Miri, a slight variant of this would help reduce the size of a fairly common type from 32 bytes to 24 bytes.

Unfortunately even #94075 does not help here. The entire concept of reading a single field to determine the discriminant is not flexible enough to represent this layout.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-layoutArea: Memory layout of typesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions