I talked briefly with Graydon Hoare about Rust and C++ at Mozilla Summit 2010 in Whistler, Canada, and since then I keep an eye on the project. Recently I started to read seriously about Rust and I made a plan for my possible contribution to Rust. I would like feedback on the feasibility of the plan and if there is an implementation and it is successful, would the Rust project be interested in using it

urust2c: Unsafe Rust transpiler to C

The sole purpose of the transpiler is to serve as stage0 in bootstrapping Rust in platforms that has only C compiler. Everything that doesn’t serve this purpose is cut off.

(Lack of) Features:

No borrow checker and also other checks. urust2c will be more unsafe than unsafe {}.

No descriptive error messages. On the first error, urust2c will just panic with showing source location and urust2c source location where the panic was triggered.

Here’s a thought: would there be value in a “bootstrap-friendly” Rust interpreter in something more broadly supported (like C) that omits all the correctness analysis, and just assumes the code its given is correct? I’m not sure how much...

Should it be possible to write a program that, given a Rust program, spits out a C11 program that does the same thing? Is it possible today?
This question affects many language points such as the memory model and how volatile reads and writes work. In particular, AFAICT, one cannot implement LLVM’s volatile reads and writes in ISO C11, because LLVM’s volatile read and write primitives cannot be expressed in C.
My own opinion is that it would be a useful experiment to build such a translator be…

For my part I’m skeptical; yes, you can get by without borrowck or dropck, but you still need typeck because it controls overloading and name resolution, and Rust has return type overloading so you can’t cheat with a dynamically typed implementation. Very interested to see what people can come up with though.

This is very similar to the approach I’m doing for my project ‘mrustc’ (http://github.com/thepowersgang/mrustc) - I may eventually get to the point when I can generate readable C code, but for now I’m still slowly working through the compiler stages.

This is very similar to the approach I’m doing for my project ‘mrustc’
(http://github.com/thepowersgang/mrustc) - I may eventually get to the
point when I can generate readable C code, but for now I’m still slowly
working through the compiler stages.

Oh, so there are projects like this. And C++11 is definately nicer than
C+glib

Is the lack of features only to make the analysis phase of your compiler easier? Maybe you could reuse the existing rust compiler as a first pass to check the code validity, before running your own code generator.

Is the lack of features only to make the analysis phase of your
compiler easier? Maybe you could reuse the existing rust compiler as a
first pass to check the code validity, before running your own code
generator.

Lack of these features eases greatly development and future maintenance
of the project while providing stage0 rustc for any platform supported
by glib. urust2c is not meant for any other purpose so it is OK. The
"dialect" we are talking about is like having everything inside unsafe
{}.