Skip to content

Commit 7da22aa

Browse files
authored
Rollup merge of #134941 - workingjubilee:rustc-abi-normal, r=Noratrieb
compiler: Add a statement-of-intent to `rustc_abi` This just documents the most basic idea of what the crate is even for in my view, rather than leaving that strewn about GitHub issues, PR reviews, and Zulip streams. In particular, I hope to make it clearer what code should go in `rustc_abi` and what should not, which is of immediate relevance to contributors. I considered going even further and explaining ideas like "ABI compatibility", prologues, and so on. However, because of the cross-cutting nature of ABI, I think such explanations should probably live in the place for cross-cutting documents: the rustc dev guide. This is only meant to be a quick "by the way".
2 parents f3748c4 + c0d3634 commit 7da22aa

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

compiler/rustc_abi/src/lib.rs

+32
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,38 @@
88
#![warn(unreachable_pub)]
99
// tidy-alphabetical-end
1010

11+
/*! ABI handling for rustc
12+
13+
## What is an "ABI"?
14+
15+
Literally, "application binary interface", which means it is everything about how code interacts,
16+
at the machine level, with other code. This means it technically covers all of the following:
17+
- object binary format for e.g. relocations or offset tables
18+
- in-memory layout of types
19+
- procedure calling conventions
20+
21+
When we discuss "ABI" in the context of rustc, we are probably discussing calling conventions.
22+
To describe those `rustc_abi` also covers type layout, as it must for values passed on the stack.
23+
Despite `rustc_abi` being about calling conventions, it is good to remember these usages exist.
24+
You will encounter all of them and more if you study target-specific codegen enough!
25+
Even in general conversation, when someone says "the Rust ABI is unstable", it may allude to
26+
either or both of
27+
- `repr(Rust)` types have a mostly-unspecified layout
28+
- `extern "Rust" fn(A) -> R` has an unspecified calling convention
29+
30+
## Crate Goal
31+
32+
ABI is a foundational concept, so the `rustc_abi` crate serves as an equally foundational crate.
33+
It cannot carry all details relevant to an ABI: those permeate code generation and linkage.
34+
Instead, `rustc_abi` is intended to provide the interface for reasoning about the binary interface.
35+
It should contain traits and types that other crates then use in their implementation.
36+
For example, a platform's `extern "C" fn` calling convention will be implemented in `rustc_target`
37+
but `rustc_abi` contains the types for calculating layout and describing register-passing.
38+
This makes it easier to describe things in the same way across targets, codegen backends, and
39+
even other Rust compilers, such as rust-analyzer!
40+
41+
*/
42+
1143
use std::fmt;
1244
#[cfg(feature = "nightly")]
1345
use std::iter::Step;

0 commit comments

Comments
 (0)