Skip to content

TypeId should be (u64, u64) instead of u128 to save space #115620

Closed
@stepancheg

Description

@stepancheg

On Apple Silicon (unlike x86_64) u128 is 16-bytes aligned. So it takes extra space with little or no benefit. I looked at generated code, it is the same:

https://rust.godbolt.org/z/3sE7sMsjj

(Note just using repr(packed(8)) won't work because it will pass TypeId by reference not by value)

Additionally the issue with current TypeId is that is has different alignment on different platforms. Rust does not provide guarantees about the alignment, but if this was the same everywhere, it'd make life easier. (Practically we encountered this issue when our CI worked fine on Apple x86_64 macs, but the program didn't work on Apple Silicon.)

rustc 1.74.0-nightly (a991861 2023-09-05)
macOS, Apple Silicon

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-libsRelevant to the library 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