476: reclaim stack space used in late init r=korken89 a=conorpp

Fixes #474.

Tested that there is no longer any stack overhead leftover from moving init resources.

(made mistake force pushing with last PR when trying to fix lint)

The expansion for an example with 2 buffers as resources changes from:


```rust
let (late, mut monotonics) = crate::APP::init(init::Context::new(core.into()));
__rtic_internal_mybuffer.as_mut_ptr().write(late.mybuffer);
__rtic_internal_mybuffer2.as_mut_ptr().write(late.mybuffer2);
rtic::export::interrupt::enable();
crate::APP::idle(idle::Context::new(&rtic::export::Priority::new(0)))
```

to:

```rust
#[inline(never)]
fn __rtic_init_resources<F>(f: F)
where
    F: FnOnce(),
{
    f();
}
__rtic_init_resources(|| {
    let (late, mut monotonics) = crate::APP::init(init::Context::new(core.into()));
    __rtic_internal_mybuffer.as_mut_ptr().write(late.mybuffer);
    __rtic_internal_mybuffer2.as_mut_ptr().write(late.mybuffer2);
    rtic::export::interrupt::enable();
});
crate::APP::idle(idle::Context::new(&rtic::export::Priority::new(0)))
```

Co-authored-by: Conor Patrick <conorpp94@gmail.com>
This commit is contained in:
bors[bot] 2021-04-20 13:58:22 +00:00 committed by GitHub
commit f586c3c5a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -66,9 +66,17 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
#(#pre_init_stmts)* #(#pre_init_stmts)*
#call_init #[inline(never)]
fn __rtic_init_resources<F>(f: F) where F: FnOnce() {
f();
}
#(#post_init_stmts)* // Wrap late_init_stmts in a function to ensure that stack space is reclaimed.
__rtic_init_resources(||{
#call_init
#(#post_init_stmts)*
});
#call_idle #call_idle
} }