GCC Rust Weekly Status Report 27

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

Milestone Progress

Last week saw lots of great progress and collaboration within the community. As a result, we can now compile code that will require the expansion of multiple files, super trait support now enforces improved type-bounds handling, and we have initial support for some compiler intrinsics. Although compiler intrinsics are not part of the traits milestone, there are over 200 of them to implement and will be an excellent way for people to gain exposure to GCC and compiler development.

The remaining work to complete the traits milestone is about operator overloading and where constraints. The other related piece is that implementing the autoderef system for method resolution requires operator overloading to be done first since this system relies on the Deref Trait. I will be moving this to the next control flow milestone.

Since the community is making significant progress, I will be sticking to my original plan of going onto control flow 2 (Pattern Matching) next. There is plenty of work here to help clean up the compiler in general before working on macros and expansions.

Linux Plumbers 2021

I will be giving a talk about GCC Rust on the 20th September 2021 at 0900 (us-pacific-time). Find more information over on https://linuxplumbersconf.org/event/11/contributions/911/

Thanks to Miguel Ojeda for reaching out to let me know about the Rust toolchain within the Kernel microconference: https://linuxplumbersconf.org/event/11/contributions/970/

Detailed changelog

Super Traits

Getting super traits working is a bit like lowering a trait definition like this:

trait A: B {}
trait A where Self: B {}

Pretty much all of the items in a trait declaration are a bunch of generic functions with the implicit TypeParameter of Self which has the Bound of the super Trait. The example below demonstrates how we combine super traits and qualified paths. Thanks to Philipp Krones for writing this test case.

extern "C" {
    fn printf(s: *const i8, ...);
}

trait A {
    fn a() -> i32 {
        123
    }
}

trait B: A {
    fn b() -> i32 {
        <T as A>::a() + 456
    }
}

struct T;
impl A for T {
    fn a() -> i32 {
        321
    }
}

struct S;
impl A for S {}
impl B for S {}

fn main() -> i32 {
    let aa = S::a();
    let bb = S::b();

    unsafe {
        let a = "%i, %i\n\0";
        let b = a as *const str;
        let c = b as *const i8;

        printf(c, aa, bb);
    }
    0
}

ABI Options

We have added the initial support for other ABI options for example:

extern "stdcall" {
    pub fn test(a: i32) -> i32;
}

extern "C" {
    fn printf(s: *const i8, ...);
}

fn main() -> i32 {
    unsafe {
        let a = 3;
        let res = test(a);

        let a = "%i\n\0";
        let b = a as *const str;
        let c = b as *const i8;

        printf(c, res);
    }
    0
}

Which can be linked against C code such as:

__attribute__ ((stdcall)) int test(int x)  {
  return x + 3;
}

This ABI option can then be used by compiling like this:

$ gccrs -g -O0 -m32 -c test.rs -o test.o
$ gcc -g -O0 -m32 -c lib.c -o lib.o
$ gcc -m32 -o test test.o lib.o

Multiple File Parsing

Thanks to Marc Poulhiès and Arthur Cohen their combined efforts have now let the GCC Rust compiler expand modules

#[path ="modules/valid_path.rs"]
mod path_without_extra_equal;

mod some_module;

Note we still do not have support for visibility modifiers.

Intrinsics

extern "rust-intrinsic" {
    pub fn sqrtf32(x: f32) -> f32;
    pub fn sinf32(x: f32) -> f32;
}

fn main() {
    let mut f32;

    f32 = sqrtf32(5f32);
    f32 = sinf32(39f32);
}

We have only implemented some basic intrinsics so far there is a lot work though see this checklist. Note that we have not implemented the feature gate around allowing users to define this rust-intrinsic block.

Completed Activities

Contributors this week

Excluding merges, 5 authors have pushed 24 commits to master and 24 commits to all branches. On master, 52 files have changed and there have been 1,686 additions and 618 deletions.

Overall Task Status

CategoryLast WeekThis WeekDelta
TODO8989
In Progress66
Completed186190+4
GitHub Issues

Test Cases

CategoryLast WeekThis WeekDelta
Passing41444309+165
XFAIL2121
make check-rust

Bugs

CategoryLast WeekThis WeekDelta
TODO1819+1
In Progress33
Completed6465+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 – Traits92%95%+3%20th May 202127th Aug 2021
Control Flow 2 – Pattern Matching0%0%29th Oct 2021
Imports and Visibility0%0%TBD
Macros and cfg expansion0%0%TBD
Const Generics0%0%TBD
Intrinsics0%0%TBD
GitHub Milestones

Planned Activities

  • Dynamic trait objects
  • Where constraints

Leave a Reply

Your email address will not be published.