Skip to content

Consider const asserts in pgrx's derives based on alignment #2233

@workingjubilee

Description

@workingjubilee

Many of pgrx's derives implicitly provide a way to move data into certain places in Postgres data structures that are (not) held to certain alignment requirements, and then read out that data as Rust types. The typed read can be a 16-byte-aligned access if it's, for example, u128, which will often involve a movaps on x86_64! The compiler said "hey, it's UB!" and you didn't listen, assuming you understood the Byzantine nightmare that is 21st Century computing better than the compiler: "x86_64 will never fault on unaligned-" "WRONG!"

While in some cases we do overhead-laden translations that may elide these requirements, I'm not entirely confident we generate correct code in every case. @k0nserv on Discord ran into this while implementing a custom type "by hand", but started with the derives. If we emitted some const _: () = assert!();s, he might have caught the problem in his choice of repr then, before it became an issue.

This is related to #1942 and will need thought about design with other parts.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions