204 points · by markdog12 · 8y ago · 86 comments
NLL is on by default in the Rust 2018 mode of the Rust 1.31 release, shipping December 6.
NLL will be enabled in Rust 2015 sometime early next year, we do not have a precise release yet.
But if you enable NLL in Rust 2015 mode, that code will no longer compile with Rust v1.0. Which means we're still back at square 1 (meaning each crate has to specify which compiler version it requires).
Could you help enlighten me on why this is safe to backport to Rust 2015?
With backward compatibility, old programs will work with new versions of the compiler (alternatively, for web browsers, "old websites will work with new versions of the browser" (or for operating systems, "old binaries will work with new versions of the OS" (or for game consoles, "old games will work with new versions of the console", etc.))).
In this case, code written as of Rust 1.0 should continue compiling with Rust 2015, respective of the compatibility guarantee ( https://blog.rust-lang.org/2014/10/30/Stability.html ). By this definition, Rust is backwards-compatible.
What Rust is not, and has never been, is forwards-compatible. Very few systems in the wild are forwards-compatible. A C++ compiler from 2003 is not able to compile C++17 programs, and is thus not forwards-compatible. Likewise, web browsers from 2003 cannot render web pages from 2018, Windows ME cannot run binaries compiled for Windows 10, PS2 cannot play PS4 games, and so on.
> meaning each crate has to specify which compiler version it requires
Every Rust crate that does not specify a compiler version is compiled in 2015 mode. It must be this way, for backwards-compatibility. However, when you run `cargo new`, cargo should automatically insert the directive specifying the most recent edition supported by your compiler. In this way, Rust can gradually push the ecosystem forward without any additional burden to the user and without leaving behind any code that doesn't update.
Wouldn't that be 2019 not 2015?
> Rust ships releases on a six-week cycle. This means that users get a constant stream of new features. This is much faster than updates for other languages, but this also means that each update is smaller. After a while, all of those tiny changes add up. But, from release to release, it can be hard to look back and say "Wow, between Rust 1.10 and Rust 1.20, Rust has changed a lot!"
> Every two or three years, we'll be producing a new edition of Rust. Each edition brings together the features that have landed into a clear package, with fully updated documentation and tooling. New editions ship through the usual release process.
[1] https://rust-lang-nursery.github.io/edition-guide/editions/i...
Hmm. For me, fast compile times have vastly more ergonomic benefit than NLL.
[1]: http://smallcultfollowing.com/babysteps/blog/2018/10/31/mir-...
For newcomers it's the opposite. They'll have tiny projects, maybe in the hundreds-of-lines range, probably not a ton of fancy types and generics either. Their compile times are going to be quite small. But lifetimes, those will cost them a ton.
Well we weren't getting those anyway :(
Both compile times and NLL are, and have been, at the top of requests from production and hobbyist users alike for a long time now.
Although I still hope they will eventually come around to fix it.
Ultimately I think the answer would be a mix of "you could absolutely write a version of Rust that would compile reasonably on hardware from 1990", but also that the hardware limitations of that era would absolutely feed back into the design of the language in determining what features and implementation details would be feasible, which suggests that the language itself could very well look very different than it does today, even while maintaining the philosophy of no-GC memory-safety.
Heavily templated C++ code is notoriously slow to compile so it's no surprise that heavily genericized Rust code doesn't fare much better.
On top of that Rust builds one crate at a time basically, it's not like C where you typically have plenty of smaller compilation units that are black-boxes to one-another. C++ has the same compilation model but as mentioned above templates need to be resolved completely at compile-time so all templated code ends up in headers and therefore in copy/pasted by the processor every compilation unit it's used in.
And then after all that in Rust you have the borrow checker which probably ads a non-negligible runtime overhead.
I agree that it's an interesting evolution as far as programming languages are concerned. I consider that Rust is overall superior to C but at the same time in the seventies nobody could have run a Rust compiler on anything more than a Hello World. Meanwhile I've just compiled (with optims) an auto-generated C file of about 20k lines almost instantly on my 2018 computer.
Still slower than compiling Ada, Delphi, Eiffel, D code, though.
I'm not sure. Here's what I know: Rust has a complex type system. It also compiles whole packages (crates) at a time, and heavily uses monomorphization for generic code (that is probably less important for the type checking step but is quite heavy on the final compile-with-LLVM/link step).
If it was necessary, I'm sure it'd be possible to trade in some memory usage for CPU time (IIRC, a lot of memory is used for caching/memoization). But aside from outliners like that "10GB less memory usage" fix, rustc doesn't use that much RAM.
I'm guessing you could have a very efficient implementation of Rust, but that it would be rewrite instead of an incremental fix. This statement is likely to be unpopular.
Your work is very much appreciated, thank you.
Thankfully someone in IRC told me back then to just switch on the feature flag. Never looked back.
Rust is still solidly in the "minutes" bucket for compile time. I don't see it ever breaking into the "seconds" bucket. That's fine. I'll take ergonomics improvements every time.
You just made me feel glad I'm mainly a C dev these days. Since you typically rebuild one C file at a time (unless you make changes to header files potentially) compilation times of a fraction of a second are the norm here.
That being said I agree with you that between 1mn compile time and 1mn10s compile time it might not make all that much of a difference in practice.
However one thing Rust does that mitigates these problems a little is that diagnostics and errors are typically generated early in the build process, so generally if you see that it started off well you can focus your attention elsewhere (or even interrupt the build early to start a new one if you make small, incremental changes).
In this context I assume that the NLL checker added time to this early phase of the boot process and it might be worth optimizing that bit in particular. If you have a lifetime issue you don't want to wait 30s to have your build error.
You can also run the compiler with `cargo check` and it only does type- and borrow checking. I haven't worked on any huge Rust codebases, but in my experience it usually takes only a fraction of a second at best or a few seconds at worst.
Likewise, which traits would you expect an anonymous struct to implement?
However, if you did want optional parameters, you could potentially have them be `Option` types.
Go does.
Indexing arrays is definitely faster. Bitsets also do array indexing but have to target particular bits too.
If I want to index 1309402 bit, I have to calculate where it is in memory, for an array representing a bit, it's super quick.
Rarely have I encountered that memory occupied by an array is a bottleneck.
NLL itself definitely worth it, no disagreement there.