Skip to content

Commit 81dadf6

Browse files
committed
the call ABI does not have to be fully equal; explicilty discuss incompleteness
1 parent b1a7983 commit 81dadf6

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

library/core/src/primitive_docs.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -1529,16 +1529,20 @@ mod prim_ref {}
15291529
///
15301530
/// ### ABI compatibility
15311531
///
1532-
/// Generally, when a function is declared with one signature and called via a function pointer
1533-
/// with a different signature, the two signatures must be *ABI-compatible* or else this call is
1532+
/// Generally, when a function is declared with one signature and called via a function pointer with
1533+
/// a different signature, the two signatures must be *ABI-compatible* or else this call is
15341534
/// Undefined Behavior. ABI compatibility is a lot stricter than merely having the same
15351535
/// representation in memory; for example, even if `i32` and `f32` have the same size and alignment,
15361536
/// they might be passed in different registers and hence not be ABI-compatible.
15371537
///
1538-
/// For two signatures to be considered *ABI-compatible*, they must declare the same `extern` ABI
1539-
/// string, must take the same number of arguments, and the individual argument types and the return
1540-
/// types must be ABI-compatible.
1541-
/// The relation of when two types are ABI-compatible is defined as follows:
1538+
/// For two signatures to be considered *ABI-compatible*, they must use a compatible call ABI (as
1539+
/// declared via `extern "ABI"`), must take the same number of arguments, and the individual
1540+
/// argument types and the return types must be ABI-compatible.
1541+
///
1542+
/// The call ABIs are guaranteed to be compatible if they are the same, or if the caller ABI is
1543+
/// `$X-unwind` and the callee ABI is `$X`.
1544+
///
1545+
/// The following types are guaranteed to be ABI-compatible:
15421546
///
15431547
/// - Every type is ABI-compatible with itself.
15441548
/// - If `<T as Pointee>::Metadata == ()`, then `*const T`, `*mut T`, `&T`, `&mut T`, `Box<T>`,
@@ -1555,17 +1559,20 @@ mod prim_ref {}
15551559
/// field type was changed from `T1` to `T2` are ABI-compatible.
15561560
/// - ABI-compatibility is symmetric and transitive.
15571561
///
1558-
/// Noteworthy cases of types *not* being ABI-compatible are `bool` vs `u8`, and `i32` vs `u32`: on
1559-
/// some targets, the calling conventions for these types differ in terms of what they guarantee for
1560-
/// the remaining bits in the register that are not used by the value. `i32` vs `f32` has already
1561-
/// been mentioned above.
1562+
/// More signatures can be ABI-compatible on specific targets, but that should not be relied upon
1563+
/// since it is not portable and not a stable guarantee.
1564+
///
1565+
/// Noteworthy cases of types *not* being ABI-compatible in general are `bool` vs `u8`, and `i32` vs
1566+
/// `u32`: on some targets, the calling conventions for these types differ in terms of what they
1567+
/// guarantee for the remaining bits in the register that are not used by the value. `i32` vs `f32`
1568+
/// has already been mentioned above.
15621569
///
15631570
/// Note that these rules describe when two completely known types are ABI-compatible. When
15641571
/// considering ABI compatibility of a type declared in another crate (including the standard
15651572
/// library), consider that any type that has a private field or the `#[non_exhaustive]` attribute
15661573
/// may change its layout as a non-breaking update unless documented otherwise -- so for instance,
15671574
/// even if such a type is a 1-ZST or `repr(transparent)` right now, this might change with any
1568-
/// library version change.
1575+
/// library version bump.
15691576
///
15701577
/// ### Trait implementations
15711578
///

library/std/src/primitive_docs.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -1529,16 +1529,20 @@ mod prim_ref {}
15291529
///
15301530
/// ### ABI compatibility
15311531
///
1532-
/// Generally, when a function is declared with one signature and called via a function pointer
1533-
/// with a different signature, the two signatures must be *ABI-compatible* or else this call is
1532+
/// Generally, when a function is declared with one signature and called via a function pointer with
1533+
/// a different signature, the two signatures must be *ABI-compatible* or else this call is
15341534
/// Undefined Behavior. ABI compatibility is a lot stricter than merely having the same
15351535
/// representation in memory; for example, even if `i32` and `f32` have the same size and alignment,
15361536
/// they might be passed in different registers and hence not be ABI-compatible.
15371537
///
1538-
/// For two signatures to be considered *ABI-compatible*, they must declare the same `extern` ABI
1539-
/// string, must take the same number of arguments, and the individual argument types and the return
1540-
/// types must be ABI-compatible.
1541-
/// The relation of when two types are ABI-compatible is defined as follows:
1538+
/// For two signatures to be considered *ABI-compatible*, they must use a compatible call ABI (as
1539+
/// declared via `extern "ABI"`), must take the same number of arguments, and the individual
1540+
/// argument types and the return types must be ABI-compatible.
1541+
///
1542+
/// The call ABIs are guaranteed to be compatible if they are the same, or if the caller ABI is
1543+
/// `$X-unwind` and the callee ABI is `$X`.
1544+
///
1545+
/// The following types are guaranteed to be ABI-compatible:
15421546
///
15431547
/// - Every type is ABI-compatible with itself.
15441548
/// - If `<T as Pointee>::Metadata == ()`, then `*const T`, `*mut T`, `&T`, `&mut T`, `Box<T>`,
@@ -1555,17 +1559,20 @@ mod prim_ref {}
15551559
/// field type was changed from `T1` to `T2` are ABI-compatible.
15561560
/// - ABI-compatibility is symmetric and transitive.
15571561
///
1558-
/// Noteworthy cases of types *not* being ABI-compatible are `bool` vs `u8`, and `i32` vs `u32`: on
1559-
/// some targets, the calling conventions for these types differ in terms of what they guarantee for
1560-
/// the remaining bits in the register that are not used by the value. `i32` vs `f32` has already
1561-
/// been mentioned above.
1562+
/// More signatures can be ABI-compatible on specific targets, but that should not be relied upon
1563+
/// since it is not portable and not a stable guarantee.
1564+
///
1565+
/// Noteworthy cases of types *not* being ABI-compatible in general are `bool` vs `u8`, and `i32` vs
1566+
/// `u32`: on some targets, the calling conventions for these types differ in terms of what they
1567+
/// guarantee for the remaining bits in the register that are not used by the value. `i32` vs `f32`
1568+
/// has already been mentioned above.
15621569
///
15631570
/// Note that these rules describe when two completely known types are ABI-compatible. When
15641571
/// considering ABI compatibility of a type declared in another crate (including the standard
15651572
/// library), consider that any type that has a private field or the `#[non_exhaustive]` attribute
15661573
/// may change its layout as a non-breaking update unless documented otherwise -- so for instance,
15671574
/// even if such a type is a 1-ZST or `repr(transparent)` right now, this might change with any
1568-
/// library version change.
1575+
/// library version bump.
15691576
///
15701577
/// ### Trait implementations
15711578
///

0 commit comments

Comments
 (0)