Here's a rant (opinion?) that I'll turn in to a blog post soon.

I think Rust should have a third ABI, not repr(C) or repr(Rust), and it should be used to slowly phase out the C ABI for a better one. Want to hear more of my unreasonable thoughts about ABIs? Read on.
First off: we should look at languages like Swift, Zig, Python, maybe even Go or C++, and find a better set of primitives to work with. I think there is a common set of features that wouldn't have everything, but would prevent falling back to the nuts and bolts of C.
Second: we shouldn't try to make the whole language follow this ABI. It should be relegated to API boundaries that are meant for FFI. This way we can keep language-specific optimizations in the normal case, and only pay a static ABI cost at the API surface area.
Third: the ABI should have the concept of semver baked in, or at least a monotonically increasing version number. It should be expected that this ABI increases regularly (1/months-years).
Third again: Compilers should be able to support emitting multiple different versions of this new ABI, based on a sliding window of version support. Linkers/Dynamic linkers should learn how to polyfill mismatched version numbers
Fourth: The ABI should encode some basic concept of ownership/lifetimes, even if the language only supports cloning/copying out of the borrow.
Fifth: The ABI should include the ability to encode information about types and layouts, not just function names. This should be used at compile/runtime to provide type information. Compilers should be able to import ABI libraries directly, or provide codegen tools to get headers
Sixth: The ABI should include a standard for enough introspection to at least get type and signature information for functions and data structures, both for the compiler and for humans. Ideally, you could include doc comments as a first class citizen as well.
Those are the things that come to mind first, and I'm sure all of these items exist in one form or another in a lot of different environments/runtimes! But these are all things that have bit me while trying to use Rust with other languages, and I think we can do better.
You can follow @bitshiftmask.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: