Implementation details?


#1

Are the rust implementation details in any way documented outside of the source code? I’ve been trying to find information on calling conventions (ABI and whatnot) and I can’t find anything.

Also, is this the right part of the forum to be posting this?


#2

Insofar as I’m aware, there is no defined ABI, and the ABI that exists is not guaranteed to be stable. It’s also not a target for 1.0.

That is, to be clear, excluding things like #[repr(C)].


#3

Okay, thought I’d ask. Nobody seems to know implememtation details. Maybe I’m looking in the wrong places.


#4

Rust’s ABI is undefined and unstable. The only place it is documented is in the compiler implementation, and in the heads of the people who work on it.


#5

There is a lot of documentation in the compiler source code. For high level stuff, look for doc.rs in various directories, as well as big comments at the top of files.


#6

Note that this may change anytime and might already have changed:

The function call ABI puts all structures bigger than a pointer behind a reference, same goes for RVO which triggers for everything bigger than a pointer. Struct layout currently is the same as C’s, for enums it’s a tagged union with an integer at the beginning that is big enough to cover all the variants (most of the time it’s a u8).


#7

Are fat pointers (2 words: begin + size) or equivalent user defined structures passed this way too?


#8

Unless there was a change here, yes.


#9

I’m quite sure we use the System V ABI, which triggers RVO only for structs at least 2 pointers big.


#10

No, we don’t, we have our own “larger than a pointer” rule, and sadly there’s a lot of trans code that assumes that threshold so you can’t just change it to see if you get a perf increase or something.