GCC Rust Weekly Status Report 36

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

Milestone Progress

Before starting any development on macros, I have been working through the branches of code I have sitting around before they go stale. So I merged the constexpr work, which begins the port of the C++ frontend’s constexpr support. I have two remaining branches, one implementing slices needed for our goal test case and another, which fixes up our method resolution, which I want to get merged this week so we can get stuck into macros without hangover branches which could get lost. Apart from that, I found there were already quite a few issues relating to macros and config expansion we had already created, which has helped plan our macros milestone. However, some details need to be filled in, but this has bootstrapped our milestone planning.

Google Summer of Code 2022

As part of the GCC organisation we hope to be accepted for Google Summer of Code 2022 this year if you wish to find out more information please read:

Community Call

We had our community call on 14th Jan 2022 you can find the meeting notes over here: https://github.com/Rust-GCC/Reporting/blob/main/2022-01-14-community-call.md

Completed Activities

  • Add constant folding to const functions PR870
  • Track begin and end location info on block expressions improving debug information PR874

Contributors this Week

Overall Task Status

CategoryLast WeekThis WeekDelta
In Progress1918-1
GitHub Issues

Test Cases

CategoryLast WeekThis WeekDelta
make check-rust


CategoryLast WeekThis WeekDelta
In Progress65-1
GitHub Bugs

Milestones Progress

MilestoneLast WeekThis WeekDeltaStart DateCompletion DateTarget
Data Structures 1 – Core100%100%30th Nov 202027th Jan 202129th Jan 2021
Control Flow 1 – Core100%100%28th Jan 202110th Feb 202126th Feb 2021
Data Structures 2 – Generics100%100%11th Feb 202114th May 202128th May 2021
Data Structures 3 – Traits100%100%20th May 202117th Sept 202127th Aug 2021
Control Flow 2 – Pattern Matching100%100%20th Sept 202129th Nov 2021
Macros and cfg expansion0%9%+9%1st Dec 202128th Mar 2022
Imports and Visibility0%0%29th Mar 202227th May 2022
Const Generics0%0%30th May 202225th Jul 2022
Intrinsics0%0%6th Sept 202130th Sept 2022
GitHub Milestones


RiskImpact (1-3)Likelihood (0-10)Risk (I * L)Mitigation
Rust Language Changes3721Keep up to date with the Rust language on a regular basis
Going over target dates3515Maintain status reports and issue tracking to stakeholders

Planned Activities

  • Complete work on Slices
  • Complete bug fixes for Method Resolution

Detailed changelog

Initial support for constant evaluation of const functions

Rust supports constant evaluation of constants including constant functions. Below is an example of this:

const A: i32 = 1;
const B: i32 = { A + 2 };

const fn test() -> i32 {

const C: i32 = {
    const a: i32 = 4;
    test() + a

fn main() -> i32 {
    C - 7

In Rust this compilation unit is expected to evaluate the main function to return zero always. This is evident when you evaluate the constants, the problem for GCC Rust arose when you consider this example using arrays:

const fn const_fn() -> usize {

const FN_TEST: usize = const_fn();

const TEST: usize = 2 + FN_TEST;

fn main() -> i32 {
    let a: [_; 12] = [5; TEST * 2];
    a[6] - 5

Arrays in rust always have a constant capacity to disallow any variable-length arrays. This means we need to be able to type check that the array capacities match correctly. In GCC this compilation unit can be optimized and folded when optimizations are enabled, but in Rustc this still works regardless of optimization level. So GCC Rust needed the same behaviour and it turns out constexpr in C++ is very similar to this, and we are now reusing the C++ front-ends constexpr code to get this support. Now that we are reusing this C++ front-end code we can get the array capacity checking as well so when we get a case where the capacities are bad we get the following error message:

<source>:2:21: error: expected an array with a fixed size of 5 elements, found one with 3 elements
    2 |     let a:[i32;5] = [1;3];
      |                     ^

Leave a Reply

Your email address will not be published. Required fields are marked *