GCC Front-End For Rust

Alternative Rust Compiler for GCC

View the Project on GitHub

February 2025 Monthly report

Overview

Thanks again to Open Source Security, inc and Embecosm for their ongoing support for this project.

Project update

We are still working hard to get as many features completed in time before the release of GCC 15.1. We have started preparing our branch for upstreaming patches to the compiler, and are in the process of improving our upstreaming and fork-updating process to make it more streamlined and enable upstreams to happen more often. This is taking quite a bit of time, but we are still on track regarding the milestones we set ourselves for GCC 15.1

We have started work on two major technical features required for handling Rust-for-Linux code: impl Trait types and let-else, two patterns used in the kernel and also often found in user code. Note also that impl Trait types are also used extensively in core, and are thus a requirement for properly handling the Rust standard library.

We have also continued work on our ongoing milestones, such as macro expansion fixes, our name resolution rewrite, and the handling of conditional compilation directives for core. We will then start working on a slimmed down version of specialization, as it is seldom used in core, but still required for properly compiling it.

Pierre-Emmanuel and Arthur will be attending Rust in Paris on the 14th of March, and we are hoping to meet lots of other French Rustaceans. Our next event will then be RustWeek in the Netherlands in May, and we will also be attending EuroRust in Paris where we hope to give a talk on the current state of gccrs.

A missing part of our macro expansion implementation was the handling of the $crate metavar, a special meta-variable used in macros which allows to refer to items defined in the same crate as the macro itself. When such a macro is used in an external crate, the metavar needs to be replaced by the crate-name and a scope resolution operator (::<crate_name>), but when it is used in the current crate, it can simply be replaced by the crate path segment.

In RfL’s inner implementation of its printing macros, this is used for making a call to a specific function: call_printk. This enables calling the macro from the kernel as well as from any kernel modules which uses the kernel as a dependency.


macro_rules! print_macro (
  ($format_string:path, false, $($arg:tt)+) => (
      match format_args!($($arg)+) {
          args => unsafe {
              $crate::print::call_printk(
                  &$format_string,
                  crate::__LOG_PREFIX,
                  args,
              );
          }
      }
  );
);

Another feature we need to handle for Rust in the Linux kernel is let else statements. let else statements look just like regular let statements with a pattern, with an extra diverging else block in case the pattern does not match. This example is taken directly from the kernel’s inner implementation for parsing some of its macros.


let Some(TokenTree::Ident(ident)) = tokens.next() else {
  panic!("expected identifier as modifier");
};

Functionally, the above code is similar to this one:


let ident = match tokens.next() {
  Some(TokenTree::Ident(ident)) => ident,
  _ => panic!("expected identifier as modifier"),
};

However, we cannot just desugar to a match expression despite the behavior being the same. The reason for this is that the following code typechecks:


let foo = match bar() {
  Some(value) => value,
  None => default_value,
};

While this one does not:


let Some(value) = bar() else {
  Some(default_value)
};

As the else block of a let else must be a diverging expression, whose type can only be !. So, something like a return expression or a macro invocation of unreachable!() or panic!().

Playground example


let Some(TokenTree::Ident(ident)) = tokens.next() else {
  panic!("expected identifier as modifier");
};

Finally, we also started working on handling opaque types/~impl Trait types~. This is required for many existing Rust programs and libraries, as it is a feature often used for refering to unnameable types or for more concise code. For example, when specifying complex bounds on a generic type, one can often use an impl Trait type instead:


fn foo<T: Iterator<Item = Bar>>(iterator: T) {}

// becomes

fn foo(iterator: impl Iterator<Item = Bar>) {}

More importantly, they are required for returning unnameable types, for example in the case of closures. We know that closures implement function-like traits, but they don’t have a type that is defined anywhere in source - their type is only known by the compiler. This makes it extremely hard to return them, as one is not quite sure what to put in their function’s signature. We can use the impl Trait notation to express the fact that what we are returning implements a certain trait that we know about (in the case of closures, often Fn, FnOnce or FnMut), and the typechecker will ensure that is the case.


#[inline]
fn flatten<U: Iterator, Acc>(
  fold: &mut impl FnMut(Acc, U::Item) -> Acc,
) -> impl FnMut(Acc, U) -> Acc + '_ {
  move |acc, iter| iter.fold(acc, &mut *fold)
}

In the case of Rust-for-Linux, this is also used to abstract complex memory operations used when dealing with self-referential types. The kernel offers a helpful pin_init!() macro for initializing self-referrential types, but the concrete type is not known by the user and thus cannot be named - all the user needs to know about is that this type implements the PinInit trait.


impl Example {
  fn new() -> impl PinInit<Self> {
      pin_init!(Self {
          c: 10,
          d <- new_mutex!(Inner { a: 20, b: 30 }),
      })
  }
}

Call for contribution

Completed Activities

Contributors this month

Overall Task Status

Category Last Month This Month Delta
TODO 308 294 -14
In Progress 96 93 -3
Completed 933 981 +48

Bugs

Category Last Month This Month Delta
TODO 108 102 -6
In Progress 43 32 -11
Completed 461 477 +16

Test Cases

TestCases Last Month This Month Delta
Passing 9500 9762 +262
Failed - - -
XFAIL 182 114 -68
XPASS - - -

Milestones Progress

Milestone Last Month This Month Delta Start Date Completion Date Target Target GCC
Name resolution 2.0 rework 28% 28% - 1st Jun 2024 - 1st Apr 2025 GCC 15.1
Macro expansion 56% 86% +30% 1st Jun 2024 - 1st Jan 2025 GCC 15.1
Remaining typecheck issues 88% 88% - 21st Oct 2024 - 1st Mar 2025 GCC 15.1
cfg-core 15% 75% +60% 1st Dec 2024 - 1st Mar 2025 GCC 15.1
Codegen fixes 10% 10% - 7th Oct 2024 - 1st Mar 2025 GCC 15.1
black_box intrinsic 20% 50% +30% 28th Oct 2024 - 28th Jan 2025 GCC 15.1
Question mark operator 66% 100% +34% 15th Dec 2024 21st Feb 2025 21st Feb 2025 GCC 15.1
let-else 0% 30% +30% 28th Jan 2025 - 28th Feb 2025 GCC 15.1
Specialization 0% 0% - 1st Jan 2025 - 1st Mar 2025 GCC 15.1
Upcoming Milestone Last Month This Month Delta Start Date Completion Date Target Target GCC
Unstable RfL features 0% 0% - 7th Jan 2025 - 1st Mar 2025 GCC 15.1
cfg-rfl 0% 0% - 7th Jan 2025 - 15th Feb 2025 GCC 15.1
Explicit generics with impl Trait 0% 0% - 28th Feb 2025 - 28th Mar 2025 GCC 15.1
Downgrade to Rust 1.49 0% 0% - - - 1st Apr 2025 GCC 15.1
offset_of!() builtin macro 0% 0% - 15th Mar 2025 - 15th May 2025 GCC 15.1
Generic Associated Types 0% 0% - 15th Mar 2025 - 15th Jun 2025 GCC 16.1
RfL const generics 0% 0% - 1st May 2025 - 15th Jun 2025 GCC 16.1
frontend plugin hooks 0% 0% - 15th May 2025 - 7th Jul 2025 GCC 16.1
Handling the testsuite issues 0% 0% - 15th Sep 2024 - 15th Sep 2025 GCC 16.1
main shim 0% 0% - 28th Jul 2025 - 15th Sep 2025 GCC 16.1
Past Milestone Last Month This Month Delta Start Date Completion Date Target Target GCC
Data Structures 1 - Core 100% 100% - 30th Nov 2020 27th Jan 2021 29th Jan 2021 GCC 14.1
Control Flow 1 - Core 100% 100% - 28th Jan 2021 10th Feb 2021 26th Feb 2021 GCC 14.1
Data Structures 2 - Generics 100% 100% - 11th Feb 2021 14th May 2021 28th May 2021 GCC 14.1
Data Structures 3 - Traits 100% 100% - 20th May 2021 17th Sep 2021 27th Aug 2021 GCC 14.1
Control Flow 2 - Pattern Matching 100% 100% - 20th Sep 2021 9th Dec 2021 29th Nov 2021 GCC 14.1
Macros and cfg expansion 100% 100% - 1st Dec 2021 31st Mar 2022 28th Mar 2022 GCC 14.1
Imports and Visibility 100% 100% - 29th Mar 2022 13th Jul 2022 27th May 2022 GCC 14.1
Const Generics 100% 100% - 30th May 2022 10th Oct 2022 17th Oct 2022 GCC 14.1
Initial upstream patches 100% 100% - 10th Oct 2022 13th Nov 2022 13th Nov 2022 GCC 14.1
Upstream initial patchset 100% 100% - 13th Nov 2022 13th Dec 2022 19th Dec 2022 GCC 14.1
Update GCC’s master branch 100% 100% - 1st Jan 2023 21st Feb 2023 3rd Mar 2023 GCC 14.1
Final set of upstream patches 100% 100% - 16th Nov 2022 1st May 2023 30th Apr 2023 GCC 14.1
Borrow Checking 1 100% 100% - TBD 8th Jan 2024 15th Aug 2023 GCC 14.1
Procedural Macros 1 100% 100% - 13th Apr 2023 6th Aug 2023 6th Aug 2023 GCC 14.1
GCC 13.2 Release 100% 100% - 13th Apr 2023 22nd Jul 2023 15th Jul 2023 GCC 14.1
GCC 14 Stage 3 100% 100% - 1st Sep 2023 20th Sep 2023 1st Nov 2023 GCC 14.1
GCC 14.1 Release 100% 100% - 2nd Jan 2024 2nd Jun 2024 15th Apr 2024 GCC 14.1
format_args!() support 100% 100% - 15th Feb 2024 - 1st Apr 2024 GCC 14.1
GCC 14.2 100% 100% - 7th Jun 2024 15th Jun 2024 15th Jun 2024 GCC 14.2
GCC 15.1 100% 100% - 21st Jun 2024 31st Jun 2024 1st Jul 2024 GCC 15.1
Unhandled attributes 100% 100% - 1st Jul 2024 15th Aug 2024 15th Aug 2024 GCC 15.1
Inline assembly 100% 100% - 1st Jun 2024 26th Aug 2024 15th Sep 2024 GCC 15.1
Rustc Testsuite Adaptor 100% 100% - 1st Jun 2024 26th Aug 2024 15th Sep 2024 GCC 15.1
Borrow checker improvements 100% 100% - 1st Jun 2024 26th Aug 2024 15th Sep 2024 GCC 15.1
Deref and DerefMut improvements 100% 100% - 28th Sep 2024 25th Oct 2024 28th Dec 2024 GCC 15.1
Indexing fixes 100% 100% - 21st Jul 2024 25th Dec 2024 15th Nov 2024 GCC 15.1
Iterator fixes 100% 100% - 21st Jul 2024 25th Dec 2024 15th Nov 2024 GCC 15.1
Auto traits improvements 100% 100% - 15th Sep 2024 20th Jan 2025 21st Dec 2024 GCC 15.1
Lang items 100% 100% - 1st Jul 2024 10th Jan 2025 21st Nov 2024 GCC 15.1
alloc parser issues 100% 100% - 7th Jan 2025 31st Jun 2024 28th Jan 2025 GCC 15.1
std parser issues 100% 100% - 7th Jan 2025 31st Jun 2024 28th Jan 2025 GCC 16.1

Planned Activities

Risks

We have now entered Stage 3 of GCC development, and all of the patches we needed to get upstreamed have been upstreamed. The risk that were outlined here are no longer present, and we are focusing on getting as many features implemented and upstreamed as possible.