4 ms·
Rust generics are sanely statically typed instead of duck typed, so parsing should be cheaper, but they can still cause duplicate codegen that the optimizer the
by MaulingMonkey 7y ago
Rust generics are sanely statically typed instead of duck typed, so parsing should be cheaper, but they can still cause duplicate codegen that the optimizer then needs to sift through and deduplicate, optimize, etc.
- umanwizard 7y agoSorry, I didn’t mean to imply that Rust’s generics don’t slow down compilation at all. They surely do, as does any form of code generation. My bad for not being more clear — I just wanted to point out that Rust doesn’t have anything like the full, accidentally Turing complete template metalanguage that C++ has.
- terminaljunkid 7y agoAt the point, all that matters is if templates are monomorphized or not. Other things don't affect much. Your previous statement just counts like fanboy-ism.
- adev_ 7y ago> My bad for not being more clear — I just wanted to point out that Rust doesn’t have anything like the full, accidentally Turing complete template metalanguage that C++ has. That's irrelevant. Being Turing complete does not mean being slow. Having template with duck typing does not imply being slow. That's completely irrelevant and pretty fanboy. The main reason C++ template are slow to compile is that they have to be header-based..... Meaning parsed again and again and again in every translation unit. Which is by itself pretty insane, and when you realize that, you realize that C++ compilers are in fact pretty fast compare to the job they do. Ideally c++ modules might solve that on the long term.
- pjmlp 7y agoThey are not parsed again and again when using pre-compiled headers.
- carlhjerpe 7y agoBut then touching one of those headers basically triggers a full rebuild.
- pjmlp 7y agoWhich, given the fact that a modular build makes proper use of binary dependencies across modules, has very little impact on what is being built, with the incremental compiler and linker giving an helping hand. Really, package each module on their own lib/dll, no need to compile everything from scratch other than self flagellation. A full build only becomes necessary when a new version of a low level module gets released into the library staging area.
- gpderetta 7y ago> Having template with duck typing does not imply being slow Right, the original Concepts designs in C++0x had type checking of template definitions. It had a huge negative impact on compilation time and was one reason why it was dropped. Mind you, had it been accepted it is possible it might have been optimizable, and certainly retrofitting it didn't help, but yes, you are right, not checking is not going to slow things down.
- MaulingMonkey 7y ago> I just wanted to point out that Rust doesn’t have anything like the full, accidentally Turing complete template metalanguage that C++ has. Rust's generics are pretty complete/full/equivalent to C++ templates. The type system is already turing complete, and even if we assume that generics alone aren't turing complete on their own on stable (I suspect this is a bad assumption!), they soon will be thanks to features like const_if_match, const generics, etc. Even ignoring those features - check out the typenum crate for some of the nonsense that can be done with stable rust already. I did get your fundamental point, but the counterpoint I'm trying to make here is that the differences are perhaps fewer than one might hope, and every single concern gpderetta raised about C++ templates can - at least theoretically - apply to Rust generics as well. While Rust generics might not be abused as much as C++ templates in practice - so far, anyways - that's mostly because Rust macros are more way more powerful than C++'s, very turing complete, and are abused for complicated stuff instead.