Expand description
ABI handling for rustc
§What is an “ABI”?
Literally, “application binary interface”, which means it is everything about how code interacts, at the machine level, with other code. This means it technically covers all of the following:
- object binary format for e.g. relocations or offset tables
- in-memory layout of types
- procedure calling conventions
When we discuss “ABI” in the context of rustc, we are probably discussing calling conventions.
To describe those rustc_abi also covers type layout, as it must for values passed on the stack.
Despite rustc_abi being about calling conventions, it is good to remember these usages exist.
You will encounter all of them and more if you study target-specific codegen enough!
Even in general conversation, when someone says “the Rust ABI is unstable”, it may allude to
either or both of
repr(Rust)types have a mostly-unspecified layoutextern "Rust" fn(A) -> Rhas an unspecified calling convention
§Crate Goal
ABI is a foundational concept, so the rustc_abi crate serves as an equally foundational crate.
It cannot carry all details relevant to an ABI: those permeate code generation and linkage.
Instead, rustc_abi is intended to provide the interface for reasoning about the binary interface.
It should contain traits and types that other crates then use in their implementation.
For example, a platform’s extern "C" fn calling convention will be implemented in rustc_target
but rustc_abi contains the types for calculating layout and describing register-passing.
This makes it easier to describe things in the same way across targets, codegen backends, and
even other Rust compilers, such as rust-analyzer!
Re-exports§
pub use callconv::Heterogeneous;pub use callconv::HomogeneousAggregate;pub use callconv::Reg;pub use callconv::RegKind;pub use canon_abi::ArmCall;pub use canon_abi::CanonAbi;pub use canon_abi::InterruptKind;pub use canon_abi::X86Call;pub use extern_abi::CVariadicStatus;pub use extern_abi::ExternAbi;pub use extern_abi::all_names;pub use layout::FIRST_VARIANT;pub use layout::FieldIdx;pub use layout::LayoutCalculator;pub use layout::LayoutCalculatorError;pub use layout::VariantIdx;pub use layout::Layout;pub use layout::TyAbiInterface;pub use layout::TyAndLayout;pub use wrapping_range::WrappingRange;pub(crate) use std::cmp::min;🔒pub(crate) use std::fmt;🔒pub(crate) use std::iter::Step;🔒Experimental pub(crate) use NonZero;🔒pub(crate) use ParseIntError;🔒pub(crate) use Add;🔒pub(crate) use AddAssign;🔒pub(crate) use Mul;🔒pub(crate) use Sub;🔒pub(crate) use std::range::RangeInclusive;🔒pub(crate) use std::str::FromStr;🔒pub(crate) use bitflags::bitflags;🔒pub(crate) use rustc_data_structures::stable_hash::StableOrd;🔒pub(crate) use DiagArgValue;🔒pub(crate) use IntoDiagArg;🔒pub(crate) use Diag;🔒pub(crate) use DiagCtxtHandle;🔒pub(crate) use Diagnostic;🔒pub(crate) use Level;🔒pub(crate) use msg;🔒pub(crate) use rustc_hashes::Hash64;🔒pub(crate) use Idx;🔒pub(crate) use IndexSlice;🔒pub(crate) use IndexVec;🔒pub(crate) use Decodable_NoContext;🔒pub(crate) use Encodable_NoContext;🔒pub(crate) use StableHash;🔒pub(crate) use Symbol;🔒pub(crate) use sym;🔒
Modules§
- callconv 🔒
- canon_
abi 🔒 - extern_
abi 🔒 - layout 🔒
- wrapping_
range 🔒
Structs§
- Address
Space - An identifier that specifies the address space that some operation should operate on. Special address spaces have an effect on code generation, depending on the target and the address spaces it implements.
- Align
- Alignment of a type in bytes (always a power of two).
- Backend
Lane Count - The number of lanes in a
BackendRepr::SimdVector,1..=MAX_SIMD_LANES. - Layout
Data - Niche
- NumScalable
Vectors - How many scalable vectors are in a
BackendRepr::ScalableVector? - Pointee
Info - Encodes extra information we have about a pointer.
- Pointer
Spec - How pointers are represented in a given address space
- Repr
Flags - Repr
Options - Represents the repr options provided by the user.
- Size
- Size of a type in bytes.
- Target
Data Layout - Parsed Data layout for a target, which contains everything needed to compute layouts.
- Variant
Layout - The layout information for a variant.
Enums§
- AbiFrom
StrErr - Align
From Bytes Error - Backend
Repr - The way we represent values to the backend
- Endian
- Endianness of the target, which must match cfg(target-endian).
- Fields
Shape - Describes how the fields of a type are located in memory.
- Float
- Floating-point types.
- Integer
- Integers, also used for enum discriminants.
- Integer
Type - Niche
Optimizations - Whether niche optimizations should be performed during layout calculation.
- Numeric
- Numeric primitives.
- Pointer
Kind - Primitive
- Fundamental unit of memory access and layout.
- Scalable
Elt - Scalar
- Information about one scalar component of a Rust type.
- Struct
Kind - TagEncoding
- Target
Data Layout Error - Variants
- Describes the variants of a type.
Constants§
- MAX_
SIMD_ LANES - The maximum supported number of lanes in a SIMD vector.