GCC Front-End For Rust

Alternative Rust Compiler for GCC

View the Project on GitHub

March 2025 Monthly report

Overview

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

Project update

74 pull-requests were merged this month, with multiple internal compiler error fixes thanks to the fuzzing work done by Matthias Krüger, which helped expose multiple invalid code paths in the compiler. Thank you!

We also spent some time getting our mininum supported Rust version down to Rust 1.49 for our Rust components. As a reminder, Rust 1.49 is the version that gccrs currently targets, and getting our own Rust components compilable with this version also means getting closer and closer to gccrs compiling its own components - an objective we will pursue as soon as we are able to compile the Rust standard library. This also enables for more testing on less common systems, as certain versions of Darwin or Ubuntu still in use by our community only have access to older Rust installations.

We are still working on developing new features and upstreaming them in time for the GCC 15.1 release. The cutoff date for the branch is yet to be announced, but should happen soon. We have continued work on our milestones, and have spent a lot of time getting further and further into the compilation of core. This opened new issues on the project with our macro expansion and name resolution, which we quickly fixed in the last few weeks.

One of the focus of this month was adding support for the min_specialization feature, which you can learn more about here. In its current form, gccrs only supports a subset of min_specialization, which itself is a subset of specialization in general. We are required to support parts of this feature as it used in core to improve runtime performance in certain cases.

For example, the machinery responsible for implementing Iterator::zip (as a reminder, Iterator::zip enables you to tie together two iterators and advance them as the same time) lives in the core::iter::adapters::ZipImpl trait, whose definition looks like this:


// Zip specialization trait
#[doc(hidden)]
trait ZipImpl<A, B> {
    type Item;
    fn new(a: A, b: B) -> Self;
    fn next(&mut self) -> Option<Self::Item>;
    fn size_hint(&self) -> (usize, Option<usize>);
    fn nth(&mut self, n: usize) -> Option<Self::Item>;
    fn next_back(&mut self) -> Option<Self::Item>
    where
        A: DoubleEndedIterator + ExactSizeIterator,
        B: DoubleEndedIterator + ExactSizeIterator;
    // This has the same safety requirements as `Iterator::__iterator_get_unchecked`
    unsafe fn get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item
    where
        Self: Iterator + TrustedRandomAccess;
}

If we keep reading through the file, we can see two implementations for this trait:


impl<A, B> ZipImpl<A, B> for Zip<A, B>
where
    A: Iterator,
    B: Iterator,
{ /* ... */ }

// and ...

#[doc(hidden)]
impl<A, B> ZipImpl<A, B> for Zip<A, B>
where
    A: TrustedRandomAccess + Iterator,
    B: TrustedRandomAccess + Iterator,
{ /* ... */ }

In one case, the implementation is more specialized and adds an extra bound - TrustedRandomAccess. Without specialization, these two implementations are ambiguous, as they contain similar bounds. But by using specialization, the core library is able to provide a default, safe and slower implementation of zip while also providing a fast one where possible, for example if the iterators support trusted random access, meaning it supports efficent and safe random index accesses.

The method next for these two implementations of ZipImpl thus look like the following:


impl<A, B> ZipImpl<A, B> for Zip<A, B>
where
    A: Iterator,
    B: Iterator,
{
    #[inline]
    default fn next(&mut self) -> Option<(A::Item, B::Item)> {
        let x = self.a.next()?;
        let y = self.b.next()?;
        Some((x, y))
    }
}

// and...

impl<A, B> ZipImpl<A, B> for Zip<A, B>
where
    A: TrustedRandomAccess + Iterator,
    B: TrustedRandomAccess + Iterator,
{
    #[inline]
    fn next(&mut self) -> Option<(A::Item, B::Item)> {
        if self.index < self.len {
            let i = self.index;
            self.index += 1;
            // SAFETY: `i` is smaller than `self.len`, thus smaller than `self.a.len()` and `self.b.len()`
            unsafe {
                Some((self.a.__iterator_get_unchecked(i), self.b.__iterator_get_unchecked(i)))
            }
        } else if A::may_have_side_effect() && self.index < self.a.size() {
            // match the base implementation's potential side effects
            // SAFETY: we just checked that `self.index` < `self.a.len()`
            unsafe {
                self.a.__iterator_get_unchecked(self.index);
            }
            self.index += 1;
            None
        } else {
            None
        }
    }
}

In the more specific method, the behavior is the same, but the implementation makes use of extra type information to provide faster runtime performance when selecting the next items to iterate on. With the work done this month, gccrs is now able to select these faster methods without producing an “ambiguous method resolution” error. While specialization is not used in Rust-for-Linux, it is important that we are able to resolve to the same methods as rustc when compiling code. This will also make for more optimized binaries and a faster kernel once we are able to compile Rust-for-Linux. In order to fully support min_specialization however, we would need to implement a new algorithm for deciding between two default functions and choosing the most specific one, which would require the development of a new decision tree and the associated algorithms. This is not required for core or Rust-for-Linux, and will thus be worked on at a later date.

Community call

We will have our next monthly community call on the 22nd of April at 9am UTC. You can subscribe to our calendar to see when the next one will be held. The call is open to everyone, even if you would just like to sit-in and listen. You can also subscribe to our mailing-list or join our Zulip chat to be notified of upcoming events.

Call for contribution

Completed Activities

Contributors this month

Overall Task Status

Category Last Month This Month Delta
TODO 294 493 +199
In Progress 93 119 +26
Completed 981 1035 +54

Bugs

Category Last Month This Month Delta
TODO 102 218 +116
In Progress 32 55 -23
Completed 477 510 +33

Test Cases

TestCases Last Month This Month Delta
Passing 9762 10296 +534
Failed - - -
XFAIL 114 81 -33
XPASS - - -

Milestones Progress

Milestone Last Month This Month Delta Start Date Completion Date Target Target GCC
Name resolution 2.0 rework 28% 49% +21% 1st Jun 2024 - 1st Apr 2025 GCC 15.1
Macro expansion 86% 90% +4% 1st Jun 2024 - 1st Jan 2025 GCC 15.1
Remaining typecheck issues 88% 98% +10% 21st Oct 2024 - 1st Mar 2025 GCC 15.1
cfg-core 75% 100% +25% 1st Dec 2024 24th Mar 2025 1st Mar 2025 GCC 15.1
Codegen fixes 10% 100% +90% 7th Oct 2024 1st Apr 2025 1st Mar 2025 GCC 15.1
blackbox intrinsic 50% 75% +25% 28th Oct 2024 - 28th Jan 2025 GCC 15.1
let-else 30% 60% +30% 28th Jan 2025 - 28th Feb 2025 GCC 15.1
Specialization 0% 100% +100% 1st Jan 2025 1st Apr 2025 1st Mar 2025 GCC 15.1
cfg-rfl 0% 100% +100% 7th Jan 2025 19th Mar 2025 15th Feb 2025 GCC 15.1
Downgrade to Rust 1.49 0% 100% +100% 14th Mar 2025 26th Mar 2025 1st Apr 2025 GCC 15.1
Explicit generics with impl Trait 0% 40% +40% 28th Feb 2025 - 28th 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 Aug 2025 GCC 16.1
offsetof!() builtin macro 0% 0% - 15th Mar 2025 - 15th Aug 2025 GCC 16.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
formatargs!() 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
Question mark operator 100% 100% - 15th Dec 2024 21st Feb 2025 21st Feb 2025 GCC 15.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.