public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Arthur Cohen <arthur.cohen@embecosm.com>
To: GCC Mailing List <gcc@gcc.gnu.org>
Subject: [Request for Comments] Using Rust libraries in the Rust frontend
Date: Mon, 22 Jan 2024 18:30:41 +0100	[thread overview]
Message-ID: <34fec7ea-8762-4cac-a1c8-ff54e20e31ed@embecosm.com> (raw)

Hi everyone,

In order to increase the development speed of Rust features, we are 
seeking feedback on reusing some Rust components directly within our 
front-end. As mentioned in other conferences, the most important 
component we would like to integrate into the front-end is the polonius 
borrow-checker. Another component we've become interested in is the 
`rustc_format_parser` library, responsible for handling parsing and 
handling of format arguments as described in the documentation for 
`std::fmt` [1].

However, since these libraries are written in Rust, GCC in itself is not 
yet able to compile them. They all depend on the Rust standard library, 
which we cannot yet compile and link properly. This obviously raises a 
question - how to actually compile, integrate and distribute these 
components?

We do have the option to rewrite them from scratch, but we feel that 
spending time on these existing, correct, battle-tested and easily 
integrable components instead of focusing on other aspects of the 
language would be a mistake. Spending this time instead on Rust features 
that we are missing for compiling these components would, in our 
opinion, yield more results, as it would also help in compiling other 
Rust programs.

We could either distribute these components as compiled libraries, or 
look at integrating the official Rust compiler to our build system as a 
temporary measure. I am aware that this would mean restricting the Rust 
GCC front-end to platforms where the official Rust compiler is also 
available, which is less than ideal. However, this would only be 
temporary - as soon as the Rust front-end is able to compile these 
components, we would simply reuse them and compile them with gccrs as 
part of our bootstrapping process.

The documentation for `std::fmt` [1] describes all of the features 
available in Rust format strings. It also contains a grammar for the 
format-string parser, which we would need to re-implement on top of 
supporting all the formatting features. As a prototype, I wrote an FFI 
interface to the `rustc_format_parser`  library and integrated it to our 
macro expansion system, which took me less than a couple hours. In less 
than an afternoon, we had bindings for all of the exported types and 
functions in the library and had access to a compliant and performant 
Rust format string parser. But re-implementing a correct 
`format_args!()` parser - with the same performance as the Rust one, and 
the same amount of features - would probably take days, if not weeks. 
And we are talking about one of the simplest components we aim to reuse. 
Something like a fully-compliant trait solver for the Rust programming 
language would take months if not years to implement properly from scratch.

I would like to stress once again that relying on distributing compiled 
libraries or using `rustc` in our build system would be temporary, and 
that these measures would be removed as soon as gccrs is able to compile 
these components from source.

I am looking for comments on this decision as well as the best practices 
we could adopt. Have there been any similar decisions for other 
self-hosted front-ends? Any previous email threads/commits that you 
could point me to would be greatly appreciated.

Thanks,

Arthur

[1]: https://doc.rust-lang.org/std/fmt/

             reply	other threads:[~2024-01-22 17:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-22 17:30 Arthur Cohen [this message]
2024-01-23  7:23 ` Richard Biener
2024-01-25 15:03   ` Arthur Cohen
2024-01-25 15:55     ` connor horman
2024-01-26  9:30       ` Arthur Cohen
2024-01-25 16:26     ` Iain Sandoe
2024-01-26  9:28       ` Arthur Cohen
2024-01-26 21:39       ` NightStrike
2024-01-26 23:25         ` David Starner
2024-01-25 18:19     ` Richard Biener
2024-01-26  9:24       ` Arthur Cohen
2024-01-26 21:41 ` NightStrike

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=34fec7ea-8762-4cac-a1c8-ff54e20e31ed@embecosm.com \
    --to=arthur.cohen@embecosm.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).