GCC Rust – Weekly Status Report – 1st to 8th Feb 2021

The control flow one milestone is filling in the gaps in basic rust compilation such as impl blocks, method resolution, block expressions and loops.

When the PR for block expressions was merged regressions in implicit returns were found via manual testing. The automated test suite failed to pick this up due to a bug in the fail compilation test suite where we have test cases which we expect the compiler to find an error such as expected <integer> got bool for example. The dejagnu test suite needs some work to conform to more of the GCC idioms to fix this. We can also implement a macro interception for println and assert_eq to resolve to a libc equivalent until macro expansion is ready.

Gaps in automated testing will be addressed when moving into Generics and Traits where regressions might creep in.

Milestone Overview

We can now compile block expressions such as:

fn test() -> i32 {
    123
}

fn main() {
    let a = {
        let a = test() + 2;
        a + 123
    };
    let b = {
        if a > 10 {
            a - 1
        } else {
            a + 1
        }
    };
}

Many rust developers will rightly comment that the above example could be much simpler such as:

let b = if a > 10 { a - 1 } else { a + 1 };

Currently the parser has a bug in parsing the block without braces at the start which has been raised but in theory all the code is there to handle this when this bug is fixed. The other major feature was method resolution and impl blocks such as:

struct Point {
    x: f64,
    y: f64,
}

impl Point {
    fn origin() -> Point {
        Point { x: 0.0, y: 0.0 }
    }

    fn new(x: f64, y: f64) -> Point {
        Point { x: x, y: y }
    }
}

struct Rectangle {
    p1: Point,
    p2: Point,
}

impl Rectangle {
    fn from(p1: Point, p2: Point) -> Self {
        Self { p1, p2 }
    }
}

fn main() {
    let p1 = Point::origin();
    let p2 = Point::new(3.0, 4.0);
    let rect = Rectangle::from(p1, p2);

    let sum = rect.sum_x();
}

impl Rectangle {
    fn sum_x(self) -> f64 {
        let p1 = self.p1;
        let p2 = self.p2;
        p1.x + p2.x
    }
}

This example shows a method being resolved and called (Rectangle::sum_x), which leads to realising scanning for unused names or types cannot be done until we resolve all types because it is only at that point the compiler can resolve fields in algebraic data types as well as methods which were also fixed.

Completed Activities

  • Block Expressions: PR210 PR211 PR215
  • Compiler Warning Fixes: PR209
  • Enforce Duplicate definition rules: PR207
  • Move scan for unused names/types to be after type resolution: PR206
  • Impl Blocks and method resolution with self and Self: PR203 PR205
  • Split out the integer inference variable tests and add missing cases: PR202

Overall Task Status

Last WeekThis WeekDelta
TODO5553-2
In Progress34+1
Completed4654+8
GitHub Issues

Test Cases

Last WeekThis WeekDelta
Passing556688+132
Failed000
make check-rust

Bugs

Last WeekThis WeekDelta
TODO34+1
In Progress02+2
Completed910+1
GitHub bugs

Milestones Progress

MilestoneLast WeekThis WeekDeltaStart DateCompletion DateTarget
Data Structures 1100%100%30th November 202027th Jan 202129th Jan 2021
Control Flow 114%68%+54%28th Jan 202126th Feb 2021
Data Structures 20%0%28st May 2021
Data Structures 30%0%27th Aug 2021
Control Flow 20%0%29th Oct 2021
Imports and Visibility0%0%TBD
GitHub milestones

Risks

RiskImpact (1-3)Likelihood (0-10)Risk (I * L)Mitigation
Copyright assignments2510Be up front on all PRs that the code is destined to be upstreamed to FSF

Planned Activities

  • Bugs
  • Loops
  • Documentation

Leave a Reply

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