From 9bfd5a3bb201dad2327f3347133d4098a67cd7fe Mon Sep 17 00:00:00 2001 From: Henri Lunnikivi Date: Tue, 28 May 2024 09:01:53 +0300 Subject: [PATCH] Improve error output for prios > dispatchers (#943) * Improve error output for prios > dispatchers * Update changelog --- rtic-macros/CHANGELOG.md | 4 ++++ rtic-macros/src/analyze.rs | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/rtic-macros/CHANGELOG.md b/rtic-macros/CHANGELOG.md index a0d761bb2e..5f21838230 100644 --- a/rtic-macros/CHANGELOG.md +++ b/rtic-macros/CHANGELOG.md @@ -7,6 +7,10 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top! ## [Unreleased] +### Changed + +- Improve error output for prios > dispatchers + ## [v2.1.0] - 2024-02-27 ### Added diff --git a/rtic-macros/src/analyze.rs b/rtic-macros/src/analyze.rs index 2227308d0f..ab6abc024f 100644 --- a/rtic-macros/src/analyze.rs +++ b/rtic-macros/src/analyze.rs @@ -24,7 +24,7 @@ impl ops::Deref for Analysis { // Assign an interrupt to each priority level pub fn app(analysis: analyze::Analysis, app: &App) -> Analysis { - let mut available_interrupt = app.args.dispatchers.clone(); + let mut available_dispatchers = app.args.dispatchers.clone(); // the set of priorities (each priority only once) let priorities = app @@ -35,12 +35,26 @@ pub fn app(analysis: analyze::Analysis, app: &App) -> Analysis { // map from priorities to interrupts (holding name and attributes) - let interrupts: BTreeMap = priorities + let nonzero_priorities = priorities .iter() - .filter(|prio| **prio > 0) // 0 prio tasks are run in main + // 0 prio tasks are run in main + .filter(|prio| **prio > 0); + assert!( + available_dispatchers.len() >= nonzero_priorities.clone().count(), + "The number of dispatchers must be equal to or greater than the number of distinct task priorities." + ); + let interrupts: BTreeMap = nonzero_priorities .copied() .rev() - .map(|p| (p, available_interrupt.pop().expect("UNREACHABLE"))) + .map(|p| { + ( + p, + available_dispatchers + .pop() + // EXPECT: covered by above assertion + .expect("UNREACHABLE"), + ) + }) .collect(); let max_async_prio = app