2019-06-13 23:56:59 +02:00
|
|
|
use proc_macro2::TokenStream as TokenStream2;
|
|
|
|
use quote::quote;
|
|
|
|
|
2020-08-27 13:21:56 +02:00
|
|
|
use crate::analyze::Analysis;
|
2019-06-13 23:56:59 +02:00
|
|
|
|
|
|
|
/// Generates compile-time assertions that check that types implement the `Send` / `Sync` traits
|
2020-08-27 13:21:56 +02:00
|
|
|
pub fn codegen(analysis: &Analysis) -> Vec<TokenStream2> {
|
2019-06-13 23:56:59 +02:00
|
|
|
let mut stmts = vec![];
|
|
|
|
|
|
|
|
// we don't generate *all* assertions on all cores because the user could conditionally import a
|
|
|
|
// type only on some core (e.g. `#[cfg(core = "0")] use some::Type;`)
|
|
|
|
|
2020-08-27 13:21:56 +02:00
|
|
|
//if let Some(types) = analysis.send_types {
|
|
|
|
for ty in &analysis.send_types {
|
2020-06-11 19:18:29 +02:00
|
|
|
stmts.push(quote!(rtic::export::assert_send::<#ty>();));
|
2019-06-13 23:56:59 +02:00
|
|
|
}
|
2020-08-27 13:21:56 +02:00
|
|
|
//}
|
2019-06-13 23:56:59 +02:00
|
|
|
|
2020-08-27 13:21:56 +02:00
|
|
|
//if let Some(types) = analysis.sync_types {
|
|
|
|
for ty in &analysis.sync_types {
|
2020-06-11 19:18:29 +02:00
|
|
|
stmts.push(quote!(rtic::export::assert_sync::<#ty>();));
|
2019-06-13 23:56:59 +02:00
|
|
|
}
|
2020-08-27 13:21:56 +02:00
|
|
|
//}
|
2019-06-13 23:56:59 +02:00
|
|
|
|
2019-06-24 14:09:12 +02:00
|
|
|
// if the `schedule` API is used in more than one core then we need to check that the
|
|
|
|
// `monotonic` timer can be used in multi-core context
|
2020-08-27 13:21:56 +02:00
|
|
|
/*
|
2019-06-24 14:09:12 +02:00
|
|
|
if analysis.timer_queues.len() > 1 && analysis.timer_queues.contains_key(&core) {
|
|
|
|
let monotonic = extra.monotonic();
|
2020-06-11 19:18:29 +02:00
|
|
|
stmts.push(quote!(rtic::export::assert_multicore::<#monotonic>();));
|
2019-06-24 14:09:12 +02:00
|
|
|
}
|
2020-08-27 13:21:56 +02:00
|
|
|
*/
|
2019-06-24 14:09:12 +02:00
|
|
|
|
2019-06-13 23:56:59 +02:00
|
|
|
stmts
|
|
|
|
}
|