News for hackers. Stuff that matters.
Re:C++ vs. Rust Build Times by choeger on Friday January 06, 2023 @04:00AM (#34272564)
"Beyond" in the sense of "after". Languages that support separate compilation usually have some sort of artifacts that do not need to be type-checked anymore. Say, you compile an Ocaml module. The result is a compiled (bytecode or native code) file that represents the implementation of the module and doesn't need to be generated ever again. Essentially, the compiler abstracts over a module after it dealt with it. You could the

If you do the same in rust, you need access to the module's implementation for monomorphization. You might skip the type checking of a function of the implementation or even cache the generated code for a monomorphization as optimizations, but generally you have to treat every function as often as it is used. So the best rust could do is akin to C++ precompiled headers whereas a language like OCaml can simply compile every module exactly once.

Note: OCaml pays for this elegance. Its uniform object representation is less efficient than what rust does. It's a trade-off that the rust designers consciously made, I think.

Re:C++ vs. Rust Build Times by scaredginger on Friday January 06, 2023 @05:21AM (#34273069)
What you've said here is mostly correct. The key part you've omitted is that monomorphization is opt-in. One could write Rust like C if they wanted to; they would have to be insane, but they could
Re:C++ vs. Rust Build Times by vegerot on Friday January 06, 2023 @06:49PM (#34283098)
“opt-in” in the sense that I could just multiple versions of my functions if I want to? Agreed!
Re:C++ vs. Rust Build Times by scaredginger on Friday January 06, 2023 @11:11PM (#34285112)
Yeah, or accept a small runtime cost in exchange for a smaller binary