The Rust calling convention we deserve (2024)
56 points
3 days ago
| 4 comments
| mcyoung.xyz
| HN
dataflow
1 hour ago
[-]
Can someone explain the part about Diana's $89 dress?
reply
devinvs
46 minutes ago
[-]
x86_64 function arguments in linux are passed in registers RDI, RSI, RDX, RCX, R8, R9. The mnemonic helps remember the order.
reply
wahern
3 hours ago
[-]
This reads like word games. The article basically argues for optimizing the calling discipline on a per-function basis, using the function body to guide the optimization. That's not a calling convention and definitely not a standard ABI. What they're arguing for is a kind of static optimization mid-way between targeting a calling convention and inlining. That's not a bad idea on its face, but has nothing at all to do with the C ABI. As to whether it would actually improve anything, frankly, I'm half-surprised compilers don't already do this, i.e. for functions where it's deemed too costly to inline, but which aren't externally visible, and the fact that they don't suggests that maybe there's not much to gain here.

I've yet to read an article criticizing the so-called C ABI that doesn't end up effectively changing the problem statement (in this case, into something utterly incomparable), as opposed to providing a better solution to the same problem. Changing the problem statement is often how you arrive at better solutions overall, but don't try to sell it as something it isn't, insinuating that the pre-existing solution is stupid.

reply
dmitrygr
2 hours ago
[-]

  > for functions where it's deemed too costly to inline, but which aren't externally visible
in LTO mode, gcc does
reply
jauntywundrkind
3 hours ago
[-]
What was the interval of time for Rust having green threads, out of curiosity? How if at all had that affected layout and calling?
reply
JoshTriplett
3 hours ago
[-]
Pre-1.0. Rust removed the green-threads runtime prior to stabilization.

I personally think this was one of the most important changes Rust made; without it, Rust would have been interesting but would not have been able to compete directly with C and C++ for systems programming.

reply
irishcoffee
1 hour ago
[-]
> without it, Rust would have been interesting

Thanks for articulating what I’ve failed to do for a decade.

reply
satvikpendem
2 hours ago
[-]
Yep, it would've just been another OCaml with C style syntax.
reply
JoshTriplett
2 hours ago
[-]
Or another Go, with a mandatory runtime, which would have been a useful language but not something you'd add to a production OS kernel or firmware or similar.
reply
satvikpendem
2 hours ago
[-]
I wonder if we'd have eventually saw something like Nim, which has optional green thread concurrency and a garbage collector. Rust does not have these currently right? At least I haven't heard of them.
reply
JoshTriplett
1 hour ago
[-]
Some of Rust's async runtimes seem pretty similar to "optional green threads". There's no garbage collection; you can get something like a reference-counted GC by using Arc everywhere, but it's neither automatic nor universal.

Would we have gotten to "optional"? Maybe! But it's hard to predict the counterfactual, especially when substantial success usually has components of both design and luck/right-place-right-time. Rust hit a sweet spot, and it's not clear how a different history of Rust would have turned out.

reply
tomhow
4 hours ago
[-]
Previously:

The Rust calling convention we deserve - https://news.ycombinator.com/item?id=40081314 - April 2024 (137 comments)

reply