1

Rust support coming to GCC

 1 year ago
source link: https://lwn.net/Articles/917207/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Rust support coming to GCC

Posted Dec 7, 2022 11:18 UTC (Wed) by Tobu (subscriber, #24111) [Link]

There is much better success achieving these goals (access to more targets) by getting GCC integrated into rustc as a backend. Besides LLVM, rustc master has in-development backends for Cranelift (faster debug compiles) and GCC (access to architectures that don't have LLVM support). Here are rustc-codegen-gcc progress reports, for comparison.

Rust support coming to GCC

Posted Dec 7, 2022 14:42 UTC (Wed) by mathstuf (subscriber, #69389) [Link]

For target support goals, yes, the GCC backend is probably better and likely to cover the majority of code sooner. But for hammering out what the language means and discovering corner cases therein, a new frontend is better.

Rust support coming to GCC

Posted Dec 7, 2022 15:29 UTC (Wed) by TheGopher (subscriber, #59256) [Link]

Seconded - Rust is in real need of more formal definitions. I'm really missing https://en.cppreference.com when trying to work with rust, may not miss the C++ language, but they are way ahead when it comes to documentation and advanced examples.

Rust support coming to GCC

Posted Dec 8, 2022 0:53 UTC (Thu) by tialaramex (subscriber, #21167) [Link]

Really? I don't see it in terms of programmer documentation.

Like here's Rust's String class:

https://doc.rust-lang.org/std/string/struct.String.html

We get a discussion of the features, mentioning that Deref<Target=str> (ie you can use a String almost anywhere &str would work), explaining about UTF-8, how String works (e.g. capacity) and so on, we get a break down of all the methods on String, (and on &str because of the Deref I mentioned) with examples in many cases you can play with straight from your browser and links to the actual implementation of these features in fairly readable Rust.

Now here's the closest CPP Reference gets us:

https://en.cppreference.com/w/cpp/string/basic_string

That's a pretty intimidating wall of text, and it's that way because CPP Reference documents all C++ versions, which of course are incompatible, and so stuff appeared or disappeared in different versions and there are numerous exceptions, and the exceptions to those exceptions, as a result. It's also that way because C++ has a tremendous number of "string" types documented here.

We need to guess what we might be interested in and drill into individual methods like contains() to get to examples we can try, and so those examples can't realistically help us explore this type.

Maybe it's unfair to focus on Strings, since although they're a common idea C famously can't get them right so why should C++. Lets try a more fundamental type, char:

https://doc.rust-lang.org/std/primitive.char.html

versus

https://en.cppreference.com/w/cpp/language/types#Characte...

Wow, C++ even manages to have lots of char types. Of them char32_t is the closest to usable. But, I happen to know this documentation isn't sparse by mistake, these types just don't have any features. In C they wouldn't be able to have features and so perhaps out of perverse solidarity, they have no features in C++ either. As you can see the Rust char type has methods, constants, associated functions, and implements a bunch of traits.

Furthermore though, Rust provides documentation in this same style automatically for your own libraries. Here's the documentation for my LoadLetter type, which is an implementation of two I/O traits which just always fails.

https://docs.rs/misfortunate/1.0.0/misfortunate/struct.Lo...

So far as I can tell, if I write some C++ I don't get a CPP Reference page for it.

Fundamental concepts from Unsafe Rust could do with more documentation, but the vast majority of a team's effort and of most programmer's time will be spent with safe Rust, for which in my opinion Rust's documentation is in better shape than CPP Reference.

Rust support coming to GCC

Posted Dec 7, 2022 11:32 UTC (Wed) by JMB (guest, #74439) [Link]

Additionally, GCC is the main driver of standards (like C and C++) and the only free compiler collection.
LLVM is tailored to the needs of industrial stakeholders - so suitable for mainstream ...
and thus lacking in respect of research.
Concerning the way to make Rust part of GCC I am always in favour of competition.
For me it is not that clear which way is most reasonable:
project gccrs being topic here making rustc in C++ (which I am favouring currently) or
project rustc_codegen_gcc to extend rustc to be able to use GCC as backend.

Rust support coming to GCC

Posted Dec 7, 2022 12:36 UTC (Wed) by nix (subscriber, #2304) [Link]

LLVM is tailored to the needs of industrial stakeholders - so suitable for mainstream ... and thus lacking in respect of research.

I am a massive GCC booster, but this is just a bizarre statement. The insides of LLVM are (or, rather, have a reputation as) sufficiently much cleaner than GCC that most research work has been done with LLVM as a basis for many years now (as any quick random check of papers and research-grade experimental compilers shows). I thought this was widely enough known (and uncontroversial) that finding people claiming the opposite is weird, like seeing someone who says that Bill Clinton is still the US president. GCC *was* the major compiler research platform... in the late 90s. It is no longer the late 90s.

Rust support coming to GCC

Posted Dec 7, 2022 13:24 UTC (Wed) by pbonzini (subscriber, #60935) [Link]

Not even then, the only "good" times for GCC as a research platform were 2005-2010. GCC 3.x's optimizer architecture was obsolete, with interprocedural optimizations only appearing in 3.4 and a processor-independent, SSA-based intermediate representation in 4.0.

Rust support coming to GCC

Posted Dec 7, 2022 14:54 UTC (Wed) by mathstuf (subscriber, #69389) [Link]

Hmm. Numerous features are farther along in GCC than Clang. Standard modules for one (Clang has to deal with supporting "clang modules" at the same time). Concepts were developed in GCC (as are all of the features coming from Andrew Sutton's team AFAIK). I don't know that I'd say either is "ahead" of the other overall though; it's all pretty congenial and collaborative from what I can tell at standards meetings.

Personally? I found GCC easier to hack on myself in the corners I've touched at least. Between the faster compilation and more "direct" coding style, pulling threads to implement a prototype for P1689[1] took a day or two in GCC. Meanwhile, I got lost in the abstractions LLVM contains for tracking dependencies and the various "holes" I was missing to get the information I needed seemed to involve coding up new modes to not require actual BMI files when encountering an `import` statement. Luckily, a more seasoned LLVM developer came around and managed to know where to put in the right bits (now in `clang-scan-deps` rather than the compiler itself).

[1] http://wg21.link/p1689r5

Rust support coming to GCC

Posted Dec 7, 2022 17:25 UTC (Wed) by khim (subscriber, #9252) [Link]

From practical POV sanitizers are much more important than standard modules or concepts.

I'm not sure LLVM is strictly better for research purposes that gcc (number of papers is larger simply because LLVM license makes it safer to make proprietary forks), but it's not worse, at least.

I would say gcc is main driving force if we look on C++ development while LLVM used for many more things.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK