Skip to content

Proposal: Change @alignOf of bit-packed types to either return null or be an error #7227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rohlem opened this issue Nov 26, 2020 · 0 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@rohlem
Copy link
Contributor

rohlem commented Nov 26, 2020

Sibling-proposal, depends-on-but-half-in-conflict-with #7221 (read that one for context) .

Currently @alignOf returns a special value 0 for bit-packed types. The argument has been made that the definition of alignment requirements as a power of two is more consistent both semantically and for hardware, however this prohibits the special value 0.
Code dealing with byte alignment is (I think?) already not intended to be used with bit-packed types, so this may lead to mathematical errors in unsuspecting formulae. Instead, I think it's worthwhile to force a manual distinction, by either

  • making @alignOf return an optional type.
    To not clutter code with .? (which isn't very intrusive in the first place imho) users can just use @alignOf indirectly via a helper function.
  • or making @alignOf of bit-packed types a compile error (which would complicate comptime/reflection code using it though - you'd be forced to reimplement and perform the validity check in userspace).
@rohlem rohlem changed the title Proposal: Change @alignOf of bit-packed types either null or an error Proposal: Change @alignOf of bit-packed types to either return null or be an error Nov 26, 2020
@Vexu Vexu added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Nov 27, 2020
@Vexu Vexu added this to the 0.8.0 milestone Nov 27, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Jul 9, 2023
@andrewrk andrewrk modified the milestones: 0.14.0, 0.15.0 Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

3 participants