Skip to content

Commit 521041a

Browse files
Remove rustc's notion of "preferred" alignment AKA __alignof
In PR 90877 T-lang decided not to remove `intrinsics::pref_align_of`. However, the intrinsic and its supporting code 1. is a nightly feature, so can be removed at compiler/libs discretion 2. requires considerable effort in the compiler to support, as it necessarily complicates every single site reasoning about alignment 3. has been justified based on relevance to codegen, but it is only a requirement for C++ (not C, not Rust) stack frame layout for AIX, in ways Rust would not consider even with increased C++ interop 4. is only used by rustc to overalign some globals, not correctness 5. can be adequately replaced by other rules for globals, as it mostly affects alignments for a few types under 16 bytes of alignment 6. has only one clear benefactor: automating C -> Rust translation for GNU extensions like `__alignof` 7. such code was likely intended to be `alignof` or `_Alignof`, because the GNU extension is a "false friend" of the C keyword, which makes the choice to support such a mapping very questionable 8. makes it easy to do incorrect codegen in the compiler by its mere presence as usual Rust rules of alignment (e.g. `size == align * N`) do not hold with preferred alignment The implementation is clearly damaging the code quality of the compiler. Thus it is within the compiler team's purview to simply rip it out. If T-lang wishes to have this intrinsic restored for c2rust's benefit, it would have to use a radically different implementation that somehow does not cause internal incorrectness. Until then, remove the intrinsic and its supporting code, as one tool and an ill-considered GCC extension cannot justify risking correctness. Because we touch a fair amount of the compiler to change this at all, and unfortunately the duplication of AbiAndPrefAlign is deep-rooted, we keep an "AbiAlign" type which we can wean code off later.
1 parent 798baa5 commit 521041a

File tree

1 file changed

+0
-9
lines changed

1 file changed

+0
-9
lines changed

core/src/intrinsics/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,15 +2651,6 @@ pub const fn size_of<T>() -> usize;
26512651
#[rustc_intrinsic]
26522652
pub const fn min_align_of<T>() -> usize;
26532653

2654-
/// The preferred alignment of a type.
2655-
///
2656-
/// This intrinsic does not have a stable counterpart.
2657-
/// It's "tracking issue" is [#91971](https://github.com/rust-lang/rust/issues/91971).
2658-
#[rustc_nounwind]
2659-
#[unstable(feature = "core_intrinsics", issue = "none")]
2660-
#[rustc_intrinsic]
2661-
pub const unsafe fn pref_align_of<T>() -> usize;
2662-
26632654
/// Returns the number of variants of the type `T` cast to a `usize`;
26642655
/// if `T` has no variants, returns `0`. Uninhabited variants will be counted.
26652656
///

0 commit comments

Comments
 (0)