Skip to content

Commit 2e47cec

Browse files
committed
Remove i128 and u128 from improper_ctypes_definitions
Rust's 128-bit integers have historically been incompatible with C [1]. However, there have been a number of changes in Rust and LLVM that mean this is no longer the case: * Incorrect alignment of `i128` on x86 [1]: adjusting Rust's alignment proposed at rust-lang/compiler-team#683, implemented at rust-lang#116672. * LLVM version of the above: resolved in LLVM, including ABI fix. Present in LLVM18 (our minimum supported version). * Incorrect alignment of `i128` on 64-bit PowerPC, SPARC, and MIPS [2]: Rust's data layouts adjusted at rust-lang#132422, rust-lang#132741, rust-lang#134115. * LLVM version of the above: done in LLVM 20 llvm/llvm-project#102783. * Incorrect return convention of `i128` on Windows: adjusted to match GCC and Clang at rust-lang#134290. At [3], the lang team considered it acceptable to remove `i128` from `improper_ctypes_definitions` if the LLVM version is known to be compatible. Time has elapsed since then and we have dropped support for LLVM versions that do not have the x86 fixes, meaning a per-llvm-version lint should no longer be necessary. The PowerPC, SPARC, and MIPS changes only came in LLVM 20 but since Rust's datalayouts have also been updated to match, we will be using the correct alignment regardless of LLVM version. `repr(i128)` was added to this lint in [4], but is also removed here. Part of the decision is that `i128` should match `__int128` in C on platforms that provide it, which documentation is updated to indicate. We will not guarantee that `i128` matches `_BitInt(128)` since that can be different from `__int128`. Some platforms (usually 32-bit) do not provide `__int128`; if any ABIs are extended in the future to define it, we will need to make sure that our ABI matches. Closes: rust-lang#134288 Closes: rust-lang#128950 [1]: rust-lang#54341 [2]: rust-lang#128950 [3]: rust-lang/lang-team#255 (comment) [4]: rust-lang#138282
1 parent 3be7537 commit 2e47cec

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

core/src/primitive_docs.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,18 @@ mod prim_i64 {}
14281428
#[rustc_doc_primitive = "i128"]
14291429
//
14301430
/// The 128-bit signed integer type.
1431+
///
1432+
/// # ABI compatibility
1433+
///
1434+
/// Rust's `i128` is expected to be ABI-compatible with C's `__int128` on platforms where the type
1435+
/// is available, which includes most 64-bit architectures. If any platforms that do not specify
1436+
/// `__int128` are updated to introduce it, the Rust `i128` ABI on relevant targets will be changed
1437+
/// to match.
1438+
///
1439+
/// It is important to note that in C, `__int128` is _not_ the same as `_BitInt(128)`, and the two
1440+
/// types are allowed to have different ABIs. In particular, on x86, `__int128` and `_BitInt(128)`
1441+
/// do not use the same alignment. `i128` is intended to always match `__int128` and does not
1442+
/// attempt to match `_BitInt(128)` on platforms without `__int128`.
14311443
#[stable(feature = "i128", since = "1.26.0")]
14321444
mod prim_i128 {}
14331445

@@ -1458,6 +1470,8 @@ mod prim_u64 {}
14581470
#[rustc_doc_primitive = "u128"]
14591471
//
14601472
/// The 128-bit unsigned integer type.
1473+
///
1474+
/// Please see [the documentation for `i128`](prim@i128) for information on ABI compatibility.
14611475
#[stable(feature = "i128", since = "1.26.0")]
14621476
mod prim_u128 {}
14631477

0 commit comments

Comments
 (0)