GCC Rust Weekly Status Report 15

Overview

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

Milestone Progress

As of the 14th of May the Generics milestone is now completed. This was a big goal for the compiler as it forms a basis to move forward with substitutions in general which are required for Traits since Traits can also be generic. Please note that the compiler explorer version of GCC Rust is several weeks out of date, leading bug reports for things that are already fixed/implemented.

Vacation

Philip Herron is taking 17th, 18th and 19th May 2021 as vacation.

Detailed changelog

Support impl items with generic parameters

Rust allows for the impl block to be generic like we have already seen in previous status reports, but it also allows for the impl items which inherit those generic parameters to also then be generic. This was a great test for the generics implementation since it required a cleanup of existing code rather than rewriting or changing the implementation to fit. The compiler in this instance is performing 2 substitutions in order to support this.

  1. Where the method test applies the substitutions from the variable ‘a’ Foo<i32, f32> onto self
  2. Infer the final type parameter X on the method or apply the turbo fish.
struct Foo<A, B>(A, B);

impl<T> Foo<T, f32> {
    fn test<X>(self, a: X) -> (T, X) {
        (self.0, a)
    }
}

fn main() {
    let a;
    a = Foo(123, 456f32);

    let b;
    b = a.test::<bool>(false);
}

Symbol mangling

Rustc supports two types of symbol mangling:

V0 is used in the Rust Linux project but as it is unstable/incomplete it seems prudent to wait for that to stabilise before implementing this but the goal is that GCC Rust should implement both Legacy and V0. The Issue with the legacy symbol mangling is that it uses characters such as $ and has an unstable SIP128 has at the end of the symbol. We now support the legacy symbol mangling but the hash is an FNV-128 hash for now as FNV is simpler to implement than SIP-128.

With the latest version of binutils you can invoke the rust-demangling with:

$ /opt/binutils-master/bin/c++filt --format=rust _ZN9TestCrate3foo17h3085c8a5747c85a8E
TestCrate::foo::h3085c8a5747c85a8

Fix Duplicate function generation

When we have generic methods/functions the compiler needs to substitute the types apropriately so when we see Foo::new called with the same type the compiler needs to check if we have already generated a generic function implementation for this already. Otherwise this leads to duplicate symbol generation issues and increased code size.

struct Foo<A, B>(A, B);

impl Foo<i32, bool> {
    fn new<T>(a: T) -> (Self, T) {
        (Self(123, false), a)
    }
}

fn main() {
    let _a = Foo::new(123f32);
    let _b = Foo::new(123f32);

    let _d = Foo::new(123u32);
    let _d = Foo::new(123u32);
}

In this example there should only be 2 versions of Foo::new generated.

  • Foo::new<f32>
  • Foo::new<u32>

Completed Activities

  • Fix duplicate generic function/method generation – PR427
  • Add legacy symbol mangling – PR425 PR430
  • Support Impl items to also be generic – PR424
  • Add test case to cover bug report (already fixed) – PR422

Overall Task Status

CategoryLast WeekThis WeekDelta
TODO6976+7
In Progress84-2
Completed128133+5
GitHub Issues

Test Cases

CategoryLast WeekThis WeekDelta
Passing22612314+53
XFAIL4042+2
Failed
make check-rust

Bugs

CategoryLast WeekThis WeekDelta
TODO1517+2
In Progress51-4
Completed3742+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 – Generics92%100%+8%11th Feb 202114th May 202128th May 2021
Data Structures 3 – Traits0%0%27th Aug 2021
Control Flow 2 – Pattern Matching0%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
Rust Language Changes3721Keep up to date with the Rust language on a regular basis

Planned Activities

  • Plan out traits milestone

Leave a Reply

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