3 ms·
It really depends on exactly what you mean. There's one significant thing that's in C that's not in Rust: alloca. If you need that, well, we've talked about it
by steveklabnik 8y ago
It really depends on exactly what you mean.
There's one significant thing that's in C that's not in Rust: alloca. If you need that, well, we've talked about it, but haven't accepted a design, and some people never want to gain it directly.
EDIT: another comment pointed out goto; I have no idea what the performance implications are but I’ll have to add that to my list of “stuff C has that Rust doesn’t.”
Sometimes, you need nightly-only features. This means that, in some sense, today's Rust is slower, but tomorrow's Rust may not be.
Sometimes, "equivalence” is the issue. You can turn off bounds checking for array access, for example, but most Rust code doesn't, for hopefully good reason. Sometimes those checks are elided, and so it's exactly the same. Sometimes they're not. Sometimes they're not and that inhibits other optimizations. Is unsafe Rust "equivalent" to the C? Or does that not count? (Unsafe Rust is not always faster than Safe Rust...)
At the theory level, I can't think of anything off the top of my head that would inherently make Rust slower than C, generally speaking. There's also some degree of argument that in theory, Rust should be faster than C, thanks to how much more we know about aliasing, etc. That's a whole other can of worms...
- simcop2387 8y ago> Sometimes those checks are elided, and so it's exactly the same. Sometimes they're not. This is something I've personally thought about a lot and I have no idea how I'd actually want it implemented either on the backend or in the syntax, but I think it'd be useful to have some way to say "I want these bound checks to be elided, if they can't be then make that an error". Similar to how you'd decorate a pure function in other languages to say that it can't cause side effects or depend on side effects for what it's doing. I think that's probably a high level ask that's probably significantly more difficult that it seems initially too.
- edflsafoiewq 8y agoCan this sort of information be gotten out of LLVM?
- steveklabnik 8y agoYeah that'd be very interesting.
- andrewflnr 8y agoYou probably just want a dependently typed language. Proving bounds at compile time is an introductory exercise for the likes of Idris.
- zem 8y agoats [http://www.ats-lang.org/ http://www.ats-lang.org/] is a C-level language with dependent types
- lodi 8y agoNote that ATS has a limited version of dependent types as compared to Idris/Agda/Coq/etc. As I understand it, you can't run arbitrary (recursive, etc) functions at the type level. But even this 'lite' version lets you express preconditions like "n is a multiple of 4" or "the source array and destination array must not overlap in memory".
- simcop2387 8y agoQuite possibly that's what would work. I haven't tried any of them in any kind of serious capacity before. Edit: Looks like there's been an RFC in the past to add it to rust, but it got punted because the const generics stuff went in first and they wanted to see how that would shake out before trying to fully tackle this. https://github.com/ticki/rfcs/blob/pi-types-ext-2/text/0000-fully-dependent-pi-types.md https://github.com/ticki/rfcs/blob/pi-types-ext-2/text/0000-...
- JoshTriplett 8y ago> EDIT: another comment pointed out goto; I have no idea what the performance implications are but I’ll have to add that to my list of “stuff C has that Rust doesn’t.” On that front, one interesting thought would be to reimplement the CPython bytecode interpreter in Rust and see if you can match the performance of C using computed goto. In principle, there's no fundamental reason Rust couldn't optimize "loop around match" exactly the same way, without needing the computed goto. (For that matter, so could C.) Doing that would help cases like this.