Thanks again to Open Source Security, inc and Embecosm for their ongoing support for this project.
Milestone Progress
We have achieved a major step this week by merging the work required to get slices working. This long battle has exposed many flaws in our implementation of generics which have now been fixed, and is bringing us closer and closer to compiling an early version of the core Rust library. We are still going through a first dive into a privacy/visibility set of visitors, which will allow us to report privacy errors properly. Finally, we have also started looking into metadata exports which will allow us to use items from multiple crates compiled together. As a side note, our OSX support was broken and is now fixed thanks to a new contributor. The system has been added as a target to our CI to make sure it does not happen again.
Completed Activities
- Move `cfg!()` macro to builtins. Fixes #1039 PR1116
- rust: Use -Otarget when building and logging warnings PR1114
- macros: Add env! macro PR1113
- rust: Clang/macOS Testing PR1112
- Add AST Private Visibilities PR1111
- Add Reachability visitors for items with generics PR1110
- rust: Allow gccrs to build on x86_64-apple-darwin with clang/libc++ PR1109
- Add missing unify rules for inference variables PR1108
- macros: fix an infinite loop in `concat!` macro parser PR1106
- Lower AST::Visibility to HIR::Visibility properly PR1103
- Add helper as_string for DefIds PR1101
- Add known lang item const_slice_ptr mappings PR1100
- Fix bad inherent overlap error PR1099
- Ensure unsize method resolutions actually unsize PR1098
- Support mangling \*const ptr and slices like \*const [T] PR1097
- Add -frust-edition flag and possible values PR1091
- macros: add concat! macro PR1090
- rust-session-manager: better crate name handling logic PR1088
- Slice support PR1086
- Add base for privacy visitor PR1082
Contributors this week
- Arthur Cohen
- liushuyu
- Simon Cook (new-contributor)
- Ondřej Machota (new-contributor)
- antego (new-contributor)
Overall Task Status
Category | Last Week | This Week | Delta |
TODO | 118 | 128 | +10 |
In Progress | 24 | 23 | -1 |
Completed | 339 | 346 | +7 |
Test Cases
Category | Last Week | This Week | Delta |
Passing | 5735 | 5845 | +110 |
Failed | – | – | – |
XFAIL | 22 | 24 | +2 |
XPASS | – | – | – |
Bugs
Category | Last Week | This Week | Delta |
TODO | 41 | 49 | +8 |
In Progress | 10 | 13 | +2 |
Completed | 131 | 133 | +2 |
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 | 100% | 100% | – | 20th May 2021 | 17th Sept 2021 | 27th Aug 2021 |
Control Flow 2 – Pattern Matching | 100% | 100% | – | 20th Sept 2021 | 9th Dec 2021 | 29th Nov 2021 |
Macros and cfg expansion | 100 | 100% | – | 1st Dec 2021 | 31st Mar 2022 | 28th Mar 2022 |
Imports and Visibility | 0% | 35% | +35 | 29th Mar 2022 | – | 27th May 2022 |
Const Generics | 0% | 0% | – | 30th May 2022 | – | 25th Jul 2022 |
Intrinsics | 0% | 0% | – | 6th Sept 2021 | – | 30th Sept 2022 |
Risks
Risk | Impact (1-3) | Likelihood (0-10) | Risk (I * L) | Mitigation |
Rust Language Changes | 3 | 7 | 21 | Keep up to date with the Rust language on a regular basis |
Going over target dates | 2 | 5 | 10 | Maintain status reports and issue tracking to stakeholders |
Planned Activities
- Continue work into privacy pass
- Continue work on metadata exports
Detailed changelog
Slices support
We finally got slice generation support merged, this is the extracted code from Rustc libcore 1.49.0. The key thing here is that this test case exposed lots of bugs in our type resolution system so working through this was pretty key. We are working on a blog post to explain how this works, as slice generation is actually implemented via the trick of unsized method resolution and clever use of libcore. For now please review the code below and you can see the slice generation via passing a range to the array index expression kicks off the array index operator overload for a Range<usize> as the entry point which uses the generic higher-ranked trait bound.
// { dg-additional-options "-w" }
extern "rust-intrinsic" {
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
}
struct FatPtr<T> {
data: *const T,
len: usize,
}
union Repr<T> {
rust: *const [T],
rust_mut: *mut [T],
raw: FatPtr<T>,
}
#[lang = "Range"]
pub struct Range<Idx> {
pub start: Idx,
pub end: Idx,
}
#[lang = "const_slice_ptr"]
impl<T> *const [T] {
pub const fn len(self) -> usize {
let a = unsafe { Repr { rust: self }.raw };
a.len
}
pub const fn as_ptr(self) -> *const T {
self as *const T
}
}
#[lang = "const_ptr"]
impl<T> *const T {
pub const unsafe fn offset(self, count: isize) -> *const T {
unsafe { offset(self, count) }
}
pub const unsafe fn add(self, count: usize) -> Self {
unsafe { self.offset(count as isize) }
}
pub const fn as_ptr(self) -> *const T {
self as *const T
}
}
const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
unsafe {
Repr {
raw: FatPtr { data, len },
}
.rust
}
}
#[lang = "index"]
trait Index<Idx> {
type Output;
fn index(&self, index: Idx) -> &Self::Output;
}
pub unsafe trait SliceIndex<T> {
type Output;
unsafe fn get_unchecked(self, slice: *const T) -> *const Self::Output;
fn index(self, slice: &T) -> &Self::Output;
}
unsafe impl<T> SliceIndex<[T]> for Range<usize> {
type Output = [T];
unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T] {
unsafe {
let a: *const T = slice.as_ptr();
let b: *const T = a.add(self.start);
slice_from_raw_parts(b, self.end - self.start)
}
}
fn index(self, slice: &[T]) -> &[T] {
unsafe { &*self.get_unchecked(slice) }
}
}
impl<T, I> Index<I> for [T]
where
I: SliceIndex<[T]>,
{
type Output = I::Output;
fn index(&self, index: I) -> &I::Output {
index.index(self)
}
}
fn main() -> i32 {
let a = [1, 2, 3, 4, 5];
let b = &a[1..3];
0
}
see: https://godbolt.org/z/csn8hMej8
More built-in macros
Our first builtin macro, cfg!
, has been moved with the rest of the builtin macros: It can now benefit from the other helper functions we have developed in this module to help consuming tokens and generating AST fragments. Two new macros have also been added:
concat!
, which allows the concatenation of literal tokens at compile-time
concat!("hey", 'n', 0, "w"); // expands to "heyn0w"
env!
, which allows fetching environment variables during compilation.
let path = env!("PATH");
// expands to the content of the user's path when they invoked `gccrs`
env!
is interesting as it is one of the first built-in with an optional extra argument: You can specify an extra error message to display if the variable is not present.
macro_rules! env {
($name:expr $(,)?) => { ... };
($name:expr, $error_msg:expr $(,)?) => { ... };
}
This enables us to start looking into properly checking for multiple “matchers” in builtins, and parse and fetch them accordingly.
A lot of built-in macros remain to implement, and we’d love for you to have a go at them if you’re interested! Feel free to drop by our Zulip or ask on GitHub for any question you might have.