|
|
Subscribe / Log in / New account

A Rust frontend for GCC

From:  Philip Herron <redbrain-/MQLu3FmUzdAfugRpC6u6w-AT-public.gmane.org>
To:  gcc-/MQLu3FmUzdAfugRpC6u6w-AT-public.gmane.org, "rust-dev-4eJtQOnFJqFAfugRpC6u6w-AT-public.gmane.org" <rust-dev-4eJtQOnFJqFAfugRpC6u6w-AT-public.gmane.org>
Subject:  Rust front-end to GCC
Date:  Tue, 3 Dec 2013 17:22:07 +0000
Message-ID:  <CAEvRbeoL2NiJ+sfVEtWFMTdP8aWk2jOzmbRbLspj7GSynWQLhQ@mail.gmail.com>
Archive‑link:  Article

Hey all

Some of you may have noticed the gccrs branch on the git mirror. Since
PyCon IE 2013 i gave a talk on my Python Front-end pet project and heard
about rust by a few people and i never really looked at it before until
then but i've kind of been hooked since.

So to learn the language i've been writing this front-end to GCC. Only
really a a month or  so on and off work in between work. Currently it
compiles alot of rust already in fairly little effort on my side GCC is
doing loads of the heavy lifting.

Currently it compiles most of the basic stuff such as a struct an impl
block while loop, functions expressions calling methods passing arguments
etc. Currently focusing on getting the typing working correctly to support
& and ~ and look at how templates might work as well as need to implement
break and return.

There is still a lot of work but i would really like to share it and see
what people think. Personally i think rust will target GCC very well and be
a good addition (if / when it works). I really want to try and give back to
this community who have been very good to me in learning over the last few
years with GSOC.

To get a jist of what i am compiling in my tests are something like:

fn fib1 (n:int) -> int {
    if (n <= 1) { 1 }
    else { n * fib1 (n - 1) }
}

fn fib2 (n:int) -> int {
    let mut i = 1;
    let mut result = 1;
    while (i <= n) {
        result = result * i;
        i = i + 1;
    }
    result
}

fn main () {
    fib1 (10);
    fib2 (10);
}

Or

struct mytype {
    x : int
}

impl mytype {
    fn test (self) -> int {
        println ("yyoyoyo");
        test2 (1)
    }
}

fn main () {
    let x = mytype { x : 1 };
    let z = x.x;
    let y = x.test ();
    let a = test2 (y);
}

fn test2 (x : int) -> int {
    let z = x;
    1 + z
}

Theses are both pretty abstract test cases but were the ones i just made
work a while ago. Lots more work to do on it but i feel these 2 test cases
working is kind of a mile stone for me.

I will start a wiki page on the project and the code i work on is at
http://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads... and i have
it on github first mostly for travis CI and so i can do a bunch of commits
and rebase etc http://github.com/redbrain/gccrs

Thanks

--Phil



to post comments

Great news!

Posted Dec 3, 2013 19:32 UTC (Tue) by HelloWorld (guest, #56129) [Link]

I really hope a Rust front-end will end up in GCC one day. The combination of an efficient execution model, memory safety and a highly expressive type system (region pointers, type classes and more) is sorely missing in today's world. It's sad that systems programming today is still dominated by a 1970s language, and I really hope that Rust will help us move away from that.

A Rust frontend for GCC

Posted Dec 4, 2013 8:01 UTC (Wed) by smurf (subscriber, #17840) [Link]

Nice.

But: please name your functions correctly. You want "fac". ;-)

fib(n) := n<2 ? n : fib(n-1)+fib(n-2)
fac(n) := n<2 ? n : n*fac(n-1)

Frontends for GCC

Posted Dec 4, 2013 9:08 UTC (Wed) by rvfh (guest, #31018) [Link] (1 responses)

Does writing a GCC frontend mean that the code could be compiled, linked with shared libraries? Like, I would write Python code and link it with C/C++ libraries into a binary?

Forgive my GCC ignorance...

Frontends for GCC

Posted Dec 4, 2013 9:37 UTC (Wed) by mathstuf (subscriber, #69389) [Link]

It's more like GCC can now understand rust code and convert it to GIMPLE (its internal data structures) and use its optimizers and such. Rust specifies an ABI (IIRC), so it shouldn't have issues like C++ with different compilers mangling symbols their own way.

A Rust frontend for GCC

Posted Dec 4, 2013 10:36 UTC (Wed) by Otus (subscriber, #67685) [Link] (9 responses)

Is there a good Rust tutorial? The official one reads like it's written for language designers. Lots of information on how the language works, with three or four ways to do everything, but nothing about how you are supposed to use it.

How do you write "rustic" programs?

A Rust frontend for GCC

Posted Dec 4, 2013 11:19 UTC (Wed) by HelloWorld (guest, #56129) [Link]

I don't know a tutorial other than the official one, but there's a style guide.
https://github.com/mozilla/rust/wiki/Note-style-guide

A Rust frontend for GCC

Posted Dec 4, 2013 12:34 UTC (Wed) by apoelstra (subscriber, #75205) [Link] (1 responses)

Over the last two weeks I've had every git commit (and diff) emailed to me to get a feel for how the project is progressing. It is very exciting but the language is far from stable.

There is a tutorial that ships with Rust. It is the same as the online one but will be different if you download git HEAD because that's just how fast the language moves.

Shortly before I arrived there was a deprecation of '@' pointers, which appeared in the online tutorial. I've seen the tutorial updated to account for this, development on GC'd and ref-counted pointers which are supposed to replace '@' (which are unspecified "managed" pointers). I've also seen the deprecation of &fn "borrowed function" syntax in favor of something more precise with different syntax ('procedures' which are non-mutable in some sense and can be passed between tasks, and something mutable which can't, IIRC).

There was an LWN article in July which described the semantics of for loops and lambda functions. That stuff also changed before I started following the project.

The Rust source is written in Rust, and there are developers and enthusiasts on #rust on irc.mozilla.org. These two sources should help you to write rustic code. (But "rustic" will mean something different in a month no doubt, so you might want to wait for more stability. :))

It's very exciting development and I don't mean to give the impression that this is not a worthwhile language to learn. Just that in 2013/2014 the syntax is still a moving target and that you'd best not spend time writing massive amounts of code in it.

On the other hand, Rust's safe pointer model is quite mind-bending and worth getting a jump on. So there is a motivation for learning the language today.

A Rust frontend for GCC

Posted Dec 9, 2013 1:53 UTC (Mon) by nix (subscriber, #2304) [Link]

So what you're saying is, it's changing fast, don't write anything important in it yet because your code will rust in no time flat. :)

A Rust frontend for GCC

Posted Dec 4, 2013 14:27 UTC (Wed) by Kit (guest, #55925) [Link] (4 responses)

Check out Rust for Rubyists ( http://www.rustforrubyists.com ). It's probably the best tutorial out there currently, although there's quite a bit it doesn't cover. Don't worry if you don't know Ruby, as the 'for Rubyists' part just means the author assumes no knowledge of lower level languages like C & C++.

Mind you, though, that breaking changes in the language is currently the norm, and a lot of material out there for Rust covers old versions- and some people actually try to follow Master instead of the current release, so library support can be a bit painful.

A Rust frontend for GCC

Posted Dec 4, 2013 15:01 UTC (Wed) by Otus (subscriber, #67685) [Link]

> Check out Rust for Rubyists ( http://www.rustforrubyists.com ).

Thanks, that's pretty close to what I was looking for.

A Rust frontend for GCC

Posted Dec 4, 2013 19:59 UTC (Wed) by shmerl (guest, #65921) [Link] (2 responses)

Is there any ETA when they'll try to stabilize the language?

A Rust frontend for GCC

Posted Dec 4, 2013 23:11 UTC (Wed) by stevenb (guest, #11536) [Link]

Sooner if you help? ;-)

A Rust frontend for GCC

Posted Dec 5, 2013 2:00 UTC (Thu) by Kit (guest, #55925) [Link]

You can track the rough progress towards the 1.0 milestone on their Issue tracker ( https://github.com/mozilla/rust/issues/milestones?state=o... ). Things are still being added to it, as major (breaking!) changes are still being made to the language (the changes to Managed Pointers and Vector are two big ones coming up, while the IO subsystem changes were ones that just landed in, I believe, 0.8).

There's no timeline yet, although I think (think!) a Rust dev guessed that they might have a clear path to 1.0 in about a year (not that they'd have 1.0 out then, just something akin to a timeline). Rust feels like, once it stabilizes, that it could be a true alternative to C and C++ as a "systems" language.

A Rust frontend for GCC

Posted Dec 6, 2013 0:54 UTC (Fri) by intgr (subscriber, #39733) [Link]

> How do you write "rustic" programs?

You mean, uh, "rusty"? :)

A Rust frontend for GCC

Posted Dec 9, 2013 11:10 UTC (Mon) by bgmarete (guest, #47484) [Link] (6 responses)

Shouldn't the Rust developers be helping out with the Go runtime and standard library?

A Rust frontend for GCC

Posted Dec 9, 2013 13:37 UTC (Mon) by mathstuf (subscriber, #69389) [Link] (1 responses)

What? Go and Rust may have had similar goals (courting C++ developers, being a systems language, and maybe more), but Go has ended up getting more Python and Ruby developers than C++. I think Rust is a much better candidate than Go for a replacement there because of the stronger guarantees it can make (e.g., pointer lifetimes, safe/unsafe blocks) and the lack of a required runtime with GC and such. To be fair, I have also looked more at Rust than Go, but that's because it made a better first impression on me.

A Rust frontend for GCC

Posted Dec 11, 2013 8:01 UTC (Wed) by bgmarete (guest, #47484) [Link]

I hoped (as you probably guessed) to elicit informative replies such as yours and those of below :)

I have been putting off looking at Rust, mostly because it would have been a distraction from Go which has been a lot of fun to learn and use. Like C, it is a very small language which easily fits in the head, its always-improving performance is more than acceptable (and significantly better than Python's) and it supports modern facilities that are useful and which enhance safety. All this has meant that it has replaced Python and C++ where I am concerned, and my real work (business) has come to rely on it a great deal. So I am very anxious to see it advance in great leaps and bounds.

But your comment and Cyberax's below mean that I will be taking a serious look at Rust soon.

A Rust frontend for GCC

Posted Dec 9, 2013 19:45 UTC (Mon) by Cyberax (✭ supporter ✭, #52523) [Link] (3 responses)

Go is a braindead replacement for a system language. It might be a so-so 'fast Python' language but it'll never be an 'easier C++''.

Let's see:
1) It's a compiled language with types but it still has no generics. Fail.
2) Global heap with a GC. It means an endless struggle to make it work acceptably enough on large datasets. Just ask those nice Sun JVM developers.
3) No real new ideas about multithreading.

A Rust frontend for GCC

Posted Dec 10, 2013 21:34 UTC (Tue) by lsl (subscriber, #86508) [Link] (2 responses)

Go isn't supposed to be an easier C++. Its designers made a concsious decision to not build on stuff like C++ or Java but to take a step back first and think about what a systems language really needs. In my opinion this was desperately needed.

> 1) It's a compiled language with types but it still has no generics. Fail.

It's not that bad. Sure, in some cases generics would be nice but in practice it just doesn't seem to be a serious issue. Better no generics than a botched-up design.

> 2) Global heap with a GC. [...]

You have to think about the garbage you're creating if you want good performance, true. In contrast to Java Go gives you the possibilities to acutally control the amount of garbage created (i.e. the allocations done). Oh, and the GC gets better and better with each release.

> 3) No real new ideas about multithreading.

You mean Go's support for concurrency (which is not just multithreading) at the language level? Yes, it's nothing groundbreaking. Stuff like this was available in other (though more exotic) languages for years. So what? Even though the underlying ideas are not new, the realization of them in Go is pretty nice and (IMHO) unmatched by any mainstream language.

In terms of new and exciting language features you never saw anywhere else Go certainly isn't that interesting. But doing actual programming in Go is a lot of fun. IMHO it's a very well designed language. You really notice how much thought went into certain decisions to make its parts work so nicely together. Just look at how all the interface stuff (especially the IO related ones) works out in a real program. You don't get something like that by throwing together tons of unrelated features.

For my programming needs Go replaced C in many places.

A Rust frontend for GCC

Posted Dec 10, 2013 22:48 UTC (Tue) by Cyberax (✭ supporter ✭, #52523) [Link]

> Go isn't supposed to be an easier C++. Its designers made a concsious decision to not build on stuff like C++ or Java but to take a step back first and think about what a systems language really needs. In my opinion this was desperately needed.
That's why Go mostly reminds me of pre-1.5 Java.

> It's not that bad. Sure, in some cases generics would be nice but in practice it just doesn't seem to be a serious issue. Better no generics than a botched-up design.
Mostly because people migrate to Go from dynamic languages.

> You have to think about the garbage you're creating if you want good performance, true. In contrast to Java Go gives you the possibilities to acutally control the amount of garbage created (i.e. the allocations done).
Go does not do ANYTHING different than Java in relation to GC. All the Go objects are allocated on the stack or in the heap, just like in Java.

>Oh, and the GC gets better and better with each release.
Yeah, and it can continue pretty much indefinitely. Up until recently Go used a dumb imprecise conservative GC, right now they are about 5-10 years from the current state-of-the-art GCs.

> You mean Go's support for concurrency (which is not just multithreading) at the language level? Yes, it's nothing groundbreaking.
Exactly. On the other hand, Rust provides guaranteed safe multithreading with very little effort from the programmer.

>In terms of new and exciting language features you never saw anywhere else Go certainly isn't that interesting. But doing actual programming in Go is a lot of fun.
I work on third-party Go code (Docker) and it certainly is NOT fun at all.

Frankly, I'd have preferred a clean Python code to Go code.

A Rust frontend for GCC

Posted Dec 11, 2013 3:29 UTC (Wed) by mathstuf (subscriber, #69389) [Link]

> Go isn't supposed to be an easier C++.

No, but C++ developers migrating to Go was an expectation of the developers[1]. It hasn't happened and instead they're getting Python and Ruby programmers.

[1]http://commandcenter.blogspot.se/2012/06/less-is-exponent...


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