GCC Rust Weekly Status Report 40

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

Milestone Progress

This is a milestone week for GCC Rust; our previous Google Summer of Code student Arthur Cohen joins us in Embecosm, Germany, working on the compiler full time. With the additional resource, we can split up work and delegate tasks allowing multiple streams of complex work to take place, which free’s Philip up to work on Slice’s and bugs in the type system.

Concerning our macro expansion milestone, this week saw a big push forward with the boilerplate merged; many simple macros are now working. This work includes appropriately matching rules and taking into account the fragment types such as ‘expr’ and ‘ty’ for example, this allows a kind of type checking in macro invocations.

Thanks to Mark Wielaard for his build farm, helping us catch issues early, and lending access to his build bots where we find issues on different architectures.

Completed Activities

  • Add Macro expansion tests PR926
  • BugFix CFG expansion values require quotes PR931 PR935
  • Add cargo-gccrs to our DockerFile PR937
  • Add missing location into to macros PR934 PR933 PR932
  • Add support for Macro Expansion PR938
  • Add missing location into to AST PR940
  • replace lambda with std::vector reference in AST::PathPattern PR942
  • Add clear_errors to make parser reuseable for macro expansion PR944
  • Support matching macro repetition rules PR950
  • Add name resolution for slice’s PR951

Contributors this Week

Overall Task Status

CategoryLast WeekThis WeekDelta
In Progress1116+5
GitHub Issues

Test Cases

CategoryLast WeekThis WeekDelta
make check-rust


CategoryLast WeekThis WeekDelta
In Progress16+5
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 20219th Dec 202129th Nov 2021
Macros and cfg expansion50%63%+13%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

  • Continue Macro repetition pattern support
  • Complete Slice support and retest goal test case

Detailed changelog

Declarative Macro Expansion

We have merged our first pass of the macro expansion pass. The approach taken here is that we reuse our existing parser to call the appropriate functions as specified as part of the MacroFragmentType enum if the parser does not have errors parsing that item then it must be a match. Then once we match a rule we have a map of the token begin/end offsets for each fragment match, this is then used to adjust and create a new token stream for the macro rule definition so that when we feed it to the parser the tokens are already substituted. The resulting expression or item is then attached to the respective macro invocation and this is then name resolved and used for hir lowering.

In this example, the macro has two rules so we demonstrate that we match the appropriate rule and transcribe it respectively.

macro_rules! add {
    ($a:expr,$b:expr) => {
        $a + $b
    ($a:expr) => {

fn main() -> i32 {
    let mut x = add!(1);
    x += add!(2, 3);

    x - 6

Another example:

macro_rules! Test {
    ($a:ident, $b:ty) => {
        struct $a($b);

Test!(Foo, i32);

fn main() -> i32 {
    let a = Foo(123);
    a.0 - 123

Here we take into account the context of the macro invocation and parse it into AST::Items. In the even of failure to match a rule the compiler error looks like the following:

<source>:11:17: error: Failed to match any rule within macro
    1 | macro_rules! add {
      | ~                
   11 |     let mut x = add!(1, 2, 3);
      |                 ^

More error handling has been added for when the transcribed rule actually is not fully used so for example:

<source>:4:9: error: tokens here and after are unparsed
    4 |         struct BAD($b);
      |         ^

see: https://godbolt.org/z/TK3qdG56n

Leave a Reply

Your email address will not be published.