Skip to content

Layout of pointers to slices of ZSTs #224

Open
@gnzlbg

Description

@gnzlbg

Right now, we specify here that:

The size of &[T] is two words.

However, if T is a ZST, we actually only need to store the length of the slice, and can make &[T] one word wide.

When coercing &[T] to a *const T, we can materialize the pointer out of thin air using: std::mem::align_of::<T>() as *const T.

The current specification would prevent such a layout optimization.

Is this an optimization worth supporting?


EDIT: some issues

  • (ptr, len) != [T]::from_raw_parts(ptr, len).into_raw(), since ptr does not necessarily need to be align_of::<T>(), yet if we don't store it, the address is lost

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-layoutTopic: Related to data structure layout (`#[repr]`)C-open-questionCategory: An open question that we should revisit

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions