From e7f0d9c3e3fad77dace2ce63af02559fda46cb73 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Thu, 1 Oct 2020 19:38:49 +0200 Subject: [PATCH 1/5] Now late resources are always used --- examples/baseline.rs | 4 ++- examples/binds.rs | 4 ++- examples/capacity.rs | 4 ++- examples/cfg.rs | 4 ++- examples/destructure.rs | 4 ++- examples/generics.rs | 4 ++- examples/hardware.rs | 4 ++- examples/idle.rs | 4 ++- examples/init.rs | 4 ++- examples/lock.rs | 4 ++- examples/message.rs | 4 ++- examples/not-send.rs | 4 ++- examples/not-sync.rs | 4 ++- examples/periodic.rs | 4 ++- examples/peripherals-taken.rs | 4 ++- examples/pool.rs | 4 ++- examples/preempt.rs | 4 ++- examples/ramfunc.rs | 4 ++- examples/resource.rs | 4 ++- examples/schedule.rs | 4 ++- examples/shared-with-init.rs | 4 ++- examples/t-binds.rs | 4 ++- examples/t-cfg.rs | 4 ++- examples/t-htask-main.rs | 6 +++-- examples/t-idle-main.rs | 4 ++- examples/t-init-main.rs | 4 ++- examples/t-resource.rs | 4 ++- examples/t-schedule.rs | 4 ++- examples/t-spawn.rs | 4 ++- examples/t-stask-main.rs | 4 ++- examples/task.rs | 4 ++- examples/types.rs | 4 ++- macros/Cargo.toml | 2 +- macros/src/codegen/init.rs | 50 +++++++++++++++-------------------- macros/src/codegen/module.rs | 12 ++++----- 35 files changed, 124 insertions(+), 70 deletions(-) diff --git a/examples/baseline.rs b/examples/baseline.rs index f46b273d4b..5a6dbd4c17 100644 --- a/examples/baseline.rs +++ b/examples/baseline.rs @@ -13,13 +13,15 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] const APP: () = { #[init(spawn = [foo])] - fn init(cx: init::Context) { + fn init(cx: init::Context) -> init::LateResources { // omitted: initialization of `CYCCNT` hprintln!("init(baseline = {:?})", cx.start).unwrap(); // `foo` inherits the baseline of `init`: `Instant(0)` cx.spawn.foo().unwrap(); + + init::LateResources {} } #[task(schedule = [foo])] diff --git a/examples/binds.rs b/examples/binds.rs index 82bf89640f..f3ce51ec1c 100644 --- a/examples/binds.rs +++ b/examples/binds.rs @@ -13,10 +13,12 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] const APP: () = { #[init] - fn init(_: init::Context) { + fn init(_: init::Context) -> init::LateResources { rtic::pend(Interrupt::UART0); hprintln!("init").unwrap(); + + init::LateResources {} } #[idle] diff --git a/examples/capacity.rs b/examples/capacity.rs index 00cec34459..cac0029cc1 100644 --- a/examples/capacity.rs +++ b/examples/capacity.rs @@ -12,8 +12,10 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] const APP: () = { #[init] - fn init(_: init::Context) { + fn init(_: init::Context) -> init::LateResources { rtic::pend(Interrupt::UART0); + + init::LateResources {} } #[task(binds = UART0, spawn = [foo, bar])] diff --git a/examples/cfg.rs b/examples/cfg.rs index 8eeeb2a93a..4f46724761 100644 --- a/examples/cfg.rs +++ b/examples/cfg.rs @@ -19,9 +19,11 @@ const APP: () = { } #[init(spawn = [foo])] - fn init(cx: init::Context) { + fn init(cx: init::Context) -> init::LateResources { cx.spawn.foo().unwrap(); cx.spawn.foo().unwrap(); + + init::LateResources {} } #[idle] diff --git a/examples/destructure.rs b/examples/destructure.rs index 1756bd9e75..ad1d859405 100644 --- a/examples/destructure.rs +++ b/examples/destructure.rs @@ -22,9 +22,11 @@ const APP: () = { } #[init] - fn init(_: init::Context) { + fn init(_: init::Context) -> init::LateResources { rtic::pend(Interrupt::UART0); rtic::pend(Interrupt::UART1); + + init::LateResources {} } // Direct destructure diff --git a/examples/generics.rs b/examples/generics.rs index 40ab81ac75..65c5db02a0 100644 --- a/examples/generics.rs +++ b/examples/generics.rs @@ -18,9 +18,11 @@ const APP: () = { } #[init] - fn init(_: init::Context) { + fn init(_: init::Context) -> init::LateResources { rtic::pend(Interrupt::UART0); rtic::pend(Interrupt::UART1); + + init::LateResources {} } #[task(binds = UART0, resources = [shared])] diff --git a/examples/hardware.rs b/examples/hardware.rs index 8105a7420d..30de77ab66 100644 --- a/examples/hardware.rs +++ b/examples/hardware.rs @@ -12,12 +12,14 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] const APP: () = { #[init] - fn init(_: init::Context) { + fn init(_: init::Context) -> init::LateResources { // Pends the UART0 interrupt but its handler won't run until *after* // `init` returns because interrupts are disabled rtic::pend(Interrupt::UART0); // equivalent to NVIC::pend hprintln!("init").unwrap(); + + init::LateResources {} } #[idle] diff --git a/examples/idle.rs b/examples/idle.rs index 3d28dac8a7..b029fcae27 100644 --- a/examples/idle.rs +++ b/examples/idle.rs @@ -11,8 +11,10 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] const APP: () = { #[init] - fn init(_: init::Context) { + fn init(_: init::Context) -> init::LateResources { hprintln!("init").unwrap(); + + init::LateResources {} } #[idle] diff --git a/examples/init.rs b/examples/init.rs index 315969f045..d5cebbaaa1 100644 --- a/examples/init.rs +++ b/examples/init.rs @@ -11,7 +11,7 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965, peripherals = true)] const APP: () = { #[init] - fn init(cx: init::Context) { + fn init(cx: init::Context) -> init::LateResources { static mut X: u32 = 0; // Cortex-M peripherals @@ -26,5 +26,7 @@ const APP: () = { hprintln!("init").unwrap(); debug::exit(debug::EXIT_SUCCESS); + + init::LateResources {} } }; diff --git a/examples/lock.rs b/examples/lock.rs index 5e3bce2500..ff947c5360 100644 --- a/examples/lock.rs +++ b/examples/lock.rs @@ -17,8 +17,10 @@ const APP: () = { } #[init] - fn init(_: init::Context) { + fn init(_: init::Context) -> init::LateResources { rtic::pend(Interrupt::GPIOA); + + init::LateResources {} } // when omitted priority is assumed to be `1` diff --git a/examples/message.rs b/examples/message.rs index 596f244904..a1352c0e8a 100644 --- a/examples/message.rs +++ b/examples/message.rs @@ -11,8 +11,10 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] const APP: () = { #[init(spawn = [foo])] - fn init(c: init::Context) { + fn init(c: init::Context) -> init::LateResources { c.spawn.foo(/* no message */).unwrap(); + + init::LateResources {} } #[task(spawn = [bar])] diff --git a/examples/not-send.rs b/examples/not-send.rs index 16a874dc0f..999abfaff4 100644 --- a/examples/not-send.rs +++ b/examples/not-send.rs @@ -23,9 +23,11 @@ const APP: () = { } #[init(spawn = [baz, quux])] - fn init(c: init::Context) { + fn init(c: init::Context) -> init::LateResources { c.spawn.baz().unwrap(); c.spawn.quux().unwrap(); + + init::LateResources {} } #[task(spawn = [bar])] diff --git a/examples/not-sync.rs b/examples/not-sync.rs index a7eaac8e7f..5a67489fa4 100644 --- a/examples/not-sync.rs +++ b/examples/not-sync.rs @@ -22,8 +22,10 @@ const APP: () = { } #[init] - fn init(_: init::Context) { + fn init(_: init::Context) -> init::LateResources { debug::exit(debug::EXIT_SUCCESS); + + init::LateResources {} } #[task(resources = [&shared])] diff --git a/examples/periodic.rs b/examples/periodic.rs index 405346e390..da56d468a8 100644 --- a/examples/periodic.rs +++ b/examples/periodic.rs @@ -15,10 +15,12 @@ const PERIOD: u32 = 8_000_000; #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] const APP: () = { #[init(schedule = [foo])] - fn init(cx: init::Context) { + fn init(cx: init::Context) -> init::LateResources { // omitted: initialization of `CYCCNT` cx.schedule.foo(cx.start + PERIOD.cycles()).unwrap(); + + init::LateResources {} } #[task(schedule = [foo])] diff --git a/examples/peripherals-taken.rs b/examples/peripherals-taken.rs index cd4ba0f0ed..42ad8c0fcb 100644 --- a/examples/peripherals-taken.rs +++ b/examples/peripherals-taken.rs @@ -9,8 +9,10 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] const APP: () = { #[init] - fn main(_: main::Context) { + fn main(_: main::Context) -> main::LateResources { assert!(cortex_m::Peripherals::take().is_none()); debug::exit(debug::EXIT_SUCCESS); + + main::LateResources {} } }; diff --git a/examples/pool.rs b/examples/pool.rs index 824d5bd86b..9fccdf8449 100644 --- a/examples/pool.rs +++ b/examples/pool.rs @@ -20,13 +20,15 @@ pool!(P: [u8; 128]); #[app(device = lm3s6965)] const APP: () = { #[init] - fn init(_: init::Context) { + fn init(_: init::Context) -> init::LateResources { static mut MEMORY: [u8; 512] = [0; 512]; // Increase the capacity of the memory pool by ~4 P::grow(MEMORY); rtic::pend(Interrupt::I2C0); + + init::LateResources {} } #[task(binds = I2C0, priority = 2, spawn = [foo, bar])] diff --git a/examples/preempt.rs b/examples/preempt.rs index 3cb11029b4..7103b17be2 100644 --- a/examples/preempt.rs +++ b/examples/preempt.rs @@ -11,8 +11,10 @@ use rtic::app; #[app(device = lm3s6965)] const APP: () = { #[init] - fn init(_: init::Context) { + fn init(_: init::Context) -> init::LateResources { rtic::pend(Interrupt::GPIOA); + + init::LateResources {} } #[task(binds = GPIOA, priority = 1)] diff --git a/examples/ramfunc.rs b/examples/ramfunc.rs index 1f95d496ef..214b7e6772 100644 --- a/examples/ramfunc.rs +++ b/examples/ramfunc.rs @@ -11,8 +11,10 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] const APP: () = { #[init(spawn = [bar])] - fn init(c: init::Context) { + fn init(c: init::Context) -> init::LateResources { c.spawn.bar().unwrap(); + + init::LateResources {} } #[inline(never)] diff --git a/examples/resource.rs b/examples/resource.rs index 2361fd0033..06aa975677 100644 --- a/examples/resource.rs +++ b/examples/resource.rs @@ -18,9 +18,11 @@ const APP: () = { } #[init] - fn init(_: init::Context) { + fn init(_: init::Context) -> init::LateResources { rtic::pend(Interrupt::UART0); rtic::pend(Interrupt::UART1); + + init::LateResources {} } // `shared` cannot be accessed from this context diff --git a/examples/schedule.rs b/examples/schedule.rs index 70a7a5e328..b76d9e7f81 100644 --- a/examples/schedule.rs +++ b/examples/schedule.rs @@ -14,7 +14,7 @@ use rtic::cyccnt::{Instant, U32Ext as _}; #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] const APP: () = { #[init(schedule = [foo, bar])] - fn init(mut cx: init::Context) { + fn init(mut cx: init::Context) -> init::LateResources { // Initialize (enable) the monotonic timer (CYCCNT) cx.core.DCB.enable_trace(); // required on Cortex-M7 devices that software lock the DWT (e.g. STM32F7) @@ -32,6 +32,8 @@ const APP: () = { // Schedule `bar` to run 4e6 cycles in the future cx.schedule.bar(now + 4_000_000.cycles()).unwrap(); + + init::LateResources {} } #[task] diff --git a/examples/shared-with-init.rs b/examples/shared-with-init.rs index bd55f7efd5..fa900a262d 100644 --- a/examples/shared-with-init.rs +++ b/examples/shared-with-init.rs @@ -20,12 +20,14 @@ const APP: () = { } #[init(resources = [shared])] - fn init(c: init::Context) { + fn init(c: init::Context) -> init::LateResources { // this `message` will be sent to task `UART0` let message = MustBeSend; *c.resources.shared = Some(message); rtic::pend(Interrupt::UART0); + + init::LateResources {} } #[task(binds = UART0, resources = [shared])] diff --git a/examples/t-binds.rs b/examples/t-binds.rs index 588ac46fa6..edf0fc6991 100644 --- a/examples/t-binds.rs +++ b/examples/t-binds.rs @@ -10,7 +10,9 @@ use panic_halt as _; #[rtic::app(device = lm3s6965)] const APP: () = { #[init] - fn init(_: init::Context) {} + fn init(_: init::Context) -> init::LateResources { + init::LateResources {} + } // Cortex-M exception #[task(binds = SVCall)] diff --git a/examples/t-cfg.rs b/examples/t-cfg.rs index b6c9e47207..254cb8e026 100644 --- a/examples/t-cfg.rs +++ b/examples/t-cfg.rs @@ -14,9 +14,11 @@ const APP: () = { } #[init] - fn init(_: init::Context) { + fn init(_: init::Context) -> init::LateResources { #[cfg(never)] static mut BAR: u32 = 0; + + init::LateResources {} } #[idle] diff --git a/examples/t-htask-main.rs b/examples/t-htask-main.rs index c4bebf94dc..885019a179 100644 --- a/examples/t-htask-main.rs +++ b/examples/t-htask-main.rs @@ -9,8 +9,10 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] const APP: () = { #[init] - fn init(_: init::Context) { - rtic::pend(lm3s6965::Interrupt::UART0) + fn init(_: init::Context) -> init::LateResources { + rtic::pend(lm3s6965::Interrupt::UART0); + + init::LateResources {} } #[task(binds = UART0)] diff --git a/examples/t-idle-main.rs b/examples/t-idle-main.rs index 051a9ee812..3e06cac65b 100644 --- a/examples/t-idle-main.rs +++ b/examples/t-idle-main.rs @@ -9,7 +9,9 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] const APP: () = { #[init] - fn init(_: init::Context) {} + fn init(_: init::Context) -> init::LateResources { + init::LateResources {} + } #[idle] fn main(_: main::Context) -> ! { diff --git a/examples/t-init-main.rs b/examples/t-init-main.rs index 6a6cd99164..f6c1d9cac3 100644 --- a/examples/t-init-main.rs +++ b/examples/t-init-main.rs @@ -9,7 +9,9 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] const APP: () = { #[init] - fn main(_: main::Context) { + fn main(_: main::Context) -> main::LateResources { debug::exit(debug::EXIT_SUCCESS); + + main::LateResources {} } }; diff --git a/examples/t-resource.rs b/examples/t-resource.rs index 81ba18563f..78e518c106 100644 --- a/examples/t-resource.rs +++ b/examples/t-resource.rs @@ -31,7 +31,7 @@ const APP: () = { } #[init(resources = [o1, o4, o5, o6, s3])] - fn init(c: init::Context) { + fn init(c: init::Context) -> init::LateResources { // owned by `init` == `&'static mut` let _: &'static mut u32 = c.resources.o1; @@ -42,6 +42,8 @@ const APP: () = { let _: &mut u32 = c.resources.o4; let _: &mut u32 = c.resources.o5; let _: &mut u32 = c.resources.s3; + + init::LateResources {} } #[idle(resources = [o2, &o4, s1, &s3])] diff --git a/examples/t-schedule.rs b/examples/t-schedule.rs index 3854aad36b..8af01abaa2 100644 --- a/examples/t-schedule.rs +++ b/examples/t-schedule.rs @@ -11,10 +11,12 @@ use rtic::cyccnt::{Instant, U32Ext as _}; #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] const APP: () = { #[init(schedule = [foo, bar, baz])] - fn init(c: init::Context) { + fn init(c: init::Context) -> init::LateResources { let _: Result<(), ()> = c.schedule.foo(c.start + 10.cycles()); let _: Result<(), u32> = c.schedule.bar(c.start + 20.cycles(), 0); let _: Result<(), (u32, u32)> = c.schedule.baz(c.start + 30.cycles(), 0, 1); + + init::LateResources {} } #[idle(schedule = [foo, bar, baz])] diff --git a/examples/t-spawn.rs b/examples/t-spawn.rs index 35831ccf9d..af2a79ea77 100644 --- a/examples/t-spawn.rs +++ b/examples/t-spawn.rs @@ -10,10 +10,12 @@ use panic_halt as _; #[rtic::app(device = lm3s6965)] const APP: () = { #[init(spawn = [foo, bar, baz])] - fn init(c: init::Context) { + fn init(c: init::Context) -> init::LateResources { let _: Result<(), ()> = c.spawn.foo(); let _: Result<(), u32> = c.spawn.bar(0); let _: Result<(), (u32, u32)> = c.spawn.baz(0, 1); + + init::LateResources {} } #[idle(spawn = [foo, bar, baz])] diff --git a/examples/t-stask-main.rs b/examples/t-stask-main.rs index f270940454..aefd482164 100644 --- a/examples/t-stask-main.rs +++ b/examples/t-stask-main.rs @@ -9,8 +9,10 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] const APP: () = { #[init(spawn = [main])] - fn init(cx: init::Context) { + fn init(cx: init::Context) -> init::LateResources { cx.spawn.main().ok(); + + init::LateResources {} } #[task] diff --git a/examples/task.rs b/examples/task.rs index 12c4ac8355..e148b3560b 100644 --- a/examples/task.rs +++ b/examples/task.rs @@ -11,8 +11,10 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965)] const APP: () = { #[init(spawn = [foo])] - fn init(c: init::Context) { + fn init(c: init::Context) -> init::LateResources { c.spawn.foo().unwrap(); + + init::LateResources {} } #[task(spawn = [bar, baz])] diff --git a/examples/types.rs b/examples/types.rs index 5233f868b1..46d08b8395 100644 --- a/examples/types.rs +++ b/examples/types.rs @@ -17,7 +17,7 @@ const APP: () = { } #[init(schedule = [foo], spawn = [foo])] - fn init(cx: init::Context) { + fn init(cx: init::Context) -> init::LateResources { let _: cyccnt::Instant = cx.start; let _: rtic::Peripherals = cx.core; let _: lm3s6965::Peripherals = cx.device; @@ -25,6 +25,8 @@ const APP: () = { let _: init::Spawn = cx.spawn; debug::exit(debug::EXIT_SUCCESS); + + init::LateResources {} } #[idle(schedule = [foo], spawn = [foo])] diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 610890bbfb..ec5c130c95 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -21,5 +21,5 @@ proc-macro = true proc-macro2 = "1" quote = "1" syn = "1" -rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "master", version = "0.4.0" } +rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "always_late_resources" } diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs index e0b7d69972..b41c389489 100644 --- a/macros/src/codegen/init.rs +++ b/macros/src/codegen/init.rs @@ -34,39 +34,31 @@ pub fn codegen( let mut root_init = vec![]; - let ret = { - let late_fields = analysis - .late_resources - .iter() - .flat_map(|resources| { - resources.iter().map(|name| { - let ty = &app.late_resources[name].ty; - let cfgs = &app.late_resources[name].cfgs; + let late_fields = analysis + .late_resources + .iter() + .flat_map(|resources| { + resources.iter().map(|name| { + let ty = &app.late_resources[name].ty; + let cfgs = &app.late_resources[name].cfgs; - quote!( - #(#cfgs)* - pub #name: #ty - ) - }) + quote!( + #(#cfgs)* + pub #name: #ty + ) }) - .collect::>(); + }) + .collect::>(); - if !late_fields.is_empty() { - let late_resources = util::late_resources_ident(&name); + let late_resources = util::late_resources_ident(&name); - root_init.push(quote!( - /// Resources initialized at runtime - #[allow(non_snake_case)] - pub struct #late_resources { - #(#late_fields),* - } - )); - - Some(quote!(-> #name::LateResources)) - } else { - None + root_init.push(quote!( + /// Resources initialized at runtime + #[allow(non_snake_case)] + pub struct #late_resources { + #(#late_fields),* } - }; + )); let mut locals_pat = None; let mut locals_new = None; @@ -85,7 +77,7 @@ pub fn codegen( let user_init = Some(quote!( #(#attrs)* #[allow(non_snake_case)] - fn #name(#(#locals_pat,)* #context: #name::Context) #ret { + fn #name(#(#locals_pat,)* #context: #name::Context) -> #name::LateResources { #(#stmts)* } )); diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index 863f6c5b73..85bab3ab68 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -253,14 +253,12 @@ pub fn codegen(ctxt: Context, resources_tick: bool, app: &App, extra: &Extra) -> if let Context::Init = ctxt { let init = &app.inits.first().unwrap(); - if init.returns_late_resources { - let late_resources = util::late_resources_ident(&init.name); + let late_resources = util::late_resources_ident(&init.name); - items.push(quote!( - #[doc(inline)] - pub use super::#late_resources as LateResources; - )); - } + items.push(quote!( + #[doc(inline)] + pub use super::#late_resources as LateResources; + )); } let doc = match ctxt { From 9d2598dc071882a94b813ab1d9ddf49092546257 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Thu, 1 Oct 2020 20:14:07 +0200 Subject: [PATCH 2/5] Fixing test errors --- ui/single/locals-cfg.rs | 4 ++- ui/single/locals-cfg.stderr | 16 ++++++------ ui/single/resources-cfg.rs | 4 ++- ui/single/resources-cfg.stderr | 40 ++++++++++++++--------------- ui/single/task-priority-too-high.rs | 4 ++- 5 files changed, 37 insertions(+), 31 deletions(-) diff --git a/ui/single/locals-cfg.rs b/ui/single/locals-cfg.rs index 54bba8aefd..cd8677a94c 100644 --- a/ui/single/locals-cfg.rs +++ b/ui/single/locals-cfg.rs @@ -3,11 +3,13 @@ #[rtic::app(device = lm3s6965)] const APP: () = { #[init] - fn init(_: init::Context) { + fn init(_: init::Context) -> init::LateResources { #[cfg(never)] static mut FOO: u32 = 0; FOO; + + init::LateResources {} } #[idle] diff --git a/ui/single/locals-cfg.stderr b/ui/single/locals-cfg.stderr index bb558fa60e..dc104a698b 100644 --- a/ui/single/locals-cfg.stderr +++ b/ui/single/locals-cfg.stderr @@ -5,27 +5,27 @@ error[E0425]: cannot find value `FOO` in this scope | ^^^ not found in this scope error[E0425]: cannot find value `FOO` in this scope - --> $DIR/locals-cfg.rs:18:9 + --> $DIR/locals-cfg.rs:20:9 | -18 | FOO; +20 | FOO; | ^^^ not found in this scope error[E0425]: cannot find value `FOO` in this scope - --> $DIR/locals-cfg.rs:28:9 + --> $DIR/locals-cfg.rs:30:9 | -28 | FOO; +30 | FOO; | ^^^ not found in this scope error[E0425]: cannot find value `FOO` in this scope - --> $DIR/locals-cfg.rs:36:9 + --> $DIR/locals-cfg.rs:38:9 | -36 | FOO; +38 | FOO; | ^^^ not found in this scope error[E0425]: cannot find value `FOO` in this scope - --> $DIR/locals-cfg.rs:44:9 + --> $DIR/locals-cfg.rs:46:9 | -44 | FOO; +46 | FOO; | ^^^ not found in this scope error: duplicate lang item in crate `panic_halt`: `panic_impl`. diff --git a/ui/single/resources-cfg.rs b/ui/single/resources-cfg.rs index df7ac80605..bcb712082d 100644 --- a/ui/single/resources-cfg.rs +++ b/ui/single/resources-cfg.rs @@ -41,12 +41,14 @@ const APP: () = { } #[init(resources = [o1, o4, o5, o6, s3])] - fn init(c: init::Context) { + fn init(c: init::Context) -> init::LateResources { c.resources.o1; c.resources.o4; c.resources.o5; c.resources.o6; c.resources.s3; + + init::LateResources {} } #[idle(resources = [o2, &o4, s1, &s3])] diff --git a/ui/single/resources-cfg.stderr b/ui/single/resources-cfg.stderr index c47b95d4b9..68063693ab 100644 --- a/ui/single/resources-cfg.stderr +++ b/ui/single/resources-cfg.stderr @@ -39,81 +39,81 @@ error[E0609]: no field `s3` on type `initResources<'_>` = note: available fields are: `__marker__` error[E0609]: no field `o2` on type `idleResources<'_>` - --> $DIR/resources-cfg.rs:54:21 + --> $DIR/resources-cfg.rs:56:21 | -54 | c.resources.o2; +56 | c.resources.o2; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o4` on type `idleResources<'_>` - --> $DIR/resources-cfg.rs:55:21 + --> $DIR/resources-cfg.rs:57:21 | -55 | c.resources.o4; +57 | c.resources.o4; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s1` on type `idleResources<'_>` - --> $DIR/resources-cfg.rs:56:21 + --> $DIR/resources-cfg.rs:58:21 | -56 | c.resources.s1; +58 | c.resources.s1; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s3` on type `idleResources<'_>` - --> $DIR/resources-cfg.rs:57:21 + --> $DIR/resources-cfg.rs:59:21 | -57 | c.resources.s3; +59 | c.resources.s3; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o3` on type `uart0Resources<'_>` - --> $DIR/resources-cfg.rs:64:21 + --> $DIR/resources-cfg.rs:66:21 | -64 | c.resources.o3; +66 | c.resources.o3; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s1` on type `uart0Resources<'_>` - --> $DIR/resources-cfg.rs:65:21 + --> $DIR/resources-cfg.rs:67:21 | -65 | c.resources.s1; +67 | c.resources.s1; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s2` on type `uart0Resources<'_>` - --> $DIR/resources-cfg.rs:66:21 + --> $DIR/resources-cfg.rs:68:21 | -66 | c.resources.s2; +68 | c.resources.s2; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s3` on type `uart0Resources<'_>` - --> $DIR/resources-cfg.rs:67:21 + --> $DIR/resources-cfg.rs:69:21 | -67 | c.resources.s3; +69 | c.resources.s3; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `s2` on type `uart1Resources<'_>` - --> $DIR/resources-cfg.rs:72:21 + --> $DIR/resources-cfg.rs:74:21 | -72 | c.resources.s2; +74 | c.resources.s2; | ^^ unknown field | = note: available fields are: `__marker__` error[E0609]: no field `o5` on type `uart1Resources<'_>` - --> $DIR/resources-cfg.rs:73:21 + --> $DIR/resources-cfg.rs:75:21 | -73 | c.resources.o5; +75 | c.resources.o5; | ^^ unknown field | = note: available fields are: `__marker__` diff --git a/ui/single/task-priority-too-high.rs b/ui/single/task-priority-too-high.rs index 539c3f5d0e..62e531d81d 100644 --- a/ui/single/task-priority-too-high.rs +++ b/ui/single/task-priority-too-high.rs @@ -5,7 +5,9 @@ use rtic::app; #[rtic::app(device = lm3s6965)] const APP: () = { #[init] - fn init(_: init::Context) {} + fn init(_: init::Context) -> init::LateResources { + init::LateResources {} + } #[task(binds = GPIOA, priority = 1)] fn gpioa(_: gpioa::Context) {} From c21ccd04ce52c5d469a2bdfd4e0125540ad1cddb Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Mon, 5 Oct 2020 18:30:06 +0200 Subject: [PATCH 3/5] Overwrite steerr files --- ui/single/locals-cfg.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/single/locals-cfg.stderr b/ui/single/locals-cfg.stderr index 63953fc9bc..e58bd935e3 100644 --- a/ui/single/locals-cfg.stderr +++ b/ui/single/locals-cfg.stderr @@ -31,7 +31,7 @@ error[E0425]: cannot find value `FOO` in this scope error: duplicate lang item in crate `panic_halt` (which `$CRATE` depends on): `panic_impl`. | = note: the lang item is first defined in crate `std` (which `$CRATE` depends on) - = note: first definition in `std` loaded from /usr/share/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-cf0f33af3a901778.rlib + = note: first definition in `std` loaded from /usr/share/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-cf0f33af3a901778.rlib = note: second definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-ba6f0ab3439cbc7e.rmeta error: duplicate lang item in crate `panic_semihosting`: `panic_impl`. From 44f26fe90c2b49f3a30c507bf930b6bedc283a9c Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Mon, 5 Oct 2020 20:05:52 +0200 Subject: [PATCH 4/5] Move to master of rtic-syntax --- macros/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macros/Cargo.toml b/macros/Cargo.toml index ec5c130c95..610890bbfb 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -21,5 +21,5 @@ proc-macro = true proc-macro2 = "1" quote = "1" syn = "1" -rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "always_late_resources" } +rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "master", version = "0.4.0" } From 8ab7be98714d1ef6298e6feb19f16b84cd9bb4e6 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Mon, 5 Oct 2020 20:19:52 +0200 Subject: [PATCH 5/5] Added back accidentally removed block --- macros/src/codegen/init.rs | 6 ++++++ macros/src/lib.rs | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs index 1ced68bccc..8942439bd7 100644 --- a/macros/src/codegen/init.rs +++ b/macros/src/codegen/init.rs @@ -63,6 +63,12 @@ pub fn codegen( } )); + let name_late = format_ident!("{}LateResources", name); + user_init_imports.push(quote!( + #[allow(non_snake_case)] + use super::#name_late; + )); + let mut locals_pat = None; let mut locals_new = None; if !init.locals.is_empty() { diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 94e7eec60c..e659559e9b 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -35,8 +35,7 @@ mod tests; /// /// The items allowed in the module block are specified below: /// -/// # 1. `#[resources] -/// struct ` +/// # 1. `#[resources] struct ` /// /// This structure contains the declaration of all the resources used by the application. Each field /// in this structure corresponds to a different resource. Each resource may optionally be given an