From a999d146bdeefd55364cd2d3f269438b98c67353 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Tue, 7 Jan 2025 16:35:13 +0100 Subject: [PATCH] 2024-12: Add monthly report --- _posts/2025-01-07-2024-12-monthly-report.md | 452 ++++++++++++++++++++ 1 file changed, 452 insertions(+) create mode 100644 _posts/2025-01-07-2024-12-monthly-report.md diff --git a/_posts/2025-01-07-2024-12-monthly-report.md b/_posts/2025-01-07-2024-12-monthly-report.md new file mode 100644 index 0000000..2a8ff72 --- /dev/null +++ b/_posts/2025-01-07-2024-12-monthly-report.md @@ -0,0 +1,452 @@ +## Overview + +Thanks again to [Open Source Security, inc](https://opensrcsec.com/) and +[Embecosm](https://www.embecosm.com/) for their ongoing support for this +project. + +### Project update + +This month of development was focused on three major milestones of +compiler development: auto traits, built-in macros and for-loops, which +are all important in order to compile `core 1.49` and later, the +Rust-for-Linux project. + +The most widely known auto traits in Rust may be [Send and +Sync](https://doc.rust-lang.org/nomicon/send-and-sync.html), which are +used all throughout the Rust standard library to indicate thread-safety. +As such, these traits are often used in trait-bounds to restrict sharing +behavior to thread-safe objects: + +``` rust +trait Foo { + fn foo(&self); +} + +struct Safe; + +// We cannot send pointers safely between threads +struct NonThreadSafe(*const i32); + +impl Foo for Safe { fn foo(&self) { } } +impl Foo for NonThreadSafe { fn foo(&self) { } } + +fn take_foo(foo: &(dyn Foo)) { + foo.foo(); +} + +fn take_thread_safe_foo(foo: &(dyn Foo + Send + Sync)) { + foo.foo(); +} + +fn main() { + let s = Safe; + + let i = 15; + let n_s = NonThreadSafe(&i as *const i32); + + take_foo(&s); + take_foo(&n_s); + + take_thread_safe_foo(&s); + take_thread_safe_foo(&n_s); +} +``` + +which errors out with the following: + +``` rust + Compiling playground v0.0.1 (/playground) +error[E0277]: `*const i32` cannot be shared between threads safely + --> src/main.rs:31:26 + | +31 | take_thread_safe_foo(&n_s); + | ^^^^ `*const i32` cannot be shared between threads safely + | + = help: within `NonThreadSafe`, the trait `Sync` is not implemented for `*const i32`, which is required by `NonThreadSafe: Sync` +note: required because it appears within the type `NonThreadSafe` + --> src/main.rs:8:8 + | +8 | struct NonThreadSafe(*const i32); + | ^^^^^^^^^^^^^ + = note: required for the cast from `&NonThreadSafe` to `&dyn Foo + Send + Sync` + +error[E0277]: `*const i32` cannot be sent between threads safely + --> src/main.rs:31:26 + | +31 | take_thread_safe_foo(&n_s); + | ^^^^ `*const i32` cannot be sent between threads safely + | + = help: within `NonThreadSafe`, the trait `Send` is not implemented for `*const i32`, which is required by `NonThreadSafe: Send` +note: required because it appears within the type `NonThreadSafe` + --> src/main.rs:8:8 + | +8 | struct NonThreadSafe(*const i32); + | ^^^^^^^^^^^^^ + = note: required for the cast from `&NonThreadSafe` to `&dyn Foo + Send + Sync` +``` + +Part of our pipeline was lacking support for these automatic trait +bounds, which now enables us to build this code properly. Two missing +features remain for properly handling these special bounds: + +1. Additional trait bounds can only be automatic traits + +We have to restrict the usage of additional trait bounds to auto traits +exclusively, as `rustc` does: + +``` rust +fn takes_only_clone_copy_and_fromstr(a: &(dyn Clone + Copy + FromStr)) {} +``` + +will give out the following error: + +``` rust +error[E0225]: only auto traits can be used as additional traits in a trait object + --> src/main.rs:16:55 + | +16 | fn takes_only_clone_copy_and_fromstr(a: &(dyn Clone + Copy + FromStr)) {} + | ----- ^^^^ additional non-auto trait + | | + | first non-auto trait + | + = help: consider creating a new trait with all of these as supertraits and using that trait here instead: `trait NewTrait: Clone + Copy + FromStr {}` + = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit +``` + + + +We must add additional logic to our typechecker in order to check for +these bounds, and make sure that the additional bounds we resolve to +only refer to auto traits - otherwise, error out with an appropriate +error message. This isn't a terribly difficult feature to add, but it +does require a bit of experience with our type system. + +1. Implementing Send and Sync properly + +Finally, we must implement the `Send` and `Sync` traits properly, and +auto traits in general, so that they are applied automatically unless +you opt out of it. One major difficulty comes from having to +automatically opt-out types that contains other opted-out types, like in +the following example: + +``` rust +#![feature(auto_traits)] +#![feature(negative_impls)] + +auto trait MegaAuto {} + +struct S; + +impl !MegaAuto for S {} + +struct S_Wrap(S); + +fn take_mega_auto(a: &dyn MegaAuto) {} + +fn main() { + let a = S; + let b = S_Wrap(S); + + take_mega_auto(&a); + take_mega_auto(&b); +} +``` + +which errors out with the following information: + +``` rust + +error[E0277]: the trait bound `S: MegaAuto` is not satisfied + --> src/main.rs:18:20 + | +18 | take_mega_auto(&a); + | ^^ the trait `MegaAuto` is not implemented for `S` + | + = note: required for the cast from `&S` to `&dyn MegaAuto` + +error[E0277]: the trait bound `S: MegaAuto` is not satisfied in `S_Wrap` + --> src/main.rs:19:20 + | +19 | take_mega_auto(&b); + | ^^ within `S_Wrap`, the trait `MegaAuto` is not implemented for `S` + | +note: required because it appears within the type `S_Wrap` + --> src/main.rs:10:8 + | +10 | struct S_Wrap(S); + | ^^^^^^ + = note: required for the cast from `&S_Wrap` to `&dyn MegaAuto` +``` + +This will be a lot more involved, and will require important changes to +our type system. + +The rest of the month was focused on for-loops and built-in derive +macros, which first required a major refactor of our AST and HIR. The +problem is as follows: for-loops desugar using the following pattern: + +``` rust +for in { + +} + +// becomes + +{ + let result = match ::std::iter::IntoIterator::into_iter() { + mut iter => { + loop { + let mut __next; + match ::std::iter::Iterator::next(&mut iter) { + ::std::option::Option::Some(val) => __next = val, + ::std::option::Option::None => break + }; + let = __next; + ; + } + } + }; + result +} +``` + +The paths used in this desugaring are a bit special, as they all start +with a leading `::`. [This is used to indicate that the first path +segment should refer to an external crate, and that the path should +resolve in one of these +crates](https://doc.rust-lang.org/reference/paths.html#path-qualifiers). +This is very useful to prevent ambiguity: If a user were to define their +own `std` module, with an inner `option` module and an `Option` enum, +simply using the `std::option::Option` path would resolve to this +instead of the expected standard enum. + +If for some reason this user-defined enum were to be different, the +desugared code would not work, and you would end up with cryptic errors. +But since the path is required to resolve in the extern crate `std`, +there are no issues. *However*, `gccrs` cannot yet compile the standard +library, or distribute it and link it to each program being compiled. +Meaning that we would never be able to resolve those paths, at least +until we get to compile the standard library. But the standard library +contains for-loops, so we're in a real pickle. + +Thankfully, those specific paths used for desugars or macro expansions +often refer to specific items that the compiler knows about: [lang +items](https://doc.rust-lang.org/unstable-book/language-features/lang-items.html). +By instead using "lang item paths", we can refer to these specific items +and enum variants to properly desugar our for-loops. But these paths are +extremely different from regular, segmented paths, and required a big +refactor of both our AST and HIR. Which then allowed us to almost +complete the desugaring of for-loops, and improve our handling of +built-in macros - another kind of compiler expansion that makes use of +lang items you probably already know about, such as `Copy` or `Clone`. + +We still have a few built-in derives to properly implement in order to +support all of them, and close out the `Macro expansion` milestone of +the project. These built-in derives are used all throughout `std`, and +throughout most Rust code, meaning they are essential for compiling the +Rust standard library. + +If you are interested in helping with these efforts, feel free to pick +up any of the issues mentioned in our Call for Contribution or to join +the project! We are always available on +[GitHub](https://github.com/rust-gcc/gccrs) or on our +[Zulip](https://gcc-rust.zulipchat.com/) and always happy to see new +faces. + +### Community call + +We will have our next monthly community call on the 13th of January at +10am UTC. You can subscribe to our calendar to see when the next one +will be held. The call is open to everyone, even if you would just like +to sit-in and listen. You can also subscribe to our +[mailing-list](https://gcc.gnu.org/mailman/listinfo/gcc-rust) or join +our [Zulip chat](https://gcc-rust.zulipchat.com) to be notified of +upcoming events. + +- [Jitsi link](https://meet.jit.si/gccrs-community-call-january) +- Calendar ID: + 7060a0923ffebd3cb52b1afef35a28ff7b64f05962c9af84c23b1847f1f5f894@group.calendar.google.com +- [Google calendar + link](https://calendar.google.com/calendar/embed?src=7060a0923ffebd3cb52b1afef35a28ff7b64f05962c9af84c23b1847f1f5f894%40group.calendar.google.com) +- [iCal + link](https://calendar.google.com/calendar/ical/7060a0923ffebd3cb52b1afef35a28ff7b64f05962c9af84c23b1847f1f5f894%40group.calendar.google.com/public/basic.ics) + +## Call for contribution + +- + +- + +## Completed Activities + +- gccrs: fix ICE during HIR dump + [PR3346](https://github.com/rust-gcc/gccrs/pull/3346) +- ast: Add EnumItem::Kind + [PR3342](https://github.com/rust-gcc/gccrs/pull/3342) +- nr2.0: Resolve type aliases inside trait definitions + [PR3330](https://github.com/rust-gcc/gccrs/pull/3330) +- Resolve and lower parenthesized types + [PR3328](https://github.com/rust-gcc/gccrs/pull/3328) +- parser: Add testcases for multiline strings + [PR3325](https://github.com/rust-gcc/gccrs/pull/3325) +- Add resolution for additional trait bounds + [PR3324](https://github.com/rust-gcc/gccrs/pull/3324) +- nr2.0: Handle \`Self\` properly in trait definitions + [PR3323](https://github.com/rust-gcc/gccrs/pull/3323) +- ast-builder: Add more methods + [PR3322](https://github.com/rust-gcc/gccrs/pull/3322) +- allow ptr to int and int to ptr type casting + [PR3321](https://github.com/rust-gcc/gccrs/pull/3321) +- ast: Add new Kind enums for more precise downcasting + [PR3320](https://github.com/rust-gcc/gccrs/pull/3320) +- Handle new lang items: \`Option::None\`, \`Option::Some\`, + \`IntoIterator::intoiter\`, \`Iterator::next\` + [PR3318](https://github.com/rust-gcc/gccrs/pull/3318) +- typecheck-path: Fix typo (reciever -\> receiver) + [PR3317](https://github.com/rust-gcc/gccrs/pull/3317) +- gccrs: disable macos github workflow + [PR3312](https://github.com/rust-gcc/gccrs/pull/3312) +- Fix name resolution for enums with generics + [PR3307](https://github.com/rust-gcc/gccrs/pull/3307) +- refactor(typecheck): StackedContexts for blocks + [PR3305](https://github.com/rust-gcc/gccrs/pull/3305) +- gccrs: implement the TuplePattern and use it for function patterns + [PR3303](https://github.com/rust-gcc/gccrs/pull/3303) +- gccrs: fix bad not expression in rust + [PR3301](https://github.com/rust-gcc/gccrs/pull/3301) +- gccrs: Made changes to AST::TraitImpl constructor for TypePath + [PR3298](https://github.com/rust-gcc/gccrs/pull/3298) +- ci: Update expected warnings list for 32 bits build. + [PR3295](https://github.com/rust-gcc/gccrs/pull/3295) +- build: update bootstrap req to C++14 + [PR3294](https://github.com/rust-gcc/gccrs/pull/3294) +- Use lang items as paths + [PR3290](https://github.com/rust-gcc/gccrs/pull/3290) +- Collect lang items in the AST + [PR3289](https://github.com/rust-gcc/gccrs/pull/3289) +- type-check: Remove unused capture in nr2.0 + [PR3288](https://github.com/rust-gcc/gccrs/pull/3288) +- Remove \`Rust::makeunique\` + [PR3278](https://github.com/rust-gcc/gccrs/pull/3278) +- Fix \`ForeverStack::findstartingpoint\` output parameter + [PR3247](https://github.com/rust-gcc/gccrs/pull/3247) + +### Contributors this month + +- [Sri Ganesh Thota](http://github.com/sriganeshres) (new contributor!) +- [Prajwal S N](https://github.com/snprajwal) +- [Liam Naddell](https://github.com/liamnaddell) +- [Nobel Singh](https://github.com/nobel-sh) +- [Sam James](https://github.com/thesamesam) +- [Owen Avery](https://github.com/powerboat9) +- [Marc Poulhiès](https://github.com/dkm) +- [Thomas Schwinge](https://github.com/tschwinge) +- [Philip Herron](https://github.com/philberty) +- [Pierre-Emmanuel Patry](https://github.com/P-E-P) +- [Arthur Cohen](https://github.com/CohenArthur) + +### Overall Task Status + +| Category | Last Month | This Month | Delta | +|-------------|------------|------------|-------| +| TODO | 316 | 308 | -8 | +| In Progress | 80 | 88 | +8 | +| Completed | 907 | 922 | +15 | + +### Bugs + +| Category | Last Month | This Month | Delta | +|-------------|------------|------------|-------| +| TODO | 112 | 110 | -2 | +| In Progress | 40 | 38 | -2 | +| Completed | 450 | 458 | +8 | + +### Test Cases + +| TestCases | Last Month | This Month | Delta | +|-----------|------------|------------|-------| +| Passing | 9266 | 9329 | +63 | +| Failed | \- | \- | \- | +| XFAIL | 264 | 262 | -2 | +| XPASS | \- | \- | \- | + +### Milestones Progress + +| Milestone | Last Month | This Month | Delta | Start Date | Completion Date | Target | Target GCC | +|----------------------------|------------|------------|-------|---------------|-----------------|---------------|------------| +| Name resolution 2.0 rework | 14% | 20% | \- | 1st Jun 2024 | \- | 1st Apr 2025 | GCC 15.1 | +| Macro expansion | 29% | 33% | +4% | 1st Jun 2024 | \- | 1st Jan 2025 | GCC 15.1 | +| Lang items | 90% | 90% | \- | 1st Jul 2024 | \- | 21st Nov 2024 | GCC 15.1 | +| Indexing fixes | 0% | 100% | +100% | 21st Jul 2024 | 25th Dec 2024 | 15th Nov 2024 | GCC 15.1 | +| Iterator fixes | 0% | 100% | +100% | 21st Jul 2024 | 25th Dec 2024 | 15th Nov 2024 | GCC 15.1 | +| Auto traits improvements | 0% | 60% | +60% | 15th Sep 2024 | \- | 21st Dec 2024 | GCC 15.1 | +| Remaining typecheck issues | 88% | 88% | \- | 21st Oct 2024 | \- | 1st Mar 2025 | GCC 15.1 | +| cfg-core | 0% | 0% | \- | 1st Dec 2024 | \- | 1st Mar 2025 | GCC 15.1 | +| Codegen fixes | 0% | 0% | \- | 7th Oct 2024 | \- | 1st Mar 2025 | GCC 15.1 | + +| Upcoming Milestone | Last Month | This Month | Delta | Start Date | Completion Date | Target | Target GCC | +|--------------------------------------|------------|------------|-------|---------------|-----------------|---------------|------------| +| Question mark operator | 0% | 0% | \- | 15th Dec 2024 | \- | 21st Feb 2025 | GCC 15.1 | +| Specialization | 0% | 0% | \- | 1st Jan 2025 | \- | 1st Mar 2025 | GCC 15.1 | +| Inline assembly | 100% | 100% | \- | 1st Jun 2024 | 26th Aug 2024 | 15th Sep 2024 | GCC 15.1 | +| Borrow checker improvements | 100% | 100% | \- | 1st Jun 2024 | 26th Aug 2024 | 15th Sep 2024 | GCC 15.1 | +| Rustc Testsuite Adaptor | 0% | 0% | \- | 1st Jun 2024 | \- | 15th Sep 2024 | GCC 15.1 | +| blackbox intrinsic | 0% | 0% | \- | 28th Oct 2024 | \- | 28th Jan 2025 | GCC 15.1 | +| Unstable RfL features | 0% | 0% | \- | 7th Jan 2025 | \- | 1st Mar 2025 | GCC 15.1 | +| cfg-rfl | 0% | 0% | \- | 7th Jan 2025 | \- | 15th Feb 2025 | GCC 15.1 | +| alloc parser issues | 100% | 100% | \- | 7th Jan 2025 | 31st Jun 2024 | 28th Jan 2025 | GCC 15.1 | +| let-else | 0% | 0% | \- | 28th Jan 2025 | \- | 28th Feb 2025 | GCC 15.1 | +| Explicit generics with impl Trait | 0% | 0% | \- | 28th Feb 2025 | \- | 28th Mar 2025 | GCC 15.1 | +| Downgrade to Rust 1.49 | 0% | 0% | \- | \- | \- | 1st Apr 2025 | GCC 15.1 | +| offsetof!() builtin macro | 0% | 0% | \- | 15th Mar 2025 | \- | 15th May 2025 | GCC 15.1 | +| Generic Associated Types | 0% | 0% | \- | 15th Mar 2025 | \- | 15th Jun 2025 | GCC 16.1 | +| RfL const generics | 0% | 0% | \- | 1st May 2025 | \- | 15th Jun 2025 | GCC 16.1 | +| frontend plugin hooks | 0% | 0% | \- | 15th May 2025 | \- | 7th Jul 2025 | GCC 16.1 | +| Handling the testsuite issues | 0% | 0% | \- | 15th Sep 2024 | \- | 15th Sep 2025 | GCC 16.1 | +| std parser issues | 100% | 100% | \- | 7th Jan 2025 | 31st Jun 2024 | 28th Jan 2025 | GCC 16.1 | +| main shim | 0% | 0% | \- | 28th Jul 2025 | \- | 15th Sep 2025 | GCC 16.1 | + +| Past Milestone | Last Month | This Month | Delta | Start Date | Completion Date | Target | Target GCC | +|-----------------------------------|------------|------------|-------|---------------|-----------------|---------------|------------| +| Data Structures 1 - Core | 100% | 100% | \- | 30th Nov 2020 | 27th Jan 2021 | 29th Jan 2021 | GCC 14.1 | +| Control Flow 1 - Core | 100% | 100% | \- | 28th Jan 2021 | 10th Feb 2021 | 26th Feb 2021 | GCC 14.1 | +| Data Structures 2 - Generics | 100% | 100% | \- | 11th Feb 2021 | 14th May 2021 | 28th May 2021 | GCC 14.1 | +| Data Structures 3 - Traits | 100% | 100% | \- | 20th May 2021 | 17th Sep 2021 | 27th Aug 2021 | GCC 14.1 | +| Control Flow 2 - Pattern Matching | 100% | 100% | \- | 20th Sep 2021 | 9th Dec 2021 | 29th Nov 2021 | GCC 14.1 | +| Macros and cfg expansion | 100% | 100% | \- | 1st Dec 2021 | 31st Mar 2022 | 28th Mar 2022 | GCC 14.1 | +| Imports and Visibility | 100% | 100% | \- | 29th Mar 2022 | 13th Jul 2022 | 27th May 2022 | GCC 14.1 | +| Const Generics | 100% | 100% | \- | 30th May 2022 | 10th Oct 2022 | 17th Oct 2022 | GCC 14.1 | +| Initial upstream patches | 100% | 100% | \- | 10th Oct 2022 | 13th Nov 2022 | 13th Nov 2022 | GCC 14.1 | +| Upstream initial patchset | 100% | 100% | \- | 13th Nov 2022 | 13th Dec 2022 | 19th Dec 2022 | GCC 14.1 | +| Update GCC's master branch | 100% | 100% | \- | 1st Jan 2023 | 21st Feb 2023 | 3rd Mar 2023 | GCC 14.1 | +| Final set of upstream patches | 100% | 100% | \- | 16th Nov 2022 | 1st May 2023 | 30th Apr 2023 | GCC 14.1 | +| Borrow Checking 1 | 100% | 100% | \- | TBD | 8th Jan 2024 | 15th Aug 2023 | GCC 14.1 | +| Procedural Macros 1 | 100% | 100% | \- | 13th Apr 2023 | 6th Aug 2023 | 6th Aug 2023 | GCC 14.1 | +| GCC 13.2 Release | 100% | 100% | \- | 13th Apr 2023 | 22nd Jul 2023 | 15th Jul 2023 | GCC 14.1 | +| GCC 14 Stage 3 | 100% | 100% | \- | 1st Sep 2023 | 20th Sep 2023 | 1st Nov 2023 | GCC 14.1 | +| GCC 14.1 Release | 100% | 100% | \- | 2nd Jan 2024 | 2nd Jun 2024 | 15th Apr 2024 | GCC 14.1 | +| formatargs!() support | 100% | 100% | \- | 15th Feb 2024 | \- | 1st Apr 2024 | GCC 14.1 | +| GCC 14.2 | 100% | 100% | \- | 7th Jun 2024 | 15th Jun 2024 | 15th Jun 2024 | GCC 14.2 | +| GCC 15.1 | 100% | 100% | \- | 21st Jun 2024 | 31st Jun 2024 | 1st Jul 2024 | GCC 15.1 | +| Unhandled attributes | 100% | 100% | \- | 1st Jul 2024 | 15th Aug 2024 | 15th Aug 2024 | GCC 15.1 | +| Deref and DerefMut improvements | 100% | 100% | \- | 28th Sep 2024 | 25th Oct 2024 | 28th Dec 2024 | GCC 15.1 | + +## Planned Activities + +- Implement remaining built-in derive macros +- Implement Send and Sync auto traits +- Finish for-loops code expansion +- Improve our process for updating our github repository with upstream + GCC + +### Risks + +We have now entered Stage 3 of GCC development, and all of the patches +we needed to get upstreamed have been upstreamed. The risk present in +this table is no longer present. + +| Risk | Impact (1-3) | Likelihood (0-10) | Risk (I \* L) | Mitigation | +|----------------------------------------|--------------|-------------------|---------------|-----------------------------------------------------------------| +| Missing features for GCC 15.1 deadline | 2 | 0 | 0 | Start working on required features as early as July (6mo ahead) | + +## Detailed changelog