389 points · by steveklabnik · 5y ago · 104 comments
[profile.profiling]
inherits = "release"
debug = true
[1]: <https://github.com/rust-lang/cargo/pull/9943>And then there's the less fireworky, but still appreciated, Iterator::map_while[2], which is going to be in Rust 1.57.
https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
It's a release train, similar to that used by Chromium and Firefox.
Edition releases (e.g. Rust 2021) are reserved for breaking changes only, and to retain Rust's stability promise, are opt-in.
As an example, here's a comment of mine on the original RFC (which was called "epochs"): https://github.com/rust-lang/rfcs/pull/2052#issuecomment-315... (the part with "Some language development comparisons")
Maybe it’s ironic that semver (machine-readable versioning) ended up being a liability due to interpretation by people (i.e. we can’t release a 2.0 because it would “send the wrong message”).
I think I'm in agreement :)
Is that different from compiling one lib with --std=c++11 and another with --std=c++17?
Because editions are opt-in (and library-level source metadata) the language itself can be modified in non-backwards-compatible ways.
So for instance a C++ with editions could make ctors `explicit` by default, or it could entirely change the automatic member generation (by removing it for instance). As long as the ABI and API remain compatible, that's fine.
Rust editions are closer to source code parsing modes. More like enabling trigraphs in C or "use strict" in JS.
Additionally, textual header inclusion in C makes mixing versions tricky. Rust has properly isolated crates, and tracks edition per AST node (so that even cross-crate macros work correctly with mixed editions).
By the way the difference is that Rust is not a standard, thus is easier to evolve (the process is much shorter). On the other side, the fact that a language changes slowly it's something good in a way, it means that you don't have to continue to change the way you do things, and update older projects.
That to everyone that has to maintain code for decades it's important. And every serious software project (not hobby stuff) does stay in production decades really. I don't use Rust, or even C++, for that reason.
PS: The other way around is more obviously broken, with the C++17 lib headers getting compiled using C++11.
Regardless, at the very least, you would need to write the headers to be interoperable.
Perl can do it not only at module level, but at block level within a single source file.
Adding 20 lines of #[!feature(...)] to every project would get old quick.
That's necessary b/c there are lots of breaking changes between language/compiler versions[3].
--
[1] they are more like DB triggers than contracts
[2] https://docs.soliditylang.org/en/develop/layout-of-source-fi...
[3] https://docs.soliditylang.org/en/develop/050-breaking-change...
> It just instructs the compiler to check whether its version matches the one required by the pragma. If it does not match, the compiler issues an error.
This is very different from Rust where your Rust 1.56.0 compiler will cheerfully compile Rust 2015, Rust 2018 and Rust 2021 code, into the same program even. Rust editions are not about the compiler version, they're about the language and every Rust compiler will compile every language edition it knows about.
Thanks to all the contributors for getting us to the 2021 edition!
See for example the summary at the top of https://rust-lang.github.io/rfcs/2052-epochs.html
It seems to to me that that aspect has now been dropped: TFA simply says "Editions are a mechanism for opt-in changes that may otherwise pose backwards compatibility risk."
I'm not sure this change of direction has been officially announced anywhere, though.
(I think this is a good change: last time I saw cases of people asking questions like "How do I do foo in Rust 2018", and getting a mix of answers like "Nothing in Rust 2018 affects foo" and "Since Rust 1.20 you've been able to use std::foo::bar to do that".)
• lumping marketing of cool features with an announcement of a few incompatible changes was easily misinterpreted as all new features requiring a new incompatible edition (while in fact almost all marketed features were already available in the old edition).
• celebration of features developed in recent years under one big event sounded like all these features were brand new and released at once.
For people who didn't follow Rust development, the announcement sounded like Rust suddenly made a lot of incompatible changes.
When IntoIterator for arrays first stabilized (with the hack hiding into_iter() for backwards compatibility) I considered making all the documentation changes to use natural arrays in standard library examples, which of course would now be the obvious way to write it whereas previously it was ugly.
I didn't do it (and now I have a job keeping me too busy) and I haven't gone back to look at examples to see if all/ most / some were updated to use arrays in the now natural way.
I came across this post which presents an example using rust's transmute and it's incorrect behavior when the alignment is different. https://andrewkelley.me/post/unsafe-zig-safer-than-unsafe-ru...
Is this issue still present? I tried to figure it out the other day using latest rust's nightly but the llvm ir output has so much going on that I didn't _really_ understand what was going on
#[repr(u16)]
enum Foo { A = 0, B }
#[repr(u16)]
enum Bar { A = 3200, B }
struct FooOrBar(u16);
And then proceeding to violate all of the unwritten rules of Rust by wrangling casts across these types like a goddamn wizardI'm not proud of this...
If you have a byte array that you've received over a network connection that represents an array of floats, or you need to convert a 32bit RGBA pixel buffer that you got from some clang ffi binding to a byte pixel buffer without having to split/copy to a new vector.
See https://blog.rust-lang.org/2021/06/17/Rust-1.53.0.html#whats...
"Since this special case for .into_iter() is only required to avoid breaking existing code, it is removed in the new edition, Rust 2021, which will be released later this year."
As a user, you're right that there's not really an external-facing change here.
> Until Rust 1.53, only references to arrays implement IntoIterator. This means you can iterate over &[1, 2, 3] and &mut [1, 2, 3], but not over [1, 2, 3] directly.
...now, you can also iterate over [1, 2, 3] etc.
https://doc.rust-lang.org/edition-guide/rust-2021/IntoIterat...
"for x in myArray" works fine, just like "for x in myVector" but whereas "myVector.into_iter().foo()" does what you expect, "myArray.into_iter().foo() is actually giving foo an iterator over the references just as it would have in 2017 and now produces a warning about this into the bargain.
In Rust 2021 myArray.into_iter() does what a modern Rust programmer expects it to do, provide an iterator over myArray itself.
The warning does explain how you can get that iterator in 1.53.0 of course, but you need to write some ugly syntax whereas in Rust 2021 the obvious syntax just does what you expect as if arrays had always been IntoIterator.
https://perf.rust-lang.org/compare.html?start=ef9549b6c0efb7...
Some things compile decently faster (~ 10%), some things compile a little faster or slower (~ +/- 3%), some things have a bigger perf hit but not as many as had a bigger perf gain (~ -10%).
So it's faster on average but the data is muddy enough that you probably wouldn't stick it front and center on your release notes.
It's less of a universal improvement than the pass manager, but for most of the benchmarks that it does impact it seems just as large, or larger.
https://github.com/rust-lang/rust/commit/63cc2bb
> Enable new pass manager with LLVM 13
[1]: https://twitter.com/ryan_levick/status/1443202538099073027
Rust has had LTO for quite a while, and it's normally a source of longer compilation times rather than shorter ones (since LTO in LLVM-world involves mashing all of the bitcode together and (re-)running a lot of expensive analyses to further optimize across translation unit boundaries.
OTOH they've been making continuous improvements to the incremental compilation mode since 1.51/2, so that's probably among the sources of improvements here.
There have been a few RFC trying to work on deriving a type from another, and while I agree it's much more complex than it sounds, I also find it's a huge missing point.
If I have to reimplement a wrapper myself for all Traits, I most likely won't bother, leading to less typesafety, leading to more bugs :(