mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-27 14:04:56 +01:00
Lifetime cleanup
This commit is contained in:
parent
a5195c792b
commit
08d2930fb3
3 changed files with 17 additions and 43 deletions
|
@ -43,13 +43,13 @@ mod app {
|
||||||
|
|
||||||
#[task(binds = UART1, shared = [a])]
|
#[task(binds = UART1, shared = [a])]
|
||||||
fn hw_task(cx: hw_task::Context) {
|
fn hw_task(cx: hw_task::Context) {
|
||||||
let hw_task::SharedResources { a } = cx.shared;
|
let hw_task::SharedResources { a, .. } = cx.shared;
|
||||||
hprintln!("hello from hw").ok();
|
hprintln!("hello from hw").ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(shared = [a])]
|
#[task(shared = [a])]
|
||||||
async fn async_task(cx: async_task::Context) {
|
async fn async_task(cx: async_task::Context) {
|
||||||
let async_task::SharedResources { a } = cx.shared;
|
let async_task::SharedResources { a, .. } = cx.shared;
|
||||||
hprintln!("hello from async").ok();
|
hprintln!("hello from async").ok();
|
||||||
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
debug::exit(debug::EXIT_SUCCESS);
|
||||||
|
@ -57,7 +57,7 @@ mod app {
|
||||||
|
|
||||||
#[task(priority = 2, shared = [a])]
|
#[task(priority = 2, shared = [a])]
|
||||||
async fn async_task2(cx: async_task2::Context) {
|
async fn async_task2(cx: async_task2::Context) {
|
||||||
let async_task2::SharedResources { a } = cx.shared;
|
let async_task2::SharedResources { a, .. } = cx.shared;
|
||||||
hprintln!("hello from async2").ok();
|
hprintln!("hello from async2").ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,6 @@ use crate::codegen::util;
|
||||||
|
|
||||||
/// Generates local resources structs
|
/// Generates local resources structs
|
||||||
pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
||||||
let mut lt = None;
|
|
||||||
|
|
||||||
let resources = match ctxt {
|
let resources = match ctxt {
|
||||||
Context::Init => &app.init.args.local_resources,
|
Context::Init => &app.init.args.local_resources,
|
||||||
Context::Idle => {
|
Context::Idle => {
|
||||||
|
@ -28,7 +26,6 @@ pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
||||||
|
|
||||||
let mut fields = vec![];
|
let mut fields = vec![];
|
||||||
let mut values = vec![];
|
let mut values = vec![];
|
||||||
let mut has_cfgs = false;
|
|
||||||
|
|
||||||
for (name, task_local) in resources {
|
for (name, task_local) in resources {
|
||||||
let (cfgs, ty, is_declared) = match task_local {
|
let (cfgs, ty, is_declared) = match task_local {
|
||||||
|
@ -39,12 +36,9 @@ pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
||||||
TaskLocal::Declared(r) => (&r.cfgs, &r.ty, true),
|
TaskLocal::Declared(r) => (&r.cfgs, &r.ty, true),
|
||||||
};
|
};
|
||||||
|
|
||||||
has_cfgs |= !cfgs.is_empty();
|
|
||||||
|
|
||||||
let lt = if ctxt.runs_once() {
|
let lt = if ctxt.runs_once() {
|
||||||
quote!('static)
|
quote!('static)
|
||||||
} else {
|
} else {
|
||||||
lt = Some(quote!('a));
|
|
||||||
quote!('a)
|
quote!('a)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,17 +67,12 @@ pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if lt.is_some() {
|
|
||||||
// The struct could end up empty due to `cfg`s leading to an error due to `'a` being unused
|
|
||||||
if has_cfgs {
|
|
||||||
fields.push(quote!(
|
fields.push(quote!(
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub __rtic_internal_marker: ::core::marker::PhantomData<&'a ()>
|
pub __rtic_internal_marker: ::core::marker::PhantomData<&'a ()>
|
||||||
));
|
));
|
||||||
|
|
||||||
values.push(quote!(__rtic_internal_marker: ::core::marker::PhantomData));
|
values.push(quote!(__rtic_internal_marker: ::core::marker::PhantomData));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let doc = format!("Local resources `{}` has access to", ctxt.ident(app));
|
let doc = format!("Local resources `{}` has access to", ctxt.ident(app));
|
||||||
let ident = util::local_resources_ident(ctxt, app);
|
let ident = util::local_resources_ident(ctxt, app);
|
||||||
|
@ -91,13 +80,13 @@ pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[doc = #doc]
|
#[doc = #doc]
|
||||||
pub struct #ident<#lt> {
|
pub struct #ident<'a> {
|
||||||
#(#fields,)*
|
#(#fields,)*
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
let constructor = quote!(
|
let constructor = quote!(
|
||||||
impl<#lt> #ident<#lt> {
|
impl<'a> #ident<'a> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn new() -> Self {
|
pub unsafe fn new() -> Self {
|
||||||
#ident {
|
#ident {
|
||||||
|
|
|
@ -6,8 +6,6 @@ use crate::codegen::util;
|
||||||
|
|
||||||
/// Generate shared resources structs
|
/// Generate shared resources structs
|
||||||
pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
||||||
let mut lt = None;
|
|
||||||
|
|
||||||
let resources = match ctxt {
|
let resources = match ctxt {
|
||||||
Context::Init => unreachable!("Tried to generate shared resources struct for init"),
|
Context::Init => unreachable!("Tried to generate shared resources struct for init"),
|
||||||
Context::Idle => {
|
Context::Idle => {
|
||||||
|
@ -23,13 +21,11 @@ pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
||||||
|
|
||||||
let mut fields = vec![];
|
let mut fields = vec![];
|
||||||
let mut values = vec![];
|
let mut values = vec![];
|
||||||
let mut has_cfgs = false;
|
|
||||||
|
|
||||||
for (name, access) in resources {
|
for (name, access) in resources {
|
||||||
let res = app.shared_resources.get(name).expect("UNREACHABLE");
|
let res = app.shared_resources.get(name).expect("UNREACHABLE");
|
||||||
|
|
||||||
let cfgs = &res.cfgs;
|
let cfgs = &res.cfgs;
|
||||||
has_cfgs |= !cfgs.is_empty();
|
|
||||||
|
|
||||||
// access hold if the resource is [x] (exclusive) or [&x] (shared)
|
// access hold if the resource is [x] (exclusive) or [&x] (shared)
|
||||||
let mut_ = if access.is_exclusive() {
|
let mut_ = if access.is_exclusive() {
|
||||||
|
@ -46,7 +42,6 @@ pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
||||||
let lt = if ctxt.runs_once() {
|
let lt = if ctxt.runs_once() {
|
||||||
quote!('static)
|
quote!('static)
|
||||||
} else {
|
} else {
|
||||||
lt = Some(quote!('a));
|
|
||||||
quote!('a)
|
quote!('a)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -55,16 +50,11 @@ pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
||||||
pub #name: &#lt #mut_ #ty
|
pub #name: &#lt #mut_ #ty
|
||||||
));
|
));
|
||||||
} else if access.is_shared() {
|
} else if access.is_shared() {
|
||||||
lt = Some(quote!('a));
|
|
||||||
|
|
||||||
fields.push(quote!(
|
fields.push(quote!(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
pub #name: &'a #ty
|
pub #name: &'a #ty
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
// Resource proxy
|
|
||||||
lt = Some(quote!('a));
|
|
||||||
|
|
||||||
fields.push(quote!(
|
fields.push(quote!(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
pub #name: shared_resources::#shared_name<'a>
|
pub #name: shared_resources::#shared_name<'a>
|
||||||
|
@ -92,17 +82,12 @@ pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if lt.is_some() {
|
|
||||||
// The struct could end up empty due to `cfg`s leading to an error due to `'a` being unused
|
|
||||||
if has_cfgs {
|
|
||||||
fields.push(quote!(
|
fields.push(quote!(
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub __marker__: core::marker::PhantomData<&'a ()>
|
pub __rtic_internal_marker: core::marker::PhantomData<&'a ()>
|
||||||
));
|
));
|
||||||
|
|
||||||
values.push(quote!(__marker__: core::marker::PhantomData));
|
values.push(quote!(__rtic_internal_marker: core::marker::PhantomData));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let doc = format!("Shared resources `{}` has access to", ctxt.ident(app));
|
let doc = format!("Shared resources `{}` has access to", ctxt.ident(app));
|
||||||
let ident = util::shared_resources_ident(ctxt, app);
|
let ident = util::shared_resources_ident(ctxt, app);
|
||||||
|
@ -110,13 +95,13 @@ pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[doc = #doc]
|
#[doc = #doc]
|
||||||
pub struct #ident<#lt> {
|
pub struct #ident<'a> {
|
||||||
#(#fields,)*
|
#(#fields,)*
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
let constructor = quote!(
|
let constructor = quote!(
|
||||||
impl<#lt> #ident<#lt> {
|
impl<'a> #ident<'a> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn new() -> Self {
|
pub unsafe fn new() -> Self {
|
||||||
#ident {
|
#ident {
|
||||||
|
|
Loading…
Reference in a new issue