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
- Super Traits PR669 PR666 PR662
- Support stdcall, fastcall, cdecl ABI options PR661
- Multiple File Parsing Support PR663 PR664 PR639
- Initial Compiler Intrinsics PR659 PR660
- Add compiler switch for mangling options PR656
- Initial building blocks for enum support PR657
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
Category | Last Week | This Week | Delta |
TODO | 89 | 89 | – |
In Progress | 6 | 6 | – |
Completed | 186 | 190 | +4 |
Test Cases
Category | Last Week | This Week | Delta |
Passing | 4144 | 4309 | +165 |
XFAIL | 21 | 21 | – |
Bugs
Category | Last Week | This Week | Delta |
TODO | 18 | 19 | +1 |
In Progress | 3 | 3 | – |
Completed | 64 | 65 | +1 |
Milestones Progress
Milestone | Last Week | This Week | Delta | Start Date | Completion Date | Target |
Data Structures 1 – Core | 100% | 100% | – | 30th Nov 2020 | 27th Jan 2021 | 29th Jan 2021 |
Control Flow 1 – Core | 100% | 100% | – | 28th Jan 2021 | 10th Feb 2021 | 26th Feb 2021 |
Data Structures 2 – Generics | 100% | 100% | – | 11th Feb 2021 | 14th May 2021 | 28th May 2021 |
Data Structures 3 – Traits | 92% | 95% | +3% | 20th May 2021 | – | 27th Aug 2021 |
Control Flow 2 – Pattern Matching | 0% | 0% | – | – | – | 29th Oct 2021 |
Imports and Visibility | 0% | 0% | – | – | – | TBD |
Macros and cfg expansion | 0% | 0% | – | – | – | TBD |
Const Generics | 0% | 0% | – | – | – | TBD |
Intrinsics | 0% | 0% | – | – | – | TBD |
Planned Activities
- Dynamic trait objects
- Where constraints