|
|
Subscribe / Log in / New account

editions

editions

Posted Aug 19, 2024 20:30 UTC (Mon) by tialaramex (subscriber, #21167)
In reply to: editions by josh
Parent article: FreeBSD considers Rust in the base system

Giving the benefit of the doubt, a single Edition does make it slightly simpler to teach Rust.

If you say all our code is Rust 2021 Edition, nobody needs to know anything that is gone in 2021 edition, and yet they also needn't learn anything that's new only in 2024 Edition (but they do still need to learn things that are new in that period but aren't part of the edition, they're just new).

In principle somebody maintaining 2015 Edition code ought to know Box<Goose> in that code might mean what we'd write today as Box<dyn Goose>. You can't do that in a modern edition, but in 2015 that's how people would have spelled that type and they were used to it.

Likewise your 2021 Edition code knows arrays are IntoIterator -- everybody (with a modern Rust compiler) can iterate over arrays of course, but in 2018 or 2015 edition code pretends to have no idea why that works so as to ensure compatibility with another old-timey thing people used to write back when arrays really weren't IntoIterator but references to the whole array as a slice were.

In practice what I'd expect is that FreeBSD would want a MSRV promise for this work. Maybe FreeBSD 14.1 promises Rust 1.79, while FreeBSD 14.0 says only Rust 1.70. People writing tools for such a system would judge whether they should be conservative (which might mean a lot more work) or not.

On the whole though, I see in this conversation something I see a lot in discussions with C++ programmers where they seem to imagine Rust's frequent release schedule means everything is in flux for the language, while at the same time considering C++'s lack of stability to be inconsequential. I notice that a no point does the discussion mention _which_ C++ language is in FreeBSD's base system. C++ 98? C++ 14? C++ 23? "Whatever Clang does -shrug-" ?

C++ ships new language versions every three years. Although in practice these languages are very similar as desired by the users, there actually is no formal promise of such commonality, and particularly on large codebases where people might value stability over a long span of time despite complex software C++ just doesn't always meet that expectation - it didn't promise to so no promise was broken.

Herb Sutter for example is proud of adding the <=> "spaceship" operator to C++ 20. This operator serves a similar purpose to Rust's PartialOrd trait. You implement it once, you get all the comparison operators at once, they're guaranteed consistent, that's a win for new C++ software. But of course there *was* already C++ code out there which had weird definitions of existing comparison operators and some of that code "broke" in the new C++ language either because of Herb's feature or because of knock-on effects in the stdlib. Maybe the code was already technically wrong (most C++ is) but for its owners the situation is that C++ 20 broke it.


to post comments

editions

Posted Aug 19, 2024 20:38 UTC (Mon) by josh (subscriber, #17465) [Link] (1 responses)

I definitely agree that using a single edition is easier for usability and learnability. It just didn't seem like that was the case being made; there seemed to be some impression that it was *needed* for compatibility.

And yes, it does seem like people are assuming Rust will have breakage on upgrades on par with other languages they have experience with, while not allowing for the possibility that a language can do better about compatibility.

editions

Posted Aug 20, 2024 0:17 UTC (Tue) by khim (subscriber, #9252) [Link]

> And yes, it does seem like people are assuming Rust will have breakage on upgrades on par with other languages they have experience with, while not allowing for the possibility that a language can do better about compatibility.

What they want is the exact opposite: picking one, fixed, thus, eventually, old version of LLVM and Rust and using it for the duration of certain FreeBSD release.

And for some unfathomable reason they think Rust editions would save them. They wouldn't.

Rust just doesn't work that way.

editions

Posted Aug 20, 2024 0:13 UTC (Tue) by khim (subscriber, #9252) [Link]

> Giving the benefit of the doubt, a single Edition does make it slightly simpler to teach Rust.

Exactly. Slightly simpler. Not by much.

I strongly suspect the whole discussion is based on the assumption that Rust editions are like C++ versions: you commit to one version and use features that are in there and then, 3 years later, get another version with bunch of new features.

Nothing can be further from the truth: 99% of features in Rust are added outside of any editions. GATs were added in Rust 1.65 and async fn traits have become available in Rust 1.75… these are major features that significantly change how you write code in Rust.

Editions are strictly for breaking changes and usually are limited to syntax sugar, all the major changes happen between editions.

> I notice that a no point does the discussion mention _which_ C++ language is in FreeBSD's base system. C++ 98? C++ 14? C++ 23? "Whatever Clang does -shrug-" ?

It's because it doesn't matter as much. There are lots of codebases that are using C++17 these days and the ones who are using C++20 are considered “very advanced” in spite of the fact that C++23 is already a thing.

This works fine with FreeBSD approach: if people accept patches for the five year old standard support (and they do!) then FreeBSD may just use “recent enough” C++ that's supported by whatever version of LLVM is supported by base and that's enough.

This wouldn't work with Rust. Not at all. And editions wouldn't help.

> C++ ships new language versions every three years.

What's important is not how often new version of C++ are shipped by how quickly third-party code stops supporting old versions.

In C++ world that takes years for “fast” and “advanced” codebases to stop supporting old standards (LLVM itself still requires that all code is compilable with C++17, e.g.), in Rust it takes months (same as with perl).

editions

Posted Aug 21, 2024 16:05 UTC (Wed) by mrugiero (guest, #153040) [Link] (4 responses)

One caveat that I see is missing from the editions discussion is that for this kind of project where stability is the most valued asset you should stick to at most current-1: the current edition is technically live and, while always backwards compatible, it's not necessarily forward compatible, as extensions are allowed to some degree. The same is true for the stdlib. You may find yourself in the situation where you happily coded locally with Rust 1.80 and used a feature that 1.78 doesn't have, but base uses 1.78, so you broke the build, even though both used the same allowed edition. Luckily all prior editions are already frozen because new development happens in current.

editions

Posted Aug 22, 2024 8:21 UTC (Thu) by taladar (subscriber, #68407) [Link]

That is because Rust is not designed to use an old compiler. It is designed for the new compiler to always be able to handle your old code.

editions

Posted Aug 22, 2024 12:26 UTC (Thu) by khim (subscriber, #9252) [Link]

> One caveat that I see is missing from the editions discussion is that for this kind of project where stability is the most valued asset you should stick to at most current-1: the current edition is technically live and, while always backwards compatible, it's not necessarily forward compatible, as extensions are allowed to some degree.

That's true for all editions, including the very first Rust 2015 edition. One example: Rust 2015 got NLL is year 2022, one year after Rust 2021 got it and four years after Rust 2018 got it — which means, ironically enough, that if you want to backport some code written for Rust 2015 in year 2024 it may be easier to port it to Rust 2018 than to stay with Rust 2015 if you want to use old compiler.

The only way to stay with old version of Rust compiler is to, essentially, fork everything and stay in your own little island.

> Luckily all prior editions are already frozen because new development happens in current.

I recommend you to find someone who told you this blatant lie and kick him. All prior edition have to stay compatible with all prior code (with some small caveats), but they are not frozen and they are not meant to be frozen.

Edition compatibility over time

Posted Aug 22, 2024 12:33 UTC (Thu) by farnz (subscriber, #17727) [Link]

One caveat that I see is missing from the editions discussion is that for this kind of project where stability is the most valued asset you should stick to at most current-1: the current edition is technically live and, while always backwards compatible, it's not necessarily forward compatible, as extensions are allowed to some degree

This is also not completely true; the old edition is also technically live, since, while it's not permitted to change the meaning of code that compiled under old compilers except across an edition boundary, it's permissible for a new compiler to accept code under an old edition that an old compiler rejected. So, I can write Rust 2015 code with compiler 1.80 that will not be accepted by compiler 1.50, for example, because the new compiler accepts more code than the old one did (borrow checker changes, changes to core and std to name new examples).

editions

Posted Aug 22, 2024 13:12 UTC (Thu) by laarmen (subscriber, #63948) [Link]

> Luckily all prior editions are already frozen because new development happens in current.

The scenario you describe could very well still happen even using an older edition. Even if your Rust code uses the 2018 edition, the 1.80 compiler will happily let you use stdlib APIs introduced in the 1.80 dev cycle. Editions are about incompatible changes to the syntax, changes to the default import, etc. They're not about freezing the language (in the wider sense) in time.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds