[rust-dev] ABI Opinion Poll

Niko Matsakis niko at alum.mit.edu
Wed Mar 13 09:02:40 PDT 2013



Niko Matsakis wrote:
> gcc allows you to associate multiple ABIs with a function definition, 
> one per architecture, but it is unclear to me how that interacts with 
> e.g. function pointers.  My guess is that it just...doesn't.  
> Therefore I'd prefer not to do the same.

Well, doing a bit more web searching, perhaps you can perhaps just 
attach attributes to function types in the same way.  There is very 
little discussion of this, to be sure.

Anyhow, just to spell out what I left implied in my previous e-mail, the 
alternative to that proposal is to allow multiple ABIs to be listed, and 
you just use the (first?) one that applies to the current target 
architecture.  So `extern "stdcall aapcs" fn(...) -> ...` would cover 
the example I gave before.  That's not too hard to implement, actually, 
so maybe that's the way to go.  It avoids the need for duplicate modules 
and #[cfg] tricks, which I hate, and it's really almost no extra work in 
the compiler.  It'd still be the case that `extern "C"` and `extern 
"Rust"` are the normal common cases: C would basically be shorthand for 
`cdecl aapcs` (plus whatever the defaults are on other architectures, 
like MIPS).

So far this is my preferred plan.  To summarize:

- Uppercase names "C" and "Rust" for "cross-platform" ABIs
- Lowercase names for other, platform-specific ABIs
- Multiple ABIs are permitted, compiler will use the first that applies 
to the target architecture
- Invoking an extern function without a suitable ABI for the current 
target is an error

If this doesn't seem agreeable to anyone, let me know :)


Niko


More information about the Rust-dev mailing list