GCC Rust Weekly Status Report 19

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

Milestone Progress

This week I spent the week cleaning up code, as I was working on my branch for traits I found the HIR implementation was missing a lot of desugaring. This is an important part of the HIR lowering process to turn trait-impl and normal impl blocks into a simple impl block with an optional trait reference. There are many of cases to turn methods into functions with a Self parameter. This reduces the complexity of what the type resolution step needs to think about. All of this is important as it now becomes further building blocks, as I am a big fan of iterative development making smaller steps to reach a goal and avoiding big PRs.

Linux Plumbers Conference

In other news I have submitted a talk proposal to the Linux Plumbers Conference 2021 for the Refereed-track. All going well and it is accepted I hope to present the “GCC Front-End for Rust”:

GCC Front-End for Rust – Abstract

GCC Rust is a front-end project for the GNU toolchain, a work-in-progress alternative to the official Rustc compiler. Being part of GCC, the compiler benefits from the common compiler flags, available backend targets and provides insight into its distinct optimiser’s impact on a modern language.

This project dates back to 2014 where Rust was still ~0.8, but the language was subject to frequent change making an effort too challenging to keep up. More recently, the core language is stable, and in early 2019 the development restarted. Since then, the project has laid out the core milestone targets to create the initial MVP with freely available status reports and is part of Google Summer of Code 2021 under the GCC organisation.

The GNU toolchain has been the foundation of the Linux ecosystem for years, but the official Rustc compiler takes advantage of LLVM for code generation; this leaves a gap in language availability between the toolchains. GCC Rust will eliminate this disparity and provide a compilation experience familiar to those who already use GCC.

As of 2021, GCCRS gained sponsorship from Open Source Security, inc and Embecosm to drive the effort forward. With this support, the project has gained mentorship from the GCC and Rust community.

In this talk, I will introduce the compiler, demonstrate its current state and discuss the goals and motivations for the project.

Google Summer of Code

Cargo Support

Arthur Cohen has merged the MVP to compile working binaries and has moved onto supporting static and shared library compilation. As the compiler is GCC based, we gain this support for free and can follow normal compilation commands. Thanks for Philipp Krones and bjorn3 for doing detailed code reviews.

Static Analysis

Wenzhang Yang has been working on fixing build issues for this personal macbook pro running BigSur. Recently Apple has changed a lot under the hood with its toolchain, when using GCCRS on macos users would run into unable to find libSystem.dylib but from this forum post it seems this is now a cached item: https://developer.apple.com/forums/thread/655588. He has updated the compiler README.md for working build instructions for MacOS (note GCC does not yet support the Apple-M1 chip).

Detailed changelog

Improve GDB support

Thanks to our new contributor Tom Tromey who is a GDB/GCC developer and has fixed bugs for upstream GDB support for Rust. His patches to the GCC Rust compiler include:

  • Fix tuple field names PR-514
  • Set the correct DWARF for Rust primitive types PR-505
  • Use DW_LANG_Rust in DWARF emission PR-503 PR-513

Your GCC Rust mug is on its way.

Fixing bugs in Path Expression to support modules

In Rust when you instantiate a struct you give a path to the struct you wish to reference:

let a;
a = foo::myStruct::<i32>{ ... };

This is a path expression which allows the programmer to navigate the hierarchy of modules and or impl blocks. The implementation before these fixes assumed a basic A::B::C type structure which is not the case when we want to support modules. Marc Poulhiès has got a draft PR showing the iniital support for modules within gccrs but we found the limitations in how paths blocked some progress here.

It is not always possible for the name-resolver to fully resolve a path expression, so each path is broken down into segments. the name resolver can start from the root segment and resolve for that, at which point it can keep appending segments to resolve until it either fully resolves the path or it fails. The failure case is allowed because this might be a path that resolves to an item within an Impl block which will require type-resolution of each segment in turn to then perform a path probe to lookup relevant impl blocks for that item.

HIR Cleanup

The compiler has several IRs involved within the compilation pipeline, first, the code is parsed into the AST which gives a full representation of the code. The next is HIR, a high-level IR which follows the convention of Rustc, this desugars the syntax a lot which helps ensure we canonicalize as many cases as possible to follow the same code paths.

Since our HIR was bootstrapped from the AST structures we ended up with a lot of duplication of handling methods separately from methods, and even had a trait impl block and a normal impl block. This made sense within the AST but for HIR this is not nessecary.

General cleanup

Marc Poulhiès from his PR working on modules has been able to extract out a lot of smaller PRs which improves the general quality of error messages and found a nasty usage of an object which has been moved. Thanks for all our ongoing work.

Completed Activities

Overall Task Status

CategoryLast WeekThis WeekDelta
TODO8788+1
In Progress66
Completed149151+2
GitHub Issues

Test Cases

CategoryLast WeekThis WeekDelta
Passing24472456+9
XFAIL1515
make check-rust

Bugs

CategoryLast WeekThis WeekDelta
TODO2022+2
In Progress22
Completed4647+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 – Traits10%20%+10%20th May 202127th 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 assignments236Be 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

  • Continue work on Trait Obligations and Selection

Leave a Reply

Your email address will not be published.