News for hackers. Stuff that matters.
Re:GCC-Rust: Rust frontend for GCC by Reelin on Sunday December 08, 2019 @02:46AM (#21734798)
> curious why people want this?

It's important for core infrastructure to have multiple competing implementations. On a related note, does Rust have a standard yet or are they still doing the reference implementation thing?

> I was under the impression that llvm is better than gcc?

And I thought that tabs were better than spaces, BSD beat Linux, Emacs was the one true god... what were we arguing about again?

Re:GCC-Rust: Rust frontend for GCC by sfink on Monday December 09, 2019 @02:51AM (#21741039)
My impression is that gcc produces smaller code that is roughly comparable with clang in terms of runtime performance (with a slight advantage when compiling the codebase I care about the most). Gcc has better debug info, especially when optimizing. I don't know about compile speeds. Clang has better infrastructure for writing static analysis tools. Clang is a much more realistic alternative to msvc on windows than gcc is. I don't know about their development velocities. Clang seems to have the edge in mindshare.

I'd be curious to know whether this would provide cross-language outlining during LTO using gcc. I believe some form of this is possible with llvm?

Re:GCC-Rust: Rust frontend for GCC by Reelin on Monday December 09, 2019 @03:40AM (#21741210)
My understanding is that LTO (and thus any cross-language inlining) takes place using a low level IR where language barriers aren't relevant. The GCC and LLVM backends both have full support as far as I know. Hypothetically it's simple to implement support in a given frontend, but apparently it proved to be a bit tricky in practice for Rust (http://blog.llvm.org/2019/09/closing-gap-cross-language-lto-...).
Re:GCC-Rust: Rust frontend for GCC by mjw1007 on Sunday December 08, 2019 @05:10AM (#21735186)
I don't think Rust is even defined by a reference implementation, given that they release a new compiler every six weeks.

For many practical purposes I think the closest thing to a language definition is the set of testsuites visible to Crater.

(That is: when the compiler people are considering a change, they don't say "we can't change this because we're past 1.0 and the change is technically backwards-incompatible", or "we can't change this because the Reference specifies the current behaviour"; they say "let's do a Crater run and see if anything breaks".)

Re:GCC-Rust: Rust frontend for GCC by steveklabnik on Sunday December 08, 2019 @08:26AM (#21735781)
This is not correct. We do use crater to help with questionable cases, but we often say “we can’t change this because we’re past 1.0 and the change is backwards incompatible.”
Re:GCC-Rust: Rust frontend for GCC by umanwizard on Sunday December 08, 2019 @08:56AM (#21735877)
Which is still not the same as having a spec or even a reference implementation.

It’s a bit weird how laser-focused the Rust community is on backwards compatibility, not seeming to believe that forward compatibility is also important.

e.g., if I write code targeting C++17, I can be reasonably sure it compiles with an older version of the compiler, as long as that version also claims to support C++17, modulo bugs. Not the case if I write code targeting Rust 2015 as they’re still adding features to that from time to time. Let alone Rust 2018 which changes every 6 weeks.

Will there ever be a version of Rust that the community agrees “OK, this language definition is not changing unless we find some major soundness bug” ?

This is a big blocker for mainstream adoption in Linux distributions since the maintainer wants to be able to land one specific version of rustc in the repositories, not rely on people downloading new versions with rustup continuously. But old versions of rustc are effectively useless due to the lack of forward compatibility guarantees.

Re:GCC-Rust: Rust frontend for GCC by jcranmer on Sunday December 08, 2019 @12:04PM (#21736845)
It's funny you cite C++, which has the best example of forward compatibility breakage in terms of impacting people.

g++ 4.4 implemented several key parts of C++11, including notably rvalue references, and adapted libstdc++ to use rvalue references in C++11 mode. However, the committee had to make major revisions to rvalue references subsequent to this implementation, to the point that you can't use libstdc++ 4.4's header files (such as <vector>) with a compliant C++11 compiler. So when you try to use newer clang (which prefers to use system libstdc++ for ABI reasons) on systems with 4.4 installed (because conservative IT departments), the result is lots and lots of pain.

Furthermore, it absolutely is the case that newer versions of compilers will interpret old language standards differently than older versions of the compiler. You don't notice it for the most part because the changes tend to revolve around pretty obscure language wordings involving combinations of features that most people won't hit. Compilers are going to try hard not to care about language versions past the frontend of the compiler--if the specification change lies entirely in the middle or backend, then that change is likely to be retroactively applied to past versions because otherwise the plumbing necessary is too difficult.

Re:GCC-Rust: Rust frontend for GCC by gpderetta on Sunday December 08, 2019 @01:08PM (#21737176)
Yes,gcc doesn't guarantee ABI, or even API, stability for experimental features. News at 11.
Re:GCC-Rust: Rust frontend for GCC by umanwizard on Sunday December 08, 2019 @12:50PM (#21737085)
g++ 4.4 came out before the C++11 standard was released. So I’m not sure how it’s a counterexample. C++11 was a standard under active development and so obviously you can expect changes; its status at that time was comparable to rust nightly.
Re:GCC-Rust: Rust frontend for GCC by sanxiyn on Sunday December 08, 2019 @09:24AM (#21736006)
It's not that Rust community ignores forward compatibility, it's just that right now is not the right time. Things recently landing on Rust is not new stuffs. Most of them were designed in, like, 2017. It just took years to stabilize.
Re:GCC-Rust: Rust frontend for GCC by umanwizard on Sunday December 08, 2019 @09:50AM (#21736109)
When is the right time, then? I would have thought the move to the 2018 Edition should have been the perfect time to declare the 2015 Edition as stable and unchanging, no? But it is still receiving major changes like non-lexical lifetimes.
Re:GCC-Rust: Rust frontend for GCC by kibwen on Sunday December 08, 2019 @10:15AM (#21736258)
Editions are not designed to be unchanging snapshots of the Rust compiler at a specific moment in time. By design, all Rust editions share the same middle-end and backend, and only differ in the frontiest parts of the frontend. The idea is that people should be able to update their version of the compiler without being required to update code that compiled prior to the 2018 edition.
Re:GCC-Rust: Rust frontend for GCC by umanwizard on Sunday December 08, 2019 @10:17AM (#21736268)
Yes, I understand that. I'm saying I don't understand why the Rust community has made that choice, since it essentially makes old versions of the compiler useless and therefore makes it difficult for software written in Rust to be part of a typical Linux distribution.

(And has a number of other disadvantages too, like constant cognitive load having to re-learn the language every 6 weeks).

Also, editions could be a snapshot of the language definition at a point in time, without being a snapshot of the compiler. There are still new versions of Clang and GCC coming out with new bugfixes, better optimizations, improved error messages, support for different hardware, WIP support for future language editions, etc., without changing the C++17 standard.

Re:GCC-Rust: Rust frontend for GCC by kibwen on Sunday December 08, 2019 @12:51PM (#21737087)
> I don't understand why the Rust community has made that choice, since it essentially makes old versions of the compiler useless

I mention the reason in my prior comment: to allow people to continually upgrade their compiler version without needing to change any code. Rust doesn't have a stable ABI, so all crates in a Rust project ultimately need to be built with the same compiler (and furthermore, crates must always be able to interoperate regardless of which edition they're on). That means that every new version of the compiler needs to support every old edition, because the alternative is to have users stuck on old versions of not just the compiler but also on old versions of dependencies that have since begun using features only supported by newer compilers. In Rust's case avoiding such a fundamental fracture in the community was more important, since, after all, there's still nothing stopping anyone from voluntarily sticking with an older version of the compiler if they're willing to deliberately endure such a situation.

> (And has a number of other disadvantages too, like constant cognitive load having to re-learn the language every 6 weeks).

This is quite hyperbolic. Rust introduces no more features than any other language, it simply rolls them out on a more fine-grained schedule. Furthermore, Rust hardly requires re-learning every six weeks; a "feature" introduced by a new version is often nothing more than a new convenience method in the standard library. The fact that we have established that Rust goes out of its way even to keep "old" code compiling and compatible with the rest of the ecosystem should demonstrate how little it demands that users re-learn anything.

Re:GCC-Rust: Rust frontend for GCC by jcranmer on Sunday December 08, 2019 @12:05PM (#21736854)
> (And has a number of other disadvantages too, like constant cognitive load having to re-learn the language every 6 weeks).

While the cadence may be faster, the pace of language change in Rust is slower than other popular languages such as C++ or JS.

Re:GCC-Rust: Rust frontend for GCC by pjmlp on Monday December 09, 2019 @02:55AM (#21741048)
How come, given that currently C++ has three years to release a new standard and then about the same until the latest release gets spread around all major compilers?

https://en.cppreference.com/w/cpp/compiler_support

Right now with C++20 around the corner, C++14 is still the safest bet for portable code, whereas in Rust we still see relevant crates that depend on nightly.

Re:GCC-Rust: Rust frontend for GCC by jcranmer on Monday December 09, 2019 @09:52AM (#21743096)
Here is the list of all the major features added to Rust since 1.0:

* The new lifetime model (non-lexical lifetimes)

* Async fn

* Procedural macros

* ? operator

* Import name resolution changes

* impl Trait

* C-style unions

Here's the list of features added in C++17 and C++20:

* constexpr if

* Modules

* Structured binding

* Type deduction helpers

* Coroutines

* <=> operator

* Concepts

* Expanded the set of expressions and statements that qualify as constexpr to the point that it's a very different feature from what it was in C++11.

In the same amount of time, C++ has added roughly the same number of features, but I would qualitatively say that C++'s feature additions are more impactful than Rust's feature additions, especially in terms of making newer code unrecognizable to programmers used only to the old version.

That's what I meant by pace versus cadence--overall, C++ has changed more, but it tends to change in triennial bursts instead of every six weeks.

Re:GCC-Rust: Rust frontend for GCC by pjmlp on Monday December 09, 2019 @10:56AM (#21743659)
The difference being that C++ developers have around 6 years time to get acquainted with each version.

The 3 years for each ISO revision, plus around three until the standard is actually usable in a portable way.

My old dusty non-maintained MFC applications still compile on latest Visual Studio.

Re:GCC-Rust: Rust frontend for GCC by umanwizard on Monday December 09, 2019 @11:47AM (#21744074)
> C++14 is still the safest bet for portable code

There are supported versions of RHEL that still only support C++11, FWIW.

Re:GCC-Rust: Rust frontend for GCC by pjmlp on Monday December 09, 2019 @01:33PM (#21745053)
True, but those are the same ones stuck on Java 1.4. :(
Re:GCC-Rust: Rust frontend for GCC by fluffy87 on Monday December 09, 2019 @01:35AM (#21740818)
I write standard compliant C++ code that only works with the latest compiler versions because older ones incorrectly claim support for C++ standard, but their implementation is too buggy.
Re:GCC-Rust: Rust frontend for GCC by sanxiyn on Sunday December 08, 2019 @02:48AM (#21734804)
Rust has no reasonable specification yet although it is being worked on.
Re:GCC-Rust: Rust frontend for GCC by cbmuser on Sunday December 08, 2019 @05:48AM (#21735287)
Which is the main reason why no usable alternative implementations exist yet and why Rust hasn't found its way to more low-level software projects like the Linux plumberland yet.

Rust dearly needs a stable specification, it is the main blocker why the language hasn't been more widely adopted.

Re:GCC-Rust: Rust frontend for GCC by johnisgood on Sunday December 08, 2019 @10:32AM (#21736365)
I agree. That, and no need to rush new features, stabilize old ones and fix their bugs. I am still waiting for RFC0066[1] to be fixed. It is from 2014-05-04! Here is its GitHub Issue: https://github.com/rust-lang/rust/issues/15023. Backstory: I started writing a relatively simple Rust program many years ago when I ran into this issue. It was my first attempt at writing Rust, and I did not like the workaround.

[1] https://github.com/rust-lang/rfcs/blob/master/text/0066-bett...

Re:GCC-Rust: Rust frontend for GCC by galangalalgol on Sunday December 08, 2019 @09:07AM (#21735932)
Rust has LTS like releases based on years, but the last one didnt have async await so everyone just kept tracking. I think the nexts LTS type release may snag some people and slow stuff down. Cargo should handle that fine, but not sure about maintainers. I cant get cargo in my day job, just the rustc 1.3x shipped with rhel, so I'm already standing still. Rhel's version migh make a good defacto lts in the absence of cargo, but the thin std lib makes that hard, and random old rustc versions sometimes don't play nice with every crate.
Re:GCC-Rust: Rust frontend for GCC by pietroalbini on Sunday December 08, 2019 @09:55AM (#21736133)
Rust doesn't have LTS releases. Editions are both a way to market the new features introduced in the past years as a "bundle" to outside users, and a way for us to introduce some breaking changes for the users opting into the new edition. The release an edition is stabilized in (1.31 for Rust 2018) does not get any special treatment from the Rust team though, and that includes no LTS support (for example we won't backport bug fixes, even security ones).
Re:GCC-Rust: Rust frontend for GCC by galangalalgol on Sunday December 08, 2019 @10:26AM (#21736323)
Yikes! I had no idea. It takes my company years sometimes to approve a new point release of software. Rhel subscription was my backdoor to get rust at work. I knew I'd never get a cargo access or a mirror approved, but i thought some day I'd push for an lts release. I don't see my company ever doing sw approval and transfer to our development network faster than once a year.
Re:GCC-Rust: Rust frontend for GCC by pietroalbini on Sunday December 08, 2019 @02:10PM (#21737575)
Well with RHEL 8 you can get a pretty up to date rustc, as they update the version in their stable repos every three months (so every two releases): https://developers.redhat.com/blog/2019/11/07/support-lifecy...
Re:GCC-Rust: Rust frontend for GCC by umanwizard on Sunday December 08, 2019 @10:02AM (#21736176)
As I pointed out in another comment, the definition of the 2015 edition is still changing (i.e., features from 2018 are getting backported to 2015), severely limiting the usefulness of the "edition" concept.

E.g., if someone thinks "I'm going to target 2015 because I want my code to run on the rustc shipped with various slow-moving Linux distros", it doesn't help, because you might still not be able to target their code, unless they specifically target an older version of rustc, which nobody does.

Re:GCC-Rust: Rust frontend for GCC by Rusky on Sunday December 08, 2019 @01:15PM (#21737216)
Editions solve an entirely separate problem, they were never meant to be LTS language snapshots. For example, C++ is considering adopting them in addition to their current versioning scheme: http://open-std.org/JTC1/SC22/WG21/docs/papers/2019/p1881r0....

There has been discussion of a Rust LTS channel alongside stable/beta/nightly, which would try to solve that problem, but it has not been prioritized yet: https://github.com/rust-lang/rfcs/pull/2483

An actual frozen language is also a possibility, but probably won't happen until more work happens on an independent specification. Which, in fact, people are also working on: https://ferrous-systems.com/blog/sealed-rust-the-pitch/

Re:GCC-Rust: Rust frontend for GCC by umanwizard on Sunday December 08, 2019 @02:00PM (#21737501)
I wasn't aware of the Sealed Rust project. Very cool!
Re:GCC-Rust: Rust frontend for GCC by bluejekyll on Sunday December 08, 2019 @04:26AM (#21735061)
I would say that rust doesn’t have a formal specification, what it does have is close to or better than many languages “specs” with the “Rust Reference”: https://doc.rust-lang.org/stable/reference/

It really depends on how strictly you define the term specification. The Rust Reference is not required to be accurate. Though many other language compilers/implementations don’t fully implement their respective specs so, :shrug:.

Re:GCC-Rust: Rust frontend for GCC by mjw1007 on Sunday December 08, 2019 @04:51AM (#21735131)
The Rust Reference is very far from being complete, or even correct in what it does cover.

If I have a question whose answer isn't obvious, it's far more likely that I have to go trawling around in RFCs than that there's an answer in the reference.

I think most languages of a similar age (eg Go, Swift) are doing better.

Re:GCC-Rust: Rust frontend for GCC by littlestymaar on Sunday December 08, 2019 @05:09AM (#21735185)
Rust is younger than Go (released in 2015 vs 2012) and way more ambitious, especially Rust 1.0 was released as kind of an MVP and many things have changed since then, which made the maintenance of such a reference an issue. The pace of change is slowing nowadays (that's especially visible if you look new and accepted RFCs), so I hope the reference will catch up eventually.
Re:GCC-Rust: Rust frontend for GCC by clarus on Sunday December 08, 2019 @08:58AM (#21735888)
There are some people studying Rust with formal verification. For example in this paper https://plv.mpi-sws.org/rustbelt/rbrlx/paper.pdf However I do not know if the whole language is covered or only a core.
Re:GCC-Rust: Rust frontend for GCC by sanxiyn on Sunday December 08, 2019 @09:27AM (#21736020)
The big gap with RustBelt is that it does not cover traits. This actually does matter: some bugs were missed because they interact with traits.