News for hackers. Stuff that matters.
Re:Rust Weird Expressions by Macha on Friday May 14, 2021 @08:06AM (#27153324)
However, the compiler has to continue to be able to compile 2015 edition code, as it is still guaranteed to work and be intermixable with 2018 (and soon, 2021) code in the same application.
Re:Rust Weird Expressions by chrismorgan on Friday May 14, 2021 @08:18AM (#27153414)
For curious people unfamiliar with the situation with this: Rust cares about backwards-compatibility so that you should still be able to compile code from 2015 in 2042 (some libraries are just stable!), but it also wants to allow certain changes to the language that you might think would be backwards-incompatible. Each crate (library) declares an edition, and the compiler follows the rules of that edition, and then you can link all the different crates together without worrying what edition they were written in. Editions are limited in what they can change, because things like traits are shared between crates, so they can’t be changed in editions; it’s mostly syntactic stuff, like the 2018 edition making async/await keywords and making dyn a full (rather than conditional) keyword.
Re:Rust Weird Expressions by fat-chunk on Friday May 14, 2021 @10:35AM (#27154766)
I'm not very knowledgeable with how compilers or language standards work, but would there not be security implications with this approach?

For example let's say a security exploit surfaces in the 2015 edition of Rust, would that not mean all the libraries declared as 2015 edition would have to be updated or abandoned in that case?

Or now that I think about it, is it instead the case that a whole program including all dependencies will be compiled by the same compiler (of which newer editions will have the latest security fixes), just that the compiler will always have to support compiling programs using legacy syntax when it identifies the crate's edition?

Re:Rust Weird Expressions by greenshackle2 on Friday May 14, 2021 @10:44AM (#27154843)
It's just syntax differences. The newer compiler supports all previous language editions, you're not using a 2015-era compiler to compile 2015 edition code.

Rust is not ABI-stable, there is no guarantee that you can even mix libs built with different versions of the compiler. The entire Rust tooling is built around static linking and building all your dependencies from sources. So yes, all the crates that go into your program are built with the same compiler, it's just that the compiler knows how to paper over the syntax differences in the different language editions.

Re:Rust Weird Expressions by rabidferret on Friday May 14, 2021 @01:26PM (#27157028)
> Or now that I think about it, is it instead the case that a whole program including all dependencies will be compiled by the same compiler (of which newer editions will have the latest security fixes)

It's this. Rust doesn't (yet) have a stable ABI for functions that aren't marked `extern "C"`. Any security vulnerability that would affect code in rust-lang/rust would most likely be in the standard library, which doesn't change between editions. All code links to the same libstd. Only the compiler frontend changes

Re:Rust Weird Expressions by peterkelly on Friday May 14, 2021 @09:27AM (#27154043)
This is what Python should have done.
Re:Rust Weird Expressions by egeozcan on Friday May 14, 2021 @10:27AM (#27154684)
JavaScript had something close, valid on the context level, with "use strict" (which is, I guess, borrowed from Perl), and I still don't understand why they don't repeat that for newer features that would be much simpler if they broke backwards compatibility.
Re:Rust Weird Expressions by Macha on Saturday May 15, 2021 @09:18AM (#27164932)
Didn't this end up in every Perl file having a ton of different "use" statements at the top for features that became expected?
Re:Rust Weird Expressions by egeozcan on Saturday May 15, 2021 @11:54AM (#27166317)
Perl model of enabling features individually was indeed too much, I was suggesting a language-level switch.
Re:Rust Weird Expressions by winstonewert on Friday May 14, 2021 @11:28AM (#27155291)
This approach only works for syntax level changes, it wouldn't have helped the problematic changes in Python 2 -> 3.
Re:Rust Weird Expressions by cyphar on Friday May 14, 2021 @01:25PM (#27157023)
Well, the ability to specify python version by module would've made migration much easier for everyone (in theory). But you're quite right that it wouldn't by itself be a solution -- it would also have required additional complexity to handle interoperability when calling between python versions, both in the runtime and the programs themselves (even a sufficiently smart compiler can't figure out what string encoding a python2 function expects).
Re:Rust Weird Expressions by iudqnolq on Friday May 14, 2021 @12:09PM (#27155819)
There's even a handy macro for switching between them /s

https://twitter.com/m_ou_se/status/1392200805168689154