mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-18 05:45:19 +01:00
feat: allow diverding software tasks with 'static context (they never return)
This commit is contained in:
parent
267ed9dafd
commit
ff3b1ad527
3 changed files with 37 additions and 15 deletions
|
|
@ -31,24 +31,38 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
|
||||||
mod_app.push(constructor);
|
mod_app.push(constructor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !&task.is_extern {
|
if !task.is_extern {
|
||||||
let context = &task.context;
|
let context = &task.context;
|
||||||
let attrs = &task.attrs;
|
let attrs = &task.attrs;
|
||||||
let cfgs = &task.cfgs;
|
let cfgs = &task.cfgs;
|
||||||
let stmts = &task.stmts;
|
let stmts = &task.stmts;
|
||||||
let inputs = &task.inputs;
|
let inputs = &task.inputs;
|
||||||
|
|
||||||
user_tasks.push(quote!(
|
user_tasks.push(if task.is_bottom {
|
||||||
#(#attrs)*
|
quote!(
|
||||||
#(#cfgs)*
|
#(#attrs)*
|
||||||
#[allow(non_snake_case)]
|
#(#cfgs)*
|
||||||
async fn #name<'a>(#context: #name::Context<'a> #(,#inputs)*) {
|
#[allow(non_snake_case)]
|
||||||
use rtic::Mutex as _;
|
async fn #name(#context: #name::Context<'static> #(,#inputs)*) {
|
||||||
use rtic::mutex::prelude::*;
|
use rtic::Mutex as _;
|
||||||
|
use rtic::mutex::prelude::*;
|
||||||
|
|
||||||
#(#stmts)*
|
#(#stmts)*
|
||||||
}
|
}
|
||||||
));
|
)
|
||||||
|
} else {
|
||||||
|
quote!(
|
||||||
|
#(#attrs)*
|
||||||
|
#(#cfgs)*
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
async fn #name<'a>(#context: #name::Context<'a> #(,#inputs)*) {
|
||||||
|
use rtic::Mutex as _;
|
||||||
|
use rtic::mutex::prelude::*;
|
||||||
|
|
||||||
|
#(#stmts)*
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
root.push(module::codegen(Context::SoftwareTask(name), app, analysis));
|
root.push(module::codegen(Context::SoftwareTask(name), app, analysis));
|
||||||
|
|
|
||||||
|
|
@ -236,6 +236,9 @@ pub struct SoftwareTask {
|
||||||
|
|
||||||
/// The task is declared externally
|
/// The task is declared externally
|
||||||
pub is_extern: bool,
|
pub is_extern: bool,
|
||||||
|
|
||||||
|
/// The task will never return `Poll::Ready`
|
||||||
|
pub is_bottom: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Software task metadata
|
/// Software task metadata
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,9 @@ use crate::syntax::{
|
||||||
|
|
||||||
impl SoftwareTask {
|
impl SoftwareTask {
|
||||||
pub(crate) fn parse(args: SoftwareTaskArgs, item: ItemFn) -> parse::Result<Self> {
|
pub(crate) fn parse(args: SoftwareTaskArgs, item: ItemFn) -> parse::Result<Self> {
|
||||||
|
let is_bottom = util::type_is_bottom(&item.sig.output);
|
||||||
let valid_signature = util::check_fn_signature(&item, true)
|
let valid_signature = util::check_fn_signature(&item, true)
|
||||||
&& util::type_is_unit(&item.sig.output)
|
&& (util::type_is_unit(&item.sig.output) || is_bottom)
|
||||||
&& item.sig.asyncness.is_some();
|
&& item.sig.asyncness.is_some();
|
||||||
|
|
||||||
let span = item.sig.ident.span();
|
let span = item.sig.ident.span();
|
||||||
|
|
@ -28,13 +29,14 @@ impl SoftwareTask {
|
||||||
inputs,
|
inputs,
|
||||||
stmts: item.block.stmts,
|
stmts: item.block.stmts,
|
||||||
is_extern: false,
|
is_extern: false,
|
||||||
|
is_bottom,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(parse::Error::new(
|
Err(parse::Error::new(
|
||||||
span,
|
span,
|
||||||
format!("this task handler must have type signature `async fn({name}::Context, ..)`"),
|
format!("this task handler must have type signature `async fn({name}::Context, ..)` or `async fn({name}::Context, ..) -> !`"),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -44,8 +46,10 @@ impl SoftwareTask {
|
||||||
args: SoftwareTaskArgs,
|
args: SoftwareTaskArgs,
|
||||||
item: ForeignItemFn,
|
item: ForeignItemFn,
|
||||||
) -> parse::Result<Self> {
|
) -> parse::Result<Self> {
|
||||||
|
let is_bottom = util::type_is_bottom(&item.sig.output);
|
||||||
|
|
||||||
let valid_signature = util::check_foreign_fn_signature(&item, true)
|
let valid_signature = util::check_foreign_fn_signature(&item, true)
|
||||||
&& util::type_is_unit(&item.sig.output)
|
&& (util::type_is_unit(&item.sig.output) || is_bottom)
|
||||||
&& item.sig.asyncness.is_some();
|
&& item.sig.asyncness.is_some();
|
||||||
|
|
||||||
let span = item.sig.ident.span();
|
let span = item.sig.ident.span();
|
||||||
|
|
@ -64,13 +68,14 @@ impl SoftwareTask {
|
||||||
inputs,
|
inputs,
|
||||||
stmts: Vec::<Stmt>::new(),
|
stmts: Vec::<Stmt>::new(),
|
||||||
is_extern: true,
|
is_extern: true,
|
||||||
|
is_bottom,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(parse::Error::new(
|
Err(parse::Error::new(
|
||||||
span,
|
span,
|
||||||
format!("this task handler must have type signature `async fn({name}::Context, ..)`"),
|
format!("this task handler must have type signature `async fn({name}::Context, ..)` or `async fn({name}::Context, ..) -> !`"),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue