Thanks again to Open Source Security, inc and Embecosm for their ongoing support for this project.
Milestone Progress
Almost all valid rust macro syntax is supported, with some error cases remaining unchecked. We will continue to use the time of the milestone to improve this. In relation to our slices we are very close to having this working; there are three outstanding pieces of work to finish before libcore 1.49.0’s implementation of slices will work, Unsized method resolution, a bug with type-checking generic pointers and finally, an issue with generic associated types from higher-ranked trait bounds. Slices in rust (1.49.0) are pretty interesting and complex so we will write a blog post on this later in the year and the differences in later rustc versions.
Completed Activities
- Support placeholders becoming slices PR1037
- Handle -fsyntax-only PR1035
- Fix bad copy-past in can equal interface for pointer types PR1033
- Add AST kind information PR1032
- Rewrite our unconstrained type-param error checking PR1030
- Macro in trait impl block PR1029
- Allow parsing statements without closing semicolon PR1027
- Fix memory corruption in generation of builtin functions PR1025
- Fix spurious stripping of tail expression PR1022
- Do not try and re-expand macros if depth has exceeded recursion limit PR1021
Contributors this week
Overall Task Status
Category | Last Week | This Week | Delta |
TODO | 109 | 110 | +1 |
In Progress | 22 | 18 | -4 |
Completed | 317 | 327 | +10 |
Test Cases
Category | Last Week | This Week | Delta |
Passing | 5467 | 5511 | +44 |
Failed | – | – | – |
XFAIL | 21 | 22 | +1 |
XPASS | – | – | – |
Bugs
Category | Last Week | This Week | Delta |
TODO | 35 | 34 | -1 |
In Progress | 10 | 8 | -2 |
Completed | 118 | 125 | +7 |
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 | 78% | 87% | +9% | 1st Dec 2021 | – | 28th Mar 2022 |
Imports and Visibility | 0% | 0% | – | 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
- Merge unsized method resolution
- Fix bug in generic associated types for slices
- Continue work on error cases with macros
Detailed changelog
Expanding macros in more contexts
Last week’s macro improvements were focused on adding a base for in-place macro expansion. We worked on getting them properly expanded in two places, namely block statements and as crate items. However, macros can be used in many more ways:
A macro invocation expands a macro at compile-time and replaces the invocation with the result of the macro. Macros may be invoked in the following situations:
- Expressions and statements
- Patterns
- Types
- Items including associated items
- macro_rules transcribers
- External blocks
You can now call macros from inside `impl` blocks, external blocks and trait definitions or implementations. If you’ve been following the Rust-for-Linux effort, you might have seen this pattern when defining file operations for a type. This allows defining your own function or relying on the kernel’s defaults safely.
macro_rules! c_fn {
(int $name:ident ( const char_ptr $arg_name:ident)) => {
fn $name($arg_name: *const i8) -> i32;
};
}
extern "C" {
c_fn! {int puts (const char_ptr s)}
}
macro_rules! add_distract_fn {
() => {
fn distract() {
unsafe {
puts("wait this isn't C\0" as *const str as *const i8);
}
}
};
}
struct Abstract;
impl Abstract {
add_distract_fn!();
}
macro_rules! require_proc {
($fn_name:ident) => {
fn $fn_name();
};
}
trait Abstractable {
require_proc!(extract);
}
macro_rules! extract {
($fn_block:block) => {
fn extract() $fn_block
}
}
impl Abstractable for Abstract {
extract! {{ Abstract::distract(); }}
}
Relaxed parsing rules in macro definitions and invocations
To improve usability, parsing rules when expanding macro nodes are a little more relaxed. As an example, this is completely valid rust code:
macro_rules! take_stmt {
($s:stmt) => {
$s
};
}
fn f() -> i32 {
16
}
macro_rules! expand_to_stmt_or_expr {
() => {
f()
};
}
fn main() {
take_stmt!(let a1 = 15);
let a2 = {
expand_to_stmt_or_expr!(); // f is called as an expression-statement
expand_to_stmt_or_expr!() // f is called as a tail expression
};
}
This is now handled properly and makes for prettier macros and invocations, and avoids the necessity of adding extra semicolons in some cases.
The PR links appear to be broken …/pulls/ instead of …/pull/
Thanks for that we will fix those in the future reports we have a script to generate a bunch of that data must have a typo
See . 🙂
See https://github.com/Rust-GCC/Reporting/issues/20. 🙂