News for hackers. Stuff that matters.
Re:The Rust Calling Convention We Deserve by weinzierl on Friday April 19, 2024 @01:22AM (#40083668)
I very much agree with that especially since - like you said - code that looks like it will perform well, not always does.

That being said I'd like to add that in my opinion performance measurement results should not be the only guiding principle.

You said it yourself: "Another reason is that the CPUs of today are optimized [..]"

The important word is "today". CPUs evolved and still do and a calling convention should be designed for the long term.

Sadly, it means that it is beneficial to not deviate too much from what C++ does [1], because it is likely that future processor optimizations will be targeted in that direction.

Apart from that it might be worthwhile to consider general principles that are not likely to change (e.g. conserve argument registers, as you mentioned), to make the calling convention robust and future proof.

[1] It feels a bit strange, when I say that because I think Rust has become a bit too conservative in recent years, when it comes to its weirdness budget (https://steveklabnik.com/writing/the-language-strangeness-bu...). You cannot be better without being different, after all.

Re:The Rust Calling Convention We Deserve by workingjubilee on Friday April 19, 2024 @02:10AM (#40083874)
The Rust calling convention is actually defined as unstable, so 1.79 is allowed to have a different calling convention than 1.80 and so on. I don't think designing one for the long term is a real concern right now.
Re:The Rust Calling Convention We Deserve by weinzierl on Friday April 19, 2024 @02:21AM (#40083923)
I know, but from what I understand there are initiatives to stabilize the ABI, which would also mean stabilizing calling conventions. I read the article in that broader context, even if it does not talk about that directly.
Re:The Rust Calling Convention We Deserve by JoshTriplett on Friday April 19, 2024 @05:03AM (#40084660)
There's no proposal to stabilize the Rust ABI. There are proposals to define a separate stable ABI, which would not be the default ABI. (Such a separate stable ABI would want to plan for long-term performance, but the default ABI could continue to improve.)
Re:The Rust Calling Convention We Deserve by weinzierl on Friday April 19, 2024 @01:15PM (#40089425)
Thanks, I never had considered that a possibility when hearing about "Rust stable ABI", but it makes a lot if sense.
Re:The Rust Calling Convention We Deserve by zozbot234 on Friday April 19, 2024 @02:01PM (#40090052)
There is already a separate stable ABI, it's just the C ABI. There are also multiple crates that address the issue of stable ABIs for Rust code. It's not very clear why compiler involvement would be required for this.
Re:The Rust Calling Convention We Deserve by tialaramex on Saturday April 20, 2024 @06:16PM (#40101494)
Surely it would be nice to be able to specify using the repr mechanism that you explicitly want so-and-such ABI, in the same way that you can for the C ABI.

I haven't looked at the crates you're describing, but presumably they're providing a proc macro or something instead, which is not really the right layer to do this stuff.

Re:The Rust Calling Convention We Deserve by dathinab on Friday April 19, 2024 @08:54AM (#40086224)
If I remember correctly there is a bit of difference between explicit `extern "rust"` and no explicit calling convention but I'm not so sure.

Anyway at least when not using explicit rust representation Rust doesn't even guarantee that the layout of a struct is the same for two repeated build _with the same compiler and code_. That is very intentionally and I think there is no intend to change that "in general" (but various subsets might be standarized, like `Option<&T> where T: Sized` mapping `None` to a null pointer allowing you to use it in C-FFI is already a de facto standard). Which as far as I remember is where explicit extern rust comes in to make sure that we can have a prebuild libstd, it still can change with _any_ compiler version including patch versions. E.g. a hypothetical 1.100 and 1.100.1 might not have the same unstable rust calling convention.

Re:The Rust Calling Convention We Deserve by flohofwoe on Friday April 19, 2024 @02:56AM (#40084082)
> and a calling convention should be designed for the long term

...isn't the article just about Rust code calling Rust code? That's a much more flexible situation than calling into operating system functions or into other languages. For calling within the same language a stable ABI is by for not as important as on the 'ecosystem boundaries', and might actually be harmful (see the related drama in the C++ world).

Re:The Rust Calling Convention We Deserve by weinzierl on Friday April 19, 2024 @07:26AM (#40085443)
You are right, as Josh Triplett also pointed out above. I was mistaken about the plans to stabilize the ABI.
Re:The Rust Calling Convention We Deserve by Ygg2 on Friday April 19, 2024 @09:55AM (#40086884)
> means that it is beneficial to not deviate too much from what C++ does

Or just C.

Reminds me when I looked up SIMD instructions for searching string views. It was more performant to slap a '\0' on the end and use null terminated string instructions than to use string view search functions .

Re:The Rust Calling Convention We Deserve by mananaysiempre on Friday April 19, 2024 @02:47PM (#40090601)
Huh, I thought they fixed that (the PCMPISTR? string instructions from SSE4.2 being significantly faster than PCMPESTR?), but looks like the explicit-length version still takes twice as many uops on recent Intel and AMD CPUs. They don’t seem to get much use nowadays anyway, though, what with being stuck in the 128-bit realm (there’s a VEX encoding but that’s basically it).